Skip to content

feat(ir): read format 3 text and bound verification resources - #241

Merged
LunaStev merged 2 commits into
wavefnd:masterfrom
LunaStev:feat/ir-reader-and-bounded-verification
Oct 7, 2026
Merged

LunaStev merged 2 commits into
wavefnd:masterfrom
LunaStev:feat/ir-reader-and-bounded-verification

Conversation

@LunaStev

@LunaStev LunaStev commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Typed IR printed by Wave and Whale could not be read back, and deeply nested Rust IR inputs could abort their host during verification. This change adds a verified format 3 reader and bounds the type/signature and constant-expression paths used by direct frontend integrations.

Reader and CLI

  • Add parse_module / parse_module_with_limits, located ParseError diagnostics, a bounded UTF-8 lexer and strict typed syntax. Require IR format 3 / semantics version 1; reject unsupported versions, unknown fields/opcodes/escapes, conflicting annotations, invalid literals and trailing input. Semantic verification remains mandatory.
  • Read every current printer instruction and terminator form: scalar/checked arithmetic, comparisons, casts, phi/select, typed memory/GEP, constant declarations, function addresses, direct/indirect calls and traps. Preserve module/function scoped IDs, gaps, quoted names, explicit entry, physical block order, alignment, signatures, external link names, typed expression trees/cached results and exact integer/IEEE payloads. Whitespace and // comments canonicalize.
  • Make whale ir verify input.wir and whale ir print input.wir [-o output.wir] available in the default build. AST format 2 lower still requires socket-cli. Keep target rejection before input reads, feature recovery status, and atomic output/input-alias protection. Invalid options now fail explicitly; remove advertised flags that never did anything.
  • Keep the parser module private and expose its API at the crate root: publicly exporting parser conflicted with Wave's existing parser crate when importing whale_ir::*.

Verification limits

IrLimits defaults to 8 MiB input, 1,000,000 tokens/traversal nodes and type/constant depths of 128 (root 0). Depths can be lowered or raised through 256; larger configurations return a structured error. Iterative preflight covers all module type annotations and expressions before recursive cloning/equality/diagnostics. Signature validation and constant evaluation use explicit work stacks. Checked declaration and null-function APIs dispose of rejected owned signatures iteratively; callee signatures are checked before cloning.

Expose limit-aware verification, constant evaluation, signature validation and checked declaration APIs. Preserve wrapping arithmetic, exact stored float results, left-to-right references, dependency resolution and cycle diagnostics. Budgets count work at each boundary, not elapsed time or all allocations. Borrowed Rust trees remain caller-owned; arbitrary unverified clone/Drop and legacy unchecked construction APIs are outside this protection.

The reader retains legacy undef for existing lowering compatibility. This does not complete initialization tracking (#65), runtime trap enforcement, pointer shadow metadata, an interpreter or native code generation. AST JSON remains format 2; text format 2 needs explicit migration, and future incompatible syntax/semantics requires a corresponding version change.

Validation

All 23 registered GitHub CI checks passed on 32f1442, including Windows x64/ARM64 default/all, Linux/macOS, Rust 1.86, optimized regressions, RISC-V QEMU, coverage and Wave ELF. Documentation PR #480 has all four checks passing. Both PRs remain open for review.

  • Workspace offline tests: 160 default, 195 all-features passed.
  • Clippy both feature configurations, fmt, diff, public crate rustdoc and eight Python CI helper tests passed.
  • Rust 1.86 all-features workspace check and the 11 parser/resource regression tests passed.
  • Both standalone empty-PATH CLI smoke modes passed; fixtures use explicit LF on every platform and CRLF input canonicalization has a reader regression; the smoke now exercises text verify/print and rejection/output preservation on every CI platform.
  • Subprocess regressions reject 50,000-level pointer/aggregate/nested function-pointer types and left/right expressions without abort, excluding caller tree destruction; checked owned-signature cleanup and hostile resolver types are also tested. Boundary/ceiling/wide-work cases preserve numeric/reference semantics.
  • All printed scalar opcodes, predicates and casts, memory and calls, sparse/scoped identities, Unicode escapes, u128/i128 extrema, float NaN/signed-zero payloads, malformed/truncated/mutated input and atomic CLI output are covered.
  • Copied Wave's current frontend/HIR/Whale adapter into a temporary workspace (revision 13a406d0), changing only that copy's IR dependency. Real loop/if/short-circuit/call and cast programs produce byte-identical print-parse-print fixtures. The Wave checkout was not edited; tests need no Wave checkout, LLVM or external assembler.

Official reference/CLI/support-status documentation is in wavefnd/wave-platform#480, with executable IR/Rust examples and all nine existing locales. Merge the implementation before that documentation PR. No automatic merge or deployment.

Closes #238
Closes #239
Closes #83

@LunaStev
LunaStev merged commit 020d2a4 into wavefnd:master Oct 7, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant