Commit da342dbd

da342dbd2a51Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 88 files · +21 added · -67 deleted

Description

test: second bundle batch via smart bisecting loop

Run a bisecting bundle loop over remaining easy-classified tests (no top-level class/module/def/global, lines <= 80). On chunk failure the loop bisects in half; single-test bundles get unbundled back to standalone (no savings + extra file).

Net: ~30 tests folded into 11 bundle_misc_c_* bundles (each 2-6 tests). Tests left standalone are flagged with codegen edge cases (FrozenError on def-scoped literal mutation, alloc-size warnings on inlined sp_*_grow, poly-typed block-param truthy lowering, etc).

Verified: default 599/0/0, optcarrot checksum 59662.

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

Details

Commit
da342dbd2a51
Parent
61e9421debcc

test/bundle_misc_c_08.rbaddedView file

1+# Bundled tests:
2+# - dig_nested_poly_array
3+# - each_cons_map_chain_fusion
4+# - each_cons_with_index_map_chain_fusion
5+# - env_fetch
6+# - equality_should_be_true
7+# - fiber_storage_assign_expr
8+
9+# === dig_nested_poly_array ===
10+def t_dig_nested_poly_array
11+ # Array#dig walks through nested poly_array elements with int keys.
12+ # Pre-fix emit_dig_step's int-key branch only emitted an arm for
13+ # SP_BUILTIN_INT_STR_HASH; every other receiver kind collapsed the
14+ # accumulator to nil at the next step, so a nested poly_array
15+ # dig surfaced nil instead of the leaf value. Issue #619 puzzle 6.
16+
17+ p [[1, [2, "3"]]].dig(0, 1, 1) == "3" # true (string leaf)
18+ p [[1, [2, "3"]]].dig(0, 0) == 1 # true (int leaf via box_int)
19+ p [[1, [2, "3"]]].dig(0, 1, 0) == 2 # true
20+ p [[1, [2, "3"]]].dig(0, 1, 5).nil? # true (OOB at the last step)
21+end
22+t_dig_nested_poly_array
23+
24+# === each_cons_map_chain_fusion ===
25+def t_each_cons_map_chain_fusion
26+ # Phase A of Enumerator-chain strategy (#566): `arr.each_cons(n)`
27+ # called without a block returns an Enumerator in CRuby. When the
28+ # very next call is a terminal like `.map { |pair| ... }`, the
29+ # Enumerator is consumed immediately and the chain has the same
30+ # observable result as eagerly materialising each window. Spinel
31+ # fuses the source + terminal into a single C loop, so no
32+ # Enumerator object is allocated and no intermediate
33+ # array-of-arrays is built (one window allocation per iteration,
34+ # bounded by .map's accumulator).
35+ #
36+ # The terminal block may take the window as a single param
37+ # (`|pair|`, typed as the receiver's array shape) or destructure
38+ # it (`|(a, b)|`, binds individual locals -- the per-iteration
39+ # window allocation is skipped on this path).
40+
41+ # T1: plain |pair| form, scalar block result
42+ p [1, 2, 3, 4].each_cons(2).map { |pair| pair[0] + pair[1] }
43+
44+ # T2: destructure |(a, b)|, scalar block result
45+ p [10, 20, 30, 40].each_cons(2).map { |(a, b)| b - a }
46+
47+ # T3: |pair| with array-returning block -> result is int_array_ptr_array
48+ p [1, 2, 3].each_cons(2).map { |pair| [pair[0], pair[1]] }
49+
50+ # T4: empty / short receiver (length < n) -> empty result
51+ p [1].each_cons(2).map { |pair| pair[0] }
52+end
53+t_each_cons_map_chain_fusion
54+
55+# === each_cons_with_index_map_chain_fusion ===
56+def t_each_cons_with_index_map_chain_fusion
57+ # Phase A.3 of Enumerator-chain strategy (#566): three-step
58+ # `arr.each_cons(n).with_index(off).map { ... }` chain. CRuby
59+ # returns an Enumerator from each_cons, then another from
60+ # with_index, and consumes both at the terminal .map. Spinel
61+ # fuses the whole chain into a single C loop with an idx counter
62+ # initialised from `off` (default 0) and incremented after each
63+ # pair, so no Enumerator object is allocated.
64+ #
65+ # Block param shapes:
66+ # |pair, i| -- pair is the typed sub-array, i is the int idx
67+ # |(a, b), i| -- nested destructure of pair into individual
68+ # window slots (skips the per-iteration sub-
69+ # array allocation), trailing i as int idx
70+
71+ # T1: |pair, i| with explicit offset
72+ p [10, 20, 30, 40].each_cons(2).with_index(1).map { |pair, i| pair[0] + pair[1] + i }
73+
74+ # T2: |(a, b), i| destructure, explicit offset
75+ p [10, 20, 30, 40].each_cons(2).with_index(1).map { |(a, b), i| b - a + i }
76+
77+ # T3: default offset (0)
78+ p [1, 2, 3].each_cons(2).with_index.map { |pair, i| pair[1] - pair[0] + i }
79+
80+ # T4: block returns array -> result is int_array_ptr_array
81+ p [1, 2, 3, 4].each_cons(2).with_index(1).map { |(a, b), i| [b - a, i] }
82+end
83+t_each_cons_with_index_map_chain_fusion
84+
85+# === env_fetch ===
86+def t_env_fetch
87+ # Regression: `ENV.fetch(key, default)` returns the env value when
88+ # set, otherwise `default`. Pre-fix the codegen emitted "cannot
89+ # resolve call to 'fetch' on int" and segfaulted at runtime.
90+
91+ # ---- unset / default branch ----
92+
93+ # Literal default.
94+ puts ENV.fetch("DEFINITELY_UNSET_VAR_XYZ_42", "fallback-value")
95+
96+ # Default expression need not be a literal.
97+ default = "computed-default"
98+ puts ENV.fetch("ANOTHER_UNSET_VAR_XYZ_42", default)
99+
100+ # Default by string concatenation.
101+ puts ENV.fetch("THIRD_UNSET_VAR_XYZ_42", "pre-" + "fix")
102+
103+ # ---- set / retrieval branch ----
104+ # Spinel doesn't currently expose `ENV[]=` from Ruby, so we can't
105+ # set a var ourselves. HOME is always exported by POSIX `make` and
106+ # in CI, so we use that as the "set" probe. We only assert "non-
107+ # empty + not the fallback string" so the test stays portable
108+ # across runners (the actual home value differs per machine).
109+ # A regression that inverted the getenv-result ternary would
110+ # return the fallback here and print "set=fallback-not-used".
111+ home = ENV.fetch("HOME", "fallback-not-used")
112+ if home.length > 0 && home != "fallback-not-used"
113+ puts "set=ok"
114+ else
115+ puts "set=" + home
116+ end
117+
118+ # Symmetric: an unset var with a literal default round-trips
119+ # through the same ternary. (Would catch a regression that always
120+ # returned the env value -- empty string -- regardless.)
121+ maybe = ENV.fetch("DEFINITELY_UNSET_VAR_ABC_99", "fallback-used")
122+ puts "unset=" + maybe
123+end
124+t_env_fetch
125+
126+# === equality_should_be_true ===
127+def t_equality_should_be_true
128+ # #555 (gurgeous/Adam Doppelt). A corpus of `should be true`
129+ # expressions that compiled to false in spinel pre-fix.
130+ # Each line is an independent equality predicate; CRuby
131+ # returns true for all twelve, and after the followup
132+ # commits spinel matches on all 12.
133+
134+ p ({} == {}) # 01
135+ p ({a: 1} == {a: 1}) # 02
136+ p ({:a= => 1} == {:"a=" => 1}) # 03
137+ p ({:a! => 1} == {:"a!" => 1}) # 04
138+ p ({:a? => 1} == {:"a?" => 1}) # 05
139+ a = [1] ; a.shift ; a << :foo ; p (a == [:foo]) # 06
140+ p ([42, { foo: :bar }].dig(1, :foo) == :bar) # 07
141+ a2 = [1, 2, 3, 4, 5] ; p ((a2[2, 3] = 10) == 10) # 08
142+ p ("hello".chars == ['h', 'e', 'l', 'l', 'o']) # 09
143+ p "abc\r\n".chomp(nil) == "abc\r\n" # 10
144+ p ((/(.)(.)(.)/ =~ "abc") == 0) # 11
145+ p ((1..).send(:include?, 2.4) == true) # 12
146+end
147+t_equality_should_be_true
148+
149+# === fiber_storage_assign_expr ===
150+def t_fiber_storage_assign_expr
151+ # `(Fiber[:k] = v)` as an expression returns the assigned value,
152+ # matching MRI's `(h[k]=v) => v` semantics. The codegen path is
153+ # distinct from the statement form `Fiber[:k] = v` — that lands in
154+ # compile_mutating_call_stmt, while the expression-context dispatch
155+ # emits a gcc statement-expression so the RHS reaches the outer
156+ # assignment.
157+
158+ x = (Fiber[:n] = 42)
159+ puts x # 42 — value of the assignment expression
160+ puts Fiber[:n] # 42 — confirms the write also took effect
161+
162+ # Chained: `Fiber[:a] = Fiber[:b] = 7`. Right-to-left associativity
163+ # makes `Fiber[:b] = 7` evaluate first (yielding 7), then
164+ # `Fiber[:a] = 7`.
165+ Fiber[:a] = Fiber[:b] = 7
166+ puts Fiber[:a]
167+ puts Fiber[:b]
168+end
169+t_fiber_storage_assign_expr
170+