Commit aa69596f

aa69596f090fMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 227 files · +57 added · -169 deleted

Description

test: fourth bundle batch + restore int_overflow_raises standalone

Continued auto-rename bundling for the remaining medium-class tests. Adds the bundle_classd_NN sequence (~70 more tests bundled). Single- test bundles still unbundled back to standalone.

One revert: int_overflow_raises was bundled into bundle_misc_c_14 during batch 2, but Makefile's filter-out test/int_overflow_raises.rb under SPINEL_INT_OVERFLOW=promote no longer matched (the bundle file has a different name). Restored int_overflow_raises and the bundled sibling integer_div as standalone tests so the filter keeps working. Tests that are mode-incompatible at the raise level shouldn't be bundled in a way that hides them from mode-aware filters.

Verified: default 447/0/0, promote 446/0/0 (skip 1: int_overflow_raises as designed), optcarrot 59662.

Co-Authored-By: Claude Opus 4.7 [email protected]

Details

Commit
aa69596f090f
Parent
22563be619e8

test/bundle_classd_04.rbaddedView file

1+# Bundled tests:
2+# - instance_eval_return_value
3+# - map_array_block_result
4+# - map_block_returns_nested_array
5+
6+# === instance_eval_return_value ===
7+# instance_eval as an expression: the block's last expression is the
8+# call's value (CRuby semantics). Void-bodied blocks (assignment-only)
9+# fall through to a truthy receiver so `if obj.instance_eval { @f = 1 }`
10+# still works.
11+
12+class T_instance_eval_return_value_Counter
13+ def initialize
14+ @count = 0
15+ end
16+ def inc
17+ @count = @count + 1
18+ end
19+end
20+
21+c = T_instance_eval_return_value_Counter.new
22+c.inc
23+c.inc
24+c.inc
25+
26+# Int-valued block returns the ivar, not the receiver.
27+n = c.instance_eval { @count }
28+puts n # 3
29+
30+# Boolean-valued block.
31+big = c.instance_eval { @count > 2 }
32+puts big # true
33+
34+# Arithmetic expression body.
35+doubled = c.instance_eval { @count + @count }
36+puts doubled # 6
37+
38+# String-valued block (pointer-typed return).
39+class T_instance_eval_return_value_Greeter
40+ def initialize
41+ @greeting = "hello"
42+ end
43+end
44+
45+g = T_instance_eval_return_value_Greeter.new
46+msg = g.instance_eval { @greeting }
47+puts msg # hello
48+
49+# Void body: receiver flows out via comma-expr fallback, keeping the
50+# `if` arm truthy.
51+class T_instance_eval_return_value_Flag
52+ def initialize
53+ @flag = 0
54+ end
55+end
56+
57+f = T_instance_eval_return_value_Flag.new
58+if f.instance_eval { @flag = 1 }
59+ puts "truthy"
60+end
61+
62+puts "done"
63+
64+# === map_array_block_result ===
65+# `arr.map { array_block }` — outer recv is a typed Array, block
66+# returns a typed array (`(0..i).to_a` here is int_array). Without
67+# the fix, two issues conspire:
68+#
69+# - infer_method_name_type returned int_array, so the ivar `@rows`
70+# was typed as int_array. The outer accumulator was an
71+# sp_IntArray pushed via sp_IntArray_push — but each iteration's
72+# value was an sp_IntArray pointer reinterpreted as mrb_int,
73+# which gcc rejects on -Wint-conversion.
74+# - Even if the cast were silent, the inner arrays would not be
75+# traced from an IntArray slot and could be collected mid-loop.
76+#
77+# After the fix, the result is `<elem>_ptr_array` and the codegen
78+# accumulator is an sp_PtrArray pushed via sp_PtrArray_push.
79+
80+class T_map_array_block_result_C
81+ def initialize
82+ @rows = [1, 6].map { |i| (0..i).to_a }
83+ end
84+
85+ def show
86+ @rows.each do |row|
87+ row.each { |x| print x, " " }
88+ puts
89+ end
90+ end
91+end
92+
93+T_map_array_block_result_C.new.show
94+
95+# === map_block_returns_nested_array ===
96+# `Range#map` / `int_array.map` whose block returns an array
97+# (1D, 2D, 3D nested) used to silently degrade — the codegen
98+# returned `0` for non-int/string/float block returns at the
99+# Range#map path, and `int_array.map` boxed inner ptr_array
100+# results via `sp_box_ptr_array(val)` which erased the
101+# elem-type info (cls_id PTR_ARRAY only) so deeper indexing
102+# fell through every dispatch arm to `sp_box_nil()`.
103+#
104+# Fixes:
105+#
106+# - Range#map block returning a typed array now stores in
107+# `sp_PtrArray` (matching the inferred `<bret>_ptr_array`
108+# type). Deeper nesting (block returns ptr_array /
109+# poly_array) stores in `sp_PolyArray` with `box_value_to_poly`
110+# boxing — preserves cls_id chain for `arr[i][j][k]...`.
111+#
112+# - `int_array.map`'s deep-array branch (block returns
113+# `<X>_ptr_array`) converts the inner sp_PtrArray to
114+# sp_PolyArray inline via a per-element `sp_box_<elem>` re-tag,
115+# so the outer PolyArray's elements carry the right cls_id at
116+# the next dispatch level.
117+#
118+# Together this lets nested-map-of-array-block constructs
119+# (e.g. optcarrot's `TILE_LUT = [...].map { (0..7).map {
120+# (0...0x10000).map { ... } }.transpose }`) compile and read
121+# at every depth.
122+
123+# Range#map -> int_array_ptr_array (2D)
124+class T_map_block_returns_nested_array_M2
125+ def initialize
126+ @t = (0..2).map { |i| (0..3).map { |j| i * 10 + j } }
127+ end
128+ def read(i, j); @t[i][j]; end
129+end
130+m2 = T_map_block_returns_nested_array_M2.new
131+puts m2.read(0, 0) # 0
132+puts m2.read(1, 2) # 12
133+puts m2.read(2, 3) # 23
134+
135+# int_array.map { Range#map { ... } } -> 3D via PolyArray
136+class T_map_block_returns_nested_array_M3
137+ def initialize
138+ @t = [10, 20].map do |a|
139+ (0..2).map { |b| [a + b, a + b + 100] }
140+ end
141+ end
142+ def read(i, j, k); @t[i][j][k]; end
143+end
144+m3 = T_map_block_returns_nested_array_M3.new
145+puts m3.read(0, 0, 0) # 10
146+puts m3.read(0, 1, 1) # 111
147+puts m3.read(1, 2, 0) # 22
148+puts m3.read(1, 2, 1) # 122
149+