mt-lang 0.3.24 → 0.3.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/lib/milk_tea/base.rb +1 -1
  3. data/lib/milk_tea/core/bindings/attribute_binding.rb +51 -49
  4. data/lib/milk_tea/core/bindings/function_binding.rb +3 -1
  5. data/lib/milk_tea/core/bindings/module_binding.rb +42 -40
  6. data/lib/milk_tea/core/bindings/value_binding.rb +16 -14
  7. data/lib/milk_tea/core/bindings.rb +4 -9
  8. data/lib/milk_tea/core/c_backend/control_flow_emission.rb +11 -11
  9. data/lib/milk_tea/core/c_backend/expressions.rb +11 -11
  10. data/lib/milk_tea/core/c_backend/feature_detection.rb +15 -19
  11. data/lib/milk_tea/core/c_backend/format_helpers.rb +1 -1
  12. data/lib/milk_tea/core/c_backend/reinterpret.rb +10 -10
  13. data/lib/milk_tea/core/c_backend/runtime_helpers.rb +1 -1
  14. data/lib/milk_tea/core/c_backend/statements.rb +20 -20
  15. data/lib/milk_tea/core/c_backend/type_declaration.rb +4 -4
  16. data/lib/milk_tea/core/c_backend/type_system.rb +1 -1
  17. data/lib/milk_tea/core/c_backend.rb +3 -3
  18. data/lib/milk_tea/core/compile_time.rb +41 -70
  19. data/lib/milk_tea/core/control_flow/builder.rb +3 -3
  20. data/lib/milk_tea/core/control_flow/constant_propagation.rb +1 -1
  21. data/lib/milk_tea/core/control_flow/graph.rb +1 -1
  22. data/lib/milk_tea/core/control_flow/termination.rb +1 -1
  23. data/lib/milk_tea/core/cst.rb +16 -0
  24. data/lib/milk_tea/core/flow_scope.rb +13 -0
  25. data/lib/milk_tea/core/lexer/character_classes.rb +2 -2
  26. data/lib/milk_tea/core/lexer/format_strings.rb +5 -5
  27. data/lib/milk_tea/core/lexer/heredocs.rb +6 -6
  28. data/lib/milk_tea/core/lexer/indentation.rb +4 -4
  29. data/lib/milk_tea/core/lexer/numbers.rb +1 -1
  30. data/lib/milk_tea/core/lexer/strings.rb +4 -4
  31. data/lib/milk_tea/core/lexer/symbols.rb +3 -3
  32. data/lib/milk_tea/core/lexer/trivia.rb +4 -4
  33. data/lib/milk_tea/core/lexer.rb +17 -17
  34. data/lib/milk_tea/core/lowering/async/analysis.rb +210 -208
  35. data/lib/milk_tea/core/lowering/async/async_lowering.rb +1406 -0
  36. data/lib/milk_tea/core/lowering/async/frame_builder.rb +615 -613
  37. data/lib/milk_tea/core/lowering/async/normalization.rb +410 -408
  38. data/lib/milk_tea/core/lowering/block.rb +982 -980
  39. data/lib/milk_tea/core/lowering/calls.rb +1360 -1358
  40. data/lib/milk_tea/core/lowering/declarations.rb +175 -173
  41. data/lib/milk_tea/core/lowering/dyn.rb +171 -169
  42. data/lib/milk_tea/core/lowering/events.rb +946 -944
  43. data/lib/milk_tea/core/lowering/expressions.rb +1514 -1512
  44. data/lib/milk_tea/core/lowering/foreign_cstr.rb +180 -178
  45. data/lib/milk_tea/core/lowering/functions.rb +186 -184
  46. data/lib/milk_tea/core/lowering/loops.rb +1004 -1002
  47. data/lib/milk_tea/core/lowering/lowering_context.rb +1 -1
  48. data/lib/milk_tea/core/lowering/proc.rb +355 -353
  49. data/lib/milk_tea/core/lowering/resolve.rb +2127 -2125
  50. data/lib/milk_tea/core/lowering/scans.rb +162 -168
  51. data/lib/milk_tea/core/lowering/str_buffer.rb +104 -102
  52. data/lib/milk_tea/core/lowering/utils.rb +964 -963
  53. data/lib/milk_tea/core/lowering.rb +22 -22
  54. data/lib/milk_tea/core/module_binder.rb +1 -1
  55. data/lib/milk_tea/core/module_loader.rb +2 -2
  56. data/lib/milk_tea/core/parser/attributes.rb +1 -1
  57. data/lib/milk_tea/core/parser/blocks.rb +2 -2
  58. data/lib/milk_tea/core/parser/declarations.rb +15 -15
  59. data/lib/milk_tea/core/parser/expressions.rb +20 -20
  60. data/lib/milk_tea/core/parser/recovery.rb +1 -1
  61. data/lib/milk_tea/core/parser/statements.rb +3 -3
  62. data/lib/milk_tea/core/parser/types.rb +4 -4
  63. data/lib/milk_tea/core/parser.rb +39 -21
  64. data/lib/milk_tea/core/pretty_printer/ast_formatter.rb +6 -6
  65. data/lib/milk_tea/core/pretty_printer/ir_formatter.rb +5 -5
  66. data/lib/milk_tea/core/semantic_analyzer/analysis_context.rb +2 -2
  67. data/lib/milk_tea/core/semantic_analyzer/calls.rb +1 -1
  68. data/lib/milk_tea/core/semantic_analyzer/expressions.rb +4 -4
  69. data/lib/milk_tea/core/semantic_analyzer/flow_refinement.rb +37 -37
  70. data/lib/milk_tea/core/semantic_analyzer/foreign_functions.rb +4 -4
  71. data/lib/milk_tea/core/semantic_analyzer/function_binding.rb +4 -4
  72. data/lib/milk_tea/core/semantic_analyzer/generics.rb +4 -4
  73. data/lib/milk_tea/core/semantic_analyzer/name_resolution.rb +7 -7
  74. data/lib/milk_tea/core/semantic_analyzer/nullability.rb +59 -59
  75. data/lib/milk_tea/core/semantic_analyzer/statements.rb +3 -3
  76. data/lib/milk_tea/core/semantic_analyzer/top_level.rb +1 -1
  77. data/lib/milk_tea/core/semantic_analyzer/type_declaration.rb +12 -12
  78. data/lib/milk_tea/core/types/layout.rb +3 -1
  79. data/lib/milk_tea/core/types/visitor.rb +351 -349
  80. data/lib/milk_tea/core.rb +0 -2
  81. data/lib/milk_tea/tooling/cli/commands/bindgen.rb +1 -1
  82. data/lib/milk_tea/tooling/cli/commands/check.rb +5 -5
  83. data/lib/milk_tea/tooling/cli/commands/debug.rb +3 -3
  84. data/lib/milk_tea/tooling/cli/commands/deps.rb +1 -1
  85. data/lib/milk_tea/tooling/cli/commands/emit_c.rb +2 -2
  86. data/lib/milk_tea/tooling/cli/commands/format.rb +6 -6
  87. data/lib/milk_tea/tooling/cli/commands/lint.rb +3 -3
  88. data/lib/milk_tea/tooling/cli/commands/lower.rb +3 -3
  89. data/lib/milk_tea/tooling/cli/commands/parse.rb +3 -3
  90. data/lib/milk_tea/tooling/cli/commands/test.rb +3 -3
  91. data/lib/milk_tea/tooling/cli/commands/toolchain.rb +1 -1
  92. data/lib/milk_tea/tooling/cli.rb +22 -34
  93. data/lib/milk_tea/tooling/linter/flow_rules.rb +3 -3
  94. metadata +4 -5
  95. data/lib/milk_tea/core/cst_builder.rb +0 -19
  96. data/lib/milk_tea/core/lowering/async/lowering.rb +0 -1404
  97. data/lib/milk_tea/core/token_stream.rb +0 -30
@@ -619,7 +619,7 @@ module MilkTea
619
619
 
620
620
  inline = render_inline_statement(nested)
621
621
  return nil unless inline
622
- return nil if unsafe_inline_trivia_conflict?(statement, nested)
622
+ return nil if unsafe_inline_comment_conflict?(statement, nested)
623
623
 
624
624
  "unsafe: #{inline}"
625
625
  end
@@ -652,7 +652,7 @@ module MilkTea
652
652
  end
653
653
  end
654
654
 
655
- def unsafe_inline_trivia_conflict?(unsafe_stmt, nested)
655
+ def unsafe_inline_comment_conflict?(unsafe_stmt, nested)
656
656
  unsafe_line = unsafe_stmt.line
657
657
  nested_line = nested&.line
658
658
  return false unless unsafe_line && nested_line && nested_line > unsafe_line
@@ -774,7 +774,7 @@ module MilkTea
774
774
  else_expression = render_expression(expression.else_expression, IF_EXPRESSION_PRECEDENCE)
775
775
  wrap("if #{condition}: #{then_expression} else: #{else_expression}", parent_precedence, IF_EXPRESSION_PRECEDENCE)
776
776
  when AST::MatchExpr
777
- sugared = render_is_expression(expression, parent_precedence)
777
+ sugared = try_resugar_is_expression(expression, parent_precedence)
778
778
  return sugared if sugared
779
779
 
780
780
  rendered_expression = render_expression(expression.expression, IF_EXPRESSION_PRECEDENCE)
@@ -868,7 +868,7 @@ module MilkTea
868
868
  # `expr is Arm` desugars at parse time to `match expr: Arm: true; _: false`;
869
869
  # re-sugar that exact shape back to `is` so the formatter round-trips (and a
870
870
  # multi-line match does not break when used as a statement condition).
871
- def render_is_expression(expression, parent_precedence)
871
+ def try_resugar_is_expression(expression, parent_precedence)
872
872
  arms = expression.arms
873
873
  return nil unless arms.length == 2
874
874
 
@@ -892,12 +892,12 @@ module MilkTea
892
892
  end
893
893
 
894
894
  def render_postfix(expression)
895
- return render_expression(expression, POSTFIX_PRECEDENCE) if postfix_expression?(expression)
895
+ return render_expression(expression, POSTFIX_PRECEDENCE) if atomic_expression?(expression)
896
896
 
897
897
  "(#{render_expression(expression)})"
898
898
  end
899
899
 
900
- def postfix_expression?(expression)
900
+ def atomic_expression?(expression)
901
901
  expression.is_a?(AST::Identifier) || expression.is_a?(AST::MemberAccess) || expression.is_a?(AST::IndexAccess) ||
902
902
  expression.is_a?(AST::Specialization) || expression.is_a?(AST::Call) ||
903
903
  (expression.is_a?(AST::UnaryOp) && expression.operator == "?")
@@ -168,8 +168,8 @@ module MilkTea
168
168
  statement.body.each { |nested| emit_statement(nested) }
169
169
  end
170
170
  when IR::ForStmt
171
- init = render_for_clause_statement(statement.init)
172
- post = render_for_clause_statement(statement.post)
171
+ init = render_for_loop_clause(statement.init)
172
+ post = render_for_loop_clause(statement.post)
173
173
  line("for #{init}; #{render_expression(statement.condition)}; #{post}:")
174
174
  with_indent do
175
175
  statement.body.each { |nested| emit_statement(nested) }
@@ -265,7 +265,7 @@ module MilkTea
265
265
  end
266
266
  end
267
267
 
268
- def render_for_clause_statement(statement)
268
+ def render_for_loop_clause(statement)
269
269
  case statement
270
270
  when IR::LocalDecl
271
271
  "#{statement.linkage_name}: #{statement.type} = #{render_expression(statement.value)}"
@@ -279,12 +279,12 @@ module MilkTea
279
279
  end
280
280
 
281
281
  def render_postfix(expression)
282
- return render_expression(expression, POSTFIX_PRECEDENCE) if postfix_expression?(expression)
282
+ return render_expression(expression, POSTFIX_PRECEDENCE) if atomic_expression?(expression)
283
283
 
284
284
  "(#{render_expression(expression)})"
285
285
  end
286
286
 
287
- def postfix_expression?(expression)
287
+ def atomic_expression?(expression)
288
288
  expression.is_a?(IR::Name) || expression.is_a?(IR::Member) || expression.is_a?(IR::Index) || expression.is_a?(IR::Call)
289
289
  end
290
290
 
@@ -192,13 +192,13 @@ module MilkTea
192
192
  end
193
193
 
194
194
  def validate_async_expression_support!(expression, context:)
195
- unsupported_context = unsupported_async_await_context(expression)
195
+ unsupported_context = unsupported_await_position(expression)
196
196
  return unless unsupported_context
197
197
 
198
198
  raise_sema_error("await in async functions is not supported inside #{unsupported_context} yet")
199
199
  end
200
200
 
201
- def unsupported_async_await_context(expression)
201
+ def unsupported_await_position(expression)
202
202
  nil
203
203
  end
204
204
 
@@ -757,7 +757,7 @@ module MilkTea
757
757
  false
758
758
  end
759
759
 
760
- def char_array_removed_text_method?(receiver_type, name)
760
+ def char_array_text_method_unavailable?(receiver_type, name)
761
761
  return unless char_array_text_type?(receiver_type)
762
762
 
763
763
  name == "as_str" || name == "as_cstr"
@@ -397,7 +397,7 @@ module MilkTea
397
397
  element_type = array_element_type(field_receiver_type)
398
398
  return Types::Registry.span(element_type)
399
399
  end
400
- if char_array_removed_text_method?(method_receiver_type, expression.member)
400
+ if char_array_text_method_unavailable?(method_receiver_type, expression.member)
401
401
  raise_sema_error("#{method_receiver_type}.#{expression.member} is not available; array[char, N] is raw storage, use str_buffer[N] or an explicit helper")
402
402
  end
403
403
  if specialized_receiver_method_kind(method_receiver_type, expression.member)
@@ -939,7 +939,7 @@ module MilkTea
939
939
  )
940
940
 
941
941
  check_function_call(callable, expression.arguments, scopes:)
942
- validate_specialized_function_body(callable) unless callable.type_arguments.empty?
942
+ validate_specialized_function_body!(callable) unless callable.type_arguments.empty?
943
943
  callable.type.return_type
944
944
  when :method
945
945
  callable = specialize_function_binding(
@@ -952,7 +952,7 @@ module MilkTea
952
952
  raise_sema_error("cannot call editable method #{callable.name} on an immutable receiver") if callable.type.receiver_editable && !assignable_receiver?(receiver, scopes)
953
953
 
954
954
  check_function_call(callable, expression.arguments, scopes:)
955
- validate_specialized_function_body(callable) unless callable.type_arguments.empty?
955
+ validate_specialized_function_body!(callable) unless callable.type_arguments.empty?
956
956
  callable.type.return_type
957
957
  when :callable_value
958
958
  check_callable_value_call(callable, expression.arguments, scopes:, callee_expression: expression.callee)
@@ -1349,7 +1349,7 @@ module MilkTea
1349
1349
  return [:struct_with, method_receiver_type, callee.receiver]
1350
1350
  end
1351
1351
 
1352
- if char_array_removed_text_method?(method_receiver_type, callee.member)
1352
+ if char_array_text_method_unavailable?(method_receiver_type, callee.member)
1353
1353
  raise_sema_error("#{method_receiver_type}.#{callee.member} is not available; array[char, N] is raw storage, use str_buffer[N] or an explicit helper")
1354
1354
  end
1355
1355
 
@@ -126,7 +126,7 @@ module MilkTea
126
126
  # only partially analysed, and functions whose last statement does not
127
127
  # record a snapshot).
128
128
  if binding.ast.respond_to?(:body) && binding.ast.body
129
- body_end = last_ast_line(binding.ast.body)
129
+ body_end = statement_block_last_line(binding.ast.body)
130
130
  end_line = body_end if body_end && body_end > end_line
131
131
  end
132
132
 
@@ -190,11 +190,11 @@ module MilkTea
190
190
  when AST::ErrorBlockStmt
191
191
  lines.concat(statement_list_lines(statement.body))
192
192
  when AST::LocalDecl
193
- lines << expression_end_line(statement.value) if statement.value
193
+ lines << expression_last_line(statement.value) if statement.value
194
194
  lines.concat(statement_list_lines(statement.else_body)) if statement.else_body
195
195
  when AST::IfStmt
196
196
  statement.branches.each do |branch|
197
- lines << expression_end_line(branch.condition)
197
+ lines << expression_last_line(branch.condition)
198
198
  lines.concat(statement_list_lines(branch.body))
199
199
  end
200
200
  lines.concat(statement_list_lines(statement.else_body)) if statement.else_body
@@ -205,19 +205,19 @@ module MilkTea
205
205
  if arm.respond_to?(:body)
206
206
  lines.concat(statement_list_lines(arm.body))
207
207
  else
208
- lines << expression_end_line(arm.value)
208
+ lines << expression_last_line(arm.value)
209
209
  end
210
210
  end
211
211
  when AST::DeferStmt
212
212
  lines.concat(statement_list_lines(statement.body))
213
213
  when AST::Assignment
214
- lines << expression_end_line(statement.value)
214
+ lines << expression_last_line(statement.value)
215
215
  when AST::ReturnStmt
216
- lines << expression_end_line(statement.value)
216
+ lines << expression_last_line(statement.value)
217
217
  when AST::ExpressionStmt
218
- lines << expression_end_line(statement.expression)
218
+ lines << expression_last_line(statement.expression)
219
219
  when AST::StaticAssert
220
- lines << expression_end_line(statement.condition)
220
+ lines << expression_last_line(statement.condition)
221
221
  end
222
222
 
223
223
  lines.compact.max
@@ -232,51 +232,51 @@ module MilkTea
232
232
  end
233
233
  end
234
234
 
235
- def expression_end_line(node)
235
+ def expression_last_line(node)
236
236
  return nil unless node
237
237
 
238
238
  lines = [node.line]
239
239
 
240
240
  case node
241
241
  when AST::MemberAccess
242
- lines << expression_end_line(node.receiver)
242
+ lines << expression_last_line(node.receiver)
243
243
  when AST::IndexAccess
244
- lines << expression_end_line(node.receiver)
245
- lines << expression_end_line(node.index)
244
+ lines << expression_last_line(node.receiver)
245
+ lines << expression_last_line(node.index)
246
246
  when AST::Specialization
247
- lines << expression_end_line(node.callee)
247
+ lines << expression_last_line(node.callee)
248
248
  when AST::Call
249
- lines << expression_end_line(node.callee)
250
- node.arguments.each { |argument| lines << expression_end_line(argument.value) }
249
+ lines << expression_last_line(node.callee)
250
+ node.arguments.each { |argument| lines << expression_last_line(argument.value) }
251
251
  when AST::Argument
252
- lines << expression_end_line(node.value)
252
+ lines << expression_last_line(node.value)
253
253
  when AST::UnaryOp
254
- lines << expression_end_line(node.operand)
254
+ lines << expression_last_line(node.operand)
255
255
  when AST::BinaryOp
256
- lines << expression_end_line(node.left)
257
- lines << expression_end_line(node.right)
256
+ lines << expression_last_line(node.left)
257
+ lines << expression_last_line(node.right)
258
258
  when AST::IfExpr
259
- lines << expression_end_line(node.condition)
260
- lines << expression_end_line(node.then_expression)
261
- lines << expression_end_line(node.else_expression)
259
+ lines << expression_last_line(node.condition)
260
+ lines << expression_last_line(node.then_expression)
261
+ lines << expression_last_line(node.else_expression)
262
262
  when AST::MatchExpr
263
- lines << expression_end_line(node.expression)
263
+ lines << expression_last_line(node.expression)
264
264
  node.arms.each do |arm|
265
- lines << expression_end_line(arm.pattern)
266
- lines << expression_end_line(arm.value)
265
+ lines << expression_last_line(arm.pattern)
266
+ lines << expression_last_line(arm.value)
267
267
  end
268
268
  when AST::AwaitExpr
269
- lines << expression_end_line(node.expression)
269
+ lines << expression_last_line(node.expression)
270
270
  when AST::FormatExprPart
271
- lines << expression_end_line(node.expression)
271
+ lines << expression_last_line(node.expression)
272
272
  when AST::PrefixCast
273
- lines << expression_end_line(node.expression)
273
+ lines << expression_last_line(node.expression)
274
274
  end
275
275
 
276
276
  lines.compact.max
277
277
  end
278
278
 
279
- def recovered_for_statement(statement)
279
+ def rebuild_for_statement(statement)
280
280
  AST::ForStmt.new(
281
281
  bindings: Array(statement.header_bindings),
282
282
  iterables: Array(statement.header_iterables),
@@ -364,31 +364,31 @@ module MilkTea
364
364
 
365
365
  # Returns the highest line number across a list of AST statement nodes,
366
366
  # recursing into nested bodies (if/else/match/while/for/defer/unsafe).
367
- def last_ast_line(statements)
367
+ def statement_block_last_line(statements)
368
368
  return nil if statements.nil? || statements.empty?
369
369
 
370
370
  statements.filter_map do |stmt|
371
371
  case stmt
372
372
  when AST::IfStmt
373
- branch_lines = stmt.branches.filter_map { |b| last_ast_line(b.body) }
374
- else_lines = last_ast_line(stmt.else_body)
373
+ branch_lines = stmt.branches.filter_map { |b| statement_block_last_line(b.body) }
374
+ else_lines = statement_block_last_line(stmt.else_body)
375
375
  [stmt.line, *branch_lines, else_lines].compact.max
376
376
  when AST::WhileStmt, AST::ForStmt, AST::UnsafeStmt, AST::ErrorBlockStmt
377
- [stmt.line, last_ast_line(stmt.body)].compact.max
377
+ [stmt.line, statement_block_last_line(stmt.body)].compact.max
378
378
  when AST::MatchStmt
379
379
  arm_lines = stmt.arms.filter_map do |arm|
380
380
  if arm.respond_to?(:body)
381
- last_ast_line(arm.body)
381
+ statement_block_last_line(arm.body)
382
382
  elsif arm.respond_to?(:value)
383
383
  arm.value.line
384
384
  end
385
385
  end
386
386
  [stmt.line, *arm_lines].compact.max
387
387
  when AST::DeferStmt
388
- [stmt.line, last_ast_line(stmt.body)].compact.max
388
+ [stmt.line, statement_block_last_line(stmt.body)].compact.max
389
389
  when AST::WhenStmt
390
- branch_lines = stmt.branches.filter_map { |b| last_ast_line(b.body) }
391
- else_lines = last_ast_line(stmt.else_body)
390
+ branch_lines = stmt.branches.filter_map { |b| statement_block_last_line(b.body) }
391
+ else_lines = statement_block_last_line(stmt.else_body)
392
392
  [stmt.line, *branch_lines, else_lines].compact.max
393
393
  else
394
394
  stmt.line
@@ -81,7 +81,7 @@ module MilkTea
81
81
  end
82
82
 
83
83
  def foreign_mapping_expression(decl)
84
- return decl.mapping unless foreign_mapping_auto_call_shorthand?(decl.mapping)
84
+ return decl.mapping unless foreign_mapping_implicit_call?(decl.mapping)
85
85
 
86
86
  AST::Call.new(
87
87
  callee: decl.mapping,
@@ -89,14 +89,14 @@ module MilkTea
89
89
  )
90
90
  end
91
91
 
92
- def foreign_mapping_auto_call_shorthand?(expression)
92
+ def foreign_mapping_implicit_call?(expression)
93
93
  case expression
94
94
  when AST::Identifier
95
95
  true
96
96
  when AST::MemberAccess
97
- foreign_mapping_auto_call_shorthand?(expression.receiver)
97
+ foreign_mapping_implicit_call?(expression.receiver)
98
98
  when AST::Specialization
99
- foreign_mapping_auto_call_shorthand?(expression.callee)
99
+ foreign_mapping_implicit_call?(expression.callee)
100
100
  else
101
101
  false
102
102
  end
@@ -186,7 +186,7 @@ module MilkTea
186
186
  external:,
187
187
  )
188
188
 
189
- FunctionBinding.new(
189
+ Bindings::FunctionBinding.new(
190
190
  name: decl.name,
191
191
  type: function_type,
192
192
  body_params:,
@@ -266,7 +266,7 @@ module MilkTea
266
266
  # would silently swallow body errors into @structural_errors. We
267
267
  # temporarily disable collect mode on the owner so the caller receives
268
268
  # the SemanticError directly.
269
- def validate_specialized_function_body(binding)
269
+ def validate_specialized_function_body!(binding)
270
270
  owner = binding.owner
271
271
  prev_collecting = owner.instance_variable_get(:@collecting_errors)
272
272
  owner.instance_variable_set(:@collecting_errors, false)
@@ -597,7 +597,7 @@ module MilkTea
597
597
  # Scans generic method bodies for assignments to this through a
598
598
  # non-editable receiver. Full body checking is deferred to call-site
599
599
  # specialization, but immutable-this violations are type-independent.
600
- def check_generic_method_immutable_this(binding, scopes)
600
+ def check_generic_method_this_mutability(binding, scopes)
601
601
  this_binding = scopes.first&.values&.find { |v| v.name == "this" }
602
602
  return unless this_binding
603
603
  return if this_binding.mutable
@@ -629,7 +629,7 @@ module MilkTea
629
629
  start_local_completion_frame(binding, scopes)
630
630
  if binding.type_params.any?
631
631
  if binding.ast.respond_to?(:body)
632
- check_generic_method_immutable_this(binding, scopes)
632
+ check_generic_method_this_mutability(binding, scopes)
633
633
  check_generic_method_names(binding, scopes)
634
634
  end
635
635
  return
@@ -223,7 +223,7 @@ module MilkTea
223
223
  body_params = binding.body_params.map { |param| substitute_value_binding(param, substitutions) }
224
224
  validate_specialized_function_binding!(binding.name, type, body_params)
225
225
 
226
- instance = FunctionBinding.new(
226
+ instance = Bindings::FunctionBinding.new(
227
227
  name: binding.name,
228
228
  type:,
229
229
  body_params:,
@@ -374,7 +374,7 @@ module MilkTea
374
374
  end
375
375
 
376
376
  def substitute_value_binding(binding, substitutions)
377
- ValueBinding.new(
377
+ Bindings::ValueBinding.new(
378
378
  id: binding.id,
379
379
  name: binding.name,
380
380
  storage_type: substitute_type(binding.storage_type, substitutions),
@@ -399,7 +399,7 @@ module MilkTea
399
399
  end
400
400
 
401
401
  def validate_specialized_function_type!(type, function_name:, context:)
402
- ValidateSpecializedTypeVisitor.new(
402
+ Types::ValidateSpecializedTypeVisitor.new(
403
403
  function_name:,
404
404
  context:,
405
405
  on_error: ->(msg) { raise_sema_error(msg) },
@@ -408,7 +408,7 @@ module MilkTea
408
408
  end
409
409
 
410
410
  def substitute_type(type, substitutions)
411
- SubstituteTypeVisitor.new(substitutions).apply(type)
411
+ Types::SubstituteTypeVisitor.new(substitutions).apply(type)
412
412
  end
413
413
 
414
414
  def bitwise_type?(type)
@@ -1162,7 +1162,7 @@ module MilkTea
1162
1162
  def freeze_scope_bindings(scope)
1163
1163
  frozen_scope = scope.is_a?(FlowScope) ? FlowScope.new : {}
1164
1164
  scope.each do |name, binding|
1165
- frozen_scope[name] = ValueBinding.new(
1165
+ frozen_scope[name] = Bindings::ValueBinding.new(
1166
1166
  id: binding.id,
1167
1167
  name: binding.name,
1168
1168
  storage_type: binding.storage_type,
@@ -1191,26 +1191,26 @@ module MilkTea
1191
1191
  end
1192
1192
 
1193
1193
  def stored_ref_supported_type?(type, visited = {}, allow_lifetimes: [])
1194
- visitor = StoredRefSupportedVisitor.new(allow_lifetimes:)
1194
+ visitor = Types::StoredRefSupportedVisitor.new(allow_lifetimes:)
1195
1195
  visitor.visit(type)
1196
1196
  visitor.result?
1197
1197
  end
1198
1198
 
1199
1199
  def contains_callable_ref_type?(type, visited = {})
1200
- visitor = ContainsCallableRefTypeVisitor.new
1200
+ visitor = Types::ContainsCallableRefTypeVisitor.new
1201
1201
  visitor.visit(type)
1202
1202
  visitor.found?
1203
1203
  end
1204
1204
 
1205
1205
  def contains_proc_type?(type, visited = {})
1206
- visitor = ContainsProcTypeVisitor.new
1206
+ visitor = Types::ContainsProcTypeVisitor.new
1207
1207
  visitor.visit(type)
1208
1208
  visitor.found?
1209
1209
  end
1210
1210
 
1211
1211
  def proc_storage_supported_type?(type, visited = {})
1212
1212
  return true unless contains_proc_type?(type)
1213
- visitor = ProcStorageSupportedVisitor.new
1213
+ visitor = Types::ProcStorageSupportedVisitor.new
1214
1214
  visitor.visit(type)
1215
1215
  visitor.result?
1216
1216
  end
@@ -1421,10 +1421,10 @@ module MilkTea
1421
1421
  id ||= allocate_binding_id
1422
1422
  @binding_name_by_id[id] = name
1423
1423
  @binding_type_by_id[id] = flow_type == type ? type : (flow_type || type)
1424
- ValueBinding.new(id:, name:, storage_type: type, flow_type: flow_type == type ? nil : flow_type, mutable:, kind:, const_value:)
1424
+ Bindings::ValueBinding.new(id:, name:, storage_type: type, flow_type: flow_type == type ? nil : flow_type, mutable:, kind:, const_value:)
1425
1425
  end
1426
1426
 
1427
- def binding_resolution_snapshot
1427
+ def build_binding_resolution_snapshot
1428
1428
  BindingResolution.new(
1429
1429
  identifier_binding_ids: @identifier_binding_ids.dup.freeze,
1430
1430
  declaration_binding_ids: @declaration_binding_ids.dup.freeze,