Commit d57369dc
d57369dcf89dMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
refactor(codegen): migrate single-method ptypes/pnames sites (2/N)
Continue migrating split-join boilerplate to the get/put helpers introduced in 9c353c0. This pass covers single-method use sites (per-call-site widening, signature builders, init-param-decl helpers) where reading or writing one (ci, midx) slot replaces ~10 lines of split-and-bound-check. Skips per-class loops where calling put inside the inner iteration would re-split the whole table per method (O(M²) writes).
Tests: 301 pass. Bootstrap: gen2.c == gen3.c.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- d57369dcf89d
- Parent
- f1f90f8839bc
spinel_codegen.rbmodifiedView file
@@ -1030,20 +1030,9 @@
10301030
# `def m(&b); ...; end` shape (instance_eval trampoline today;10311031
# extensible to instance_exec, tap, etc.).10321032
def cls_method_sole_proc_param_name(ci, midx)1033-
all_params = @cls_meth_params[ci].split("|")1034-
all_ptypes = @cls_meth_ptypes[ci].split("|")1035-
if midx >= all_params.length1036-
return ""1037-
end1038-
if midx >= all_ptypes.length1039-
return ""1040-
end1041-
pnames = all_params[midx].split(",")1042-
ptypes = all_ptypes[midx].split(",")1043-
if pnames.length != 11044-
return ""1045-
end1046-
if ptypes.length != 11033+
pnames = cls_meth_pnames_get(ci, midx)1034+
ptypes = cls_meth_ptypes_get(ci, midx)1035+
if pnames.length != 1 || ptypes.length != 110471036
return ""10481037
end10491038
if ptypes[0] != "proc"@@ -6501,21 +6490,13 @@
65016490
while ci < @cls_names.length65026491
@current_class_idx = ci65036492
bodies = @cls_meth_bodies[ci].split(";")6504-
all_params = @cls_meth_params[ci].split("|")6505-
all_ptypes = @cls_meth_ptypes[ci].split("|")65066493
bj = 065076494
while bj < bodies.length65086495
bid = bodies[bj].to_i65096496
if bid >= 065106497
push_scope6511-
pnames = "".split(",")6512-
ptypes = "".split(",")6513-
if bj < all_params.length6514-
pnames = all_params[bj].split(",")6515-
end6516-
if bj < all_ptypes.length6517-
ptypes = all_ptypes[bj].split(",")6518-
end6498+
pnames = cls_meth_pnames_get(ci, bj)6499+
ptypes = cls_meth_ptypes_get(ci, bj)65196500
k = 065206501
while k < pnames.length65216502
pt = "int"@@ -10553,53 +10534,11 @@
1055310534
args_id = @nd_arguments[nid]1055410535
if args_id >= 01055510536
arg_ids = get_args(args_id)10556-
all_ptypes = @cls_meth_ptypes[init_ci].split("|")10557-
all_params = @cls_meth_params[init_ci].split("|")10558-
if init_idx < all_ptypes.length10559-
ptypes = all_ptypes[init_idx].split(",")10560-
pnames = "".split(",")10561-
if init_idx < all_params.length10562-
pnames = all_params[init_idx].split(",")10563-
end10564-
k = 010565-
while k < arg_ids.length10566-
if @nd_type[arg_ids[k]] == "KeywordHashNode"10567-
# Handle keyword args10568-
elems = parse_id_list(@nd_elements[arg_ids[k]])10569-
ek = 010570-
while ek < elems.length10571-
if @nd_type[elems[ek]] == "AssocNode"10572-
key_id = @nd_key[elems[ek]]10573-
if key_id >= 010574-
kname = ""10575-
if @nd_type[key_id] == "SymbolNode"10576-
kname = @nd_content[key_id]10577-
end10578-
expr_id = @nd_expression[elems[ek]]10579-
at = infer_type(expr_id)10580-
pi = 010581-
while pi < pnames.length10582-
if pnames[pi] == kname10583-
if pi < ptypes.length10584-
ptypes[pi] = unify_call_types(ptypes[pi], at, expr_id)10585-
end10586-
end10587-
pi = pi + 110588-
end10589-
end10590-
end10591-
ek = ek + 110592-
end10593-
else10594-
at = infer_type(arg_ids[k])10595-
if k < ptypes.length10596-
ptypes[k] = unify_call_types(ptypes[k], at, arg_ids[k])10597-
end10598-
end10599-
k = k + 110600-
end10601-
all_ptypes[init_idx] = ptypes.join(",")10602-
@cls_meth_ptypes[init_ci] = all_ptypes.join("|")10537+
ptypes = cls_meth_ptypes_get(init_ci, init_idx)10538+
if ptypes.length > 010539+
pnames = cls_meth_pnames_get(init_ci, init_idx)10540+
widen_ptypes_from_args(arg_ids, pnames, ptypes)10541+
cls_meth_ptypes_put(init_ci, init_idx, ptypes)1060310542
end1060410543
end1060510544
end@@ -11041,17 +10980,8 @@
1104110980
if init_idx2 < bodies.length1104210981
if bodies[init_idx2].to_i == -21104310982
# Synthetic struct - update ivar types from init param types11044-
all_params = @cls_meth_params[i].split("|")11045-
all_ptypes = @cls_meth_ptypes[i].split("|")11046-
pnames = "".split(",")11047-
ptypes = "".split(",")11048-
11049-
if init_idx2 < all_params.length11050-
pnames = all_params[init_idx2].split(",")11051-
end11052-
if init_idx2 < all_ptypes.length11053-
ptypes = all_ptypes[init_idx2].split(",")11054-
end10983+
pnames = cls_meth_pnames_get(i, init_idx2)10984+
ptypes = cls_meth_ptypes_get(i, init_idx2)1105510985
pk = 01105610986
while pk < pnames.length1105710987
iname = "@" + pnames[pk]@@ -11074,17 +11004,8 @@
1107411004
mi = 01107511005
while mi < mnames.length1107611006
init_idx = mi11077-
all_params = @cls_meth_params[i].split("|")11078-
all_ptypes = @cls_meth_ptypes[i].split("|")11079-
pnames = "".split(",")11080-
ptypes = "".split(",")11081-
11082-
if init_idx < all_params.length11083-
pnames = all_params[init_idx].split(",")11084-
end11085-
if init_idx < all_ptypes.length11086-
ptypes = all_ptypes[init_idx].split(",")11087-
end11007+
pnames = cls_meth_pnames_get(i, init_idx)11008+
ptypes = cls_meth_ptypes_get(i, init_idx)1108811009
bodies = @cls_meth_bodies[i].split(";")1108911010
bid = -11109011011
if init_idx < bodies.length@@ -11141,21 +11062,12 @@
1114111062
oci = 01114211063
while oci < @cls_names.length1114311064
mnames = @cls_meth_names[oci].split(";")11144-
all_params = @cls_meth_params[oci].split("|")11145-
all_ptypes = @cls_meth_ptypes[oci].split("|")1114611065
bodies = @cls_meth_bodies[oci].split(";")1114711066
j = 01114811067
while j < mnames.length1114911068
if mnames[j] != "initialize"11150-
pnames = "".split(",")11151-
ptypes = "".split(",")11152-
11153-
if j < all_params.length11154-
pnames = all_params[j].split(",")11155-
end11156-
if j < all_ptypes.length11157-
ptypes = all_ptypes[j].split(",")11158-
end11069+
pnames = cls_meth_pnames_get(oci, j)11070+
ptypes = cls_meth_ptypes_get(oci, j)1115911071
bid = -11116011072
if j < bodies.length1116111073
bid = bodies[j].to_i@@ -11167,10 +11079,10 @@
1116711079
if ptypes[pk] == "int"1116811080
# Pick the class whose surface (readers + writers +1116911081
# methods, walked through parents) contains every11170-
# method actually called on this param. The old11171-
# algorithm matched on a single reader and ignored11172-
# later accesses, picking a class that didn't satisfy11173-
# them — issue #35.11082+
# method actually called on this param. Matching11083+
# only one reader and ignoring later accesses11084+
# would pick a class that fails to satisfy the11085+
# full method set.1117411086
called = "".split(",")1117511087
collect_param_methods(bid, pnames[pk], called)1117611088
if called.length > 0 && called_methods_only_on_container_builtins(called) == 0@@ -11184,8 +11096,7 @@
1118411096
end1118511097
if best >= 01118611098
ptypes[pk] = "obj_" + @cls_names[best]11187-
all_ptypes[j] = ptypes.join(",")11188-
@cls_meth_ptypes[oci] = all_ptypes.join("|")11099+
cls_meth_ptypes_put(oci, j, ptypes)1118911100
end1119011101
end1119111102
end@@ -17637,14 +17548,7 @@
1763717548
# Mirrors cls_method_has_yield: call sites use it to decide whether1763817549
# to omit the trailing &block slot from default-padding.1763917550
def cls_method_has_block_param(ci, midx)17640-
if ci < 0 || midx < 017641-
return 017642-
end17643-
all_ptypes = @cls_meth_ptypes[ci].split("|")17644-
if midx >= all_ptypes.length17645-
return 017646-
end17647-
pts = all_ptypes[midx].split(",")17551+
pts = cls_meth_ptypes_get(ci, midx)1764817552
(pts.length > 0 && pts.last == "proc") ? 1 : 01764917553
end1765017554
@@ -17847,17 +17751,8 @@
1784717751
return "void"1784817752
end1784917753
init_idx = cls_find_method_direct(init_ci, "initialize")17850-
all_params = @cls_meth_params[init_ci].split("|")17851-
all_ptypes = @cls_meth_ptypes[init_ci].split("|")17852-
pnames = "".split(",")17853-
ptypes = "".split(",")17854-
17855-
if init_idx < all_params.length17856-
pnames = all_params[init_idx].split(",")17857-
end17858-
if init_idx < all_ptypes.length17859-
ptypes = all_ptypes[init_idx].split(",")17860-
end17754+
pnames = cls_meth_pnames_get(init_ci, init_idx)17755+
ptypes = cls_meth_ptypes_get(init_ci, init_idx)1786117756
if pnames.length == 01786217757
return "void"1786317758
end@@ -17886,17 +17781,8 @@
1788617781
if init_idx < 01788717782
return ""1788817783
end17889-
all_params = @cls_meth_params[init_ci].split("|")17890-
all_ptypes = @cls_meth_ptypes[init_ci].split("|")17891-
pnames = "".split(",")17892-
ptypes = "".split(",")17893-
17894-
if init_idx < all_params.length17895-
pnames = all_params[init_idx].split(",")17896-
end17897-
if init_idx < all_ptypes.length17898-
ptypes = all_ptypes[init_idx].split(",")17899-
end17784+
pnames = cls_meth_pnames_get(init_ci, init_idx)17785+
ptypes = cls_meth_ptypes_get(init_ci, init_idx)1790017786
result = ""1790117787
j = 01790217788
while j < pnames.length@@ -28011,11 +27897,7 @@
2801127897
# this candidate accepts — happens when several classes share2801227898
# the method name but disagree on parameter count).2801327899
arm_arg_strs = ""28014-
all_ptypes = @cls_meth_ptypes[i].split("|")28015-
arm_ptypes = "".split(",")28016-
if midx < all_ptypes.length28017-
arm_ptypes = all_ptypes[midx].split(",")28018-
end27900+
arm_ptypes = cls_meth_ptypes_get(i, midx)2801927901
pk = 02802027902
while pk < arm_ptypes.length2802127903
if pk < arg_compiled.length@@ -29322,16 +29204,8 @@
2932229204
if init_idx < 02932329205
return compile_call_args(nid)2932429206
end29325-
all_params = @cls_meth_params[init_ci].split("|")29326-
all_ptypes = @cls_meth_ptypes[init_ci].split("|")29327-
pnames = "".split(",")29328-
ptypes = "".split(",")29329-
if init_idx < all_params.length29330-
pnames = all_params[init_idx].split(",")29331-
end29332-
if init_idx < all_ptypes.length29333-
ptypes = all_ptypes[init_idx].split(",")29334-
end29207+
pnames = cls_meth_pnames_get(init_ci, init_idx)29208+
ptypes = cls_meth_ptypes_get(init_ci, init_idx)2933529209
# Build args in param order using keyword values2933629210
result = ""2933729211
pk = 0