fix(compiler): keep maybeNaN on the failed edge of ordered comparisons - #141
Open
codeAnqiang-ma wants to merge 1 commit into
Open
fix(compiler): keep maybeNaN on the failed edge of ordered comparisons#141codeAnqiang-ma wants to merge 1 commit into
codeAnqiang-ma wants to merge 1 commit into
Conversation
refine() derived clearNaN from the negated operator, treating the failed edge of a < b as a >= b having held — the two differ exactly when a side is NaN, so guard-clause spellings let NaN be "proven" whole and cross a declared i64/u64 slot as an unchecked (int64_t) / fptosi conversion. Judge NaN exclusion by the relation that actually held on the edge; the numeric interval refinement is unchanged. Co-authored-by: Cursor <cursoragent@cursor.com>
|
@codeAnqiang-ma is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
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.
Fixes #139
What
refine()derived its NaN-exclusion from the negated operator instead of the relation that actually held on the edge:¬(a < b)does not implya >= b— both are false whenais NaN. So on the false edge of<,<=,>,>=the analyzer refined as if the reversed comparison had held and droppedmaybeNaN, which lets the guard-clause spelling"prove" a runtime NaN as an integer in
[0, 100]. The build then succeeds, the sidecar attests the class, and the NaN crosses the C ABI through a bare(int64_t)cast /fptosi— UB in C, poison in LLVM IR, and a platform-dependent value in practice (0on arm64,INT64_MINon x86-64). The function's own doc comment already states the intended rule ("on the failed edge NaN survives while the negated comparison still refines the numeric members"); this change makes the code match it.Fix
One line: derive
clearNaNfrom the relation that actually held on this edge, not its negated spelling —The interval refinement on the failed edge is untouched (it is sound for the non-NaN members); only the NaN bit is preserved.
!==keeps its mirror-image behavior: its failed edge means===held, which does exclude NaN.Regression tests
packages/compiler/src/library/int-infer.test.ts: four new cases in "the domain's edges beyond the corpus" — the guard-clause shape, theelsespelling, au64slot behind failed-edge guards (all REFUSE on wholeness with the NaN teaching; they reportedprovewith fabricated bounds[0, 100]before the fix), and a control pinning that failed edges still refine numeric members to an exact PROVE oncea === aexcludes NaN.tests/harness/library-int.test.ts: one new end-to-end corpus case (nan-survives-failed-guard-edge) driving the real pipeline on both emissions to the SC4022 refusal.Test evidence
With the fix:
With the
int-infer.tsfix stashed and the new tests kept (red check):Not run: the full sandbox gate (
pnpm test:sandbox— no Vercel Sandbox credentials on this machine).This fix was prepared with AI assistance; the author reproduced the bug locally (unit-level and end-to-end through the C ABI) and reviewed every change.