Skip to content

feat(codegen): i32 arithmetic in a fallible body fails with ML_ST_OVERFLOW (-3) instead of wrapping - #334

Merged
xzawed merged 2 commits into
mainfrom
feat/checked-arithmetic
Sep 26, 2026
Merged

xzawed merged 2 commits into
mainfrom
feat/checked-arithmetic

Conversation

@xzawed

@xzawed xzawed commented Sep 26, 2026

Copy link
Copy Markdown
Owner

SPEC-checked-arithmetic §6 작업 1. DP-O1~O9 사용자 확인(2026-09-26). 관련: D17(음수 status 예약), D18(ABI 버전 — 불변).

무엇이 바뀌나

실패 가능 본문(-> T! · -> string! · -> [T]!) 안에서:

연산 ! 본문 무한 함수
i32 + - *, 단항 - 넘치면 ML_ST_OVERFLOW = -3 wrap(그대로)
i32::MIN / -1 -3 wrap
x / 0, x % 0, i32::MIN % -1 0(DP-N4, DP-O5) 0
f64 as i32 NaN · 절단 뒤 i32 밖이면 -3 절단 + 포화, NaN→0
  • 무한 헬퍼가 탈출구다(DP-O7). 리터럴만의 오버플로는 실행 시 -3(DP-O9).
  • .h/.pas는 한 술어(ir::can_fail_overflow, 실패 가능 함수만)로 낼 수 있는 모듈에만 ML_ST_OVERFLOW를 선언한다.
  • 지문·ABI 버전 불변(DP-O4) — 골든에서 IFACE_HASH 줄은 하나도 움직이지 않았다.
  • 머지 순간 거짓이 되는 문서를 같은 PR에서 고쳤다: LANGUAGE.md(wrap·나눗셈·변환·공백 블록), HOST_ABI.md(status 표·현재 경계·재시도), STATUS.md §5-4와 시작 블록, 두 README, SPEC 상태, 슬라이스 색인. 그래서 오라클 값 테스트도 작업 2에서 이쪽으로 옮겼다(SPEC §6에 적음).

근거 (E2)

  • 전체 게이트 MATHLESS_GATE_D=require MATHLESS_GATE_FPC=require MATHLESS_GATE_FPC_HOST=require cargo test --workspace --locked — exit 0, 79개 바이너리 전부 ok, 건너뜀 없음. 골든 재생성 뒤 생성 헤더를 cl /W4 /WX·FPC가 컴파일한다.
  • 오라클 값(hosts/rust-oracle/tests/checked_arithmetic.rs, 7개): 연산마다 경계 양쪽, MIN % -1 = 0, f64 as i32의 NaN·±inf·3e9, string!·[T]! 모양, result 뒤 재호출도 -3, 무한 본문은 wrap, 리터럴, 헬퍼, 중간값 오버플로.
  • 결함 심기 6/6 적발(커밋된 트리에서): 체크드 + - * 끄기 → 골든 + 오라클 4 · checked_neg 끄기 → 오라클 · %에 checked_rem 의미 → 골든 + 오라클 · 변환 상한 1 줄이기 → 오라클 · 술어에서 + - * 빼기 → 바인딩 행렬 + 표 + 골든 2 · 술어가 무한 본문도 보기 → 표 + 골든 2.
  • doc_claims 50/50, language_gaps, fmt, clippy -D warnings.

Grok 2차 검증 (한 번에 주장 하나, 6회 — 전부 CONFIRMED)

  1. + - *·단항 - 방출이 모양별 bail · 무한 본문 wrap
  2. /의 MIN/-1 bail, 피연산자 왼쪽부터, %는 템플릿 그대로
  3. 변환 구간 (-2147483649, 2147483648) = 절단이 i32에 드는 집합, NaN·inf 포함
  4. 술어가 codegen의 네 자리를 과소 보고하지 않는다(IR 전 변형 방문)
  5. .h·.pas 선언이 한 술어·abi.rs 상수
  6. LANGUAGE.md가 적은 값이 오라클 테스트에 단언돼 있다 — UNASKED 줄이 빈틈 하나를 찾았다: "중간값만 넘쳐도 실패" 문장에 측정이 없었다 → an_intermediate_overflow_fails_even_when_the_answer_fits 추가(df6506b).

남은 것 (작업 2, 별도 PR)

실제 C 호스트가 -3을 받는 수용 D · §9-69의 161행 재측정 · 크기 변화 · 슬라이스 닫기.

🤖 Generated with Claude Code

xzawed and others added 2 commits September 26, 2026 14:36
…RFLOW instead of wrapping

SPEC-checked-arithmetic §6 task 1 (DP-O1..O9, user-confirmed 2026-09-26).

In a fallible body (`-> T!`, `-> string!`, `-> [T]!`) i32 `+ - *`, unary `-`,
`i32::MIN / -1`, and `f64 as i32` of NaN or a value that truncates outside i32
return the new reserved status ML_ST_OVERFLOW = -3. `%` keeps wrapping_rem
(DP-O5: MIN % -1 = 0 exists). Infallible bodies keep wrapping and saturating;
an infallible helper is the escape hatch (DP-O7). Literal-only overflow fails
at run time (DP-O9). Fingerprints and the ABI version are unchanged (DP-O4) —
no IFACE_HASH line moved in the goldens.

The .h and .pas declare ML_ST_OVERFLOW from one predicate, ir::can_fail_overflow,
only for modules with a fallible body that can reach it; the binding matrix in
bindings.rs gains the row and column.

Docs that this makes false are fixed in the same change: LANGUAGE.md (wrap,
division, conversion, gap block), HOST_ABI.md (status table, current boundary,
retry note), STATUS §5-4 and the start block, both READMEs, the SPEC status
and the slice index. Oracle value tests moved into this PR for that reason.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…price LANGUAGE.md names, measured

Grok verify (docs vs tests) noted the sentence had no input and no assert.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@xzawed

xzawed commented Sep 26, 2026

Copy link
Copy Markdown
Owner Author

⚠️ AI 리뷰가 완전 검증되지 않음 — 기본값이 적용됐습니다(비활성/API 키 없음/빈 diff). AI 배점은 측정값이 아니므로 총점을 부분 점수로 보세요.
ℹ️ 범용 검사기만 본 언어 포함: rust — 이 배포에서 해당 언어의 전담 분석기가 하나도 실행되지 않아, 다언어 범용 분석기 하나에만 기대었습니다. 그 규칙 밀도는 언어마다 편차가 큽니다 — 여기서의 만점은 "깨끗함" 이 아니라 "거의 검사 안 됨" 입니다 — AI 리뷰와 수동 검토로 보완하세요.

🔵 SCAManager 분석 결과

총점: 89/100 (등급 B)

점수 상세

항목 점수 만점
커밋 메시지 13 15
코드 품질 25 25
보안 20 20
구현 방향성 (AI) 21 25
테스트 10 15

@xzawed
xzawed merged commit 04da06d into main Sep 26, 2026
2 checks passed
@xzawed
xzawed deleted the feat/checked-arithmetic branch September 26, 2026 06:00
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