Commit 213cb83f
213cb83f635fMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 4 files · +2 added · ~2 modified
Description
Merge branch 'master' into pr-514
Details
- Commit
- 213cb83f635f
- Parent
- 15b181e2f756
- Merge parent
- f968c231f600
spinel_analyze.rbmodifiedView file
@@ -4906,6 +4906,29 @@
49064906
end49074907
49084908
def infer_constant_recv_type(nid, mname, recv)4909+
# `Mod.accessor` read for a module-level singleton attr_accessor.4910+
# The poly-slot const synthesized at module-collect time4911+
# backs the read; codegen returns it as cst_<Mod>_<accessor>4912+
# (sp_RbVal). Skip when args are present so this doesn't4913+
# collide with method-style calls. Issue #511.4914+
if recv >= 0 && @nd_type[recv] == "ConstantReadNode"4915+
args_id_acc = @nd_arguments[nid]4916+
if args_id_acc < 0 || get_args(args_id_acc).length == 04917+
rcname_acc = @nd_name[recv]4918+
if module_name_exists(rcname_acc) == 14919+
if find_module_acc_idx(rcname_acc + "." + mname) >= 04920+
slot_a = rcname_acc + "_" + mname4921+
if find_const_idx(slot_a) >= 04922+
rconsts_a = module_acc_resolved(rcname_acc, mname)4923+
if rconsts_a == "" || rconsts_a == "?"4924+
@needs_rb_value = 14925+
return "poly"4926+
end4927+
end4928+
end4929+
end4930+
end4931+
end49094932
# File operations49104933
if recv >= 049114934
if @nd_type[recv] == "ConstantReadNode"@@ -9051,6 +9074,11 @@
90519074
# module-level singleton accessor. Stage 1 of the90529075
# accessor's value is resolved later via the constant-fold pass90539076
# (rewrite_module_singleton_accessors) once we've seen all writes.9077+
# ALSO synthesize a poly-typed file-scope const `<Mod>_<accessor>`9078+
# so that non-constant assignments (`M.adapter = "x"`) have a9079+
# backing slot to write to. The constant-fold path takes priority9080+
# when every RHS is a ConstantReadNode; otherwise codegen falls9081+
# through to a direct cst_<Mod>_<accessor> read/write. Issue #511.90549082
if @nd_type[sid] == "SingletonClassNode"90559083
sbody = @nd_body[sid]90569084
if sbody >= 0@@ -9065,6 +9093,14 @@
90659093
accessor = @nd_content[aid]90669094
@module_acc_keys.push(mname + "." + accessor)90679095
@module_acc_consts.push("")9096+
slot_name = mname + "_" + accessor9097+
if find_const_idx(slot_name) < 09098+
@const_names.push(slot_name)9099+
@const_types.push("poly")9100+
@const_expr_ids.push(-1)9101+
@const_scope_names.push(mname)9102+
@needs_rb_value = 19103+
end90689104
end90699105
}90709106
endspinel_codegen.rbmodifiedView file
Loading diff…
test/module_singleton_attr_accessor.rbaddedView file
Loading diff…
test/module_singleton_attr_accessor.rb.expectedaddedView file
Loading diff…