Skip to content

Fix: Last step of convergence loop can report false failure - #458

Closed
aqk wants to merge 2 commits into
20260217-introspective-constantsfrom
fix-convergence-test
Closed

aqk wants to merge 2 commits into
20260217-introspective-constantsfrom
fix-convergence-test

Conversation

@aqk

@aqk aqk commented Apr 28, 2026 •

Copy link
Copy Markdown
Contributor

The convergence loop exits when either prev_repr == this_repr (success) or steps >= CONSTANT_GENERATIONS_ALLOWED (failure). The post-loop check if steps == CONSTANT_GENERATIONS_ALLOWED cannot distinguish those two cases when convergence actually happens on the very last allowed iteration, and will incorrectly raise "Constant generation didn't converge in allowed iteration limit" for a program that did in fact converge.

Changes Made
Made the limit configurable (src/compiler/comptypes.rs, src/compiler/compiler.rs): Added constant_generation_limit() / set_constant_generation_limit() to CompilerOpts, DefaultCompilerOpts, and the delegation trait. This allows tests to exercise the boundary condition with small limits.

Wrote a regression test (src/tests/compiler/modules.rs): test_convergence_loop_boundary_does_not_false_positive sets the limit to 1 and compiles a module that converges in one iteration, directly triggering the false-positive error.

Fixed the check (src/compiler/codegen.rs): Changed from if steps == generation_limit to if prev_repr != this_repr, which directly tests whether convergence actually happened regardless of step count.


Note

Medium Risk
Touches the module constant-generation convergence loop and compiler option plumbing; while the behavioral change is small, it affects core codegen termination/error conditions for module compilation.

Overview
Fixes a boundary-condition in the module constant-generation convergence loop so compilation no longer errors when convergence happens on the last allowed iteration (post-loop check now verifies prev_repr != this_repr rather than relying on the step counter).

Makes the convergence iteration limit configurable via CompilerOpts (constant_generation_limit + setter), wires it through DefaultCompilerOpts, and adds a regression test that sets the limit to 1 to exercise the failing edge case.

Reviewed by Cursor Bugbot for commit 8e62882. Bugbot is set up for automated code reviews on this repo. Configure here.

aqk added 2 commits April 28, 2026 11:28
The convergence loop exits when either prev_repr == this_repr (success) or steps >= CONSTANT_GENERATIONS_ALLOWED (failure). The post-loop check if steps == CONSTANT_GENERATIONS_ALLOWED cannot distinguish those two cases when convergence actually happens on the very last allowed iteration, and will incorrectly raise "Constant generation didn't converge in allowed iteration limit" for a program that did in fact converge.

Changes Made
Made the limit configurable (src/compiler/comptypes.rs, src/compiler/compiler.rs): Added constant_generation_limit() / set_constant_generation_limit() to CompilerOpts, DefaultCompilerOpts, and the delegation trait. This allows tests to exercise the boundary condition with small limits.

Wrote a regression test (src/tests/compiler/modules.rs): test_convergence_loop_boundary_does_not_false_positive sets the limit to 1 and compiles a module that converges in one iteration, directly triggering the false-positive error.

Fixed the check (src/compiler/codegen.rs): Changed from if steps == generation_limit to if prev_repr != this_repr, which directly tests whether convergence actually happened regardless of step count.
@aqk

aqk commented Apr 28, 2026

Copy link
Copy Markdown
Contributor Author

We will make a smaller, more focused PR

@aqk aqk closed this Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant