From e0c060f866babd3cf1607a2a5577d04a6eda4cb1 Mon Sep 17 00:00:00 2001 From: tignear Date: Thu, 29 Oct 2026 01:59:43 +0900 Subject: [PATCH] feat(sv): pass unpacked structures by reference A `ref` or `const ref` formal of unpacked structure type was rejected, which blocks UVM: `uvm_reg_adapter::reg2bus(const ref uvm_reg_bus_op rw)` and `bus2reg(..., ref uvm_reg_bus_op rw)` are elaborated with every `uvm_pkg`. A structure is a set of member variables, so its reference formal is now one reference per member, bound to the matching member of the actual (IEEE 1800-2023 13.5.2): writes through the formal are seen at once in both directions, also across task suspensions. - The analyzer records the members of a structure formal in `SubroutineParam::leaves`. A reference formal gets no copy-in or copy-out. The body that dispatches a virtual method forwards the members, so a call through a pure virtual method binds the override's members to the caller's. - Actuals: structure variables, members that are structures, class properties of structure type and their members. A scalar member of a structure is now also an ordinary reference actual (`bump(x.a)`). - Type equivalence (6.22.2) compares structure types by identity, also for containers of structures (`ref s_t q[$]`). - `const ref` writes, nonblocking writes and fork uses are checked per member. - The frontend binds each member like a scalar reference. A concatenation assignment to members bound to class properties writes temporaries in their place, so every destination position is taken before any write, then stores each property. A formal bound to a property and passed on to an `output` or `inout` structure argument copies each member back. - A receiver with a side effect (a pop, `$urandom`, a call) is rejected for a structure property actual, as for its whole reads, since each member would evaluate it again. Tests cover callee whole assignment, patterns, comparisons and passing on by reference or value; enumeration, string, class handle and 4-state members; handle members across heap collections; pure virtual `reg2bus`/`bus2reg`; and a task holding the reference across delays. Verilator 5.052 rejects two cases that bind a class property in a function that constructs an object (`%Error-IMPURE`, also with a scalar `ref`). xezim 0.11.3 shows its known copy semantics and padded string properties. Icarus does not support unpacked structures. The docs state that structure members may not be dynamic containers. Change-Id: I41a3098eb3b4359ca618580fb4de6bff25676be4 --- crates/celox-frontend-sv/src/lowering/comb.rs | 25 ++ crates/celox-frontend-sv/src/lowering/ff.rs | 167 +++++++++++-- .../src/ast/const_functions.rs | 1 + .../src/ast/expression_binding/direct.rs | 2 +- .../src/ast/expression_binding/references.rs | 52 ++-- .../celox-sv-analyzer/src/ast/procedural.rs | 87 ++++--- .../src/ast/procedural/randomization.rs | 3 + .../src/ast/procedural/references.rs | 13 +- crates/celox-sv-analyzer/src/ast/scope.rs | 1 + crates/celox-sv-analyzer/src/procedural.rs | 7 + crates/celox-test-suite/LIMITATIONS.md | 14 +- .../src/sv/cases/unpacked_structs.vtest | 228 ++++++++++++++++++ .../tests/retained_reports.rs | 4 +- ...erilator_property_reference_constructor.sv | 23 ++ .../sv_xezim_struct_reference_copies.sv | 23 ++ .../sv/icarus/unpacked_structs.json | 115 +++++++++ .../verification/sv/limitations.json | 5 + .../sv/verilator/unpacked_structs.json | 55 +++++ .../sv/xezim/unpacked_structs.json | 55 +++++ .../verification/xezim-review.json | 16 ++ .../systemverilog/unpacked_structs.rs | 83 ++++++- docs/guide/systemverilog-reference.md | 16 +- docs/ja/guide/systemverilog-reference.md | 9 +- scripts/check-external-suite-report.test.mjs | 2 + 24 files changed, 922 insertions(+), 84 deletions(-) create mode 100644 crates/celox-test-suite/verification/repros/sv_verilator_property_reference_constructor.sv create mode 100644 crates/celox-test-suite/verification/repros/sv_xezim_struct_reference_copies.sv diff --git a/crates/celox-frontend-sv/src/lowering/comb.rs b/crates/celox-frontend-sv/src/lowering/comb.rs index cc62339d02d..34d1634119f 100644 --- a/crates/celox-frontend-sv/src/lowering/comb.rs +++ b/crates/celox-frontend-sv/src/lowering/comb.rs @@ -3446,6 +3446,31 @@ impl<'p, 'a> Comb<'p, 'a> { .cloned() .flatten() .or_else(|| param.default.clone()); + if param.direction.is_reference() && !param.leaves.is_empty() { + // Each member of a formal of unpacked structure type names + // the matching member variable of the actual. + let targets = match &actual { + Some(sv::ir::Expr::Concat(parts)) if parts.len() == param.leaves.len() => parts + .iter() + .map(|part| match part { + sv::ir::Expr::Ident(actual) => self.m.id(actual), + _ => None, + }) + .collect::>>(), + _ => None, + } + .ok_or_else(|| { + unsupported(format!("ref argument `{}` of `{name}`", param.source_name)) + })?; + for (leaf, target) in param.leaves.iter().zip(targets) { + let id = self + .m + .id(leaf) + .ok_or_else(|| unsupported(format!("argument `{}`", param.source_name)))?; + references.push((leaf.clone(), id, target)); + } + continue; + } if param.direction.is_reference() { // A reference formal names the actual variable itself // (IEEE 1800-2023 13.5.2); other actuals fall back to Ff. diff --git a/crates/celox-frontend-sv/src/lowering/ff.rs b/crates/celox-frontend-sv/src/lowering/ff.rs index 1616a675ef9..efefd064c83 100644 --- a/crates/celox-frontend-sv/src/lowering/ff.rs +++ b/crates/celox-frontend-sv/src/lowering/ff.rs @@ -4628,12 +4628,12 @@ impl<'p, 'a> Ff<'p, 'a> { let mut activation = Vec::new(); if self.kernel.is_some() && (subroutine.is_task || self.forked) { for name in &subroutine.automatic_locals { - // A reference formal has no storage of its own. - if subroutine - .params - .iter() - .any(|param| ¶m.name == name && param.direction.is_reference()) - { + // A reference formal, or a member of one, has no storage of + // its own. + if subroutine.params.iter().any(|param| { + param.direction.is_reference() + && (¶m.name == name || param.leaves.contains(name)) + }) { continue; } let original = self @@ -4701,11 +4701,42 @@ impl<'p, 'a> Ff<'p, 'a> { .cloned() .flatten() .or_else(|| param.default.clone()); - match self.reference(name, param, actual)? { - Reference::Variable(target) => { - references.push((param.name.clone(), id, target)); + if param.leaves.is_empty() { + match self.reference(name, param, actual)? { + Reference::Variable(target) => { + references.push((param.name.clone(), id, target)); + } + Reference::Alias(alias) => aliases.push(*alias), + } + continue; + } + // Each member of a formal of unpacked structure type refers to + // the matching member of the actual, which the analyzer binds as + // the concatenation of its members. + let parts = match actual { + Some(sv::ir::Expr::Concat(parts)) if parts.len() == param.leaves.len() => parts, + _ => { + return Err(unsupported(format!( + "ref argument `{}` of `{name}`", + param.source_name + ))); + } + }; + for (leaf, part) in param.leaves.iter().zip(parts) { + let id = self + .m + .id(leaf) + .ok_or_else(|| unsupported(format!("argument `{}`", param.source_name)))?; + let member = sv::ir::SubroutineParam { + name: leaf.clone(), + leaves: Vec::new(), + default: None, + ..param.clone() + }; + match self.reference(name, &member, Some(part))? { + Reference::Variable(target) => references.push((leaf.clone(), id, target)), + Reference::Alias(alias) => aliases.push(*alias), } - Reference::Alias(alias) => aliases.push(*alias), } } // An input evaluates into a register, which a host request in a later @@ -4748,8 +4779,12 @@ impl<'p, 'a> Ff<'p, 'a> { .ok_or_else(|| unsupported("missing output argument"))?; // A reference formal bound to a class property, forwarded: // its object was evaluated when the reference was made. - if let Some(store) = forwarded_property(reference, ¶m.name) { + if let Some(store) = + forwarded_property(reference, sv::ir::Expr::Ident(param.name.clone())) + { property_outputs.push(store); + } else if let Some(stores) = forwarded_members(reference, ¶m.name) { + property_outputs.extend(stores); } else { let lvalues = lvalue_from_expr(reference).ok_or_else(|| { unsupported(format!( @@ -4859,6 +4894,7 @@ impl<'p, 'a> Ff<'p, 'a> { let constant = |position: &sv::ir::ConstExpr| { sv::typecheck::eval_const_expr_with_types(position, constants, parameter_types) }; + self.split_property_concats(&mut body, &aliases); for alias in &aliases { body = alias.rewrite(body, &constant)?; } @@ -4902,6 +4938,67 @@ impl<'p, 'a> Ff<'p, 'a> { Ok(result) } + /// Rewrite each assignment in `body` to a concatenation that has members + /// of a structure reference formal bound to a class property, which + /// [`references::Alias::rewrite`] stores one property at a time: the + /// concatenation writes temporaries in their place, so every position + /// of its other parts is taken before any write, and each property is + /// then stored from its temporary. + fn split_property_concats(&mut self, body: &mut [sv::ir::Stmt], aliases: &[references::Alias]) { + let properties: HashSet<&str> = aliases + .iter() + .filter(|alias| matches!(alias.target, references::Target::Property { .. })) + .map(|alias| alias.formal.as_str()) + .collect(); + if properties.is_empty() { + return; + } + for stmt in body { + stmt.walk_mut(&mut |stmt| { + let sv::ir::Stmt::AssignConcat { + parts, + nonblocking, + .. + } = stmt + else { + return; + }; + if !parts.iter().any(|part| properties.contains(part.name())) { + return; + } + let nonblocking = *nonblocking; + let mut stores = Vec::new(); + for part in parts.iter_mut() { + if !matches!(part, sv::ir::LValue::Ident(name) if properties.contains(name.as_str())) + { + continue; + } + // A select of a member is left to the rewrite to reject. + let Ok(width) = self.lvalue_width(part) else { + continue; + }; + let (_, temp) = self.m.temp("ref_member", width, false, self.m.four_state); + let member = std::mem::replace(part, sv::ir::LValue::Ident(temp.clone())); + stores.push(sv::ir::Stmt::Assign { + lhs: member, + rhs: sv::ir::Expr::Ident(temp), + nonblocking, + }); + } + if stores.is_empty() { + return; + } + let assignment = std::mem::replace(stmt, sv::ir::Stmt::Break); + stores.insert(0, assignment); + *stmt = sv::ir::Stmt::If { + condition: sv::ir::Expr::Literal("1'b1".into()), + then_body: stores, + else_body: Vec::new(), + }; + }); + } + } + /// What reference formal `param` of `name` refers to for a call with /// `actual`. The object of a property is evaluated here, at the call. fn reference( @@ -8380,10 +8477,10 @@ enum Reference { Alias(Box), } -/// The store that copies formal `formal` back into the class property that -/// `actual` reads through the object of a reference formal (see +/// The store that copies `value` back into the class property that `actual` +/// reads through the object of a reference formal (see /// [`references::Alias`]), when it is such a read. -fn forwarded_property(actual: &sv::ir::Expr, formal: &str) -> Option { +fn forwarded_property(actual: &sv::ir::Expr, value: sv::ir::Expr) -> Option { let sv::ir::Expr::Call { callee: sv::ir::Callee::Object(op), args, @@ -8400,11 +8497,45 @@ fn forwarded_property(actual: &sv::ir::Expr, formal: &str) -> Option Option> { + let sv::ir::Expr::Concat(parts) = actual else { + return None; + }; + let widths = parts + .iter() + .map(|part| match part { + sv::ir::Expr::Call { + callee: sv::ir::Callee::Object(op), + .. + } => match **op { + sv::ir::ObjectOp::Load(field) => Some(field.width as usize), + _ => None, + }, + _ => None, + }) + .collect::>>()?; + let mut lsb = widths.iter().sum::(); + parts + .iter() + .zip(widths) + .map(|(part, width)| { + lsb -= width; + let bits = sv::ir::Expr::Select { + expr: Box::new(sv::ir::Expr::Ident(formal.to_owned())), + msb: sv::ir::ConstExpr::Literal((lsb + width - 1).to_string()), + lsb: sv::ir::ConstExpr::Literal(lsb.to_string()), + signed: false, + }; + forwarded_property(part, bits) + }) + .collect() +} diff --git a/crates/celox-sv-analyzer/src/ast/const_functions.rs b/crates/celox-sv-analyzer/src/ast/const_functions.rs index 22a41a5f0ba..e0a21c2a96b 100644 --- a/crates/celox-sv-analyzer/src/ast/const_functions.rs +++ b/crates/celox-sv-analyzer/src/ast/const_functions.rs @@ -342,6 +342,7 @@ impl ConstantFunctions { direction: crate::procedural::ParamDirection::Input, r#type: ty.clone(), default: function.argument_defaults[position].clone().map(Into::into), + leaves: Vec::new(), }) .collect(), body: function diff --git a/crates/celox-sv-analyzer/src/ast/expression_binding/direct.rs b/crates/celox-sv-analyzer/src/ast/expression_binding/direct.rs index 5829c89dd6d..d6eab346513 100644 --- a/crates/celox-sv-analyzer/src/ast/expression_binding/direct.rs +++ b/crates/celox-sv-analyzer/src/ast/expression_binding/direct.rs @@ -1594,7 +1594,7 @@ fn read_index_value( Ok(value) } -fn path( +pub(super) fn path( mut root: ExprId, native: &Declarations, tree: &AnalysisContext<'_>, diff --git a/crates/celox-sv-analyzer/src/ast/expression_binding/references.rs b/crates/celox-sv-analyzer/src/ast/expression_binding/references.rs index 6c419491854..ba27eb45c81 100644 --- a/crates/celox-sv-analyzer/src/ast/expression_binding/references.rs +++ b/crates/celox-sv-analyzer/src/ast/expression_binding/references.rs @@ -48,12 +48,20 @@ pub(super) fn check_actual( "a constant is not a variable (IEEE 1800-2023 13.5.2)", )); } - None => objects::property(tree, actual, native, dimensions)? - .map(|(property, _)| procedural::dimensions_from_type(&property.r#type)), + None => property_shape(tree, actual, native, dimensions)?, } } - ExprKind::Member { .. } => match objects::property(tree, actual, native, dimensions)? { - Some((property, _)) => Some(procedural::dimensions_from_type(&property.r#type)), + ExprKind::Member { .. } => match property_shape(tree, actual, native, dimensions)? { + Some(shape) => Some(shape), + // A member of a variable of unpacked structure type is a + // variable of its own (see `unpacked_structs`). + None if let (parts, None) = direct::path(actual, native, tree, dimensions)? + && let [variable] = parts.as_slice() + && let Some(shape) = dimensions.get(variable) + && !dimensions.const_env.contains_key(variable) => + { + Some(shape.clone()) + } // A static property is a variable of its class's scope. None if let Some(variable) = objects::static_property(tree, actual, native, dimensions)? => @@ -134,15 +142,6 @@ pub(super) fn check_actual( .subroutine_param_shapes .get(name) .and_then(|shapes| shapes.get(position)); - // The members of a structure are separate variables, which one reference - // cannot alias. - if formal.is_some_and(|formal| formal.unpacked_struct.is_some()) - || shape.unpacked_struct.is_some() - { - return Err(unsupported(format!( - "ref argument of `{name}` of unpacked structure type" - ))); - } // Bounded and unbounded queues are equivalent (6.22.2), but a formal's // operations would apply its own bound to the actual. if let (Some(formal), Some(actual)) = ( @@ -167,9 +166,29 @@ pub(super) fn check_actual( Ok(()) } +/// The shape of class property `actual`, also of unpacked structure type. +fn property_shape( + tree: &AnalysisContext<'_>, + actual: ExprId, + native: &Declarations, + dimensions: &PackedDimensions, +) -> Converted> { + if let Some((property, _)) = objects::property(tree, actual, native, dimensions)? { + return Ok(Some(procedural::dimensions_from_type(&property.r#type))); + } + // `objects::aggregate_load` rejects a receiver that calls a subroutine, + // which each member would evaluate again. + let Some((aggregate, _, _)) = objects::aggregate_property(tree, actual, native, dimensions)? + else { + return Ok(None); + }; + Ok(Some(procedural::dimensions_from_type(&aggregate.r#type))) +} + /// Whether variables of shapes `a` and `b` have equivalent types (IEEE /// 1800-2023 6.22.2). Integral types compare by total width, signedness and -/// state count; an enumeration only by its members. +/// state count; an enumeration only by its members; an unpacked structure +/// only with the same structure type. fn equivalent( state: &AnalysisState, a: &VariableDimensions, @@ -219,6 +238,11 @@ fn equivalent( if a.real != b.real || a.string != b.string || a.class != b.class { return false; } + match (&a.unpacked_struct, &b.unpacked_struct) { + (None, None) => {} + (Some(a), Some(b)) if a.same_type(b) => {} + _ => return false, + } if (a.enum_domain.is_some() || b.enum_domain.is_some()) && a.enum_domain != b.enum_domain { return false; } diff --git a/crates/celox-sv-analyzer/src/ast/procedural.rs b/crates/celox-sv-analyzer/src/ast/procedural.rs index b03fb5067f0..8d360c66a55 100644 --- a/crates/celox-sv-analyzer/src/ast/procedural.rs +++ b/crates/celox-sv-analyzer/src/ast/procedural.rs @@ -2888,6 +2888,7 @@ pub(super) fn lower_subroutine( }, ), default, + leaves: Vec::new(), }); } let return_var = return_type @@ -2927,39 +2928,46 @@ pub(super) fn lower_subroutine( } result_leaves = Some((result.clone(), leaves)); } - if dispatch.is_none() { - for (index, r#type) in &aggregate_formals { - let param = &lowered_params[*index]; - let (name, source, direction) = ( - param.name.clone(), - param.source_name.clone(), - param.direction, - ); - let leaves = builder - .declare_aggregate(&source, r#type)? - .into_iter() - .map(|(leaf, _)| leaf) - .collect::>(); - if direction.is_read() { - aggregate_prologue.push(Stmt::AssignConcat { - parts: leaves.iter().cloned().map(LValue::Ident).collect(), - rhs: Expr::Ident(name.clone()), - nonblocking: false, - }); - } else if builder.automatic { - // An automatic output starts each call at its default. - aggregate_prologue.extend(leaves.iter().map(|leaf| Stmt::Local { - name: leaf.clone(), - init: None, - })); - } - if direction.is_written() { - aggregate_epilogue.push(Stmt::Assign { - lhs: LValue::Ident(name), - rhs: Expr::Concat(leaves.into_iter().map(Expr::Ident).collect()), - nonblocking: false, - }); - } + for (index, r#type) in &aggregate_formals { + let param = &lowered_params[*index]; + let (name, source, direction) = ( + param.name.clone(), + param.source_name.clone(), + param.direction, + ); + // The members of a reference formal are bound to the members of the + // actual, also in the body that dispatches a virtual method. + if dispatch.is_some() && !direction.is_reference() { + continue; + } + let leaves = builder + .declare_aggregate(&source, r#type)? + .into_iter() + .map(|(leaf, _)| leaf) + .collect::>(); + lowered_params[*index].leaves = leaves.clone(); + if direction.is_reference() { + continue; + } + if direction.is_read() { + aggregate_prologue.push(Stmt::AssignConcat { + parts: leaves.iter().cloned().map(LValue::Ident).collect(), + rhs: Expr::Ident(name.clone()), + nonblocking: false, + }); + } else if builder.automatic { + // An automatic output starts each call at its default. + aggregate_prologue.extend(leaves.iter().map(|leaf| Stmt::Local { + name: leaf.clone(), + init: None, + })); + } + if direction.is_written() { + aggregate_epilogue.push(Stmt::Assign { + lhs: LValue::Ident(name), + rhs: Expr::Concat(leaves.into_iter().map(Expr::Ident).collect()), + nonblocking: false, + }); } } // The members of formals and of the result have the subroutine's @@ -3189,7 +3197,15 @@ fn dispatch_body( let this = Expr::Ident(params[0].name.clone()); let args = params .iter() - .map(|param| Some(Expr::Ident(param.name.clone()))) + .map(|param| { + Some( + if param.direction.is_reference() && !param.leaves.is_empty() { + Expr::Concat(param.leaves.iter().cloned().map(Expr::Ident).collect()) + } else { + Expr::Ident(param.name.clone()) + }, + ) + }) .collect::>(); let items = targets .iter() @@ -3619,6 +3635,7 @@ fn lower_class( direction: ParamDirection::Input, r#type: ir_type, default: None, + leaves: Vec::new(), }], return_var: Some(result), body, @@ -3717,6 +3734,7 @@ fn lower_cast( direction: ParamDirection::Inout, r#type: ir_handle.clone(), default: None, + leaves: Vec::new(), }, SubroutineParam { name: source.clone(), @@ -3724,6 +3742,7 @@ fn lower_cast( direction: ParamDirection::Input, r#type: ir_handle, default: None, + leaves: Vec::new(), }, ], return_var: Some(result.clone()), diff --git a/crates/celox-sv-analyzer/src/ast/procedural/randomization.rs b/crates/celox-sv-analyzer/src/ast/procedural/randomization.rs index 1b0503e0a00..ae8ef1d1485 100644 --- a/crates/celox-sv-analyzer/src/ast/procedural/randomization.rs +++ b/crates/celox-sv-analyzer/src/ast/procedural/randomization.rs @@ -78,6 +78,7 @@ fn lower_methods( direction: ParamDirection::Input, r#type: convert_type(handle.clone()), default: None, + leaves: Vec::new(), }, SubroutineParam { name: argument.clone(), @@ -85,6 +86,7 @@ fn lower_methods( direction: ParamDirection::Input, r#type: convert_type(argument_type), default: None, + leaves: Vec::new(), }, ]; let mut input_values = Vec::new(); @@ -97,6 +99,7 @@ fn lower_methods( direction: ParamDirection::Input, r#type: convert_type(ty.clone()), default: None, + leaves: Vec::new(), }); input_values.push(Expr::Ident(name)); } diff --git a/crates/celox-sv-analyzer/src/ast/procedural/references.rs b/crates/celox-sv-analyzer/src/ast/procedural/references.rs index 62d4d1406b4..d3398066219 100644 --- a/crates/celox-sv-analyzer/src/ast/procedural/references.rs +++ b/crates/celox-sv-analyzer/src/ast/procedural/references.rs @@ -147,10 +147,17 @@ pub(in crate::ast) fn validate<'a>( .iter() .filter(|param| param.direction.is_reference()) { - let formal = param.name.as_str(); + // A formal of unpacked structure type is used through its members. + let formals = if param.leaves.is_empty() { + std::slice::from_ref(¶m.name) + } else { + param.leaves.as_slice() + }; let mut error = None; - for stmt in &subroutine.body { - check_formal(stmt, formal, param.direction, directions, &mut error); + for formal in formals { + for stmt in &subroutine.body { + check_formal(stmt, formal, param.direction, directions, &mut error); + } } if let Some(detail) = error { return Err(invalid(&subroutine.name, ¶m.source_name, detail)); diff --git a/crates/celox-sv-analyzer/src/ast/scope.rs b/crates/celox-sv-analyzer/src/ast/scope.rs index 90bf23bc45b..222fa6f97b1 100644 --- a/crates/celox-sv-analyzer/src/ast/scope.rs +++ b/crates/celox-sv-analyzer/src/ast/scope.rs @@ -1065,6 +1065,7 @@ impl Renamer<'_> { .map(|param| crate::procedural::SubroutineParamBase { name: self.name(¶m.name), default: param.default.map(|default| self.expr(default)), + leaves: param.leaves.iter().map(|leaf| self.name(leaf)).collect(), ..param }) .collect(), diff --git a/crates/celox-sv-analyzer/src/procedural.rs b/crates/celox-sv-analyzer/src/procedural.rs index 9117e78ae3a..18d1e32321b 100644 --- a/crates/celox-sv-analyzer/src/procedural.rs +++ b/crates/celox-sv-analyzer/src/procedural.rs @@ -670,6 +670,12 @@ pub struct SubroutineParamBase { pub direction: ParamDirection, pub r#type: T, pub default: Option, + /// The local names of the members of a formal of unpacked structure + /// type, in the order of its flat value; empty for other formals and, in + /// the body that dispatches a virtual method, for formals passed by + /// value. A reference formal binds each to the matching member of its + /// actual. + pub leaves: Vec, } impl SubroutineBase { @@ -694,6 +700,7 @@ impl SubroutineBase { direction: param.direction, r#type: ft(param.r#type), default: param.default.map(&mut *fe), + leaves: param.leaves, }) .collect(), return_var: self.return_var, diff --git a/crates/celox-test-suite/LIMITATIONS.md b/crates/celox-test-suite/LIMITATIONS.md index 106251a144e..4571b041648 100644 --- a/crates/celox-test-suite/LIMITATIONS.md +++ b/crates/celox-test-suite/LIMITATIONS.md @@ -627,7 +627,7 @@ four-state expectations; the assertions remain enabled on all Celox variants. | `sv_icarus_integral_format_string` | execute | icarus | 1 | Icarus 13.0 compiles `$sformatf` with a `bit` vector variable as the format, then `vvp` stops: "$sformatf's first argument must be a string or a register." IEEE 1800-2023 21.3.3 reads the content of an integral format expression as the format; Verilator 5.052 gives the expected output, xezim 0.11.3 prints the format as a value (`sv_integral_format_string` in the xezim review). | | `sv_icarus_string_associative_arrays_and_property_queue_methods` | compile | icarus | 2 | Icarus 13.0 rejects associative arrays with `string` and `bit [63:0]` indices and queue methods called on a class property ("Can't find task push_back in class Log"), which IEEE 1800-2023 7.8 and 7.10 define; Verilator 5.052 and xezim 0.11.3 compile the cases. | | `sv_verilator_associative_index_cast` | execute | verilator | 1 | Verilator 5.052 evaluates an associative index `x + 32'd1` at 32 bits and stores key 0; IEEE 1800-2023 7.8.4 evaluates it as a cast to the `bit [63:0]` index type (6.24.1), giving `64'h100000000`. xezim 0.11.3 also stores key 0 (`sv_associative_index_cast` in its review). [Evidence](verification/repros/sv_associative_index_cast.json). | -| `sv_icarus_unpacked_structs` | compile | icarus | 16 | Icarus 13.0 does not support unpacked structures ("sorry: Unpacked structs not supported."), which IEEE 1800-2023 7.2 defines; the standalone source reproduces the diagnostic. Verilator passes all but the nested default pattern, see sv_verilator_nested_struct_default. | +| `sv_icarus_unpacked_structs` | compile | icarus | 21 | Icarus 13.0 does not support unpacked structures ("sorry: Unpacked structs not supported."), which IEEE 1800-2023 7.2 defines; the standalone source reproduces the diagnostic. Verilator passes all but the nested default pattern, see sv_verilator_nested_struct_default. | | `sv_icarus_nested_containers` | compile | icarus | 4 | Icarus 13.0 rejects an associative array whose index type is a type name ("Type names are not valid expressions here."), as for the class-handle and string indices of these nested containers, does not support a dynamic array of dynamic arrays ("Sorry: Dynamic array of type `dynamic array of ...` is not yet supported."), and does not support unpacked structures (see sv_icarus_unpacked_structs). IEEE 1800-2023 7.4.5, 7.8 and 7.8.5 define these. Verilator passes these cases. | | `sv_verilator_nested_struct_default` | execute | verilator | 1 | Verilator 5.052 applies '{default: 5, ...} to the int member of a nested unpacked structure but leaves its bit [3:0] member 0 ("5 0000 1" in the standalone source; a top-level '{default: 5} sets both). IEEE 1800-2023 10.9.2 applies the default recursively to each member of an unmatched substructure and evaluates it in the context of an assignment to a simple bit vector member, giving 4'b0101. | @@ -1266,3 +1266,15 @@ executed mismatches in [the report](verification/sv/xezim/references.json). The [its observations](verification/repros/ref_arguments.json) reproduce the same values without the suite adapters; the observations are from the installed build, not a current-pin validation. + +The five `unpacked_structs::reference_*` cases pass `ref` and `const ref` formals +of unpacked structure type (13.5.2): variables, nested members, class properties +and their members, through virtual methods, across task suspensions, and with +handle and string members across heap collections. Celox passes all of them on +every backend. Verilator 5.052 rejects the two that bind a class property in a +function that also constructs an object with `%Error-IMPURE` "External variable +referenced by non-inlined function/task", also for a `ref` class-handle formal; +the [standalone source](verification/repros/sv_verilator_property_reference_constructor.sv) +reproduces it. These are executed compile failures. xezim 0.11.3 gives copy +semantics in the suspended-task case (`sv_ref_copy_semantics`) and the padded +string members of class properties (`sv_rest-X84`) in the heap case. diff --git a/crates/celox-test-suite/src/sv/cases/unpacked_structs.vtest b/crates/celox-test-suite/src/sv/cases/unpacked_structs.vtest index 096581f0eaa..88cdfc2893c 100644 --- a/crates/celox-test-suite/src/sv/cases/unpacked_structs.vtest +++ b/crates/celox-test-suite/src/sv/cases/unpacked_structs.vtest @@ -578,3 +578,231 @@ endmodule (top Top) (run_until 6000) (expect_output "3 [2997] [2999*] [n2999] 3000\n")) + +(case reference_formals + (source "unpacked_struct_references.sv" #" +module Top(output bit done); + class Node; + string n; + function new(string n); + this.n = n; + endfunction + endclass + typedef enum { READ, WRITE } kind_e; + typedef struct { kind_e kind; bit [63:0] addr; string tag; Node node; int n; } op_t; + typedef struct { op_t op; int count; } outer_t; + function automatic void fill(ref op_t r, input string tag); + r = '{kind: WRITE, addr: 64'h10, tag: tag, node: null, n: 0}; + r.node = new({tag, "!"}); + r.n = 7; + r.addr++; + endfunction + function automatic bit same(const ref op_t a, const ref op_t b); + return a.kind == b.kind && a.addr == b.addr && a.tag == b.tag; + endfunction + function automatic int sum(op_t r); + return int'(r.addr) + r.n; + endfunction + function automatic void forward(ref op_t r); + op_t copy; + fill(r, {r.tag, "f"}); + r.n = sum(r); + copy = r; + copy.tag = "copy"; + endfunction + function automatic void bump(ref int i); + i++; + endfunction + function automatic void bump64(ref bit [63:0] i); + i++; + endfunction + function automatic void show(const ref op_t r); + $display("%s %0d %s %s %0d", r.kind == WRITE ? "W" : "R", r.addr, r.tag, r.node.n, r.n); + endfunction + class Holder; + op_t p; + function void touch(); + forward(p); + endfunction + endclass + initial begin + op_t a, b; + outer_t o; + Holder h; + h = new; + fill(a, "a"); + show(a); + b = a; + $display("same %0d", same(a, b)); + b.tag = "b"; + $display("same %0d", same(a, b)); + o.op.tag = "o"; + forward(o.op); + bump(o.count); + show(o.op); + $display("nested %0d %0d", o.op.n, o.count); + h.p.tag = "h"; + h.touch(); + forward(h.p); + bump64(h.p.addr); + show(h.p); + done = 1; + end +endmodule +"#) + (top Top) (run_until 0) (assert_eq done 1) + (expect_output "W 17 a a! 7\nsame 1\nsame 0\nW 17 of of! 24\nnested 24 1\nW 18 hff hff! 24\n")) + +(case reference_formals_of_virtual_methods + (source "unpacked_struct_virtual_references.sv" #" +module Top(output bit done); + typedef enum { UVM_READ, UVM_WRITE } uvm_access_e; + typedef enum { UVM_IS_OK, UVM_NOT_OK } uvm_status_e; + typedef struct { + uvm_access_e kind; + bit [63:0] addr; + bit [63:0] data; + int n_bits; + bit [7:0] byte_en; + uvm_status_e status; + } bus_op_t; + class item; + bit [31:0] addr, data; + bit write; + endclass + virtual class adapter; + pure virtual function item reg2bus(const ref bus_op_t rw); + pure virtual function void bus2reg(item bus_item, ref bus_op_t rw); + endclass + class my_adapter extends adapter; + virtual function item reg2bus(const ref bus_op_t rw); + item i = new; + i.addr = rw.addr; + i.data = rw.data; + i.write = rw.kind == UVM_WRITE; + return i; + endfunction + virtual function void bus2reg(item bus_item, ref bus_op_t rw); + rw.kind = bus_item.write ? UVM_WRITE : UVM_READ; + rw.addr = bus_item.addr; + rw.data = bus_item.data + 1; + rw.n_bits = 32; + rw.byte_en = 8'hf; + rw.status = UVM_IS_OK; + endfunction + endclass + initial begin + adapter a; + my_adapter m; + bus_op_t op, back; + item i; + m = new; + a = m; + op = '{kind: UVM_WRITE, addr: 'h40, data: 'h1234, n_bits: 32, byte_en: 'hf, status: UVM_NOT_OK}; + i = a.reg2bus(op); + $display("reg2bus %h %h %0d", i.addr, i.data, i.write); + back.status = UVM_NOT_OK; + a.bus2reg(i, back); + $display("bus2reg %0d %h %h %0d %h %0d", back.kind, back.addr, back.data, back.n_bits, back.byte_en, back.status); + done = 1; + end +endmodule +"#) + (top Top) (run_until 0) (assert_eq done 1) + (expect_output "reg2bus 00000040 00001234 1\nbus2reg 1 0000000000000040 0000000000001235 32 0f 0\n")) + +(case reference_formals_across_time + (source "unpacked_struct_timed_references.sv" #" +module Top(output bit done); + typedef struct { int a; string s; } row_t; + row_t shared; + task automatic watch(ref row_t r, output int seen); + #2 seen = r.a; + r.s = {r.s, "+"}; + #2 r.a = r.a * 10; + endtask + initial begin + int seen; + shared = '{1, "x"}; + fork + watch(shared, seen); + begin + #1 shared.a = 5; + #2 $display("mid %0d %s", shared.a, shared.s); + end + join + $display("end %0d %s %0d %0d", shared.a, shared.s, seen, $time); + done = 1; + end +endmodule +"#) + (top Top) (run_until 10) (assert_eq done 1) + (expect_output "mid 5 x+\nend 50 x+ 5 4\n")) + +(case reference_formals_four_state + (four_state) + (source "unpacked_struct_four_state_references.sv" #" +module Top(output bit done); + typedef struct { logic [3:0] l; int i; bit [1:0] b; } access_t; + class Holder; + access_t p; + endclass + function automatic void mark(ref access_t r); + r.l = 4'b1z0x; + r = '{l: {r.l[3:1], 1'bx}, i: 'x, b: 2'b1x}; + endfunction + function automatic bit unknown(const ref access_t r); + return $isunknown(r.l); + endfunction + initial begin + access_t a; + Holder h; + h = new; + $display("def %b %0d", a.l, unknown(a)); + mark(a); + $display("mark %b %0d %b %0d", a.l, a.i, a.b, unknown(a)); + mark(h.p); + $display("prop %b %0d %b", h.p.l, h.p.i, h.p.b); + done = 1; + end +endmodule +"#) + (top Top) (run_until 0) (assert_eq done 1) + (expect_output "def xxxx 1\nmark 1z0x 0 10 1\nprop 1z0x 0 10\n")) + +(case reference_formal_handles_survive_heap_collections + (source "unpacked_struct_reference_handles.sv" #" +module Top(output int n); + class Node; + string text; + function new(string text); + this.text = text; + endfunction + endclass + typedef struct { Node m_type; string m_type_name; } pair_t; + class Holder; + pair_t p; + endclass + logic clk = 0; + always #1 clk = ~clk; + pair_t last; + Holder h = new; + string number; + function automatic void set(ref pair_t r, input string text); + r = '{m_type: null, m_type_name: {text, "!"}}; + r.m_type = new(text); + endfunction + initial forever begin + @(posedge clk); + number.itoa(n); + set(last, number); + set(h.p, {"h", number}); + n = n + 1; + end + initial #6000 $display("[%s] [%s] [%s] [%s] %0d", last.m_type.text, last.m_type_name, + h.p.m_type.text, h.p.m_type_name, n); +endmodule +"#) + (top Top) + (run_until 6000) + (expect_output "[2999] [2999!] [h2999] [h2999!] 3000\n")) diff --git a/crates/celox-test-suite/tests/retained_reports.rs b/crates/celox-test-suite/tests/retained_reports.rs index 89559fdc2a3..3b7b9b5be14 100644 --- a/crates/celox-test-suite/tests/retained_reports.rs +++ b/crates/celox-test-suite/tests/retained_reports.rs @@ -479,7 +479,9 @@ fn systemverilog_retained_reports_explain_exclusions_and_executed_failures() { ( "verilator", "references::ref_array_element_index_is_fixed_at_the_call" - | "references::ref_class_property_names_the_object_of_the_call", + | "references::ref_class_property_names_the_object_of_the_call" + | "unpacked_structs::reference_formal_handles_survive_heap_collections" + | "unpacked_structs::reference_formals", ) => ( "compile_error", "compile", diff --git a/crates/celox-test-suite/verification/repros/sv_verilator_property_reference_constructor.sv b/crates/celox-test-suite/verification/repros/sv_verilator_property_reference_constructor.sv new file mode 100644 index 00000000000..9a541c38d26 --- /dev/null +++ b/crates/celox-test-suite/verification/repros/sv_verilator_property_reference_constructor.sv @@ -0,0 +1,23 @@ +// Verilator 5.052 rejects this with %Error-IMPURE "External variable referenced by +// non-inlined function/task: 'set'" (also with a ref Node formal); IEEE 1800-2023 +// 13.5.2 permits a class property actual. Celox prints "h". +module Top; + class Node; + string text; + function new(string text); + this.text = text; + endfunction + endclass + typedef struct { Node m_type; } pair_t; + class Holder; + pair_t p; + endclass + Holder h = new; + function automatic void set(ref pair_t r, input string text); + r.m_type = new(text); + endfunction + initial begin + set(h.p, "h"); + $display("%s", h.p.m_type.text); + end +endmodule diff --git a/crates/celox-test-suite/verification/repros/sv_xezim_struct_reference_copies.sv b/crates/celox-test-suite/verification/repros/sv_xezim_struct_reference_copies.sv new file mode 100644 index 00000000000..35101b40298 --- /dev/null +++ b/crates/celox-test-suite/verification/repros/sv_xezim_struct_reference_copies.sv @@ -0,0 +1,23 @@ +// xezim 0.11.3 prints "mid 5 x" and "end 10 x+ 1": the task's ref formal +// is a copy of shared (IEEE 1800-2023 13.5.2 gives "mid 5 x+" and "end 50 x+ 5"). +module top; + typedef struct { int a; string s; } row_t; + row_t shared; + task automatic watch(ref row_t r, output int seen); + #2 seen = r.a; + r.s = {r.s, "+"}; + #2 r.a = r.a * 10; + endtask + initial begin + int seen; + shared = '{1, "x"}; + fork + watch(shared, seen); + begin + #1 shared.a = 5; + #2 $display("mid %0d %s", shared.a, shared.s); + end + join + $display("end %0d %s %0d", shared.a, shared.s, seen); + end +endmodule diff --git a/crates/celox-test-suite/verification/sv/icarus/unpacked_structs.json b/crates/celox-test-suite/verification/sv/icarus/unpacked_structs.json index f0921a6595b..4e30b6a3d99 100644 --- a/crates/celox-test-suite/verification/sv/icarus/unpacked_structs.json +++ b/crates/celox-test-suite/verification/sv/icarus/unpacked_structs.json @@ -322,6 +322,121 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Types", + "detail": "Icarus 13.0 does not support unpacked structures (\"sorry: Unpacked structs not supported.\"), which IEEE 1800-2023 7.2 defines; the standalone source reproduces the diagnostic. Verilator passes all but the nested default pattern, see sv_verilator_nested_struct_default.", + "expectation": "Simulation", + "known_issue": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/repros/sv_icarus_unpacked_structs.sv", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_icarus_unpacked_structs", + "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", + "phase": "compile", + "reason": "Icarus 13.0 does not support unpacked structures (\"sorry: Unpacked structs not supported.\"), which IEEE 1800-2023 7.2 defines; the standalone source reproduces the diagnostic. Verilator passes all but the nested default pattern, see sv_verilator_nested_struct_default.", + "upstream": [] + }, + "name": "unpacked_structs::reference_formal_handles_survive_heap_collections", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "Icarus 13.0 does not support unpacked structures (\"sorry: Unpacked structs not supported.\"), which IEEE 1800-2023 7.2 defines; the standalone source reproduces the diagnostic. Verilator passes all but the nested default pattern, see sv_verilator_nested_struct_default.", + "expectation": "Simulation", + "known_issue": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/repros/sv_icarus_unpacked_structs.sv", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_icarus_unpacked_structs", + "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", + "phase": "compile", + "reason": "Icarus 13.0 does not support unpacked structures (\"sorry: Unpacked structs not supported.\"), which IEEE 1800-2023 7.2 defines; the standalone source reproduces the diagnostic. Verilator passes all but the nested default pattern, see sv_verilator_nested_struct_default.", + "upstream": [] + }, + "name": "unpacked_structs::reference_formals", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "Icarus 13.0 does not support unpacked structures (\"sorry: Unpacked structs not supported.\"), which IEEE 1800-2023 7.2 defines; the standalone source reproduces the diagnostic. Verilator passes all but the nested default pattern, see sv_verilator_nested_struct_default.", + "expectation": "Simulation", + "known_issue": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/repros/sv_icarus_unpacked_structs.sv", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_icarus_unpacked_structs", + "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", + "phase": "compile", + "reason": "Icarus 13.0 does not support unpacked structures (\"sorry: Unpacked structs not supported.\"), which IEEE 1800-2023 7.2 defines; the standalone source reproduces the diagnostic. Verilator passes all but the nested default pattern, see sv_verilator_nested_struct_default.", + "upstream": [] + }, + "name": "unpacked_structs::reference_formals_across_time", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "Icarus 13.0 does not support unpacked structures (\"sorry: Unpacked structs not supported.\"), which IEEE 1800-2023 7.2 defines; the standalone source reproduces the diagnostic. Verilator passes all but the nested default pattern, see sv_verilator_nested_struct_default.", + "expectation": "Simulation", + "known_issue": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/repros/sv_icarus_unpacked_structs.sv", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_icarus_unpacked_structs", + "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", + "phase": "compile", + "reason": "Icarus 13.0 does not support unpacked structures (\"sorry: Unpacked structs not supported.\"), which IEEE 1800-2023 7.2 defines; the standalone source reproduces the diagnostic. Verilator passes all but the nested default pattern, see sv_verilator_nested_struct_default.", + "upstream": [] + }, + "name": "unpacked_structs::reference_formals_four_state", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "Icarus 13.0 does not support unpacked structures (\"sorry: Unpacked structs not supported.\"), which IEEE 1800-2023 7.2 defines; the standalone source reproduces the diagnostic. Verilator passes all but the nested default pattern, see sv_verilator_nested_struct_default.", + "expectation": "Simulation", + "known_issue": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/repros/sv_icarus_unpacked_structs.sv", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_icarus_unpacked_structs", + "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", + "phase": "compile", + "reason": "Icarus 13.0 does not support unpacked structures (\"sorry: Unpacked structs not supported.\"), which IEEE 1800-2023 7.2 defines; the standalone source reproduces the diagnostic. Verilator passes all but the nested default pattern, see sv_verilator_nested_struct_default.", + "upstream": [] + }, + "name": "unpacked_structs::reference_formals_of_virtual_methods", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Types", "detail": "Icarus 13.0 does not support unpacked structures (\"sorry: Unpacked structs not supported.\"), which IEEE 1800-2023 7.2 defines; the standalone source reproduces the diagnostic. Verilator passes all but the nested default pattern, see sv_verilator_nested_struct_default.", diff --git a/crates/celox-test-suite/verification/sv/limitations.json b/crates/celox-test-suite/verification/sv/limitations.json index 623ea0723a1..678cda31ec5 100644 --- a/crates/celox-test-suite/verification/sv/limitations.json +++ b/crates/celox-test-suite/verification/sv/limitations.json @@ -2997,6 +2997,11 @@ "unpacked_structs::initializers_results_and_defaults", "unpacked_structs::members_whole_copies_and_equality", "unpacked_structs::module_variables", + "unpacked_structs::reference_formal_handles_survive_heap_collections", + "unpacked_structs::reference_formals", + "unpacked_structs::reference_formals_across_time", + "unpacked_structs::reference_formals_four_state", + "unpacked_structs::reference_formals_of_virtual_methods", "unpacked_structs::results_and_outputs", "unpacked_structs::subroutine_arguments_and_results" ] diff --git a/crates/celox-test-suite/verification/sv/verilator/unpacked_structs.json b/crates/celox-test-suite/verification/sv/verilator/unpacked_structs.json index 037e6d81c89..abcad6c2f42 100644 --- a/crates/celox-test-suite/verification/sv/verilator/unpacked_structs.json +++ b/crates/celox-test-suite/verification/sv/verilator/unpacked_structs.json @@ -166,6 +166,61 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Types", + "detail": "Verilator build exit status: 1; see /build.log\n%Error-IMPURE: /source_0.sv:18:29: Unsupported: External variable referenced by non-inlined function/task: 'set'\n : ... note: In instance 'celox_suite_tb.dut'\n 18 | function automatic void set(ref pair_t r, input string text);\n | ^~~\n /source_0.sv:6:18: ... Location of the external reference: 'text'\n 6 | this.text = text;\n | ^~~~\n ... For error description see https://verilator.org/warn/IMPURE?v=5.052\n%Warning-ZERODLY: /testbench.sv:103:25: Value of # delay control statically unknown. Assuming it can be #0.\n : ... If all # delays are non-zero at runtime,\n : ... use '--no-sched-zero-delay' for improved performance.\n : ... If a real #0 is expected at runtime,\n : ... use '--sched-zero-delay' to suppress this warning.\n 103 | if (t1 > $time) #(t1 - $time);\n | ^\n ... For warning description see https://verilator.org/warn/ZERODLY?v=5.052\n ... Use \"/* verilator lint_off ZERODLY */\" and lint_on around source to disable this message.\n%Error: Exiting due to 1 error(s)\n", + "expectation": "Simulation", + "name": "unpacked_structs::reference_formal_handles_survive_heap_collections", + "phase": "compile", + "status": "compile_error", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "Verilator build exit status: 1; see /build.log\n%Error-IMPURE: /source_0.sv:24:29: Unsupported: External variable referenced by non-inlined function/task: 'forward'\n : ... note: In instance 'celox_suite_tb.dut'\n 24 | function automatic void forward(ref op_t r);\n | ^~~~~~~\n /source_0.sv:6:18: ... Location of the external reference: 'n'\n 6 | this.n = n;\n | ^\n ... For error description see https://verilator.org/warn/IMPURE?v=5.052\n%Warning-ZERODLY: /testbench.sv:103:25: Value of # delay control statically unknown. Assuming it can be #0.\n : ... If all # delays are non-zero at runtime,\n : ... use '--no-sched-zero-delay' for improved performance.\n : ... If a real #0 is expected at runtime,\n : ... use '--sched-zero-delay' to suppress this warning.\n 103 | if (t1 > $time) #(t1 - $time);\n | ^\n ... For warning description see https://verilator.org/warn/ZERODLY?v=5.052\n ... Use \"/* verilator lint_off ZERODLY */\" and lint_on around source to disable this message.\n%Error: Exiting due to 1 error(s)\n", + "expectation": "Simulation", + "name": "unpacked_structs::reference_formals", + "phase": "compile", + "status": "compile_error", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "", + "expectation": "Simulation", + "name": "unpacked_structs::reference_formals_across_time", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "four-state expectations", + "expectation": "Simulation", + "name": "unpacked_structs::reference_formals_four_state", + "phase": "compile", + "status": "unsupported", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "", + "expectation": "Simulation", + "name": "unpacked_structs::reference_formals_of_virtual_methods", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Types", "detail": "", diff --git a/crates/celox-test-suite/verification/sv/xezim/unpacked_structs.json b/crates/celox-test-suite/verification/sv/xezim/unpacked_structs.json index e368bcbaa51..d71d341f19e 100644 --- a/crates/celox-test-suite/verification/sv/xezim/unpacked_structs.json +++ b/crates/celox-test-suite/verification/sv/xezim/unpacked_structs.json @@ -154,6 +154,61 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Types", + "detail": "unpacked_structs::reference_formal_handles_survive_heap_collections at 808:3: expect_output: expected [91, 50, 57, 57, 57, 93, 32, 91, 50, 57, 57, 57, 33, 93, 32, 91, 104, 50, 57, 57, 57, 93, 32, 91, 104, 50, 57, 57, 57, 33, 93, 32, 51, 48, 48, 48, 10], got [91, 50, 57, 57, 57, 93, 32, 91, 50, 57, 57, 57, 33, 93, 32, 91, 32, 93, 32, 91, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 104, 50, 57, 57, 57, 33, 93, 32, 51, 48, 48, 48, 10]", + "expectation": "Simulation", + "name": "unpacked_structs::reference_formal_handles_survive_heap_collections", + "phase": "execute", + "status": "mismatch", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "", + "expectation": "Simulation", + "name": "unpacked_structs::reference_formals", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "unpacked_structs::reference_formals_across_time at 740:3: expect_output: expected [109, 105, 100, 32, 53, 32, 120, 43, 10, 101, 110, 100, 32, 53, 48, 32, 120, 43, 32, 53, 32, 52, 10], got [109, 105, 100, 32, 53, 32, 120, 10, 101, 110, 100, 32, 49, 48, 32, 120, 43, 32, 49, 32, 52, 10]", + "expectation": "Simulation", + "name": "unpacked_structs::reference_formals_across_time", + "phase": "execute", + "status": "mismatch", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "", + "expectation": "Simulation", + "name": "unpacked_structs::reference_formals_four_state", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "", + "expectation": "Simulation", + "name": "unpacked_structs::reference_formals_of_virtual_methods", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Types", "detail": "unpacked_structs::results_and_outputs at 186:3: expect_output: expected [109, 97, 107, 101, 32, 48, 10, 111, 117, 116, 115, 32, 97, 98, 99, 10, 111, 117, 116, 122, 32, 48, 10, 115, 116, 97, 116, 105, 99, 32, 49, 32, 50, 10, 115, 116, 97, 116, 105, 99, 32, 50, 32, 50, 10], got [109, 97, 107, 101, 32, 48, 10, 111, 117, 116, 115, 32, 97, 98, 99, 10, 111, 117, 116, 122, 32, 120, 10, 115, 116, 97, 116, 105, 99, 32, 49, 32, 50, 10, 115, 116, 97, 116, 105, 99, 32, 50, 32, 50, 10]", diff --git a/crates/celox-test-suite/verification/xezim-review.json b/crates/celox-test-suite/verification/xezim-review.json index 39f718bd0c6..6e78d1ff9d7 100644 --- a/crates/celox-test-suite/verification/xezim-review.json +++ b/crates/celox-test-suite/verification/xezim-review.json @@ -4687,6 +4687,22 @@ "classification": "xezim_bug", "bug": "sv_rest-X90", "note": "m[next_index()].push_back(7) calls next_index() three times per statement (i = 6 after two statements, elements lost), and $unpacked_dimensions(grid)/$dimensions(grid) of int grid[][] print 1 2 instead of 2 3." + }, + { + "suite": "sv", + "name": "unpacked_structs::reference_formals_across_time", + "status": "mismatch", + "classification": "xezim_bug", + "bug": "sv_ref_copy_semantics", + "note": "A suspended task's ref formal of unpacked structure type neither sees the caller's write (shared.a = 5) nor writes shared until it returns: xezim prints \"mid 5 x\" and \"end 10 x+ 1\" where 13.5.2 gives \"mid 5 x+\" and \"end 50 x+ 5\". Reproduced by verification/repros/sv_xezim_struct_reference_copies.sv." + }, + { + "suite": "sv", + "name": "unpacked_structs::reference_formal_handles_survive_heap_collections", + "status": "mismatch", + "classification": "xezim_bug", + "bug": "sv_rest-X84", + "note": "h.p.m_type_name, the string member of a class property written through a ref formal, prints as a space-padded wide value and h.p.m_type.text prints empty; xezim does the same for a direct write of the property (h.p = '{...}). Reproduced by verification/repros/sv_xezim_unpacked_struct_properties.sv." } ] } diff --git a/crates/celox/tests/frontends/systemverilog/unpacked_structs.rs b/crates/celox/tests/frontends/systemverilog/unpacked_structs.rs index 00b23d1619c..dfd2fee522c 100644 --- a/crates/celox/tests/frontends/systemverilog/unpacked_structs.rs +++ b/crates/celox/tests/frontends/systemverilog/unpacked_structs.rs @@ -271,6 +271,46 @@ sv_backends! { let done = sim.signal("done"); assert_eq!(sim.get(done), BigUint::from(1u8)); } + fn property_bound_structure_references_forward_and_capture(sim) { + @setup { + let source = r#"module Top(output int value); + typedef struct { int a; string s; } pair_t; + class H; + pair_t p; + endclass + int arr[2]; + function automatic void set_pair(output pair_t p); + p = '{7, "s"}; + endfunction + function automatic void bump_pair(inout pair_t p); + p.a++; + p.s = {p.s, "!"}; + endfunction + function automatic void forward(ref pair_t r); + set_pair(r); + bump_pair(r); + endfunction + function automatic void place(ref pair_t r); + {r.a, arr[r.a]} = {32'd1, 32'd7}; + endfunction + initial begin + H h; + pair_t v; + h = new; + forward(h.p); + forward(v); + value = h.p.a * 1000 + v.a * 100 + h.p.s.len() * 10 + v.s.len(); + h.p.a = 0; + place(h.p); + value = value * 100 + h.p.a * 10 + arr[0] + arr[1]; + end + endmodule"#; + } + @build celox::Simulation::from_sv_sources(vec![(source, Path::new("struct.sv"))], "Top"); + sim.run_until(0).unwrap(); + let value = sim.signal("value"); + assert_eq!(sim.get(value), BigUint::from(882217u32)); + } fn redeclared_structure_properties_hide_their_members(sim) { @setup { let source = r#"module Top(output int value); @@ -310,6 +350,21 @@ sv_backends! { fn unpacked_struct_four_state_members(sim) { @case "unpacked_structs::four_state_members"; } + fn unpacked_struct_reference_formals(sim) { + @case "unpacked_structs::reference_formals"; + } + fn unpacked_struct_reference_formals_of_virtual_methods(sim) { + @case "unpacked_structs::reference_formals_of_virtual_methods"; + } + fn unpacked_struct_reference_formals_across_time(sim) { + @case "unpacked_structs::reference_formals_across_time"; + } + fn unpacked_struct_reference_formals_four_state(sim) { + @case "unpacked_structs::reference_formals_four_state"; + } + fn unpacked_struct_reference_formal_handles_survive_heap_collections(sim) { + @case "unpacked_structs::reference_formal_handles_survive_heap_collections"; + } fn unpacked_struct_class_properties(sim) { @case "unpacked_structs::class_properties"; } @@ -446,8 +501,32 @@ fn unsupported_and_illegal_uses_are_rejected() { "whole unpacked structure property read through a receiver with a side effect", ), ( - "function automatic void f(ref i_t r); r.a++; endfunction i_t v; initial f(v);", - "ref argument of `f` of unpacked structure type", + "typedef struct { int a; bit b; } j_t; function automatic void f(ref i_t r); r.a++; endfunction j_t v; initial f(v);", + "not equivalent", + ), + ( + "typedef struct { int a; bit b; } j_t; function automatic void f(ref i_t q[$]); endfunction j_t v[$]; initial f(v);", + "not equivalent", + ), + ( + "function automatic void f(const ref i_t r); r = '{1, 0}; endfunction i_t v; initial f(v);", + "const ref argument cannot be", + ), + ( + "function automatic void f(const ref i_t r); r.a = 1; endfunction i_t v; initial f(v);", + "const ref argument cannot be", + ), + ( + "function automatic void g(ref int x); endfunction function automatic void f(const ref i_t r); g(r.a); endfunction i_t v; initial f(v);", + "const ref argument cannot be", + ), + ( + "function automatic void f(ref i_t r); endfunction i_t q[$]; initial f(q[0]);", + "ref argument of `f` bound to an element of a dynamic array", + ), + ( + "class C; i_t v; endclass C cs[$]; function automatic void f(ref i_t r); endfunction initial f(cs[$urandom_range(0, 1)].v);", + "whole unpacked structure property read through a receiver with a side effect", ), ( "class B; i_t p; endclass class D extends B; int p; endclass D d; int x; initial begin d = new; x = d.p.a; end", diff --git a/docs/guide/systemverilog-reference.md b/docs/guide/systemverilog-reference.md index 9f7812ef13b..6548eb8681b 100644 --- a/docs/guide/systemverilog-reference.md +++ b/docs/guide/systemverilog-reference.md @@ -332,7 +332,7 @@ Unpacked structures (IEEE 1800-2023 7.2) may have integral, enumeration, members, each keeping its own 2-state or 4-state type. Variables of such a type may be module variables, procedural locals, class properties, queue, dynamic and associative array elements (`q[i].m` reads a member), and -subroutine arguments of any direction and results. Members are read and written like variables of +subroutine arguments of any direction, including [`ref`](#reference-arguments), and results. Members are read and written like variables of their type; a whole structure is assigned and compared with `==`, `!=`, `===` and `!==` against a value of the same type, chosen with `?:`, or built from an assignment pattern (`'{a, b}`, `'{m: v, default: d}`, `T'{...}`, with @@ -364,7 +364,8 @@ constructs without a dedicated issue point to the frontend roadmap, [#88](https: array, ANSI port default values, tagged unions, unpacked unions, packed union assignment patterns, internal nets without a driver ([#460](https://github.com/celox-sim/celox/issues/460)), `real`, and unpacked structs as ports, nets, parameters, static, `rand` or `const` class properties, fixed-size array elements, or with members that - are arrays, `real`, or have default values. + are arrays (also dynamic arrays, queues and associative arrays), `real`, or + have default values. - Sequential processes: `iff` qualifiers in `always_ff` event lists ([#452](https://github.com/celox-sim/celox/issues/452)), and in `always_ff` edge operands other than a plain signal ([#464](https://github.com/celox-sim/celox/issues/464)), multi-bit edge signals, and several edges without an asynchronous reset. @@ -754,8 +755,11 @@ A `ref` or `const ref` formal is the actual itself, not a copy (IEEE 1800-2023 alias it, and a task keeps the reference while it is suspended. The actual can be a variable, including a string, class handle, queue, dynamic or associative array, or unpacked array; a property of a class object, whose handle is -evaluated at the call; or an element of a fixed-size unpacked array, whose -index is evaluated at the call. A `const` qualifier, like the direction, carries +evaluated at the call; an element of a fixed-size unpacked array, whose +index is evaluated at the call; or a member of an unpacked structure. A formal +of [unpacked structure](#unpacked-structures) type refers to each member of a +structure variable, member or class property, also through virtual methods. +A `const` qualifier, like the direction, carries over to the following formals (13.3). These are rejected as the standard requires: `ref` formals of subroutines with @@ -768,8 +772,8 @@ continuous assignment or an event expression (13.4.1; `const ref` is allowed). `ref static`, elements of dynamic arrays, queues and associative arrays (whose references would have to outlive a resize, 13.5.2), elements of class -properties, members of unpacked structures, writes to part of a formal bound to -a class property, and selects of a formal bound to an array element at a +properties, writes to part of a formal bound to a class property or to a +member of one, and selects of a formal bound to an array element at a position only known at run time (positions of unrolled loops are known) are unsupported and rejected. A formal bound to a class property can be passed on to an `output` or `inout` argument; it is written back when that call returns. diff --git a/docs/ja/guide/systemverilog-reference.md b/docs/ja/guide/systemverilog-reference.md index 6ae5d465d85..ab322a46e41 100644 --- a/docs/ja/guide/systemverilog-reference.md +++ b/docs/ja/guide/systemverilog-reference.md @@ -210,7 +210,7 @@ unpacked 構造体(IEEE 1800-2023 7.2)のメンバには、整数型、列 クラスハンドル、packed 構造体、入れ子の unpacked 構造体を使え、各メンバは自身の 2 値・4 値の型を保ちます。この型の変数は、モジュール変数、手続き内のローカル変数、クラスプロパティ、 キュー・動的配列・連想配列の要素(`q[i].m` でメンバを読めます)、 -任意の方向のサブルーチン引数と戻り値にできます。メンバはその型の変数と同じように +任意の方向([`ref`](#reference-arguments) を含む)のサブルーチン引数と戻り値にできます。メンバはその型の変数と同じように 読み書きできます。構造体全体は、同じ型の値との代入と `==`・`!=`・`===`・`!==` による 比較、`?:` による選択、assignment pattern(`'{a, b}`、`'{m: v, default: d}`、 `T'{...}`。`default` は入れ子の構造体のメンバにも適用)による構築ができます。 @@ -237,7 +237,7 @@ unpacked 構造体(IEEE 1800-2023 7.2)のメンバには、整数型、列 - `always_comb` の暗黙のラッチ推論はデフォルトで拒否します。`celox.toml` の `[diagnostics]` で `inferred_latch = "warn"` または `"allow"` を指定すると許可できます。通常の `always @*` と明示的な `always_latch` にはこの設定は不要です。 - ポートとインスタンス:non-ANSI 形式のポート式(`module m({a, b}, c[3:0], .p(d))` など、[#1953](https://github.com/celox-sim/celox/issues/1953))、`ref` ポート([#427](https://github.com/celox-sim/celox/issues/427))、 ワイルドカード接続 `.*`([#442](https://github.com/celox-sim/celox/issues/442))、ゲートプリミティブ([#457](https://github.com/celox-sim/celox/issues/457))、`bind`。 -- 宣言:interface 配列のメンバーの変数宣言の初期化子、ANSI ポートの既定値、tagged union、unpacked union、packed union の assignment pattern、ドライバを持たない内部ネット([#460](https://github.com/celox-sim/celox/issues/460))、`real`、ポート・ネット・パラメータ・static / `rand` / `const` のクラスプロパティ・固定長配列の要素としての unpacked 構造体、配列・`real`・既定値を持つメンバ。 +- 宣言:interface 配列のメンバーの変数宣言の初期化子、ANSI ポートの既定値、tagged union、unpacked union、packed union の assignment pattern、ドライバを持たない内部ネット([#460](https://github.com/celox-sim/celox/issues/460))、`real`、ポート・ネット・パラメータ・static / `rand` / `const` のクラスプロパティ・固定長配列の要素としての unpacked 構造体、配列(動的配列・キュー・連想配列を含む)・`real`・既定値を持つメンバ。 - 順序回路のプロセス:`always_ff` のイベントリストの `iff` 修飾([#452](https://github.com/celox-sim/celox/issues/452))、および `always_ff` での 単純な信号以外のエッジオペランド([#464](https://github.com/celox-sim/celox/issues/464))、複数ビットのエッジ信号、 非同期リセットを持たない複数のエッジ。 @@ -367,7 +367,8 @@ tagged union と unpacked union は未対応です。 仮引数への書き込みはすぐに見え、実引数の別の名前とも別名になり、task は待ちの間も参照を保ちます。 実引数には、変数(`string`、クラスハンドル、キュー、動的配列、連想配列、unpacked 配列を含む)、 呼び出し時にハンドルを評価するクラスオブジェクトのプロパティ、呼び出し時に添字を評価する -固定長 unpacked 配列の要素を渡せます。`const` は方向と同様に後続の仮引数に引き継がれます(13.3)。 +固定長 unpacked 配列の要素、unpacked 構造体のメンバを渡せます。[unpacked 構造体](#unpacked-structures)型の +仮引数は、構造体の変数・メンバ・クラスプロパティの各メンバを参照します(仮想メソッド経由でも同じ)。`const` は方向と同様に後続の仮引数に引き継がれます(13.3)。 規格どおり次を拒否します:static な寿命のサブルーチンの `ref` 仮引数、式・定数・部分選択・ネット、 または仮引数と等価でない型(6.22.2)の実引数、`const ref` 仮引数への書き込み、`ref` 仮引数への @@ -376,7 +377,7 @@ tagged union と unpacked union は未対応です。 (13.4.1。`const ref` は可)。 `ref static`、動的配列・キュー・連想配列の要素(参照がサイズ変更より長く生きる必要がある、13.5.2)、 -クラスプロパティの要素、unpacked 構造体のメンバ、クラスプロパティに束縛した仮引数の一部への書き込み、 +クラスプロパティの要素、クラスプロパティやそのメンバに束縛した仮引数の一部への書き込み、 配列要素に束縛した仮引数の実行時にしか決まらない位置での選択(展開されるループの位置は決まる)は 未対応として拒否します。クラスプロパティに束縛した仮引数は `output` / `inout` 引数に渡せ、その呼び出しが 戻るときに書き戻します。 diff --git a/scripts/check-external-suite-report.test.mjs b/scripts/check-external-suite-report.test.mjs index df9b5afb1a2..12278f72695 100644 --- a/scripts/check-external-suite-report.test.mjs +++ b/scripts/check-external-suite-report.test.mjs @@ -418,6 +418,8 @@ test("every retained baseline accepts only its existing failures", () => { "tagged_unions::writable_system_arguments", "tagged_unions::writable_task_arguments", "timing::final_procedure_output_survives_program_completion", + "unpacked_structs::reference_formal_handles_survive_heap_collections", + "unpacked_structs::reference_formals", ], ); } else {