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 >= 0branch (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 >= 08508+
# Issue #667: method redefinition is a subset limitation. spinel8509+
# is an AOT compiler with static dispatch; preserving CRuby's8510+
# "call site binds to the version current at the source position"8511+
# semantics would require source-order call-site versioning across8512+
# analyze + codegen. We follow the simpler "last def wins" rule8513+
# (matches class reopen for adding new methods) and warn so the8514+
# user can spot the divergence from CRuby's intermediate-version8515+
# 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("|")test/method_redefinition_warning.rbaddedView file
Loading diff…
test/method_redefinition_warning.rb.expectedaddedView file
Loading diff…