Commit 690abf09
690abf0987ccMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 1 file · ~1 modified
Description
fix: remove unused variables and dead code in generated C
- Remove unused method: new_label
- Remove unused variables: actual_init_idx, struct_kw_init, mi (3 places), changed, has_reader, saved, cname (2 places), defval, arg, is_splat_call, at_guess, bp1
- Guard sp_last_status with @needs_system flag (separate from @needs_file_io)
Generated C warnings: 106 → 46 (only unused-function remains). return-type: 0, unused-variable: 0, unused-but-set: 0.
Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]
Details
- Commit
- 690abf0987cc
- Parent
- be009f4f03d7
spinel_codegen.rbmodifiedView file
@@ -122,6 +122,7 @@
122122
123123
# Feature flags124124
@needs_gc = 0125+
@needs_system = 0125126
@needs_int_array = 0126127
@needs_float_array = 0127128
@needs_str_array = 0@@ -198,11 +199,6 @@
198199
def new_temp199200
@temp_counter = @temp_counter + 1200201
"_t" + @temp_counter.to_s201-
end202-
203-
def new_label204-
@label_counter = @label_counter + 1205-
"_L" + @label_counter.to_s206202
end207203
208204
# ---- AST reader ----@@ -2371,7 +2367,6 @@
23712367
# Add as top-level method with prefix23722368
mname = @nd_name[sid]23732369
# Store with special naming for lookup2374-
mi = @meth_names.length23752370
@meth_names.push("__oc_" + cname + "_" + mname)23762371
params = collect_params_str(sid)23772372
@meth_param_names.push(params)@@ -2389,7 +2384,6 @@
23892384
parent = ""23902385
sp = @nd_superclass[nid]23912386
struct_fields = "".split(",")2392-
struct_kw_init = 023932387
if sp >= 023942388
if @nd_type[sp] == "CallNode"23952389
if @nd_name[sp] == "new"@@ -2411,7 +2405,7 @@
24112405
struct_fields.push(fname)24122406
end24132407
if @nd_type[sarg_ids[sk]] == "KeywordHashNode"2414-
struct_kw_init = 12408+
# keyword_init detected24152409
end24162410
sk = sk + 124172411
end@@ -3254,7 +3248,6 @@
32543248
if @nd_type[@nd_receiver[sid]] == "SelfNode"32553249
dmname = @nd_name[sid]32563250
# Create as top-level method with module prefix for dispatch3257-
mi = @meth_names.length32583251
@meth_names.push(mname + "_cls_" + dmname)32593252
@meth_param_names.push(collect_params_str(sid))32603253
@meth_param_types.push(collect_ptypes_str(sid, -1))@@ -3837,7 +3830,6 @@
38373830
all_params = @cls_meth_params[oci].split("|")38383831
all_ptypes = @cls_meth_ptypes[oci].split("|")38393832
bodies = @cls_meth_bodies[oci].split(";")3840-
changed = 038413833
j = 038423834
while j < mnames.length38433835
if mnames[j] != "initialize"@@ -3899,7 +3891,6 @@
38993891
ptypes[pk] = "obj_" + @cls_names[ci2]39003892
all_ptypes[j] = ptypes.join(",")39013893
@cls_meth_ptypes[oci] = all_ptypes.join("|")3902-
changed = 139033894
end39043895
end39053896
ci2 = ci2 + 1@@ -5345,6 +5336,7 @@
53455336
end53465337
if mname == "system"53475338
@needs_file_io = 15339+
@needs_system = 153485340
end53495341
if @nd_receiver[nid] >= 053505342
if @nd_type[@nd_receiver[nid]] == "ConstantReadNode"@@ -6137,7 +6129,9 @@
61376129
emit_raw("static const char*sp_int_chr(mrb_int n){char*s=(char*)malloc(2);s[0]=(char)n;s[1]=0;return s;}")61386130
emit_raw("typedef struct{mrb_int first;mrb_int last;}sp_Range;")61396131
emit_raw("static sp_Range sp_range_new(mrb_int f,mrb_int l){sp_Range r;r.first=f;r.last=l;return r;}")6140-
emit_raw("static int sp_last_status = 0;")6132+
if @needs_system == 16133+
emit_raw("static int sp_last_status = 0;")6134+
end61416135
emit_raw("")61426136
end61436137
@@ -6758,16 +6752,6 @@
67586752
bid = bodies[mi].to_i67596753
if is_simple_writer_method(mn, bid) == 167606754
append_attr_writer(i, bname)6761-
# Also ensure the corresponding reader exists6762-
readers = @cls_attr_readers[i].split(";")6763-
has_reader = 06764-
ri = 06765-
while ri < readers.length6766-
if readers[ri] == bname6767-
has_reader = 16768-
end6769-
ri = ri + 16770-
end67716755
end67726756
end67736757
end@@ -6991,8 +6975,6 @@
69916975
69926976
def recalc_needs_gc69936977
# Recalculate @needs_gc: only needed if non-value-type classes are used6994-
# Save and reset, then re-enable if needed6995-
saved = @needs_gc69966978
@needs_gc = 069976979
# Non-value-type class exists → GC needed69986980
i = 0@@ -7664,10 +7646,6 @@
76647646
end76657647
76667648
init_ci = find_init_class(ci)7667-
actual_init_idx = -17668-
if init_ci >= 07669-
actual_init_idx = cls_find_method_direct(init_ci, "initialize")7670-
end76717649
76727650
if init_idx >= 076737651
bodies = @cls_meth_bodies[ci].split(";")@@ -9560,7 +9538,6 @@
95609538
cidx = cls_find_method(@current_class_idx, mname)95619539
if cidx >= 095629540
ca = compile_call_args(nid)9563-
cname = @cls_names[@current_class_idx]95649541
owner = find_method_owner(@current_class_idx, mname)95659542
if ca != ""95669543
return "sp_" + owner + "_" + sanitize_name(mname) + "(self, " + ca + ")"@@ -9884,7 +9861,6 @@
98849861
aargs = get_args(args_id)98859862
if aargs.length >= 198869863
# Hash.new(default_val) - check type9887-
defval = compile_expr(aargs.first)98889864
dt = infer_type(aargs.first)98899865
if dt == "string"98909866
@needs_str_str_hash = 1@@ -10426,7 +10402,6 @@
1042610402
if mname == "zip"1042710403
# zip returns array of pairs; for length-only usage, return array with same length1042810404
tmp = new_temp10429-
arg = compile_arg0(nid)1043010405
emit(" sp_IntArray *" + tmp + " = sp_IntArray_new();")1043110406
emit(" for (mrb_int _i = 0; _i < sp_IntArray_length(" + rc + "); _i++) sp_IntArray_push(" + tmp + ", sp_IntArray_get(" + rc + ", _i));")1043210407
return tmp@@ -11135,7 +11110,6 @@
1113511110
i = 01113611111
while i < @cls_names.length1113711112
cname = @cls_names[i]11138-
mi = cls_find_method(@cls_names.length - 1 - i, mname)1113911113
# Check if this class has the method1114011114
midx = cls_find_method_direct(i, mname)1114111115
if midx >= 0@@ -11245,7 +11219,6 @@
1124511219
kw_names = "".split(",")1124611220
kw_vals = "".split(",")1124711221
positional_ids = []11248-
is_splat_call = 01124911222
ak = 01125011223
while ak < arg_ids.length1125111224
if @nd_type[arg_ids[ak]] == "KeywordHashNode"@@ -11287,7 +11260,6 @@
1128711260
if k < ptypes.length1128811261
if ptypes[k] == "poly"1128911262
# Need to box - kw_vals[ki] is already compiled11290-
at_guess = "string"1129111263
result = result + "sp_box_str(" + kw_vals[ki] + ")"1129211264
else1129311265
result = result + kw_vals[ki]@@ -14071,8 +14043,6 @@
1407114043
# catch(:tag) do ... end1407214044
tag = compile_arg0(nid)1407314045
blk = @nd_block[nid]14074-
bp1 = get_block_param(nid, 0)14075-
1407614046
emit(" sp_catch_tag[sp_catch_top] = " + tag + ";")1407714047
emit(" sp_catch_top++;")1407814048
emit(" if (setjmp(sp_catch_stack[sp_catch_top-1]) == 0) {")@@ -14624,7 +14594,6 @@
1462414594
saved_ci = @current_class_idx1462514595
@current_class_idx = cci1462614596
14627-
cname = @cls_names[cci]1462814597
@block_counter = @block_counter + 11462914598
suffix = "_y" + @block_counter.to_s1463014599