fix: preserve boolean checks through TCO#817
Merged
stephenamar-db merged 1 commit intodatabricks:masterfrom May 1, 2026
Merged
fix: preserve boolean checks through TCO#817stephenamar-db merged 1 commit intodatabricks:masterfrom
stephenamar-db merged 1 commit intodatabricks:masterfrom
Conversation
8afc6d3 to
711e0e6
Compare
Motivation: The straightforward fix would be to resolve a TailCall inside visitAndRhsTailPos/visitOrRhsTailPos and then call asBoolean. That path was intentionally avoided: nested resolution re-enters the trampoline from inside the current function body, can restore stack growth for deep &&/|| chains, and can move the lazy evaluation boundary. We still need recursive TailCall rhs values to obey normal boolean operator result checks. Modification: Carry &&/|| result validation as delayed TailCall state and apply it only when the outer TailCall.resolve loop produces the final value. Keep auto-TCO arguments under TailstrictModeAutoTCO and add non-boolean TailCall rhs regression tests for both && and ||. Result: Deep boolean auto-TCO chains remain stack-safe and lazy, while recursive rhs values that resolve to non-booleans now report the same type errors as direct true && 0 / false || 0 expressions. Risk: The main risk is accidentally replacing this with immediate nested resolution later. Code comments now document why the delayed check lives on TailCall instead of resolving inside the &&/|| helpers. Error-value tail propagation is intentionally left as-is in this PR; the existing directional fixture is restored but remains a non-asserted coverage gap for a follow-up.
711e0e6 to
aeb1ec4
Compare
stephenamar-db
approved these changes
May 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Recursive calls in tail-position
&&/||rhs can return through the TailCall trampoline. Before this change, direct non-boolean rhs values were rejected, but non-boolean values produced after resolving a TailCall could skip the normal boolean operator result check.The obvious fix would be to call
TailCall.resolve(tc).asBooleaninsidevisitAndRhsTailPos/visitOrRhsTailPos. That path is intentionally avoided: nested resolution re-enters the trampoline from inside the current function body, can restore stack growth for deep&&/||chains, and can move the lazy evaluation boundary.Modification
&&/||result validation as delayedTailCallstate and apply it only when the outerTailCall.resolveloop produces the final value.TailstrictModeAutoTCO; the helper only attaches a delayed check and does not force nested TailCalls.&&and||.Result
errorarguments through both&&and||still stay unevaluated.true && 0/false || 0expressions.Verification:
./mill -i __.test(SUCCESS, 176s)./mill -i __.checkFormat(SUCCESS, 6s)git diff --checkRisk
The main risk is that a future cleanup replaces the delayed check with immediate nested TailCall resolution. This PR documents the reason in code comments near both the
&&/||tail helpers andTailCall.BooleanCheck.Error-value tail propagation is intentionally left as-is in this PR. The existing
auto_tco_directional.jsonnetfixture entry is restored, but it is not asserted today; real coverage for that path should be handled in a follow-up so this PR stays focused on boolean operator correctness.