Skip to content

feat(toolchain): harden inputs and add integer lowering and interpreted calls - #293

Merged
LunaStev merged 8 commits into
wavefnd:masterfrom
LunaStev:feat/toolchain-correctness-and-execution
Oct 12, 2026
Merged

LunaStev merged 8 commits into
wavefnd:masterfrom
LunaStev:feat/toolchain-correctness-and-execution

Conversation

@LunaStev

@LunaStev LunaStev commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Summary

Malformed assembly could be accepted, public Rust inputs could abort before resource checks, and valid IR calls could not execute. This series rejects malformed input with preserved artifacts, bounds public construction/serialization work, expands integer frontend and AMD64 instruction support, and executes direct/indirect Whale calls with tracked pointer identity and shared limits.

The requested delivery is one PR containing exactly eight signed commits covering 40 issues, in the following order. Each batch has focused regressions; the final combined tree is tested in both feature configurations, at MSRV, and in release mode.

Batch Commit Scope Issues
1 00a5195 Assembler parsing and token coordinates #132, #133, #134, #135, #137, #138
2 4c5557d CLI I/O and bootstrap publication #15, #139, #248, #249, #250
3 b5d0eb1 Assembler allocation, globals and relaxation #33, #34, #42
4 aae8209 Checked public APIs and ELF preflight #55, #244, #245, #246, #247
5 bf712f1 Verification and relocation scaling #251, #252, #253, #288
6 5061bde Lazy Bool and typed integer frontend operators #151, #152, #153, #154
7 e0d0a61 AMD64 scalar instruction forms #40, #127, #92, #195, #196, #197, #275, #276, #280
8 a393c65 Bounded direct/indirect calls and pointer identity #254, #255, #256, #257

Motivation and resulting behavior

  • Parsing: reject missing operands, bad separators and adjacent statements while preserving label-plus-instruction and explicit empty-string data. CR/LF/CRLF coordinate tracking and UTF-8 byte offsets are consistent.
  • CLI and publication: version comes from package metadata; non-UTF-8 arguments fail normally before I/O. Assembly/raw-object input uses adjustable streaming byte limits. IR BrokenPipe exits normally, other stdout failures are diagnostics, and bootstrap archiver failure preserves the prior archive.
  • Assembler correctness: configurable materialized-output and relaxation budgets reject before oversized allocations or stale branch bytes. BSS remains logical. Undefined globals fail; forward definitions and declared externals remain valid. Branch targets are independently decoded in cascading and boundary fixtures.
  • Public APIs: checked builder operations reject invalid IDs/order without mutation; legacy convenience operations remain explicit. Safe layout depth, iterative AST inspection/disposal and bounded JSON output guard direct Rust inputs. ELF preflight includes names, synthesized symbols, tables and alignment before payload copying. Shared in-memory validation runs at symbol resolution.
  • Performance: reuse one borrowed SSA type index per function, dominator-tree interval queries and a shared analysis-work budget. Globals use a read-only constant overlay; ELF relocations are grouped in one pass without reordering entries.
  • Frontend expressions: lower bitwise/not, signed/unsigned division/remainder, shifts and Bool short-circuit logic in runtime and preserved constant forms. MIN/-1 wraps; counts use the complete unsigned bit pattern modulo width. Skipped RHS trees remain present and statically validated. A combined frontend/call regression checks exactly-once execution and shared fuel.
  • AMD64: add SPL/BPL/SIL/DIL, LEA, standard Jcc/aliases, scalar shifts, DIV/IDIV, CWD/CDQ/CQO, NOT/NEG, TEST and immediate IMUL. Exact-byte fixtures cover widths, immediates, extended registers and high-byte/REX legality; LEA fixtures also have independent disassembly.
  • Calls: use an explicit invocation stack, shared fuel/memory and depth/frame/live-value budgets. Caller-owned pointer authority survives calls; returned local pointers expire. Function pointers preserve full signature/convention through movement, storage and split copies, and checked public values retain their originating module. Raw bits cannot acquire callable authority; unsupported reachable callees are rejected before effects.

Target and compatibility impact

  • Canonical AST JSON is format 3 and typed IR is format 5, semantics version 1. AST 2 and IR 3/4 remain readable for existing syntax; new operators require the new version. Both AST schemas are retained.
  • AstLimits defaults to a safe 32-level nesting ceiling; oversized owned ASTs are disposed iteratively. Assembly output defaults to 64 MiB; CLI input defaults are 8 MiB for assembly and 256 MiB for raw objects, configurable with --max-input N.
  • IrLimits adds a shared 16,777,216-unit analysis budget. InterpreterOptions adds call depth (256), total frame (100,000) and simultaneously reserved SSA-slot (1,000,000) limits. Explicit struct initializers may need the new fields or ..Default::default().
  • New checked builder, AST-limit, verification-statistics and runtime-value APIs are documented. The scalar interpreter/CLI remains available; checked pointer/callable values use the library runtime API.
  • The output target remains AMD64 ELF64. This PR adds neither a complete native IR backend nor executable linking. Floating execution, external/SysV execution, aggregate values, native pointer shadowing and other targets remain outside these scoped issues.

Validation

Final head a393c65cd48689e5a36e0fa301ea3050174ad5e7, Linux x86_64, Rust 1.96.0 and MSRV 1.86.0. Cargo used --locked --offline, separate target directories and CARGO_INCREMENTAL=0 for final checks.

  • cargo test --workspace --locked --offline: 248 passed.
  • cargo test --workspace --all-features --locked --offline: 303 passed.
  • cargo +1.86.0 test --workspace --all-features --locked --offline: 303 passed.
  • cargo test --workspace --all-features --release --locked --offline: 303 passed.
  • Workspace cargo clippy --all-targets [--all-features] --locked --offline -- -D warnings: both configurations passed.
  • Default/all-feature workspace builds and matching empty-PATH tools/ci_smoke.py: passed sequentially.
  • python3 -m unittest discover -s tools -p 'test_*.py': 15 passed; bootstrap tests use fake build stages and require no Wave/LLVM installation.
  • RUSTDOCFLAGS='-D warnings' cargo doc --workspace --all-features --no-deps --locked --offline, cargo fmt --all -- --check, git diff --check: passed.
  • Both AST schemas pass Draft 2020-12 schema validation and representative call-fixture validation.
  • Two ignored scaling probes were run explicitly in the performance batch; normal suites do not use wall-clock assertions. SSA/CFG work counts scale linearly in chain fixtures.
  • Independent temporary probes checked 3,920 CFG cases against a dominator-set oracle, 150 ELF objects at exact output-budget boundaries, and 2,016 integer cases comparing preserved constant and executable IR results. Capped child regressions cover deep types/ASTs and oversized symbol names.
  • Contemporaneous standalone debug verification probes at the performance commit observed 8k Mov 218.869 → 39.668 ms, 8k CFG 350.073 → 50.807 ms, and 1k globals/functions 108.830 → 35.164 ms (median of three after warmup, Ryzen 5 2600X). These are local observations, not timing gates or guaranteed speedups.

Windows/macOS/emulated host checks, coverage and the optional Wave-record bootstrap were not rerun locally; the registered CI workflows handle those paths. Initial CI passed all 19 non-macOS checks; four macOS checks identified APFS rejection of the raw-byte test filename. Batch 2 now accommodates that fixture-creation failure while still exercising every CLI rejection and preservation assertion. The focused CLI suite (5 tests), Clippy and formatting passed after this test-only correction. All 23 GitHub CI checks now pass at the head above, including native Linux/macOS/Windows on x64 and ARM64, MSRV, release regressions, coverage, RISC-V/QEMU and Wave ELF smoke. Normal tests require no external assembler. Temporary build-artifact quota exhaustion during final preparation was resolved by removing this task's generated build directories; all final checks above subsequently passed.

CI run: all 23 checks passed.

Linked issues

Batch 1: Closes #132, Closes #133, Closes #134, Closes #135, Closes #137, Closes #138.

Batch 2: Closes #15, Closes #139, Closes #248, Closes #249, Closes #250.

Batch 3: Closes #33, Closes #34, Closes #42.

Batch 4: Closes #55, Closes #244, Closes #245, Closes #246, Closes #247.

Batch 5: Closes #251, Closes #252, Closes #253, Closes #288.

Batch 6: Closes #151, Closes #152, Closes #153, Closes #154.

Batch 7: Closes #40, Closes #127, Closes #92, Closes #195, Closes #196, Closes #197, Closes #275, Closes #276, Closes #280.

Batch 8: Closes #254, Closes #255, Closes #256, Closes #257.

Checklist

  • Exactly eight commits, in the requested batch order, each with DCO Signed-off-by.
  • Focused regressions and final combined default/all-feature/MSRV/release validation.
  • README, assembler reference, schemas, help and diagnostics reflect compatibility and actual availability.
  • Independent reviews fixed checked-entry insertion and cross-module callable identity before publication.
  • Existing attribution/license notices preserved; no unrelated release, deployment, or native-backend changes.

…ocation work

Add fallible IR construction, safe type-layout overrides, bounded direct AST
lowering/encoding with iterative rejection disposal, complete ELF output
preflight, and shared object validation at symbol resolution.

Fixes wavefnd#55
Fixes wavefnd#244
Fixes wavefnd#245
Fixes wavefnd#246
Fixes wavefnd#247

Signed-off-by: LunaStev <[email protected]>
Add Bool-only logical expressions with preserved RHS control flow and phi
results, integer bitwise/not, division/remainder and signedness-aware shifts.
Preserve and validate the corresponding constant trees and evaluate logical
constant expressions lazily with defined integer trap/wrap/count semantics.

Write AST format 3 and typed IR format 5, gate the new syntax by version, and
retain compatibility with AST 2 and typed IR 3/4 inputs. Bound AST nesting to
32 levels so accepted trees also roundtrip through the JSON recursion limit.

Fixes wavefnd#151
Fixes wavefnd#152
Fixes wavefnd#153
Fixes wavefnd#154

Signed-off-by: LunaStev <[email protected]>
Execute defined Whale calls with private invocation environments and shared fuel, stack-memory, depth, frame and live-value budgets. Preserve module-local typed callable identity and data-pointer capabilities across calls, returns, storage and split byte copies; reject unsupported reachable callees before effects and raw callable authority at dispatch.

Refs wavefnd#254, wavefnd#255, wavefnd#256, wavefnd#257

Signed-off-by: LunaStev <[email protected]>
@LunaStev
LunaStev force-pushed the feat/toolchain-correctness-and-execution branch from df2cdbb to a393c65 Compare October 12, 2026 07:29
@LunaStev
LunaStev merged commit 9eed195 into wavefnd:master Oct 12, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment