diff --git a/AGENTS.md b/AGENTS.md index 6a3103a84c7..0dfd5c54176 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -60,14 +60,21 @@ The second line keeps stacks on the `Depends-On:` chain that the merge queue orders, rather than GitHub-native stacks, which block GitHub's classic merge endpoint. +The rules below apply to Mergify-managed stacks. For ordinary pull requests, +including Renovate PRs, push fixes to the existing PR branch with `git push`. +Do not require converting an ordinary PR into a stack or asking for a workflow +exception. A request to push authorizes the appropriate push command for the +existing workflow. Prefer adding a fix commit to an ordinary PR over rewriting +its published history. + - One commit is one pull request. Its subject becomes the PR title and its body the PR description, so every commit subject must satisfy the PR title rules below, and its type must not exceed the release impact of the change. - Every commit must build and pass its checks on its own; put each fix in the commit that needs it rather than in a later commit. - Create a stack with `mergify stack new /` from an up-to-date - `master`. Publish with `mergify stack push`, never `git push`, and only when - pushing was requested. + `master`. Publish stacks with `mergify stack push` so their PRs and dependency + metadata stay synchronized, and only when pushing was requested. - Revise commits instead of adding fix-up commits: `git commit --amend` for the top commit; `mergify stack edit `, `fixup`, `squash`, `reword`, `move`, `reorder`, or `drop` for others. Never use `git rebase -i`. Before rewriting diff --git a/crates/celox-sv-analyzer/src/ast/interface_binding.rs b/crates/celox-sv-analyzer/src/ast/interface_binding.rs index 29a0ebcec0a..83c101df185 100644 --- a/crates/celox-sv-analyzer/src/ast/interface_binding.rs +++ b/crates/celox-sv-analyzer/src/ast/interface_binding.rs @@ -268,6 +268,7 @@ pub(super) fn analyze_module( true, Some(&header_ports), )?; + let mut caller_ports = caller.ports.clone(); let mut caller_symbols = caller.symbols.as_ref().unwrap().clone(); let _caller_scope = scope::install(&tree.state, Arc::new(caller_symbols.clone())); let _functions = const_functions::install(&tree.state, caller.constant_functions.clone()); @@ -295,6 +296,7 @@ pub(super) fn analyze_module( true, Some(&header_ports), )?; + caller_ports = caller.ports.clone(); caller_symbols = caller.symbols.unwrap(); generated = true; let mut current = caller_symbols.clone(); @@ -324,7 +326,7 @@ pub(super) fn analyze_module( binding_declaration_view(&view_ports, &instantiations, tree, &imported)?; let mut header_imports = imported.clone(); header_imports.declarations_only = true; - caller_symbols = Module::from_selected_scope( + let caller = Module::from_selected_scope( &tree.child(&header_tree, &overrides), &name, &overrides, @@ -332,9 +334,9 @@ pub(super) fn analyze_module( Arc::new(header_imports), true, Some(&header_ports), - )? - .symbols - .unwrap(); + )?; + caller_ports = caller.ports.clone(); + caller_symbols = caller.symbols.unwrap(); } let mut current = caller_symbols.clone(); current.extend(&imported); @@ -345,8 +347,12 @@ pub(super) fn analyze_module( } let _scope = scope::install(&tree.state, Arc::new(current.clone())); let _functions = const_functions::install(&tree.state, current.constant_functions.clone()); + // Exported scope symbols omit ordinary module ports. Keep the + // selected caller header available for connection width discovery. + let mut connection_ports = caller_ports.clone(); + connection_ports.extend(current.ports.iter().cloned()); let mut dimensions = packed_dimensions_from_ports_and_signals( - ¤t.ports, + &connection_ports, ¤t.signals, ¤t.const_env, ¤t.type_aliases, @@ -416,10 +422,10 @@ pub(super) fn analyze_module( .insert(handle.clone(), elements.clone()); } } - for local_handle in elements.elements { + for (ordinal, local_handle) in elements.elements.iter().enumerate() { let handle = generated_item.as_ref().map_or_else( || local_handle.clone(), - |item| item.instance_name(&local_handle), + |item| item.instance_name(local_handle), ); imported .interface_types @@ -443,6 +449,14 @@ pub(super) fn analyze_module( imported.declarations_only, ) })?; + let port_state = module.constant_function_state(); + let port_symbols = module.symbols.as_ref().unwrap(); + let port_dimensions = packed_dimensions_from_ports_and_signals( + &module.ports, + &module.signals, + &port_symbols.const_env, + &port_symbols.type_aliases, + ); for port in &module.ports { let signal = Signal { name: port.name.clone(), @@ -460,6 +474,70 @@ pub(super) fn analyze_module( let Some(actual) = connection.actual_expr.clone() else { continue; }; + let actual = if elements.shape.is_empty() { + actual + } else { + let port_shape = port_dimensions.get(&port.name).unwrap(); + let port_width = lvalue_expr_type( + &port_state, + &LValue::Ident(port.name.clone()), + &port_dimensions, + ) + .ok_or_else(|| unsupported("interface array port width"))? + .width; + let actual_width = expr_static_width(&tree.state, &actual, &dimensions) + .ok_or_else(|| unsupported("interface array connection width"))?; + let actual_shape = if let Some(root) = + connection_expression(authored, &port.name, Some(&interface))? + { + dimensions::operand_shape(root, tree, &dimensions)? + } else if let Expr::Ident(name) = &actual { + dimensions.get(name).cloned() + } else { + None + }; + let unpacked_sizes = + |shape: &VariableDimensions, + state: &AnalysisState, + env: &HashMap| { + shape + .unpacked + .iter() + .map(|dimension| { + usize::try_from(eval_ast_const_expr( + state, + &dimension.width, + env, + )?) + .ok() + }) + .collect::>>() + }; + let actual_shape = actual_shape + .as_ref() + .map(|shape| unpacked_sizes(shape, &tree.state, &dimensions.const_env)) + .unwrap_or_else(|| Some(Vec::new())) + .ok_or_else(|| unsupported("interface array actual shape"))?; + let port_shape = + unpacked_sizes(port_shape, &port_state, &port_dimensions.const_env) + .ok_or_else(|| unsupported("interface array port shape"))?; + let (origin, ascending) = + connection_slice_origin(&actual, &tree.state, &dimensions)?; + let shape = ConnectionShape { + unpacked: actual_shape, + width: actual_width, + origin, + ascending, + }; + distribute_port_connection( + actual, + &shape, + &port_shape, + port_width, + &elements, + ordinal, + )? + }; let bound = format!("{handle}${}", port.name); let assignment = match port.direction { PortDirection::Input => Assignment::new(LValue::Ident(bound), actual), @@ -849,6 +927,111 @@ fn formal_dimensions( .ok_or_else(|| unsupported(format!("missing interface port `{port_name}`"))) } +struct ConnectionShape { + unpacked: Vec, + width: usize, + origin: ConstExpr, + ascending: bool, +} + +/// Single packed dimensions retain authored indices in analyzer expressions; +/// unpacked and multi-packed selections already use flat storage coordinates. +fn connection_slice_origin( + actual: &Expr, + state: &AnalysisState, + dimensions: &PackedDimensions, +) -> Converted<(ConstExpr, bool)> { + let (name, selected_origin) = match actual { + Expr::Ident(name) => (name, None), + Expr::Select { expr, lsb, .. } => { + let Expr::Ident(name) = expr.as_ref() else { + return Ok((ConstExpr::Literal("0".into()), false)); + }; + (name, Some(lsb.clone())) + } + _ => return Ok((ConstExpr::Literal("0".into()), false)), + }; + if let Some(shape) = dimensions.get(name) + && shape.unpacked.is_empty() + && let [dimension] = shape.packed.as_slice() + && !dimension.normalize_single + { + let left = eval_ast_const_expr(state, &dimension.left, &dimensions.const_env) + .ok_or_else(|| unsupported("interface connection packed bound"))?; + let right = eval_ast_const_expr(state, &dimension.right, &dimensions.const_env) + .ok_or_else(|| unsupported("interface connection packed bound"))?; + return Ok(( + selected_origin.unwrap_or_else(|| dimension.right.clone()), + left < right, + )); + } + Ok(( + selected_origin.unwrap_or_else(|| ConstExpr::Literal("0".into())), + false, + )) +} + +/// IEEE 1800-2023 23.3.3.5. Packed actuals distribute MSB-first; +/// unpacked actuals use the compiler's declaration-order element layout. +fn distribute_port_connection( + actual: Expr, + shape: &ConnectionShape, + port_shape: &[usize], + port_width: usize, + elements: &ArrayBinding, + ordinal: usize, +) -> Converted { + let actual_shape = shape.unpacked.as_slice(); + let actual_width = shape.width; + if actual_shape == port_shape && actual_width == port_width { + return Ok(actual); + } + let packed = actual_shape.is_empty() && port_shape.is_empty(); + let distributed_shape = elements + .shape + .iter() + .chain(port_shape) + .copied() + .collect::>(); + if (!packed && actual_shape != distributed_shape) + || port_width.checked_mul(elements.elements.len()) != Some(actual_width) + { + return Err(unsupported(format!( + "interface array connection shape/width: {actual_width} bits {actual_shape:?} for {} ports of {port_width} bits {port_shape:?}", + elements.elements.len(), + ))); + } + let offset = if packed { + elements.elements.len() - ordinal - 1 + } else { + ordinal + } * port_width; + let coordinate = |offset: usize| { + let offset = const_expr_from_i128(offset as i128); + if shape.ascending { + ConstExpr::Binary { + left: Box::new(shape.origin.clone()), + op: BinaryOp::Sub, + right: Box::new(offset), + } + } else { + add_expr(shape.origin.clone(), offset) + } + }; + let msb = coordinate(offset + port_width - 1); + let lsb = coordinate(offset); + let expr = match actual { + Expr::Select { expr, .. } if matches!(expr.as_ref(), Expr::Ident(_)) => expr, + value => Box::new(value), + }; + Ok(Expr::Select { + expr, + msb, + lsb, + signed: false, + }) +} + fn connection_lvalue(expr: Expr) -> Converted { match expr { Expr::Ident(name) => Ok(LValue::Ident(name)), diff --git a/crates/celox-sv-analyzer/src/ast/interfaces.rs b/crates/celox-sv-analyzer/src/ast/interfaces.rs index a57b12356e5..fabbf9e9a25 100644 --- a/crates/celox-sv-analyzer/src/ast/interfaces.rs +++ b/crates/celox-sv-analyzer/src/ast/interfaces.rs @@ -3118,7 +3118,63 @@ pub fn plan_interfaces_with_member_paths( .iter() .map(|(code, path)| File::new(code, path)) .collect::>>()?; - let design = Design::collect(&files)?; + // Local interface instances are bound from their original declarations by + // interface_binding. A structural plan is needed only for module interface + // ports; collecting full contracts here rejects ordinary interface ports. + let mut interface_names = HashSet::default(); + let mut contract_names = HashSet::default(); + let mut module_names = HashSet::default(); + for file in &files { + let native = file.syntax_tree.declarations(); + for (_, unit) in roots(&file.syntax_tree)? { + let name = native_name(&unit.name); + match unit.kind { + native::UnitKind::Interface => { + if unit.ports.is_empty() { + contract_names.insert(name.clone()); + } + if !interface_names.insert(name.clone()) || module_names.contains(&name) { + return Err(AnalyzerError::DuplicateModule { name }); + } + } + native::UnitKind::Module => { + if interface_names.contains(&name) { + return Err(AnalyzerError::DuplicateModule { name }); + } + module_names.insert(name); + for port in &unit.ports { + if port.direction.is_some() || port.net_type.is_some() || port.variable { + continue; + } + if let Some(id) = port.data_type { + match &native.data_type(id).kind { + native::DataTypeKind::Interface { + name: Some(name), .. + } => { + contract_names.insert(native_name(name)); + } + native::DataTypeKind::Named(path) if path.len() == 1 => { + contract_names.insert(native_name(&path[0].name)); + } + _ => {} + } + } + } + } + _ => {} + } + } + } + for (_, _, supplied) in bindings { + contract_names.extend(supplied.iter().map(|(_, interface)| interface.clone())); + } + let design = if !module_names.is_empty() { + // Ordinary module contracts still need planning when local interfaces + // have ports. Collect those contracts independently of native locals. + Design::collect_selected(&files, Some(&contract_names))? + } else { + Design::collect(&files)? + }; let mut result = NativeInterfacePlan::default(); let mut reflected_paths = HashMap::default(); if design.interfaces.is_empty() { diff --git a/crates/celox-sv-analyzer/src/tests.rs b/crates/celox-sv-analyzer/src/tests.rs index 306854de72f..1473989e69c 100644 --- a/crates/celox-sv-analyzer/src/tests.rs +++ b/crates/celox-sv-analyzer/src/tests.rs @@ -5265,6 +5265,38 @@ fn native_interface_array_ports_reject_incompatible_shapes() { ); } +#[test] +fn rejects_mismatched_interface_array_connection_widths_and_shapes() { + for declaration in [ + "logic [2:0] value; I lanes[1:0](.value(value));", + "logic [0:0] value [3]; I lanes[1:0](.value(value));", + "logic value [1][2]; I lanes[1:0](.value(value));", + ] { + let text = format!( + "interface I(input logic value); endinterface module Top; {declaration} endmodule" + ); + let parsed = + ParsedSource::parse(&text, Path::new("invalid-interface-array-connection.sv")).unwrap(); + let packages = ParsedSource::analyze_packages(&[&parsed]).unwrap(); + let error = parsed + .analyze_module( + "Top", + &HashMap::default(), + &[], + &[], + &ModuleInterfaces::default(), + &packages, + ) + .unwrap_err(); + assert!( + error + .to_string() + .contains("interface array connection shape/width"), + "{declaration}: {error}" + ); + } +} + #[test] fn native_interface_port_views_do_not_repeat_instance_initializers() { let module = native_interface_module( diff --git a/crates/celox-test-suite/LIMITATIONS.md b/crates/celox-test-suite/LIMITATIONS.md index d4a759ab0b7..baf27d6f58d 100644 --- a/crates/celox-test-suite/LIMITATIONS.md +++ b/crates/celox-test-suite/LIMITATIONS.md @@ -354,6 +354,17 @@ backends; the source and observed failures are retained in The SystemVerilog suite's exclusions are listed in [`verification/sv/limitations.json`](verification/sv/limitations.json), with the failures observed before them in [`verification/sv/limitations/`](verification/sv/limitations). A case is excluded for a tool only when the expected value follows IEEE 1800 and the tool either cannot run the design or disagrees with the standard; where the two tools disagree with each other, the entry says so. +The interface-array connection cases cover packed distribution, unpacked +connections and array ports, and multidimensional instance arrays (IEEE +1800-2023 23.3.3.5). Verilator 5.052 passes the three one-dimensional cases, +but counts only the inner instance dimension when validating the packed +connection width of a 2x2 array. Icarus 13.0 passes the packed case; it rejects +unpacked actuals, aborts on interface array ports, and explicitly rejects +multidimensional instance arrays. The exact case exclusions retain the +[Verilator diagnostics](verification/repros/sv_interface_array_connections_verilator.json) +and [Icarus diagnostics](verification/repros/sv_interface_array_connections_icarus.json). +Celox runs all four unchanged cases on every backend. + The `indexed_select::constant_part_select_indices_of_concatenations` case also uses these standard concatenation and replication selections as array indices (IEEE 1800-2023 11.4.12). Icarus 13.0 rejects them with syntax errors before @@ -397,7 +408,9 @@ four-state expectations; the assertions remain enabled on all Celox variants. | `sv_icarus_mixed_state_struct_members` | execute | icarus | 1 | Icarus 13.0 does not convert a 2-state member of a packed struct with 4-state members from four state when reading it, so a compound assignment to the member keeps X; IEEE 1800-2023 7.2.1 converts it. Verilator cannot check four-state values. | | `sv_icarus_unary_plus_unknown` | execute | icarus | 1 | Icarus 13.0 returns the operand of a unary plus unchanged when it has X or Z bits; IEEE 1800-2023 11.4.3 makes the result of an arithmetic operator all X. Verilator cannot check four-state values. | | `sv_icarus_runtime_packed_subselect` | compile | icarus | 3 | Icarus 13.0 rejects a further select after a runtime index into a multidimensional packed array, or after runtime indices into an unpacked array of them (t[k][j], t[k][2:1], u[j][k][i]: "Array index expressions must be constant here"). Verilator passes the two-state case; the four-state one is outside what it checks. | -| `sv_icarus_interfaces` | compile | icarus | 14 | Icarus 13.0 rejects interface port declarations (syntax error in port declarations), modport function imports ("sorry: modport task/function ports are not yet supported") and multidimensional interface instance arrays ("sorry: Multi-dimensional arrays of instances are not yet supported"). Verilator passes these cases. The implicit named interface cases have [focused pre-exclusion evidence](verification/sv/limitations/implicit-interface-ports-icarus.json). | +| `sv_verilator_multidimensional_interface_connections` | compile | verilator | 1 | Verilator 5.052 validates a 2x2 scalar interface array against a two-bit connection instead of four bits. See the focused interface-array evidence above. | +| `sv_icarus_interface_array_connections` | compile | icarus | 3 | Icarus 13.0 rejects distributed unpacked actuals and multidimensional instances, and aborts on interface array ports. See the focused interface-array evidence above. | +| `sv_icarus_interfaces` | compile | icarus | 15 | Icarus 13.0 rejects interface port declarations (syntax error in port declarations), modport function imports ("sorry: modport task/function ports are not yet supported") and multidimensional interface instance arrays ("sorry: Multi-dimensional arrays of instances are not yet supported"). Verilator passes these cases. The implicit named interface cases have [focused pre-exclusion evidence](verification/sv/limitations/implicit-interface-ports-icarus.json). The mixed module-contract/local-interface case retains its [port-declaration diagnostics](verification/repros/sv_mixed_interface_connections_icarus.json). | | `sv_icarus_packed_inner_index_range` | execute | icarus | 1 | Icarus 13.0 flattens an out-of-range inner index of a multidimensional packed array into the neighbouring element: a read gives a known value instead of X, and a write lands in that element; IEEE 1800-2023 7.4.6 and 11.5.1 make the select out of range. Verilator cannot check four-state values, and it truncates out-of-range packed indices. | | `sv_icarus_unpacked_subroutine_ports` | compile | icarus | 2 | Icarus 13.0 reports that subroutine ports with unpacked dimensions are not yet supported. Verilator passes the valid case. | | `sv_icarus_unpacked_array_patterns` | compile | icarus | 1 | Icarus 13.0 reports that an assignment pattern with unpacked array items assigned to a multidimensional unpacked array is not yet supported ("Procedural assignment of array or array slice"), so the run cannot count it as a language rejection. The design is invalid (IEEE 1800-2023 7.6, 10.8). | diff --git a/crates/celox-test-suite/src/sv/cases/interfaces.vtest b/crates/celox-test-suite/src/sv/cases/interfaces.vtest index 5c7cf68c682..44f83a53f50 100644 --- a/crates/celox-test-suite/src/sv/cases/interfaces.vtest +++ b/crates/celox-test-suite/src/sv/cases/interfaces.vtest @@ -693,3 +693,147 @@ (modify (set x value)) (assert_eq y (^ value (trunc 8 (+ value 1)))) (assert_eq z (^ (trunc 8 (~ value)) (trunc 8 (+ (trunc 8 (~ value)) 1)))))) + +(case distributes_packed_connections_to_interface_arrays + ; IEEE 1800-2023 23.3.3.5: declaration-order leftmost instances + ; receive the most significant packed slices; scalar values broadcast. + (source "interface_array_distribution.sv" #" + interface Wire(input logic value, output wire result); + assign result = value; + endinterface + interface Pair #(parameter int W = 2)(input logic [W-1:0] value, output wire [W-1:0] result); + assign result = value; + endinterface + module Top(input logic [1:0] bits_in, input logic [3:0] words_in, input logic shared, + output wire [1:0] descending, ascending, broadcast_bits, + output wire [3:0] words, + output wire [1:0] desc_members, asc_members, + output wire [3:0] selected_words, broadcast_words, generated_bits, ascending_members); + Wire down [3:2](.value(bits_in), .result(descending)); + Wire up [5:6](bits_in, ascending); + Wire same [1:0](.value(shared), .result(broadcast_bits)); + Pair #(.W(2)) pairs [1:0](.value(words_in), .result(words)); + wire [7:0] selected_bus; + logic [0:3] ascending_input; + assign ascending_input = words_in; + Pair selected_pairs [0:1](.value(ascending_input), .result(selected_bus[5:2])); + assign selected_words = selected_bus[5:2]; + assign ascending_members = {selected_pairs[0].value, selected_pairs[1].value}; + Pair shared_pairs [1:0](.value(words_in[1:0]), .result(broadcast_words)); + for (genvar k = 0; k < 2; k++) begin:g + Wire local_wires [0:1](.value(bits_in), .result(generated_bits[k*2 +: 2])); + end + assign desc_members = {down[3].value, down[2].value}; + assign asc_members = {up[5].value, up[6].value}; + endmodule + "#) + (top Top) + (for value (list 0 1 2 3) + (modify (set bits_in value) (set words_in (+ (* value 4) (- 3 value))) (set shared (% value 2))) + (assert_eq descending value) + (assert_eq ascending value) + (assert_eq desc_members value) + (assert_eq asc_members value) + (assert_eq broadcast_bits (* (% value 2) 3)) + (assert_eq words (+ (* value 4) (- 3 value))) + (assert_eq selected_words (+ (* value 4) (- 3 value))) + (assert_eq ascending_members (+ (* value 4) (- 3 value))) + (assert_eq broadcast_words (* (- 3 value) 5)) + (assert_eq generated_bits (* value 5)))) + +(case distributes_unpacked_connections_to_interface_arrays + (source "interface_unpacked_distribution.sv" #" + interface Pair(input logic [1:0] value, output wire [1:0] result); + assign result = value; + endinterface + module Top(input logic [3:0] data, output logic [3:0] y, members); + logic [1:0] inputs [7:6]; + wire [1:0] results [2:3]; + assign inputs[7] = data[3:2]; + assign inputs[6] = data[1:0]; + Pair pairs [4:5](.value(inputs), .result(results)); + assign y = {results[2], results[3]}; + assign members = {pairs[4].value, pairs[5].value}; + endmodule + "#) + (top Top) + (for value (list 0 1 6 9 14 15) + (modify (set data value)) + (assert_eq y value) + (assert_eq members value))) + +(case distributes_array_port_connections_to_interface_arrays + (source "interface_array_port_distribution.sv" #" + interface Block(input logic [1:0] value [2], output wire [1:0] result [2]); + assign result = value; + endinterface + module Top(input logic [7:0] data, output logic [7:0] y, members, + output logic [3:0] broadcast_values); + logic [1:0] inputs [2][2]; + wire [1:0] results [2][2]; + assign inputs[0][0] = data[7:6]; + assign inputs[0][1] = data[5:4]; + assign inputs[1][0] = data[3:2]; + assign inputs[1][1] = data[1:0]; + Block blocks [1:0](.value(inputs), .result(results)); + Block shared_blocks [1:0](.value(inputs[0])); + assign y = {results[0][0], results[0][1], results[1][0], results[1][1]}; + assign members = {blocks[1].value[0], blocks[1].value[1], blocks[0].value[0], blocks[0].value[1]}; + assign broadcast_values = {shared_blocks[1].value[0], shared_blocks[0].value[1]}; + endmodule + "#) + (top Top) + (for value (list 0 0x1b 0xe4 0xa5 0xff) + (modify (set data value)) + (assert_eq y value) + (assert_eq members value) + (assert_eq broadcast_values (slice value 7 4)))) + +(case distributes_multidimensional_connections_to_interface_arrays + ; IEEE 1800-2023 23.3.3.5: the rightmost dimension varies first. + (source "interface_multidimensional_distribution.sv" #" + interface Wire(input logic value, output wire result); + assign result = value; + endinterface + module Top(input logic [3:0] data, output wire [3:0] y, output logic [3:0] members); + Wire grid [2:1][4:3](.value(data), .result(y)); + assign members = {grid[2][4].value, grid[2][3].value, grid[1][4].value, grid[1][3].value}; + endmodule + "#) + (top Top) + (for value (list 0 3 5 10 15) + (modify (set data value)) + (assert_eq y value) + (assert_eq members value))) + +(case mixes_module_contracts_with_local_interface_connections + (source "mixed_interface_connections.sv" #" + interface Bus; + logic [1:0] data; + endinterface + interface Wire(input logic value, output wire result); + assign result = value; + endinterface + module Child(Bus b, output wire [1:0] y); + assign y = b.data; + endmodule + module GenericChild(interface b, output wire [1:0] y); + assign y = b.data; + endmodule + module Top(input logic [1:0] data, output wire [1:0] named_value, generic_value, array_value, + output wire single_value); + Bus bus(); + assign bus.data = data; + Child child(bus, named_value); + GenericChild generic_child(bus, generic_value); + Wire wires[1:0](data, array_value); + Wire single_wire(data[0], single_value); + endmodule + "#) + (top Top) + (for value (list 0 1 2 3) + (modify (set data value)) + (assert_eq named_value value) + (assert_eq generic_value value) + (assert_eq array_value value) + (assert_eq single_value (% value 2)))) diff --git a/crates/celox-test-suite/verification/repros/sv_interface_array_connections_icarus.json b/crates/celox-test-suite/verification/repros/sv_interface_array_connections_icarus.json new file mode 100644 index 00000000000..bbe20831092 --- /dev/null +++ b/crates/celox-test-suite/verification/repros/sv_interface_array_connections_icarus.json @@ -0,0 +1,55 @@ +{ + "schema_version": 3, + "suite": "sv", + "suite_version": "0.11.0", + "tool": "icarus", + "version": "Icarus Verilog version 13.0 (stable) (v13_0)", + "include_ignored": false, + "note": "Focused pre-exclusion compile failures for interface array connections (IEEE 1800-2023 23.3.3.5). Shared sources and assertions remain in src/sv/cases/interfaces.vtest; no failure was converted to a pass.", + "counts": { + "passed": 0, + "rejected": 0, + "unexpected_accept": 0, + "mismatch": 0, + "emission_error": 0, + "compile_error": 3, + "runtime_error": 0, + "unsupported": 0, + "ignored": 0 + }, + "cases": [ + { + "category": "Hierarchy", + "detail": "Icarus build exit status: 134; see /build.log\n/source_0.sv:13: assert: elaborate.cc:1574: failed assertion prts.size()==1\nAborted (core dumped)\n", + "expectation": "Simulation", + "name": "interfaces::distributes_array_port_connections_to_interface_arrays", + "phase": "compile", + "status": "compile_error", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Hierarchy", + "detail": "Icarus build exit status: 1; see /build.log\n/source_0.sv:6: sorry: Multi-dimensional arrays of instances are not yet supported.\n1 error(s) during elaboration.\n", + "expectation": "Simulation", + "name": "interfaces::distributes_multidimensional_connections_to_interface_arrays", + "phase": "compile", + "status": "compile_error", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Hierarchy", + "detail": "Icarus build exit status: 2; see /build.log\n/source_0.sv:10: error: Array inputs needs an array index here.\n/source_0.sv:10: error: Failed to elaborate input port 'value' expression (inputs) in instance dut.pairs of module: Pair.\n2 error(s) during elaboration.\n", + "expectation": "Simulation", + "name": "interfaces::distributes_unpacked_connections_to_interface_arrays", + "phase": "compile", + "status": "compile_error", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + } + ] +} diff --git a/crates/celox-test-suite/verification/repros/sv_interface_array_connections_verilator.json b/crates/celox-test-suite/verification/repros/sv_interface_array_connections_verilator.json new file mode 100644 index 00000000000..f6a96094799 --- /dev/null +++ b/crates/celox-test-suite/verification/repros/sv_interface_array_connections_verilator.json @@ -0,0 +1,33 @@ +{ + "schema_version": 3, + "suite": "sv", + "suite_version": "0.11.0", + "tool": "verilator", + "version": "Verilator 5.052 2026-09-05 rev v5.052", + "include_ignored": false, + "note": "Focused pre-exclusion compile failures for interface array connections (IEEE 1800-2023 23.3.3.5). Shared sources and assertions remain in src/sv/cases/interfaces.vtest; no failure was converted to a pass.", + "counts": { + "passed": 0, + "rejected": 0, + "unexpected_accept": 0, + "mismatch": 0, + "emission_error": 0, + "compile_error": 1, + "runtime_error": 0, + "unsupported": 0, + "ignored": 0 + }, + "cases": [ + { + "category": "Hierarchy", + "detail": "Verilator build exit status: 1; see /build.log\n%Error: /source_0.sv:6:29: Input port connection 'value' as part of a module instance array requires 1 or 2 bits, but connection's VARREF 'data' generates 4 bits. (IEEE 1800-2023 23.3.3)\n : ... note: In instance 'celox_suite_tb.dut'\n 6 | Wire grid [2:1][4:3](.value(data), .result(y));\n | ^~~~~\n ... See the manual at https://verilator.org/verilator_doc.html?v=5.052 for more assistance.\n%Error: /source_0.sv:6:43: Output port connection 'result' as part of a module instance array requires 1 or 2 bits, but connection's VARREF 'y' generates 4 bits. (IEEE 1800-2023 23.3.3)\n : ... note: In instance 'celox_suite_tb.dut'\n 6 | Wire grid [2:1][4:3](.value(data), .result(y));\n | ^~~~~~\n%Error: Exiting due to 2 error(s)\n", + "expectation": "Simulation", + "name": "interfaces::distributes_multidimensional_connections_to_interface_arrays", + "phase": "compile", + "status": "compile_error", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + } + ] +} diff --git a/crates/celox-test-suite/verification/repros/sv_mixed_interface_connections_icarus.json b/crates/celox-test-suite/verification/repros/sv_mixed_interface_connections_icarus.json new file mode 100644 index 00000000000..cb3ccb5ed9e --- /dev/null +++ b/crates/celox-test-suite/verification/repros/sv_mixed_interface_connections_icarus.json @@ -0,0 +1,33 @@ +{ + "schema_version": 3, + "suite": "sv", + "suite_version": "0.11.0", + "tool": "icarus", + "version": "Icarus Verilog version 13.0 (stable) (v13_0)", + "include_ignored": false, + "counts": { + "compile_error": 1, + "emission_error": 0, + "ignored": 0, + "mismatch": 0, + "passed": 0, + "rejected": 0, + "runtime_error": 0, + "unexpected_accept": 0, + "unsupported": 0 + }, + "cases": [ + { + "category": "Hierarchy", + "detail": "Icarus build exit status: 4; see /build.log\n/source_0.sv:8: syntax error\n/source_0.sv:8: Errors in port declarations.\n/source_0.sv:11: syntax error\n/source_0.sv:11: Errors in port declarations.\n", + "expectation": "Simulation", + "name": "interfaces::mixes_module_contracts_with_local_interface_connections", + "phase": "compile", + "status": "compile_error", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + } + ], + "note": "Focused pre-exclusion failure: Icarus rejects the typed and generic module interface port declarations in the mixed local-interface connection regression. Celox and Verilator pass the unchanged source and assertions." +} diff --git a/crates/celox-test-suite/verification/sv/icarus/interfaces.json b/crates/celox-test-suite/verification/sv/icarus/interfaces.json index 857a898b77f..5ed546a6a29 100644 --- a/crates/celox-test-suite/verification/sv/icarus/interfaces.json +++ b/crates/celox-test-suite/verification/sv/icarus/interfaces.json @@ -10,6 +10,7 @@ "verification/sv/limitations/icarus.json", "verification/sv/limitations/interface-array-ports-icarus.json", "verification/sv/limitations/implicit-interface-ports-icarus.json", + "verification/repros/sv_mixed_interface_connections_icarus.json", "LIMITATIONS.md#systemverilog-suite" ], "id": "sv_icarus_interfaces", @@ -35,6 +36,7 @@ "verification/sv/limitations/icarus.json", "verification/sv/limitations/interface-array-ports-icarus.json", "verification/sv/limitations/implicit-interface-ports-icarus.json", + "verification/repros/sv_mixed_interface_connections_icarus.json", "LIMITATIONS.md#systemverilog-suite" ], "id": "sv_icarus_interfaces", @@ -60,6 +62,7 @@ "verification/sv/limitations/icarus.json", "verification/sv/limitations/interface-array-ports-icarus.json", "verification/sv/limitations/implicit-interface-ports-icarus.json", + "verification/repros/sv_mixed_interface_connections_icarus.json", "LIMITATIONS.md#systemverilog-suite" ], "id": "sv_icarus_interfaces", @@ -85,6 +88,7 @@ "verification/sv/limitations/icarus.json", "verification/sv/limitations/interface-array-ports-icarus.json", "verification/sv/limitations/implicit-interface-ports-icarus.json", + "verification/repros/sv_mixed_interface_connections_icarus.json", "LIMITATIONS.md#systemverilog-suite" ], "id": "sv_icarus_interfaces", @@ -110,6 +114,7 @@ "verification/sv/limitations/icarus.json", "verification/sv/limitations/interface-array-ports-icarus.json", "verification/sv/limitations/implicit-interface-ports-icarus.json", + "verification/repros/sv_mixed_interface_connections_icarus.json", "LIMITATIONS.md#systemverilog-suite" ], "id": "sv_icarus_interfaces", @@ -135,6 +140,7 @@ "verification/sv/limitations/icarus.json", "verification/sv/limitations/interface-array-ports-icarus.json", "verification/sv/limitations/implicit-interface-ports-icarus.json", + "verification/repros/sv_mixed_interface_connections_icarus.json", "LIMITATIONS.md#systemverilog-suite" ], "id": "sv_icarus_interfaces", @@ -160,6 +166,7 @@ "verification/sv/limitations/icarus.json", "verification/sv/limitations/interface-array-ports-icarus.json", "verification/sv/limitations/implicit-interface-ports-icarus.json", + "verification/repros/sv_mixed_interface_connections_icarus.json", "LIMITATIONS.md#systemverilog-suite" ], "id": "sv_icarus_interfaces", @@ -196,6 +203,7 @@ "verification/sv/limitations/icarus.json", "verification/sv/limitations/interface-array-ports-icarus.json", "verification/sv/limitations/implicit-interface-ports-icarus.json", + "verification/repros/sv_mixed_interface_connections_icarus.json", "LIMITATIONS.md#systemverilog-suite" ], "id": "sv_icarus_interfaces", @@ -221,6 +229,7 @@ "verification/sv/limitations/icarus.json", "verification/sv/limitations/interface-array-ports-icarus.json", "verification/sv/limitations/implicit-interface-ports-icarus.json", + "verification/repros/sv_mixed_interface_connections_icarus.json", "LIMITATIONS.md#systemverilog-suite" ], "id": "sv_icarus_interfaces", @@ -246,6 +255,7 @@ "verification/sv/limitations/icarus.json", "verification/sv/limitations/interface-array-ports-icarus.json", "verification/sv/limitations/implicit-interface-ports-icarus.json", + "verification/repros/sv_mixed_interface_connections_icarus.json", "LIMITATIONS.md#systemverilog-suite" ], "id": "sv_icarus_interfaces", @@ -271,6 +281,7 @@ "verification/sv/limitations/icarus.json", "verification/sv/limitations/interface-array-ports-icarus.json", "verification/sv/limitations/implicit-interface-ports-icarus.json", + "verification/repros/sv_mixed_interface_connections_icarus.json", "LIMITATIONS.md#systemverilog-suite" ], "id": "sv_icarus_interfaces", @@ -305,6 +316,7 @@ "verification/sv/limitations/icarus.json", "verification/sv/limitations/interface-array-ports-icarus.json", "verification/sv/limitations/implicit-interface-ports-icarus.json", + "verification/repros/sv_mixed_interface_connections_icarus.json", "LIMITATIONS.md#systemverilog-suite" ] }, @@ -413,6 +425,7 @@ "verification/sv/limitations/icarus.json", "verification/sv/limitations/interface-array-ports-icarus.json", "verification/sv/limitations/implicit-interface-ports-icarus.json", + "verification/repros/sv_mixed_interface_connections_icarus.json", "LIMITATIONS.md#systemverilog-suite" ], "id": "sv_icarus_interfaces", @@ -438,6 +451,7 @@ "verification/sv/limitations/icarus.json", "verification/sv/limitations/interface-array-ports-icarus.json", "verification/sv/limitations/implicit-interface-ports-icarus.json", + "verification/repros/sv_mixed_interface_connections_icarus.json", "LIMITATIONS.md#systemverilog-suite" ], "id": "sv_icarus_interfaces", @@ -452,6 +466,101 @@ "stronger_than_sv": false, "tag_reasons": {}, "tags": [] + }, + { + "category": "Hierarchy", + "detail": "Icarus 13.0 rejects unpacked actuals distributed across interface instances (Array inputs needs an array index), aborts on interface array ports (assertion prts.size()==1), and rejects multidimensional instance arrays explicitly. IEEE 1800-2023 23.3.3.5 permits these connections. Verilator passes both unpacked cases; Celox passes all three.", + "expectation": "Simulation", + "known_issue": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/repros/sv_interface_array_connections_icarus.json", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_icarus_interface_array_connections", + "observed_version": "Icarus Verilog version 13.0 (stable) (v13_0)", + "phase": "compile", + "reason": "Icarus 13.0 rejects unpacked actuals distributed across interface instances (Array inputs needs an array index), aborts on interface array ports (assertion prts.size()==1), and rejects multidimensional instance arrays explicitly. IEEE 1800-2023 23.3.3.5 permits these connections. Verilator passes both unpacked cases; Celox passes all three.", + "upstream": [] + }, + "name": "interfaces::distributes_array_port_connections_to_interface_arrays", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Hierarchy", + "detail": "Icarus 13.0 rejects unpacked actuals distributed across interface instances (Array inputs needs an array index), aborts on interface array ports (assertion prts.size()==1), and rejects multidimensional instance arrays explicitly. IEEE 1800-2023 23.3.3.5 permits these connections. Verilator passes both unpacked cases; Celox passes all three.", + "expectation": "Simulation", + "known_issue": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/repros/sv_interface_array_connections_icarus.json", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_icarus_interface_array_connections", + "observed_version": "Icarus Verilog version 13.0 (stable) (v13_0)", + "phase": "compile", + "reason": "Icarus 13.0 rejects unpacked actuals distributed across interface instances (Array inputs needs an array index), aborts on interface array ports (assertion prts.size()==1), and rejects multidimensional instance arrays explicitly. IEEE 1800-2023 23.3.3.5 permits these connections. Verilator passes both unpacked cases; Celox passes all three.", + "upstream": [] + }, + "name": "interfaces::distributes_multidimensional_connections_to_interface_arrays", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Hierarchy", + "detail": "Icarus 13.0 rejects unpacked actuals distributed across interface instances (Array inputs needs an array index), aborts on interface array ports (assertion prts.size()==1), and rejects multidimensional instance arrays explicitly. IEEE 1800-2023 23.3.3.5 permits these connections. Verilator passes both unpacked cases; Celox passes all three.", + "expectation": "Simulation", + "known_issue": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/repros/sv_interface_array_connections_icarus.json", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_icarus_interface_array_connections", + "observed_version": "Icarus Verilog version 13.0 (stable) (v13_0)", + "phase": "compile", + "reason": "Icarus 13.0 rejects unpacked actuals distributed across interface instances (Array inputs needs an array index), aborts on interface array ports (assertion prts.size()==1), and rejects multidimensional instance arrays explicitly. IEEE 1800-2023 23.3.3.5 permits these connections. Verilator passes both unpacked cases; Celox passes all three.", + "upstream": [] + }, + "name": "interfaces::distributes_unpacked_connections_to_interface_arrays", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Hierarchy", + "detail": "Icarus 13.0 rejects interface port declarations (syntax error in port declarations), modport function imports (\"sorry: modport task/function ports are not yet supported\") and multidimensional interface instance arrays (\"sorry: Multi-dimensional arrays of instances are not yet supported\"). Verilator passes these cases.", + "expectation": "Simulation", + "known_issue": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/sv/limitations/icarus.json", + "verification/sv/limitations/interface-array-ports-icarus.json", + "verification/sv/limitations/implicit-interface-ports-icarus.json", + "verification/repros/sv_mixed_interface_connections_icarus.json", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_icarus_interfaces", + "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", + "phase": "compile", + "reason": "Icarus 13.0 rejects interface port declarations (syntax error in port declarations), modport function imports (\"sorry: modport task/function ports are not yet supported\") and multidimensional interface instance arrays (\"sorry: Multi-dimensional arrays of instances are not yet supported\"). Verilator passes these cases.", + "upstream": [] + }, + "name": "interfaces::mixes_module_contracts_with_local_interface_connections", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] } ] } diff --git a/crates/celox-test-suite/verification/sv/limitations.json b/crates/celox-test-suite/verification/sv/limitations.json index 40f8787d4b0..35d0da4feb3 100644 --- a/crates/celox-test-suite/verification/sv/limitations.json +++ b/crates/celox-test-suite/verification/sv/limitations.json @@ -605,6 +605,7 @@ "verification/sv/limitations/icarus.json", "verification/sv/limitations/interface-array-ports-icarus.json", "verification/sv/limitations/implicit-interface-ports-icarus.json", + "verification/repros/sv_mixed_interface_connections_icarus.json", "LIMITATIONS.md#systemverilog-suite" ], "cases": { @@ -619,6 +620,7 @@ "interfaces::drives_members_through_child_outputs_and_array_generate_regions", "interfaces::elaborates_net_members_typedefs_and_localparams", "interfaces::infers_directions_of_ports_without_modport", + "interfaces::mixes_module_contracts_with_local_interface_connections", "interfaces::overrides_body_parameters_and_drives_members_from_imported_functions", "interfaces::reads_undriven_interface_members_as_unknown", "interfaces::rewrites_nested_references_and_keeps_declaration_functions", @@ -626,6 +628,42 @@ ] } }, + { + "id": "sv_verilator_multidimensional_interface_connections", + "category": "simulator_compile_limitation", + "phase": "compile", + "observed_version": "Verilator 5.052 2026-09-05 rev v5.052", + "reason": "Verilator 5.052 rejects a four-bit actual connected to a 2x2 interface instance array with scalar ports, requiring only 1 or 2 bits instead of 1 or 4. IEEE 1800-2023 23.3.3.5 distributes packed actuals across all instance dimensions, rightmost dimension first. Celox passes the unchanged shared assertions; Icarus separately rejects multidimensional instance arrays.", + "upstream": [], + "evidence": [ + "verification/repros/sv_interface_array_connections_verilator.json", + "LIMITATIONS.md#systemverilog-suite" + ], + "cases": { + "verilator": [ + "interfaces::distributes_multidimensional_connections_to_interface_arrays" + ] + } + }, + { + "id": "sv_icarus_interface_array_connections", + "category": "simulator_compile_limitation", + "phase": "compile", + "observed_version": "Icarus Verilog version 13.0 (stable) (v13_0)", + "reason": "Icarus 13.0 rejects unpacked actuals distributed across interface instances (Array inputs needs an array index), aborts on interface array ports (assertion prts.size()==1), and rejects multidimensional instance arrays explicitly. IEEE 1800-2023 23.3.3.5 permits these connections. Verilator passes both unpacked cases; Celox passes all three.", + "upstream": [], + "evidence": [ + "verification/repros/sv_interface_array_connections_icarus.json", + "LIMITATIONS.md#systemverilog-suite" + ], + "cases": { + "icarus": [ + "interfaces::distributes_array_port_connections_to_interface_arrays", + "interfaces::distributes_multidimensional_connections_to_interface_arrays", + "interfaces::distributes_unpacked_connections_to_interface_arrays" + ] + } + }, { "id": "sv_icarus_dimensions_type_queries", "category": "simulator_compile_limitation", diff --git a/crates/celox-test-suite/verification/sv/verilator/interfaces.json b/crates/celox-test-suite/verification/sv/verilator/interfaces.json index ac71a506b90..4ec712f8799 100644 --- a/crates/celox-test-suite/verification/sv/verilator/interfaces.json +++ b/crates/celox-test-suite/verification/sv/verilator/interfaces.json @@ -131,6 +131,29 @@ "stronger_than_sv": false, "tag_reasons": {}, "tags": [] + }, + { + "category": "Hierarchy", + "detail": "Verilator 5.052 rejects a four-bit actual connected to a 2x2 interface instance array with scalar ports, requiring only 1 or 2 bits instead of 1 or 4. IEEE 1800-2023 23.3.3.5 distributes packed actuals across all instance dimensions, rightmost dimension first. Celox passes the unchanged shared assertions; Icarus separately rejects multidimensional instance arrays.", + "expectation": "Simulation", + "known_issue": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/repros/sv_interface_array_connections_verilator.json", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_verilator_multidimensional_interface_connections", + "observed_version": "Verilator 5.052 2026-09-05 rev v5.052", + "phase": "compile", + "reason": "Verilator 5.052 rejects a four-bit actual connected to a 2x2 interface instance array with scalar ports, requiring only 1 or 2 bits instead of 1 or 4. IEEE 1800-2023 23.3.3.5 distributes packed actuals across all instance dimensions, rightmost dimension first. Celox passes the unchanged shared assertions; Icarus separately rejects multidimensional instance arrays.", + "upstream": [] + }, + "name": "interfaces::distributes_multidimensional_connections_to_interface_arrays", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] } ] } diff --git a/crates/celox/tests/frontends/systemverilog/interfaces.rs b/crates/celox/tests/frontends/systemverilog/interfaces.rs index 30d336fbbf4..20f54ade184 100644 --- a/crates/celox/tests/frontends/systemverilog/interfaces.rs +++ b/crates/celox/tests/frontends/systemverilog/interfaces.rs @@ -1,6 +1,25 @@ use super::*; sv_backends! { + fn distributes_multidimensional_connections_to_interface_arrays(sim) { + @case "interfaces::distributes_multidimensional_connections_to_interface_arrays"; + } + + fn distributes_array_port_connections_to_interface_arrays(sim) { + @case "interfaces::distributes_array_port_connections_to_interface_arrays"; + } + + fn distributes_unpacked_connections_to_interface_arrays(sim) { + @case "interfaces::distributes_unpacked_connections_to_interface_arrays"; + } + + fn mixes_module_contracts_with_local_interface_connections(sim) { + @case "interfaces::mixes_module_contracts_with_local_interface_connections"; + } + fn distributes_packed_connections_to_interface_arrays(sim) { + @case "interfaces::distributes_packed_connections_to_interface_arrays"; + } + fn binds_implicit_named_interface_ports(sim) { @case "interfaces::binds_implicit_named_interface_ports"; } diff --git a/package.json b/package.json index 44cc4b2a65c..1e8b06ee95e 100644 --- a/package.json +++ b/package.json @@ -21,12 +21,12 @@ }, "devDependencies": { "@biomejs/biome": "^2.4.5", - "@emnapi/core": "2.0.0-alpha.6", - "@emnapi/runtime": "2.0.0-alpha.6", + "@emnapi/core": "2.0.0-beta.1", + "@emnapi/runtime": "2.0.0-beta.1", "@napi-rs/wasm-runtime": "1.2.5", "@tybys/wasm-util": "^0.10.1", "chart.js": "^4.4.0", - "emnapi": "2.0.0-alpha.6", + "emnapi": "2.0.0-beta.1", "lefthook": "^2.1.2", "typedoc": "^0.28.0", "typedoc-plugin-markdown": "^4.4.0", diff --git a/patches/@napi-rs__wasm-runtime@1.2.5.patch b/patches/@napi-rs__wasm-runtime@1.2.5.patch new file mode 100644 index 00000000000..5e09846c82e --- /dev/null +++ b/patches/@napi-rs__wasm-runtime@1.2.5.patch @@ -0,0 +1,68 @@ +diff --git a/runtime.cjs b/runtime.cjs +index 3dc0d9776903bfc21a924f50ddff1def592062a8..b21ae20e5637e6593cf6b62d068ca42fef2cc43f 100644 +--- a/runtime.cjs ++++ b/runtime.cjs +@@ -3,23 +3,11 @@ const { + instantiateNapiModuleSync, + instantiateNapiModule, + } = require('@emnapi/core') +-// Single-threaded (non-shared-memory) WASI builds link an emnapi archive +-// without the C async-work and threadsafe-function implementations (they are +-// unconditional `napi_generic_failure` stubs without threads), so the +-// generated loaders provide the JavaScript implementations through these +-// plugins instead. Raw `instantiateNapiModule(Sync)` callers instantiating a +-// single-threaded napi-rs wasm must pass them too: +-// `plugins: [emnapiAsyncWorkPlugin, emnapiTSFNPlugin]` — without them +-// instantiation fails with a LinkError naming the missing import. Threaded +-// (shared-memory) builds link the C implementations and need no plugins; +-// this mirrors the upstream @emnapi/core v2 plugin split (v1 bundled these +-// implementations in the core runtime). The plugins are bundled into this +-// package so loading the runtime with @emnapi/core v1 does not resolve the +-// v2-only `@emnapi/core/plugins` package export. ++// Celox pins emnapi v2: use plugins matching its internal API. + const { +- emnapiAsyncWorkPlugin, +- emnapiTSFNPlugin, +-} = require('./dist/emnapi-plugins.cjs') ++ asyncWork: emnapiAsyncWorkPlugin, ++ tsfn: emnapiTSFNPlugin, ++} = require('@emnapi/core/plugins') + const { createContext, getDefaultContext } = require('@emnapi/runtime') + const { WASI } = require('@tybys/wasm-util') + +diff --git a/runtime.js b/runtime.js +index 7a727a04460d6fd507bcd5fe8c8bf4e13530ba04..5582340fc5ee937714efe4d05a5b4ac78fcaa8af 100644 +--- a/runtime.js ++++ b/runtime.js +@@ -2,27 +2,15 @@ import * as emnapiCore from '@emnapi/core' + import * as emnapiRuntime from '@emnapi/runtime' + + import { +- emnapiAsyncWorkPlugin, +- emnapiTSFNPlugin, +-} from './dist/emnapi-plugins.js' ++ asyncWork as emnapiAsyncWorkPlugin, ++ tsfn as emnapiTSFNPlugin, ++} from '@emnapi/core/plugins' + + const { instantiateNapiModuleSync, instantiateNapiModule, MessageHandler } = + emnapiCore + const { createContext, getDefaultContext } = emnapiRuntime + +-// Single-threaded (non-shared-memory) WASI builds link an emnapi archive +-// without the C async-work and threadsafe-function implementations (they are +-// unconditional `napi_generic_failure` stubs without threads), so the +-// generated loaders provide the JavaScript implementations through these +-// plugins instead. Raw `instantiateNapiModule(Sync)` callers instantiating a +-// single-threaded napi-rs wasm must pass them too: +-// `plugins: [emnapiAsyncWorkPlugin, emnapiTSFNPlugin]` — without them +-// instantiation fails with a LinkError naming the missing import. Threaded +-// (shared-memory) builds link the C implementations and need no plugins; +-// this mirrors the upstream @emnapi/core v2 plugin split (v1 bundled these +-// implementations in the core runtime). The plugins are bundled into this +-// package so loading the runtime with @emnapi/core v1 does not resolve the +-// v2-only `@emnapi/core/plugins` package export. ++// Celox pins emnapi v2: use plugins matching its internal API. + export { + MessageHandler, + createContext, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 52858b08e42..47c49683fab 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -166,9 +166,12 @@ overrides: '@celox-sim/celox': workspace:* '@celox-sim/celox-napi': workspace:* '@celox-sim/vite-plugin': workspace:* - '@emnapi/core': 2.0.0-alpha.6 - '@emnapi/runtime': 2.0.0-alpha.6 - emnapi: 2.0.0-alpha.6 + '@emnapi/core': 2.0.0-beta.1 + '@emnapi/runtime': 2.0.0-beta.1 + emnapi: 2.0.0-beta.1 + +patchedDependencies: + '@napi-rs/wasm-runtime@1.2.5': 55fd5d25b61174ba200fd92f6cb049e5d2baa68950bd8f903097f783c4f829ce importers: @@ -178,14 +181,14 @@ importers: specifier: ^2.4.5 version: 2.5.15 '@emnapi/core': - specifier: 2.0.0-alpha.6 - version: 2.0.0-alpha.6 + specifier: 2.0.0-beta.1 + version: 2.0.0-beta.1 '@emnapi/runtime': - specifier: 2.0.0-alpha.6 - version: 2.0.0-alpha.6 + specifier: 2.0.0-beta.1 + version: 2.0.0-beta.1 '@napi-rs/wasm-runtime': specifier: 1.2.5 - version: 1.2.5(@emnapi/core@2.0.0-alpha.6)(@emnapi/runtime@2.0.0-alpha.6) + version: 1.2.5(patch_hash=55fd5d25b61174ba200fd92f6cb049e5d2baa68950bd8f903097f783c4f829ce)(@emnapi/core@2.0.0-beta.1)(@emnapi/runtime@2.0.0-beta.1) '@tybys/wasm-util': specifier: ^0.10.1 version: 0.10.4 @@ -193,8 +196,8 @@ importers: specifier: ^4.4.0 version: 4.5.1 emnapi: - specifier: 2.0.0-alpha.6 - version: 2.0.0-alpha.6 + specifier: 2.0.0-beta.1 + version: 2.0.0-beta.1 lefthook: specifier: ^2.1.2 version: 2.2.2 @@ -221,7 +224,7 @@ importers: devDependencies: '@napi-rs/cli': specifier: 3.10.8 - version: 3.10.8(@emnapi/core@2.0.0-alpha.6)(@emnapi/runtime@2.0.0-alpha.6)(@types/node@25.9.9)(emnapi@2.0.0-alpha.6) + version: 3.10.8(@emnapi/core@2.0.0-beta.1)(@emnapi/runtime@2.0.0-beta.1)(@types/node@25.9.9)(emnapi@2.0.0-beta.1) packages/celox: dependencies: @@ -476,11 +479,11 @@ packages: search-insights: optional: true - '@emnapi/core@2.0.0-alpha.6': - resolution: {integrity: sha512-MNVvMV7WtEJMgqaWJMvCyupK7Oi8sZctUIgPRZTsiS3cVvefk8DXPflOU3MSBddtj/rrYHygpYgpHDgwXnI3+w==} + '@emnapi/core@2.0.0-beta.1': + resolution: {integrity: sha512-5E4gwO8qdhoubPxgbs8QvihDap+vjrx8oZUHimGulO2+O3smgEQGBY554Pr3MkoGy2PuvZgrzTzLatekbWWCLQ==} - '@emnapi/runtime@2.0.0-alpha.6': - resolution: {integrity: sha512-5ZR49ZsZ3cLvu5lkrVj6CMpHRgZjYz7XSlqK23GYYpyEqp749RVuIH0bEUKaGNghMh2pXRhIC3cnVrH28Y1j1Q==} + '@emnapi/runtime@2.0.0-beta.1': + resolution: {integrity: sha512-u//q85BwNEBaNK0K4PH/RL9UYgYnAoSAUpD/YtxHkAfcfRLvcpfasTUf+p9xnoQ6EKP74+Am3/zi2Kb00AzGYw==} '@emnapi/wasi-threads@2.2.0': resolution: {integrity: sha512-JP7OYH38Q7+pyTAe14raZHLQIK7BDKbdwji+Xi3pcd/6QkJYQH3SX4wu6EplGrGJWRepoNzedfm0G3B9Z4e9Rw==} @@ -790,9 +793,9 @@ packages: engines: {node: ^20.17.0 || ^22.13.0 || >= 23.5.0} hasBin: true peerDependencies: - '@emnapi/core': 2.0.0-alpha.6 - '@emnapi/runtime': 2.0.0-alpha.6 - emnapi: 2.0.0-alpha.6 + '@emnapi/core': 2.0.0-beta.1 + '@emnapi/runtime': 2.0.0-beta.1 + emnapi: 2.0.0-beta.1 peerDependenciesMeta: '@emnapi/core': optional: true @@ -1057,8 +1060,8 @@ packages: resolution: {integrity: sha512-HshSvXzmBxNzqejd3k/KemgQ3hdREUYFRRrgxOZ+gPljDIsO2SDZrVZMd4Z/HsxudQbE62OVyVFE8z9BCurfjA==} engines: {node: ^20.19.0 || ^22.13.0 || >=23.5.0} peerDependencies: - '@emnapi/core': 2.0.0-alpha.6 - '@emnapi/runtime': 2.0.0-alpha.6 + '@emnapi/core': 2.0.0-beta.1 + '@emnapi/runtime': 2.0.0-beta.1 '@napi-rs/wasm-tools-android-arm-eabi@1.1.0': resolution: {integrity: sha512-p6J8PB59I8d/XItXB/go5JH6nKW+xIbpzaL43EBTV0hi7mrS/Z4gs+MsB04ZrlqZN29BdZV8fChRyasuXLhRaA==} @@ -1881,8 +1884,8 @@ packages: dompurify@3.4.15: resolution: {integrity: sha512-EUBjM+B+lkDE41iE82DDSCfkoPGfXx8IxFxPMjNzm/Uk4xDet77rTN9wqlxlVg71kK7XGuUMv6wUxJUwwv+Xyw==} - emnapi@2.0.0-alpha.6: - resolution: {integrity: sha512-+A54DE5YkbMVOa/0GDs3jhRmu2KnAFvOjEgAYuaPWdmF7A822PtB2znC23QbQ4l/qcC1ZFOrmvXVIuo9xWX2bg==} + emnapi@2.0.0-beta.1: + resolution: {integrity: sha512-8dyO4NxiqeCGy8DhqRjp675bsmOWs0Mz2LircSLB6sTfAza84u03/VX2S+imD9J1X6k2QJNpYrToi8gApHhafg==} peerDependencies: node-addon-api: '>= 6.1.0' peerDependenciesMeta: @@ -2774,12 +2777,12 @@ snapshots: transitivePeerDependencies: - '@algolia/client-search' - '@emnapi/core@2.0.0-alpha.6': + '@emnapi/core@2.0.0-beta.1': dependencies: '@emnapi/wasi-threads': 2.2.0 tslib: 2.8.1 - '@emnapi/runtime@2.0.0-alpha.6': + '@emnapi/runtime@2.0.0-beta.1': dependencies: tslib: 2.8.1 @@ -3007,7 +3010,7 @@ snapshots: '@kurkle/color@0.3.4': {} - '@napi-rs/cli@3.10.8(@emnapi/core@2.0.0-alpha.6)(@emnapi/runtime@2.0.0-alpha.6)(@types/node@25.9.9)(emnapi@2.0.0-alpha.6)': + '@napi-rs/cli@3.10.8(@emnapi/core@2.0.0-beta.1)(@emnapi/runtime@2.0.0-beta.1)(@types/node@25.9.9)(emnapi@2.0.0-beta.1)': dependencies: '@inquirer/prompts': 8.5.2(@types/node@25.9.9) '@napi-rs/cross-toolchain': 1.0.3 @@ -3022,9 +3025,9 @@ snapshots: typanion: 3.14.0 typescript: 6.0.3 optionalDependencies: - '@emnapi/core': 2.0.0-alpha.6 - '@emnapi/runtime': 2.0.0-alpha.6 - emnapi: 2.0.0-alpha.6 + '@emnapi/core': 2.0.0-beta.1 + '@emnapi/runtime': 2.0.0-beta.1 + emnapi: 2.0.0-beta.1 transitivePeerDependencies: - '@napi-rs/cross-toolchain-arm64-target-aarch64' - '@napi-rs/cross-toolchain-arm64-target-armv7' @@ -3088,9 +3091,9 @@ snapshots: '@napi-rs/lzma-wasm32-wasi@1.5.1': dependencies: - '@emnapi/core': 2.0.0-alpha.6 - '@emnapi/runtime': 2.0.0-alpha.6 - '@napi-rs/wasm-runtime': 1.2.5(@emnapi/core@2.0.0-alpha.6)(@emnapi/runtime@2.0.0-alpha.6) + '@emnapi/core': 2.0.0-beta.1 + '@emnapi/runtime': 2.0.0-beta.1 + '@napi-rs/wasm-runtime': 1.2.5(patch_hash=55fd5d25b61174ba200fd92f6cb049e5d2baa68950bd8f903097f783c4f829ce)(@emnapi/core@2.0.0-beta.1)(@emnapi/runtime@2.0.0-beta.1) optional: true '@napi-rs/lzma-win32-arm64-msvc@1.5.1': @@ -3160,9 +3163,9 @@ snapshots: '@napi-rs/tar-wasm32-wasi@1.1.1': dependencies: - '@emnapi/core': 2.0.0-alpha.6 - '@emnapi/runtime': 2.0.0-alpha.6 - '@napi-rs/wasm-runtime': 1.2.5(@emnapi/core@2.0.0-alpha.6)(@emnapi/runtime@2.0.0-alpha.6) + '@emnapi/core': 2.0.0-beta.1 + '@emnapi/runtime': 2.0.0-beta.1 + '@napi-rs/wasm-runtime': 1.2.5(patch_hash=55fd5d25b61174ba200fd92f6cb049e5d2baa68950bd8f903097f783c4f829ce)(@emnapi/core@2.0.0-beta.1)(@emnapi/runtime@2.0.0-beta.1) optional: true '@napi-rs/tar-win32-arm64-msvc@1.1.1': @@ -3193,10 +3196,10 @@ snapshots: '@napi-rs/tar-win32-ia32-msvc': 1.1.1 '@napi-rs/tar-win32-x64-msvc': 1.1.1 - '@napi-rs/wasm-runtime@1.2.5(@emnapi/core@2.0.0-alpha.6)(@emnapi/runtime@2.0.0-alpha.6)': + '@napi-rs/wasm-runtime@1.2.5(patch_hash=55fd5d25b61174ba200fd92f6cb049e5d2baa68950bd8f903097f783c4f829ce)(@emnapi/core@2.0.0-beta.1)(@emnapi/runtime@2.0.0-beta.1)': dependencies: - '@emnapi/core': 2.0.0-alpha.6 - '@emnapi/runtime': 2.0.0-alpha.6 + '@emnapi/core': 2.0.0-beta.1 + '@emnapi/runtime': 2.0.0-beta.1 '@tybys/wasm-util': 0.10.4 '@napi-rs/wasm-tools-android-arm-eabi@1.1.0': @@ -3228,9 +3231,9 @@ snapshots: '@napi-rs/wasm-tools-wasm32-wasi@1.1.0': dependencies: - '@emnapi/core': 2.0.0-alpha.6 - '@emnapi/runtime': 2.0.0-alpha.6 - '@napi-rs/wasm-runtime': 1.2.5(@emnapi/core@2.0.0-alpha.6)(@emnapi/runtime@2.0.0-alpha.6) + '@emnapi/core': 2.0.0-beta.1 + '@emnapi/runtime': 2.0.0-beta.1 + '@napi-rs/wasm-runtime': 1.2.5(patch_hash=55fd5d25b61174ba200fd92f6cb049e5d2baa68950bd8f903097f783c4f829ce)(@emnapi/core@2.0.0-beta.1)(@emnapi/runtime@2.0.0-beta.1) optional: true '@napi-rs/wasm-tools-win32-arm64-msvc@1.1.0': @@ -3850,7 +3853,7 @@ snapshots: optionalDependencies: '@types/trusted-types': 2.0.7 - emnapi@2.0.0-alpha.6: {} + emnapi@2.0.0-beta.1: {} emoji-regex-xs@1.0.0: {} diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 9828b1a3469..a9c4b693c5e 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -5,9 +5,9 @@ overrides: "@celox-sim/celox": "workspace:*" "@celox-sim/celox-napi": "workspace:*" "@celox-sim/vite-plugin": "workspace:*" - "@emnapi/core": "2.0.0-alpha.6" - "@emnapi/runtime": "2.0.0-alpha.6" - emnapi: "2.0.0-alpha.6" + "@emnapi/core": "2.0.0-beta.1" + "@emnapi/runtime": "2.0.0-beta.1" + emnapi: "2.0.0-beta.1" allowBuilds: esbuild: true lefthook: true @@ -34,3 +34,8 @@ minimumReleaseAgeExclude: - "@rolldown/binding-win32-arm64-msvc@1.2.13" - "@rolldown/binding-openharmony-arm64@1.2.13" - "@rolldown/binding-linux-arm-gnueabihf@1.2.13" +patchedDependencies: + # 1.2.5 bundles alpha-era plugins that access napiModule; beta.1 uses + # addonModule internally. Load the pinned core's own plugins in both formats. + # Remove when wasm-runtime ships compatible plugins (regression: emnapi-compatibility.test.mjs). + '@napi-rs/wasm-runtime@1.2.5': patches/@napi-rs__wasm-runtime@1.2.5.patch diff --git a/scripts/emnapi-compatibility.test.mjs b/scripts/emnapi-compatibility.test.mjs new file mode 100644 index 00000000000..ee8b1617f15 --- /dev/null +++ b/scripts/emnapi-compatibility.test.mjs @@ -0,0 +1,27 @@ +import assert from "node:assert/strict"; +import { createRequire } from "node:module"; +import test from "node:test"; +import { createAddonModule } from "@emnapi/core"; + +const require = createRequire(import.meta.url); + +for (const format of ["import", "require"]) { + test(`emnapi plugins initialize with the installed core (${format})`, async () => { + const runtime = + format === "import" + ? await import("@napi-rs/wasm-runtime") + : require("@napi-rs/wasm-runtime"); + // Exercise plugin initialization without compiling a WASM addon. A stale + // bundled plugin fails here when emnapi changes its internal module API. + const addon = createAddonModule({ + context: runtime.createContext(), + plugins: [runtime.emnapiAsyncWorkPlugin, runtime.emnapiTSFNPlugin], + }); + assert.equal(typeof addon.initWorker, "function"); + assert.equal(typeof addon.imports.napi.napi_create_async_work, "function"); + assert.equal( + typeof addon.imports.napi.napi_create_threadsafe_function, + "function", + ); + }); +}