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 end
49074907
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 time
4911+ # backs the read; codegen returns it as cst_<Mod>_<accessor>
4912+ # (sp_RbVal). Skip when args are present so this doesn't
4913+ # 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 == 0
4917+ rcname_acc = @nd_name[recv]
4918+ if module_name_exists(rcname_acc) == 1
4919+ if find_module_acc_idx(rcname_acc + "." + mname) >= 0
4920+ slot_a = rcname_acc + "_" + mname
4921+ if find_const_idx(slot_a) >= 0
4922+ rconsts_a = module_acc_resolved(rcname_acc, mname)
4923+ if rconsts_a == "" || rconsts_a == "?"
4924+ @needs_rb_value = 1
4925+ return "poly"
4926+ end
4927+ end
4928+ end
4929+ end
4930+ end
4931+ end
49094932 # File operations
49104933 if recv >= 0
49114934 if @nd_type[recv] == "ConstantReadNode"
@@ -9051,6 +9074,11 @@
90519074 # module-level singleton accessor. Stage 1 of the
90529075 # accessor's value is resolved later via the constant-fold pass
90539076 # (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 a
9079+ # backing slot to write to. The constant-fold path takes priority
9080+ # when every RHS is a ConstantReadNode; otherwise codegen falls
9081+ # 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 + "_" + accessor
9097+ if find_const_idx(slot_name) < 0
9098+ @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 = 1
9103+ end
90689104 end
90699105 }
90709106 end