Skip to content

Record typed HIR conversions and add checked std operations - #744

Merged
LunaStev merged 6 commits into
wavefnd:masterfrom
LunaStev:feat/typed-conversions-and-stdlib
Sep 25, 2026
Merged

LunaStev merged 6 commits into
wavefnd:masterfrom
LunaStev:feat/typed-conversions-and-stdlib

Conversation

@LunaStev

@LunaStev LunaStev commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Record ordered scalar conversions and computation types on stable HIR expression IDs. Preserve explicit/implicit intent, signedness, intermediate truncation, and source spans; verify the facts before LLVM emission and use the same conversion lowering for constants and runtime values.
  • Separate semantic type collection and numeric rules behind the verification facade, and split C ABI classifiers into target modules without changing classifier bodies.
  • Add checked signed LEB128 reader/writer operations and checked typed memory copy/move/zero helpers, with failure-state and cross-target regression coverage.

Addressed array literals retain their pointer and element contexts in HIR, so assignment, calls, and nested arrays use the destination storage widths without backend type inference.

Motivation

Numeric lowering previously reconstructed conversion decisions across several LLVM paths. For example, i32 -> u8 -> i32 must retain its intermediate truncation, and integer division must complete before conversion to a floating destination. Frontend-owned facts establish a shared semantic contract for LLVM/Whale coexistence.

Signed LEB128 and type-derived memory sizes also remove repeated, error-prone byte encoding and layout calculations from callers.

Closes #718
Closes #719
Closes #720
Closes #721
Closes #740

Target and compatibility impact

  • Preserve numeric policy, integer-division behavior, diagnostics, source identities, and supported targets. Missing or inconsistent required conversion facts produce an internal compiler error before LLVM emission.
  • Keep C ABI transport separate from language conversions; all 32 extracted ABI function bodies are unchanged.
  • Preserve existing ULEB128 and explicit-size memory APIs. SLEB128 failures preserve cursor/output state. Typed memory operations check layout-size narrowing and multiplication before access; callers remain responsible for allocation bounds.
  • No new dependency or libc FFI. Compiler and std license boundaries remain unchanged.

Validation

With LLVM_SYS_211_PREFIX=/usr/lib64/llvm21, after the addressed-array correction:

  • cargo test --workspace --jobs 2 — 289 passed, including 99 codegen regressions. The added HIR test reproduced the missing scalar facts before the fix; shared/test73.wave and the new addressed-array fixture pass at O0/O2.
  • python3 tools/run_tests.py --wavec /tmp/wave-pr744-ci/wavec-checkout --target-id linux-amd64 --report-json /tmp/wave-pr744-ci/native.json — 170 cases passed. The HTTP server case (linux/amd64/test5.wave) collided with an existing service on port 8080 and passed separately using a temporary copy with an unused port. The wrapper uses the checkout-built compiler and an aliased copy of repository std.
  • shared/test73.wave and tests/fixtures/addressed_arrays/main.wave — 60 successful object compilations across all 15 CI targets at O0/O2. The new fixture additionally passed 12 executions across AArch64/RISC-V/LoongArch QEMU, wasm32/Node, wasm64/Node, and WASI/Node at O0/O2.
  • cargo clippy --locked --workspace --all-targets --jobs 2 -- -D warnings, cargo fmt --all -- --check, and git diff --check passed.

Earlier implementation validation also passed the feature-isolated core64 workspace (275 tests), the Wave corpus (288 files and 26 std examples), and checked std fixtures on amd64, wasm32, and AArch64. Windows/macOS execution remains covered by CI; local checks for those hosts are cross-target compilation and ABI contract tests.

Checklist

  • Commits include a DCO Signed-off-by line.
  • Tests cover new behavior or the PR explains why no test is needed.
  • User-facing changes include documentation or diagnostics updates.
  • The change preserves the license boundary between the compiler and std/.

Extract declaration lookup, numeric compatibility, diagnostics, and semantic records behind the existing verification facade. Keep mutable validation state and HIR recording with their current owner.

Refs wavefnd#720

Signed-off-by: LunaStev <[email protected]>
Keep shared transport records and attribute emission behind the existing facade while preserving all classifier bodies and supported targets.

Refs wavefnd#740

Signed-off-by: LunaStev <[email protected]>
Preserve cursor and output state on failure, validate tenth-byte sign extension, and emit minimal i64 encodings. Add exact encoding and failure-state fixtures.

Refs wavefnd#718

Signed-off-by: LunaStev <[email protected]>
Check unsigned layout sizes and element-count multiplication before access. Preserve zero-sized no-ops, overlap-safe copy and move behavior, and existing explicit-size APIs.

Refs wavefnd#719

Signed-off-by: LunaStev <[email protected]>
Resolve conversion kinds, signedness, computation widths, modes, and spans in the frontend. Verify conversion chains before codegen and share their LLVM lowering between constants and runtime expressions. Preserve projected dereference storage types and reject missing numeric boundary conversions.

Add HIR invariant tests and native, wasm32, and AArch64 O0/O2 fixtures for conversions and the checked std additions.

Refs wavefnd#721

Signed-off-by: LunaStev <[email protected]>
Record scalar pointer facts and propagate pointee array types into literal elements before conversion planning. Lower addressed arrays from the frontend layout instead of inferring storage from the first LLVM value.

Cover the shared test73 assignment regression and mixed-width, floating, nested, grouped, and boolean array literals at O0/O2.

Signed-off-by: LunaStev <[email protected]>
@LunaStev
LunaStev merged commit 4c33721 into wavefnd:master Sep 25, 2026
25 checks passed
@LunaStev LunaStev mentioned this pull request Sep 30, 2026
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