Commit e47608ac
e47608acb9d6Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 7 files · +6 added · ~1 modified
Description
Merge pull request #535 from ryanseys/rs-bound-analyze-loops
fix(analyze): bound fixed-point loops and const-path recursion
Details
- Commit
- e47608acb9d6
- Parent
- 585bee04368f
- Merge parent
- 3091bd3b9dcd
spinel_analyze.rbmodifiedView file
@@ -971,10 +971,14 @@
971971
# ::C -> C972972
# M::C -> M_C973973
# A::B::C -> A_B_C974-
def const_ref_flat_name(nid)974+
def const_ref_flat_name(nid, depth = 32)975975
if nid < 0976976
return ""977977
end978+
if depth <= 0979+
$stderr.puts "Error: const_ref_flat_name exceeded depth 32 -- pathological ConstantPath nesting"980+
exit(1)981+
end978982
t = @nd_type[nid]979983
if t == "ConstantReadNode"980984
return @nd_name[nid]@@ -985,7 +989,7 @@
985989
if parent < 0986990
return leaf987991
end988-
base = const_ref_flat_name(parent)992+
base = const_ref_flat_name(parent, depth - 1)989993
if base == ""990994
return ""991995
end@@ -1136,10 +1140,14 @@
11361140
name11371141
end11381142
1139-
def resolve_const_ref_name(nid)1143+
def resolve_const_ref_name(nid, depth = 32)11401144
if nid < 011411145
return ""11421146
end1147+
if depth <= 01148+
$stderr.puts "Error: resolve_const_ref_name exceeded depth 32 -- pathological ConstantPath nesting"1149+
exit(1)1150+
end11431151
t = @nd_type[nid]11441152
if t == "ConstantReadNode"11451153
return resolve_const_read_name(@nd_name[nid])@@ -1150,7 +1158,7 @@
11501158
if parent < 011511159
return leaf11521160
end1153-
base = resolve_const_ref_name(parent)1161+
base = resolve_const_ref_name(parent, depth - 1)11541162
if base == ""11551163
return ""11561164
end@@ -14737,7 +14745,14 @@
1473714745
# Second pass: scan method bodies for parameters used as lambda receivers1473814746
# or passed to functions that expect lambda args (transitive closure)1473914747
changed = 114748+
iter = 014749+
sig_hist = "".split(",")1474014750
while changed == 114751+
iter = iter + 114752+
if iter > 25614753+
$stderr.puts "Error: infer_lambda_param_types did not converge after 256 iterations"14754+
exit(1)14755+
end1474114756
changed = 01474214757
mi = 01474314758
while mi < @meth_names.length@@ -14763,6 +14778,23 @@
1476314778
end1476414779
mi = mi + 11476514780
end14781+
# Oscillation guard: only run when this iteration claims progress14782+
# (changed == 1, so the loop will iterate again). A repeated14783+
# @meth_param_types signature under changed=1 means the lambda14784+
# flag is flip-flopping -- a bug in param_used_as_lambda, not a14785+
# "needs more iterations" situation. Fail loudly.14786+
if changed == 114787+
sig = @meth_param_types.join("|")14788+
sh = 014789+
while sh < sig_hist.length14790+
if sig_hist[sh] == sig14791+
$stderr.puts "Error: infer_lambda_param_types oscillating (iter=" + iter.to_s + ", cycle len=" + (iter - sh - 1).to_s + ")"14792+
exit(1)14793+
end14794+
sh = sh + 114795+
end14796+
sig_hist.push(sig)14797+
end1476614798
end1476714799
end1476814800
@@ -18189,11 +18221,37 @@
1818918221
1819018222
def scan_bigint_propagate(stmts, names, types)1819118223
changed = 118224+
iter = 018225+
sig_hist = "".split(",")1819218226
while changed == 118227+
iter = iter + 118228+
if iter > 25618229+
$stderr.puts "Error: scan_bigint_propagate did not converge after 256 iterations"18230+
exit(1)18231+
end1819318232
changed = 01819418233
stmts.each { |sid|1819518234
changed = propagate_bigint_node(sid, names, types, changed)1819618235
}18236+
# Oscillation guard: only run when this iteration claims progress18237+
# (changed == 1, so the loop will iterate again). A repeated `types`18238+
# signature under changed=1 means propagate_bigint_node reported a18239+
# change it didn't actually make, or a cycle is in flight. Use `|`18240+
# as the field separator because type tokens can contain commas18241+
# (e.g. `tuple:int,int`) -- a comma join would alias distinct18242+
# length-N and length-(N+1) states.18243+
if changed == 118244+
sig = types.join("|")18245+
sh = 018246+
while sh < sig_hist.length18247+
if sig_hist[sh] == sig18248+
$stderr.puts "Error: scan_bigint_propagate oscillating (iter=" + iter.to_s + ", cycle len=" + (iter - sh - 1).to_s + ")"18249+
exit(1)18250+
end18251+
sh = sh + 118252+
end18253+
sig_hist.push(sig)18254+
end1819718255
end1819818256
end1819918257
test/bigint_propagation_chain.rbaddedView file
Loading diff…
test/bigint_propagation_chain.rb.expectedaddedView file
Loading diff…
test/const_path_deep_nesting.rbaddedView file
Loading diff…
test/const_path_deep_nesting.rb.expectedaddedView file
Loading diff…
test/lambda_inference_chain.rbaddedView file
Loading diff…
test/lambda_inference_chain.rb.expectedaddedView file
Loading diff…