Commit b8f582b3
b8f582b3d120Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 3 files · ~3 modified
Description
Merge pull request #1023 from ryanseys/rs-instance-eval-splice-ivar-routing
fix(codegen): instance_eval splice routes ivar reads/writes through receiver
Details
- Commit
- b8f582b3d120
- Parent
- ffefc0d06bfa
- Merge parent
- 8811039fc472
spinel_codegen.rbmodifiedView file
@@ -5019,6 +5019,26 @@
50195019
if mod_slot != ""50205020
return mod_slot50215021
end5022+
# Rebound self (instance_eval / instance_exec splice): route ivar5023+
# access through the receiver's struct via self_arrow(), not the5024+
# toplevel static-global slot. Without this, a block body that5025+
# writes `@x = ...` at a toplevel call site (where5026+
# @current_class_idx == -1) falls into the toplevel-ivar fallback5027+
# below and emits a bare global write -- never touching the5028+
# receiver's iv_x. Detected by the section-4 regression added to5029+
# test/instance_eval_trampoline.rb.5030+
#5031+
# Gate on @instance_eval_self_var (the rebind signal from5032+
# splice_block_with_self_rebound), NOT @self_override --5033+
# @self_override is also set by compile_yield_method_call_stmt5034+
# for inlined-method-body locals + default-arg substitution, where5035+
# ivars must still resolve against the enclosing class's struct,5036+
# not the override expression. Conflating them silently mis-routes5037+
# ivar reads everywhere yield methods are inlined (including5038+
# spinel_codegen.rb's own methods during bootstrap).5039+
if @instance_eval_self_var != nil && @instance_eval_self_var != ""5040+
return self_arrow + sanitize_ivar(name)5041+
end50225042
if @current_class_idx < 0 && toplevel_ivar_type(name) != ""50235043
return sanitize_ivar(name)50245044
end@@ -9336,8 +9356,6 @@
93369356
93379357
93389358
9339-
9340-
93419359
# Walk `nid`'s subtree and collect every `Cls.new(...)` class name93429360
# into `out`. Used by detect_poly_returned_types to enumerate the93439361
# classes returned (directly or via a temp) from a poly-returning@@ -44945,11 +44963,24 @@
4494544963
end4494644964
rc = compile_expr_gc_rooted(recv)4494744965
self_var = new_temp44966+
# Value-typed receivers (@cls_is_value_type[ci] == 1) are returned44967+
# by-value from sp_<C>_new(), so (sp_<C> *)<rc> is an invalid cast44968+
# of a struct value. Handling them requires the value-vs-pointer44969+
# branch from emit_ieval_func and is tracked separately.4494844970
emit(" sp_" + cname + " *" + self_var + " = (sp_" + cname + " *)" + rc + ";")4494944971
if @in_gc_scope == 14495044972
emit(" SP_GC_ROOT(" + self_var + ");")4495144973
end44974+
# Route bare `@ivar` reads/writes inside the spliced block to the44975+
# rebound receiver. Without this, ivar_lhs's toplevel-fallback44976+
# branch returns the bare static-global slot when the splice44977+
# happens at toplevel scope — broken silently because no prior44978+
# trampoline test exercised direct ivar access inside the spliced44979+
# block (existing tests only call methods like `add` / `bump`).44980+
saved_self_override = @self_override44981+
@self_override = self_var4495244982
splice_block_with_self_rebound(@nd_body[blk], self_var, cname)44983+
@self_override = saved_self_override4495344984
end4495444985
4495544986
def compile_yield_method_call_stmt(nid, cci, midx, mname)test/instance_eval_trampoline.rbmodifiedView file
Loading diff…
test/instance_eval_trampoline.rb.expectedmodifiedView file
Loading diff…