Commit 7cacbb6f

7cacbb6f3204Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified

Description

docs(analyze): warn on method redefinition as subset limitation (#667)

Spinel is an AOT compiler with static dispatch — preserving CRuby's "the call site binds to the def current at the source position" semantics for class Foo; def m; ...; end; end; ...; class Foo; def m; ...; end; end would require source-order call-site versioning across analyze + codegen, restructuring the ~13 sites that read @cls_meth_bodies. That work is out of scope for now; document the limitation honestly:

  • append_cls_meth's existing_mi >= 0 branch (already used for class reopen "last def wins" behaviour) now emits a stderr warning identifying the redefined method and class, and notes the divergence from CRuby semantics.
  • Existing class-reopen behaviour (adding new methods on a re-opened class — no name collision) is unaffected; the warning fires only when a method body is actually being replaced.
  • New test pins the documented behaviour so a future source-order-versioning implementation can recognise it as a signal to flip the expected output.

Closes #667.

Co-Authored-By: Claude Opus 4.7 [email protected]

Details

Commit
7cacbb6f3204
Parent
d8af8d2287d6

spinel_analyze.rbmodifiedView file

@@ -8505,6 +8505,15 @@
85058505 if @cls_meth_names[ci] != ""
85068506 existing_mi = cls_find_method_direct(ci, name)
85078507 if existing_mi >= 0
8508+ # Issue #667: method redefinition is a subset limitation. spinel
8509+ # is an AOT compiler with static dispatch; preserving CRuby's
8510+ # "call site binds to the version current at the source position"
8511+ # semantics would require source-order call-site versioning across
8512+ # analyze + codegen. We follow the simpler "last def wins" rule
8513+ # (matches class reopen for adding new methods) and warn so the
8514+ # user can spot the divergence from CRuby's intermediate-version
8515+ # behaviour.
8516+ $stderr.puts "warning: method '" + name + "' on " + @cls_names[ci] + " is being redefined; spinel uses last-def-wins semantics (calls before the redefinition won't see the original body — subset limitation)"
85088517 cur_names = @cls_meth_names[ci].split(";")
85098518 cur_params = @cls_meth_params[ci].split("|")
85108519 cur_ptypes = @cls_meth_ptypes[ci].split("|")