Repository navigation
feat(codegen): a pure arithmetic tree is exact and narrowed only at its root (SPEC-wide-intermediates task 1) - #342
Merged
Merged
Conversation
…ts root (SPEC-wide-intermediates task 1) In a fallible context (a `!` body or a checked copy) an i32 arithmetic tree whose leaves are variables, i32 constants, `len`, or calls to loop-free infallible functions without string arguments is computed in i64 with checked ops and narrowed once, where its value has to become an i32 (DP-W1..W3, W5). A comparison of two pure sides compares exact values (DP-W4); `as f64` narrows first (DP-W6); DP-O9 is restated on exact values (DP-W7). Array reads, calls with `while`, calls with string arguments and `byte_len` keep the per-operator check, so a later -2 never overtakes a real overflow and no call can hang where today fails first. Infallible bodies, the fingerprint, the ABI and the bindings are unchanged (DP-W8, DP-W10). Oracle: wide_intermediates.rs (acceptance A-E and the extraction price). Two existing pins moved with the rule: checked_arithmetic mid (2^30 now answers) and helper_check_propagation big (the product is now stored in a let, so it still narrows). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
… and index; emit_exact takes its bail Grok verify (unasked lines): LANGUAGE.md names `len` as a leaf and assignment, argument and index as narrowing points, and the oracle asserted none of them. emit_exact computed its own bail with unwrap_or_default, an empty arm that was unreachable only because emit_wide checks first; the bail is now passed in, so there is no default to reach. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Owner
Author
🔵 SCAManager 분석 결과총점: 89/100 (등급 B) 점수 상세
|
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.
What
SPEC-wide-intermediates§6 task 1 (DP-W1–W11, user-confirmed 2026-09-27). In a fallible context — a!body or a checked copy — an i32 arithmetic tree whose leaves are variables, i32 constants,len, or calls to loop-free infallible functions without string arguments is computed in i64 with checked ops and narrowed once, where its value has to become an i32 (let, assignment, argument, index,as f64,return, an impure parent). A comparison of two pure sides compares exact values.ir::loop_free_functions— infallible functions with nowhileanywhere they reach (DP-W2).codegen::{is_pure, is_leaf_argument, emit_exact, emit_wide}— exhaustive matches (the crate denies wildcard arms).-2would overtake a real overflow), calls withwhile(hang), calls with string args andbyte_len(bounded only by the host's NUL contract). Those operators keep today's per-operator check.generated.rs.txtmoves.checked_arithmeticmid(2^30 now answers) andhelper_check_propagationbig(product now stored in alet, so it still narrows).Docs:
LANGUAGE.md(the rule, DP-O9 restated, the extraction price, the D19 C-backend note),HOST_ABI.md, SPEC status → 확정·구현 중 plus §2.6 helper-returnprice, index row, STATUS ▶ 1.Evidence (E2)
wide_intermediates.rs, 7 tests: A (exact /-3/ i64 bound /x/0 = 0/lenleaf / narrowing at assignment, argument, index), B (ordering-3/-2/-2, call leaves incl.byte_len), C (no hang, 10 s thread deadline), D (comparison,as f64, literals, domain fail), E (infallible wraps, checked copy widens), and the price (x*x/x= 46341;letandsq(x)/x→-3).MATHLESS_GATE_D/FPC/FPC_HOST=require): 704 passed, 0 failed on 7c2fe4e and again on the head 10fe91f.--no-fail-fast), each caught by the test meant for it:idx_after−2 ≠ −3whilecalls admittedcall_while(0 ≠ −3) + C deadlinecall_strbyte_lenas a leafdirect_blenas i32instead oftry_fromquot_div+checked_arithmeticcmpas f64widenedtof_overplain(100000 ≠ 14100)lennot a leaflen_leafNarrowing at assignment / argument / index: probe under
main's codegen gives-3for all three, head gives the exact values.Grok verify (single claims, REVIEW ONLY)
is_pureleaf set — CONFIRMED;is_leaf_argumentstring rule — CONFIRMED;emit_exactorder / zero divisor / wrapping_rem / checked ops — CONFIRMED;emit_wideinfallible no-op + root narrowing + comparison gate — CONFIRMED; bail threading after refactor — CONFIRMED; LANGUAGE values ↔ oracle asserts — CONFIRMED.loop_free_functions— DISCREPANCY in my prompt (I wrote that onlyIfnests statements;Whiledoes too, andhas_whilereturns true on it) — the code was confirmed.len/assignment/argument/index pins → added;emit_exact'sunwrap_or_defaultbail → removed (bail passed in);rhs.tyunchecked in the comparison gate → typeck gives both sides one type (comment added);Lenignores an operand →Lenhas none (ir.rs279);ConstStrnon-Str type → cannot occur.Task 2 (real C host on an existing example, 626-row re-measure, slice close) follows in a separate PR.
🤖 Generated with Claude Code