You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|`--max-pages`| Maximum memory pages when module declares no maximum | No |
51
51
52
+
**Environment variables:**
53
+
54
+
| Variable | Values | Default | Effect |
55
+
|----------|--------|---------|--------|
56
+
|`HERKOS_OPTIMIZE`|`1` or any other value | Unset (disabled) | When `HERKOS_OPTIMIZE=1`, enables IR optimization passes (currently dead block elimination). Set during transpilation, affects generated code size and performance. |
57
+
52
58
> **Current limitations**: Only the `safe` backend is implemented. The `--mode` flag accepts `safe`, `hybrid`, and `verified` but all behave identically. `--max-pages` has no effect. See [FUTURE.md](FUTURE.md) for the verified and hybrid backend plans.
53
59
54
60
### 1.3 Understanding the Output
@@ -500,27 +506,27 @@ let result = lib.call_export_transform(&mut app.memory, ptr, len)?;
@@ -809,6 +815,61 @@ Type 2: (i32) → i32 → canonical = 2 (new signature)
809
815
810
816
The transpiler builds a canonical type index mapping at transpile time. Both `FuncRef.type_index` and the type check use canonical indices. At runtime, the check is a simple integer comparison.
Traps `OutOfBounds` if either region (source or destination) exceeds bounds:
859
+
- Source: `[src_offset, src_offset + len)` must be within the data segment
860
+
- Destination: `[dst, dst + len)` must be within active memory
861
+
862
+
#### 4.6.3 `data.drop`
863
+
864
+
Marks a data segment as dropped (per Wasm spec). In the safe backend this is a no-op because data segments are stored as constant references and cannot actually be deallocated.
865
+
866
+
```rust
867
+
// Wasm: data.drop $segment
868
+
// (no-op in safe backend — const slices persist)
869
+
```
870
+
871
+
In future verified and hybrid backends, `data.drop` may enable optimizations: proving that dropped segments are never accessed again could allow proving certain addresses as never-in-bounds.
872
+
812
873
---
813
874
814
875
## 5. Integration
@@ -829,7 +890,53 @@ let result = module.process_data(&mut host, ptr, len)?;
829
890
830
891
Full type safety, zero `unsafe`, zero-cost dispatch via monomorphization.
Generated modules use a unified **Env<H>** context struct that bundles the host (generic parameter `H`) and mutable globals, simplifying parameter threading throughout function calls.
898
+
899
+
```rust
900
+
// Generated by transpiler
901
+
pubstructEnv<'a, H:ModuleHostTrait+?Sized> {
902
+
pubhost:&'amutH,
903
+
pubglobals:&'amutGlobals,
904
+
}
905
+
906
+
// Every function that needs imports or mutable state receives Env<H>
907
+
fnprocess<H:ModuleHostTrait>(
908
+
memory:&mutIsolatedMemory<MAX_PAGES>,
909
+
env:&mutEnv<H>,
910
+
input:i32,
911
+
) ->WasmResult<i32> {
912
+
// Call imported function via trait
913
+
letresult=env.host.some_import(input)?;
914
+
// Read/write mutable global
915
+
env.globals.my_global +=1;
916
+
Ok(result)
917
+
}
918
+
```
919
+
920
+
**Design rationale:**
921
+
-**Unified state**: Avoids threading `host`, `globals`, and other mutable state as separate parameters
922
+
-**Type safety**: All imports must be present in the host's trait implementation — checked at compile time
923
+
-**Zero overhead**: The Env struct is a thin wrapper; LLVM inlines and optimizes away the indirection
924
+
-**Extensibility**: Adding new imports or globals requires only modifying the trait, not all function signatures
The C ABI wrapper uses `unsafe` and raw pointers. Capability enforcement still applies inside — the wrapper calls through trait-bounded functions. This is an escape hatch, not the default.
851
958
852
-
### 5.3 Native Rust Integration
959
+
### 5.5 Native Rust Integration
853
960
854
961
Native Rust code integrates by implementing import traits directly:
0 commit comments