Commit 656e4490
656e4490896eMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 8 files · +2 added · ~6 modified
Description
Auto-promote block-loop accumulators to bigint in promote mode
--int-overflow=promote only avoided overflow when the analyzer could
prove a local grows without bound, and that detection
(infer_bigint_loop_locals) scanned while/until bodies only. A
factorial written the idiomatic way -- f = 1; n.times { f *= i } --
therefore still overflowed and raised, even though promote mode is
exactly the mode asking us not to.
Extend the same self-referential-multiply detection to block-iteration
loops (times/each/upto/downto/step/loop/each_with_index),
gated on a new g_promote_mode flag set from main.c. The default and
wrap paths stay while-only, so the gates and the wrap-pinned optcarrot
see no change (a block-loop bigint widening would wreck optcarrot's hot
.times { x = x * y } inner loops -- the original reason the detection
was while-only).
Also fix a latent bug this exposed: emit_op_assign's captured-cell path
was int-only, so n.times { h *= 3 } with a now-bigint h ran
sp_int_mul on the bigint cell and silently truncated. Route bigint cells
through the bigint helpers.
Wire the Makefile promote test mode to actually pass --int-overflow=promote to the front-end and -DSP_INT_OVERFLOW_MODE_PROMOTE to cc (it previously only filtered the test list), and add a promote-only regression test (filtered out of raise/wrap runs, where it would correctly raise).
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 656e4490896e
- Parent
- 7b31ed9d93d5
MakefilemodifiedView file
# --int-overflow=promote the same code auto-promotes and output diverges.ifeq ($(SPINEL_INT_OVERFLOW),promote)TESTS := $(filter-out test/int_overflow_raises.rb,$(TESTS))# Drive the spinel front-end and the C compile in promote mode so the test# rule actually exercises the auto-promotion path end to end.SP_OV_FLAG := --int-overflow=promoteSP_OV_DEFINE := -DSP_INT_OVERFLOW_MODE_PROMOTEelse# `promote_*` tests overflow on purpose and only have defined output under# --int-overflow=promote; in raise/wrap mode they would (correctly) raise.TESTS := $(filter-out test/promote_%.rb,$(TESTS))endif# sp_net is POSIX-only; on Windows the TU compiles to stubs and the smoke# test's output diverges. Skip it there. args=""; \ if [ -f "$<.args" ]; then args=$$(cat "$<.args"); fi; \ $(SPINEL) "$<" -c --no-line-map -o "$$cfile" 2>/dev/null && \ $(CC) $(CFLAGS) -Werror $(TEST_WARN_SUPPRESS) $(SEC_FLAGS) -Ilib "$$cfile" $(SP_RT_LIB) $(LDFLAGS) -lm $(GC_FLAGS) -o "$$bin" 2>/dev/null; \ $(SPINEL) "$<" $(SP_OV_FLAG) -c --no-line-map -o "$$cfile" 2>/dev/null && \ $(CC) $(CFLAGS) $(SP_OV_DEFINE) -Werror $(TEST_WARN_SUPPRESS) $(SEC_FLAGS) -Ilib "$$cfile" $(SP_RT_LIB) $(LDFLAGS) -lm $(GC_FLAGS) -o "$$bin" 2>/dev/null; \ if [ $$? -eq 0 ]; then \ if [ -f "$<.expected" ]; then \ LC_ALL=C sed 's/\r$$//' "$<.expected" >"$$exp.n"; \src/analyze.cmodifiedView file
Loading diff…
src/analyze.hmodifiedView file
Loading diff…
src/analyze_pass.cmodifiedView file
Loading diff…
src/codegen_stmt.cmodifiedView file
Loading diff…
src/main.cmodifiedView file
Loading diff…
test/promote_block_loop_bigint.rbaddedView file
Loading diff…
test/promote_block_loop_bigint.rb.expectedaddedView file
Loading diff…