Implementation Plan: Zero-Copy Vox Codegen
Implementation Plan: Zero-Copy Vox Codegen
Section titled “Implementation Plan: Zero-Copy Vox Codegen”Overview
Section titled “Overview”This plan outlines the technical steps to transition Vox from a “Clone-Heavy” Rust backend to a “Zero-Copy” systems-native backend. This is Phase 1 of the Native Code Emission strategy.
1. Enrich HIR with Type Information
Section titled “1. Enrich HIR with Type Information”The primary blocker for smart codegen is that HIR nodes do not know their types. We store resolved types in a centralized map within the HirModule.
- Extend
HirModuleincrates/vox-compiler/src/hir/nodes/decl.rs:- Add
pub inferred_types: HashMap<Span, HirType>field.
- Add
- Update
Checkerincrates/vox-compiler/src/typeck/checker/mod.rs:- Add
inferred_typesmap to theCheckerstruct. - Write resolved types to the map during
check_exprinexpr.rs.
- Add
- Refactor
typecheck_hir:- Pass the module’s
inferred_typesto the checker. - Resolve borrow-checker conflicts by temporarily taking ownership of the map during checking.
- Pass the module’s
2. Implement Smart Ownership Tracking in Codegen
Section titled “2. Implement Smart Ownership Tracking in Codegen”Update vox-codegen to use type information to avoid unnecessary .clone() calls.
- Refactor Codegen Layers:
- Propagate
inferred_typesthroughemit_lib,emit_fn,emit_stmt, andemit_expr_with. - Update all call sites in
stmt_expr.rs,stmt_expr_tail.rs,workflow.rs, andhttp.rs.
- Propagate
- Optimize Identifiers:
- Check for
Copytypes: If the inferred type is a primitive (int,bool,float,char,dec), omit.clone().
- Check for
- Advanced String Optimization:
- Escape Analysis: If an identifier is passed to a function that takes a reference (e.g.,
str->&str), emit&norn.as_str()instead ofn.clone(). - Last-Use Detection: If the compiler can prove an identifier is used for the last time in a scope, “move” it instead of cloning.
- Escape Analysis: If an identifier is passed to a function that takes a reference (e.g.,
3. Native UI Prototype (Visus)
Section titled “3. Native UI Prototype (Visus)”Establish a pathway for non-React UI emission.
- Create
crates/vox-native-gui:- Define a
NativeRenderertrait. - Implement a
Slintoreguibackend that mapsHirJsxElementto native widgets.
- Define a
- Update
vox-codegen:- Add
--target=nativeflag to the CLI. - Branch the
Componentlowering path:HIR→WebIR(for React) vsHIR→NativeIR(for systems UI).
- Add
4. WASM Logic Offloading
Section titled “4. WASM Logic Offloading”Enable high-performance logic offloading to WASM for @pure functions.
- Identify
@pureperformance-critical functions:- Use the
@intrinsicdecorator (proposed in research) to flag these functions.
- Use the
- Lower to WASM:
- Use
vox-wasm-engineto compile these functions to.wasmblobs. - Emit Rust glue code in the server that calls into the WASM module instead of executing interpreted logic.
- Use
Verification
Section titled “Verification”- Benchmark: Run the
vox-benchsuite before and after the “Zero-Copy” changes. - Regression: Ensure
cargo test --workspacepasses, specifically checkingvox-codegentests that previously relied on.clone()behavior.
Last Updated: 2026-05-12 Status: In Progress