Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,14 @@ jobs:
--gb-trees "$stdlib/src/gb_trees.erl" \
--work-dir "$RUNNER_TEMP/cowlib-cookie-date-eunit"

- name: Compile and run pinned MIME tables under the address-space cap
timeout-minutes: 10
run: |
python3 tests/integration/cowlib/mimetypes.py \
--nera "$GITHUB_WORKSPACE/target/release/nera" \
--source "$RUNNER_TEMP/cowlib-2.22.0/src/cow_mimetypes.erl" \
--out "$RUNNER_TEMP/cowlib-cookie-date-eunit/mimetypes"

- name: Preserve Cowlib cookie and date EUnit evidence
if: always()
uses: actions/upload-artifact@v7
Expand All @@ -312,6 +320,7 @@ jobs:
${{ runner.temp }}/cowlib-cookie-date-eunit/report.json
${{ runner.temp }}/cowlib-cookie-date-eunit/*.stdout
${{ runner.temp }}/cowlib-cookie-date-eunit/*.stderr
${{ runner.temp }}/cowlib-cookie-date-eunit/mimetypes/

thoas:
name: Thoas (Linux x86_64)
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

All notable milestones for the nera project are documented in this file.

## Generated MIME tables compile with less memory

- The compiler reuses backend variable slots for block-local temporaries in
functions without suspension points. Parameters, values shared between
blocks and values read before a local definition keep distinct slots.
- Cowlib 2.22.0's unchanged `cow_mimetypes` module now compiles and links on
Linux x86-64 under a 6,800,000 KiB address-space limit instead of aborting
on allocation. Its 1,009 literal MIME lookups and eight path/fallback checks
pass on both Nera and Erlang/OTP 27.3.4.6.

## Throw stack frames name the throw's line

- The top frame of a `throw/1` stacktrace now names the line of the throw
Expand Down
1 change: 1 addition & 0 deletions COMPATIBILITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ a dependency, or using the editor tools does not establish runtime compatibility
| --- | --- | --- | --- |
| **Thoas 1.2.1** (`7cdcec7e52b80d2869900893b2acf47199d84190`) | **Tested — scoped pass** | 2026-10-11; main `9b64f62`; fresh release; macOS arm64; OTP 29.0.5, Elixir 1.20.3 | Full ExUnit/StreamData: BEAM 338/338; Nera library through ETF 337/338. Only the copying test fails because transport copies binaries; direct memory checks pass 4/4 on both engines. JSONTestSuite 318/318 and all six properties pass (100 trials each, seed 0); no skips/exclusions or transport failures. Corpus 80/80. [Current scope and reproduction](tests/integration/thoas/README.md#current-validation--main-2026-10-11), [evidence](tests/integration/thoas/main-validation-evidence.json). |
| **Thoas 1.2.1 — upstream assertion bodies** (same pinned commit) | **Tested — scoped pass** | 2026-10-11; main `9b64f62`; macOS arm64; OTP 29.0.5 | Original EUnit 36/36 on BEAM and all 36 assertion bodies directly in Nera via the external adapter. Native EUnit runner/autoexport remain unvalidated. PR 27 CI also passes the strict native assertion gate on Linux. [Consolidated results](tests/integration/thoas/README.md#current-validation--main-2026-10-11). |
| **Cowlib 2.22.0 — generated MIME tables** (`b92326f02df30dd62045d622a17f6ba52d96d53a`) | **Tested — scoped pass** (unchanged module, object emission, native link and all literal lookups) | Linux x86-64; Rust 1.100.0; Erlang/OTP 27.3.4.6 | Under a **6,800,000 KiB address-space limit**, `cow_mimetypes` now compiles and links instead of aborting on allocation. All **1,009** literal lookups plus **8** path/fallback assertions pass on BEAM and Nera. Measured object-build peak RSS: **2,345,844 KiB**; the old compiler aborted at **5,142,956 KiB**. This does not establish full Cowlib suite or other-platform compatibility. [Reproduction and scope](tests/integration/cowlib/README.md#generated-mime-table-memory-regression). |
| **Cowlib 2.22.0 example project** (`examples/cowlib_demo`, from hex.pm) | **Tested — scoped pass** (85 calls over all 25 modules; not upstream suites) | 2026-11-12; Nera main `3b2abf2`; macOS arm64; Rust 1.99.0; OTP 29.1.2 | `nera deps get`, `nera check` (0 errors, 57 warnings on Cowlib) and `nera build` succeed. All 85 calls return natively with no exception, stable over 10 runs. Against OTP 29, 75 lines were byte-identical; 8 printed the same value differently (6 map key orders, 2 `'HTTP/1.1'` atoms printed unquoted); 2 differ only in byte order because Cowlib walks an atom-keyed map, and are equivalent when sorted. Since atoms print quoted as on OTP, 77 lines are byte-identical and only the 6 map orders and 2 byte orders remain (rerun on macOS arm64, OTP 29.1.2). [`scripts/test-cowlib-demo.py`](scripts/test-cowlib-demo.py) checks the sorted output against OTP 29 (2 known lines allowed); [`benchmarks/cowlib_bench.sh`](benchmarks/cowlib_bench.sh) times it on demand. Upstream EUnit suites other than cookie/date (next row) and PropEr properties were not rerun on 2.22.0. [Example and result](examples/cowlib_demo/README.md). |
| **Cowlib 2.22.0 — cow_cookie / cow_date upstream EUnit** (`b92326f02df30dd62045d622a17f6ba52d96d53a`) | **Tested — scoped pass** (two original functional suites and the seeded date property) | 2026-11-12; main `3b2abf2` plus the `filename:flatten/1` export, `~W`/`~P` depth fixes and three scheduler liveness fixes; macOS 27 arm64; Rust 1.99.0; OTP 29.1.2 / EUnit 2.11; PropEr 1.5.0 | Original suites through project-configured `nera test`: **157/157 cow_cookie** and **27/27 cow_date** on BEAM and natively, with EUnit framework controls passing on both; no skipped or normalized assertions. Native runs hung or exited early about once in 30 runs until the scheduler fixes; afterwards **1,200/1,200** consecutive native `cow_cookie` runs pass. The 2.20.0 Domain/HttpOnly failure no longer occurs in the suite, but the separate cookie probe still prints the attributes in another order than BEAM (`wire_equal` false). `prop_parse_date/0` passes **6,000/6,000** trials per engine with identical native and BEAM traces, once `rand:uniform/1` stopped being a built-in that `rand:seed/2` did not control. The Linux workflow runs both suites. [Results, fixes and reproduction](tests/integration/cowlib/README.md#cow_cookie--cow_date-upstream-eunit-on-cowlib-2220--2026-11-12). |
| **Cowlib 2.20.0 — first four modules** (`c768a804565ff5b8178ed968a5921e469d6bd7b2`) | **Tested — scoped pass** (four named modules; not all Cowlib) | 2026-10-12; merged main `4f5a266`; fresh release; macOS arm64; OTP 29.0.5 | **122/122 differential cases pass:** qs 29/29, cookie 34/34, date 26/26, Base64url 33/33; no blocked or skipped cases. Existing Set-Cookie attribute-order normalization and two Max-Age time-window checks retained. The 122-case gate also passed on Linux in [PR #47 CI](https://github.com/processone/nera/actions/runs/38255964315), head `e76d893`. [Current evidence](tests/integration/cowlib/main-validation-evidence.json), [scope and reproduction](tests/integration/cowlib/README.md#current-validation--merged-main-2026-10-12). |
Expand Down
54 changes: 54 additions & 0 deletions crates/nera-codegen/src/func_translator/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,60 @@ use nera_ir::ir::{BlockId, CallTarget, IrFunction, Instruction, Terminator, VarI
// Liveness analysis for variables across suspend points (receive & calls)
// ---------------------------------------------------------------------------

/// A use before a local definition must retain its incoming SSA value, even
/// when this is the only block mentioning the variable (for example a parameter).
pub(super) fn block_local_variables(ir_func: &IrFunction) -> Vec<Vec<VarId>> {
if ir_func.blocks.len() < 2 {
return Vec::new();
}
let mut owners: HashMap<VarId, Option<usize>> = ir_func
.params
.iter()
.map(|var| (*var, None))
.collect();
let mut operands = HashSet::new();
let mut defined = HashSet::new();
for (index, block) in ir_func.blocks.iter().enumerate() {
defined.clear();
for inst in &block.instructions {
collect_instruction_uses(inst, &mut operands);
for var in operands.drain() {
if !defined.contains(&var) {
owners.insert(var, None);
}
}
collect_instruction_defs(inst, &mut operands);
for var in operands.drain() {
owners
.entry(var)
.and_modify(|owner| {
if *owner != Some(index) {
*owner = None;
}
})
.or_insert(Some(index));
defined.insert(var);
}
}
collect_terminator_uses(&block.terminator, &mut operands);
for var in operands.drain() {
if !defined.contains(&var) {
owners.insert(var, None);
}
}
}
let mut locals = vec![Vec::new(); ir_func.blocks.len()];
for (var, owner) in owners {
if let Some(block) = owner {
locals[block].push(var);
}
}
for vars in &mut locals {
vars.sort_by_key(|var| var.0);
}
locals
}

/// A suspend point is a location in the function where execution may need
/// to be suspended and later resumed. This includes receive_peek calls (the
/// process waits for a message) and local function calls (the callee may
Expand Down
165 changes: 34 additions & 131 deletions crates/nera-codegen/src/func_translator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ mod signatures;
mod terminators;
#[cfg(test)]
mod tests;
#[cfg(test)]
mod slot_tests;

use std::collections::{HashMap, HashSet};

Expand All @@ -28,7 +30,7 @@ use cranelift_module::{DataId, FuncId, Linkage, Module};
use cranelift_object::ObjectModule;

use nera_ir::ir::{
BlockId, CallTarget, IrFunction, IrModule, Instruction, Terminator, VarId,
BlockId, CallTarget, IrFunction, IrModule, Instruction, VarId,
};
use crate::term_layout::*;

Expand All @@ -37,9 +39,12 @@ use signatures::{
declare_runtime_func, declare_runtime_func_void,
declare_tuple_element,
};
use liveness::{compute_suspend_points, SuspendPoint};
use liveness::{
block_local_variables, collect_instruction_defs, collect_terminator_uses,
compute_suspend_points, SuspendPoint,
};
#[cfg(test)]
use liveness::{collect_instruction_defs, collect_instruction_uses, collect_terminator_uses, terminator_successors};
use liveness::{collect_instruction_uses, terminator_successors};

/// Error during function translation.
#[derive(Debug)]
Expand Down Expand Up @@ -290,6 +295,22 @@ impl FuncTranslator {
// Variable map: IR VarId -> Cranelift Variable
let mut var_map: HashMap<VarId, Variable> = HashMap::new();

// Cranelift keeps a dense block-definition array per variable. Reusing
// slots for block-local temporaries avoids quadratic storage in generated
// lookup tables. Resumption introduces extra definitions and uses outside
// the IR blocks, so keep its variables distinct.
if suspend_info.is_empty() {
let mut local_slots = Vec::new();
for locals in block_local_variables(ir_func) {
for (slot, var) in locals.into_iter().enumerate() {
if slot == local_slots.len() {
local_slots.push(builder.declare_var(types::I64));
}
var_map.insert(var, local_slots[slot]);
}
}
}

let declare_var = |var_id: VarId,
var_map: &mut HashMap<VarId, Variable>,
builder: &mut FunctionBuilder| {
Expand All @@ -298,138 +319,20 @@ impl FuncTranslator {

self.current_blocks = block_map.clone();

// Pre-declare all variables used in the function
let mut inventory = HashSet::new();
for ir_block in &ir_func.blocks {
for inst in &ir_block.instructions {
match inst {
Instruction::Arithmetic(site) => {
if let Some(v) = site.result {
declare_var(v, &mut var_map, &mut builder);
}
}
Instruction::Const(v, _)
| Instruction::BinOp(v, _, _, _)
| Instruction::UnaryOp(v, _, _)
| Instruction::MakeTuple(v, _)
| Instruction::MakeCons(v, _, _)
| Instruction::TupleElement(v, _, _)
| Instruction::ListHead(v, _)
| Instruction::ListTail(v, _)
| Instruction::Call(v, _, _)
| Instruction::GetSelf(v)
| Instruction::Spawn(v, _, _, _)
| Instruction::Send(v, _, _)
| Instruction::SendDirect(v, _, _)
| Instruction::TypeTest(v, _, _)
| Instruction::Move(v, _)
| Instruction::TupleSize(v, _)
| Instruction::MakeBinary(v, _)
| Instruction::BinaryGetInteger(v, _, _, _, _)
| Instruction::BinaryGetFloat(v, _, _, _, _)
| Instruction::BinaryGetBinary(v, _, _, _)
| Instruction::BsMatchBitOffset(v, _)
| Instruction::BinarySize(v, _)
| Instruction::BsGetIntegerInline(v, _, _, _, _)
| Instruction::BsMaterialize(v, _, _, _)
| Instruction::MakeMap(v, _)
| Instruction::MapGet(v, _, _)
| Instruction::MapPut(v, _, _, _)
| Instruction::MapUpdateExact(v, _, _, _)
| Instruction::RaiseException(v, _, _)
| Instruction::GetExceptionClass(v)
| Instruction::GetExceptionReason(v)
| Instruction::GetExceptionStacktrace(v)
| Instruction::CheckException(v) => {
declare_var(*v, &mut var_map, &mut builder);
}
Instruction::MakeClosure(v, _, _, ref env_vars) => {
declare_var(*v, &mut var_map, &mut builder);
for ev in env_vars {
declare_var(*ev, &mut var_map, &mut builder);
}
}
Instruction::MakeRemoteFunRef(v, _, _, _) => {
declare_var(*v, &mut var_map, &mut builder);
}
Instruction::MakeDynamicRemoteFunRef(v, _, _, _) => {
declare_var(*v, &mut var_map, &mut builder);
}
Instruction::BsStartMatch(base_ptr, total_bytes, _) => {
declare_var(*base_ptr, &mut var_map, &mut builder);
declare_var(*total_bytes, &mut var_map, &mut builder);
}
Instruction::BsMatchStart2(match_ctx, base_ptr, total_bits, _) => {
declare_var(*match_ctx, &mut var_map, &mut builder);
declare_var(*base_ptr, &mut var_map, &mut builder);
declare_var(*total_bits, &mut var_map, &mut builder);
}
Instruction::BsMatchCtxAdvance(_, _) => {
// No result variables to declare — side effect only
}
Instruction::BinaryPutInteger(_, _, _, _, _) => {}
Instruction::BinaryPutFloat(_, _, _, _, _) => {}
Instruction::BinaryPutBinary(_, _, _, _) => {}
Instruction::BinaryPutUtf8(bits_written, _, _, _) => {
declare_var(*bits_written, &mut var_map, &mut builder);
}
Instruction::BinaryPutUtf16(bits_written, _, _, _, _) => {
declare_var(*bits_written, &mut var_map, &mut builder);
}
Instruction::BinaryPutUtf32(bits_written, _, _, _, _) => {
declare_var(*bits_written, &mut var_map, &mut builder);
}
Instruction::BsGetUtf8(cp, bits_consumed, _, _, _) => {
declare_var(*cp, &mut var_map, &mut builder);
declare_var(*bits_consumed, &mut var_map, &mut builder);
}
Instruction::BsGetUtf16(cp, bits_consumed, _, _, _, _) => {
declare_var(*cp, &mut var_map, &mut builder);
declare_var(*bits_consumed, &mut var_map, &mut builder);
}
Instruction::BsGetUtf32(cp, bits_consumed, _, _, _, _) => {
declare_var(*cp, &mut var_map, &mut builder);
declare_var(*bits_consumed, &mut var_map, &mut builder);
}
Instruction::BinaryResize(_, _) => {}
Instruction::CheckReductions => {}
Instruction::YieldCheck => {}
Instruction::SetLine(_) => {}
Instruction::ClearException => {}
}
}
}

// Also declare variables referenced in terminators (e.g., Return, Branch, TailCall)
for ir_block in &ir_func.blocks {
match &ir_block.terminator {
Terminator::Return(v) => {
declare_var(*v, &mut var_map, &mut builder);
collect_instruction_defs(inst, &mut inventory);
if let Instruction::MakeClosure(_, _, _, env_vars) = inst {
inventory.extend(env_vars);
}
Terminator::Branch(v, _, _) => {
declare_var(*v, &mut var_map, &mut builder);
for var in inventory.drain() {
declare_var(var, &mut var_map, &mut builder);
}
Terminator::Switch { scrutinee, .. } => {
declare_var(*scrutinee, &mut var_map, &mut builder);
}
Terminator::TailCall(_, args) => {
for a in args {
declare_var(*a, &mut var_map, &mut builder);
}
}
Terminator::Jump(_, args) => {
for a in args {
declare_var(*a, &mut var_map, &mut builder);
}
}
Terminator::Receive { clauses, timeout, .. } => {
for clause in clauses {
declare_var(clause.binding, &mut var_map, &mut builder);
}
if let Some((t, _)) = timeout {
declare_var(*t, &mut var_map, &mut builder);
}
}
Terminator::Unreachable => {}
}
collect_terminator_uses(&ir_block.terminator, &mut inventory);
for var in inventory.drain() {
declare_var(var, &mut var_map, &mut builder);
}
}

Expand Down
Loading
Loading