Skip to content

fix(ir): validate identities and literals with distinct boolean types - #213

Merged
LunaStev merged 2 commits into
wavefnd:masterfrom
LunaStev:fix/ir-validation-foundation
Sep 23, 2026
Merged

LunaStev merged 2 commits into
wavefnd:masterfrom
LunaStev:fix/ir-validation-foundation

Conversation

@LunaStev

Copy link
Copy Markdown
Member

Malformed modules can currently pass verification with duplicate IDs, inconsistent type metadata, or constants outside their declared type. AST lowering also accepts duplicate function/parameter names, silently wraps oversized integer literals, and discards expressions returned from void functions. This change rejects those inputs and separates boolean values from one-bit integers.

IR behavior

  • Give booleans their own Type::Bool / bool representation. Type::I1 is a signed one-bit integer (-1 or 0), and Type::U1 is an unsigned one-bit integer (0 or 1). Ordinary integer literals with value 1 remain supported in their respective ranges.
  • Return bool from comparisons and use it in checked-arithmetic result tuples. Branch, select, and trap conditions require bool; integers are not implicitly converted.
  • Reject duplicate block/value IDs and duplicate, missing, contradictory, or orphan value-type entries. Validate derived instruction result types against the metadata table.
  • Validate constant categories and signed/unsigned ranges, including global initializers. Global alignment must be an explicit nonzero power of two; alignment 0 is not an automatic-layout marker in completed IR.
  • Share literal range validation between function expressions and constant initializers. Invalid typed literals are diagnosed before wrapping can change their value. Existing arithmetic evaluation in required constant initializers is preserved.
  • Keep function and global variable namespaces separate, as agreed in the design discussion: a function and global with the same name are valid, while duplicates within either namespace are rejected by lowering and direct module verification.
  • Reject duplicate parameter names before lowering bodies, and reject value-bearing returns from void functions.

Compatibility: callers previously using Type::I1 for booleans must migrate to Type::Bool. Printed boolean types change from i1 to bool; the frontend JSON Bool representation is unchanged.

Repository changes

Refresh README with accurate capability descriptions, standalone assembly/IR examples, contributor links, and sponsorship information. Remove the three tracked docs/ files and ignore /docs/ as requested; local documentation remains on disk and the new local design notes are not included in this PR.

IR changes and the README/document-tracking changes are separate signed-off commits.

Validation

Executed locally on Linux with Rust/Cargo 1.96.0:

  • cargo test --workspace --locked --offline: 56 passed.
  • cargo test --workspace --all-features --locked --offline: 70 passed.
  • cargo test -p ir --all-features --release --locked --offline: 35 passed.
  • Strict workspace Clippy with all targets, in both default and all-features configurations.
  • cargo fmt --all -- --check, warning-free workspace rustdoc, and git diff --check.
  • Standalone CLI smoke checks with socket support enabled and disabled.
  • README assembly, JSON lowering, and raw-byte object examples executed with the existing debug binary; JSON syntax and local README links checked.

New identity regressions failed against the original verifier before the fix. Regression coverage includes separate namespaces, bool/i1/u1 distinctions, scalar constant boundaries, explicit global alignment, malformed metadata, parameter bindings, void returns, and retaining runtime 1 + 2 as constants plus an add instruction in O0 IR.

SSA dominance/phi validation, complete instruction type verification, pointer safety, target ABI layout, and the broader arithmetic/optimization contracts remain separate work. This PR does not claim complete UB-free execution or a finished O0 pipeline.

Fixes #46
Fixes #47
Fixes #48
Fixes #49
Fixes #140
Fixes #141
Fixes #144

Signed-off-by: LunaStev <luna@lunastev.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation ir Intermediate representation, builders, verification and lowering.

Projects

None yet

1 participant