From 9fd32cc71a055ea76670ed8d71e8602f89dfe0e3 Mon Sep 17 00:00:00 2001 From: tignear Date: Wed, 28 Oct 2026 19:36:37 +0900 Subject: [PATCH] feat(sv): support nested dynamic containers and class handle keys A dynamic container with several dynamic dimensions (`int m[string][$]`, `T m[C][C][E]`, `int grid[][]`) was rejected, as was an associative array indexed by a class (IEEE 1800-2023 7.4.5, 7.8.5), which UVM uses for its comparer, copier and recorder recursion state. An element of a container of containers is the inner container's handle. Containers are immutable heap values, so `m[a]` reads the inner container, an absent one being empty, and an update of an element's element, such as `m[a][b] = v`, `m[a].push_back(x)` or `m[a].delete(b)`, writes the updated inner container back into `m[a]`, and so on outwards. An element of container type takes a container value, so `grid[1] = new[3]` works. A class index is a handle; associative keys of object handles are traced by the heap collector (container parameter bit 46), so an object referred to only as a key stays alive. `foreach` and traversal methods take an index variable of the class type. sv-tests chapter-7/arrays/associative/class now passes in both state modes. Containers of fixed-size unpacked arrays stay unsupported. Icarus 13.0 rejects type-name indices; xezim 0.11.3 misreads two of the new cases, which the review retains. Change-Id: I54576c9fc206a0a46ff5a3e7a4782eaf5be449d3 --- conformance/sv-tests/expected.tsv | 4 +- .../src/lowering/ff/containers.rs | 115 +++++++++++++-- crates/celox-heap/src/containers.rs | 36 +++-- .../celox-sv-analyzer/src/ast/containers.rs | 139 +++++++++++++++--- .../src/ast/procedural/foreach.rs | 5 +- .../celox-sv-analyzer/src/system_functions.rs | 2 + crates/celox-test-suite/LIMITATIONS.md | 1 + .../src/sv/cases/containers.vtest | 130 ++++++++++++++++ .../repros/sv_icarus_nested_containers.sv | 16 ++ .../repros/sv_xezim_nested_containers.sv | 26 ++++ .../verification/sv/icarus.json | 1 + .../verification/sv/icarus/containers.json | 96 ++++++++++++ .../verification/sv/limitations.json | 20 +++ .../verification/sv/xezim.json | 1 + .../verification/sv/xezim/containers.json | 37 +++++ .../verification/xezim-review.json | 36 +++++ .../frontends/systemverilog/containers.rs | 27 ++++ docs/guide/systemverilog-reference.md | 13 +- 18 files changed, 658 insertions(+), 47 deletions(-) create mode 100644 crates/celox-test-suite/verification/repros/sv_icarus_nested_containers.sv create mode 100644 crates/celox-test-suite/verification/repros/sv_xezim_nested_containers.sv create mode 100644 crates/celox-test-suite/verification/sv/icarus/containers.json create mode 100644 crates/celox-test-suite/verification/sv/xezim/containers.json diff --git a/conformance/sv-tests/expected.tsv b/conformance/sv-tests/expected.tsv index 6dbe602fca6..f845ed80d19 100644 --- a/conformance/sv-tests/expected.tsv +++ b/conformance/sv-tests/expected.tsv @@ -1261,8 +1261,8 @@ chapter-7/arrays/associative/arguments.sv 2state fail chapter-7/arrays/associative/arguments.sv 4state fail chapter-7/arrays/associative/assignment.sv 2state pass chapter-7/arrays/associative/assignment.sv 4state pass -chapter-7/arrays/associative/class.sv 2state fail -chapter-7/arrays/associative/class.sv 4state fail +chapter-7/arrays/associative/class.sv 2state pass +chapter-7/arrays/associative/class.sv 4state pass chapter-7/arrays/associative/integral.sv 2state pass chapter-7/arrays/associative/integral.sv 4state pass chapter-7/arrays/associative/literals.sv 2state fail diff --git a/crates/celox-frontend-sv/src/lowering/ff/containers.rs b/crates/celox-frontend-sv/src/lowering/ff/containers.rs index b37f1933487..f186dd2b127 100644 --- a/crates/celox-frontend-sv/src/lowering/ff/containers.rs +++ b/crates/celox-frontend-sv/src/lowering/ff/containers.rs @@ -18,6 +18,13 @@ impl Ff<'_, '_> { .ok_or_else(|| unsupported("omitted container operand")) }) .collect::, _>>()?; + // An update of an element of an outer container reads that element + // and writes it back: evaluate the indices on the way once. + if op.mutates() + && let Some(receiver) = args.first_mut() + { + *receiver = self.freeze_receiver(receiver)?; + } let original_key_width = args .get(1) .and_then(|key| self.m.comparison_width(key, key)); @@ -41,9 +48,11 @@ impl Ff<'_, '_> { )?; } } + // An element of an outer container is written back through its + // read, whose indices `freeze_receiver` has evaluated. if !value_receiver && self.m.calls(&args[0]) - && !matches!(&args[0], sv::ir::Expr::Call { callee: sv::ir::Callee::Object(op), .. } if matches!(**op, sv::ir::ObjectOp::Load(_))) + && !matches!(&args[0], sv::ir::Expr::Call { callee: sv::ir::Callee::Object(op), .. } if matches!(**op, sv::ir::ObjectOp::Load(_) | sv::ir::ObjectOp::Container { op: Get, .. })) { args[0] = self.heap_operand( &args[0], @@ -85,10 +94,15 @@ impl Ff<'_, '_> { *arg = self.heap_operand(arg, context, kind)?; } } - let (kind, capacity, signed_key, string_key) = match layout.kind { - ContainerKind::Dynamic => (0, 0, false, false), - ContainerKind::Queue { capacity } => (1, capacity, false, false), - ContainerKind::Associative { signed, string, .. } => (2, 0, signed, string), + let (kind, capacity, signed_key, string_key, object_key) = match layout.kind { + ContainerKind::Dynamic => (0, 0, false, false, false), + ContainerKind::Queue { capacity } => (1, capacity, false, false, false), + ContainerKind::Associative { + signed, + string, + object, + .. + } => (2, 0, signed, string, object), }; let parameter = heap::parameter( layout.width, @@ -102,6 +116,7 @@ impl Ff<'_, '_> { capacity, signed_key, string_key, + object_key, ); let code = |opcode| encode(opcode, parameter); if op.reduction().is_some() { @@ -381,13 +396,7 @@ impl Ff<'_, '_> { let narrow = this.b.alloc_bit(32, false); this.b.emit(SIRInstruction::Slice(narrow, updated, 0, 32)); this.store(id, SIROffset::Static(0), 32, narrow); - let sv::ir::Expr::Ident(receiver) = receiver else { - return Err(unsupported("container receiver must be a variable")); - }; - this.assign( - &sv::ir::LValue::Ident(receiver), - &sv::ir::Expr::Ident(updated_name), - ) + this.container_write_back(&receiver, sv::ir::Expr::Ident(updated_name)) })?; } zero @@ -402,6 +411,88 @@ impl Ff<'_, '_> { Ok(sv::ir::Expr::Ident(name)) } + /// `receiver` with the indices of the outer containers it reads, and the + /// objects of their properties, evaluated into temporaries. + fn freeze_receiver( + &mut self, + receiver: &sv::ir::Expr, + ) -> Result { + let sv::ir::Expr::Call { + callee: sv::ir::Callee::Object(op), + args, + arg_order, + } = receiver + else { + return Ok(receiver.clone()); + }; + let frozen = match **op { + sv::ir::ObjectOp::Container { + op: ContainerOp::Get, + .. + } => { + let [Some(outer), Some(index)] = args.as_slice() else { + return Ok(receiver.clone()); + }; + let outer = self.freeze_receiver(outer)?; + let index = self.hoist(index)?; + vec![Some(outer), Some(index)] + } + sv::ir::ObjectOp::Load(_) => { + let [Some(owner)] = args.as_slice() else { + return Ok(receiver.clone()); + }; + vec![Some(self.hoist(owner)?)] + } + _ => return Ok(receiver.clone()), + }; + Ok(sv::ir::Expr::Call { + callee: sv::ir::Callee::Object(op.clone()), + args: frozen, + arg_order: arg_order.clone(), + }) + } + + /// Store the updated container `updated` where `receiver` read it: a + /// variable, or an element of an outer container (`m[a]` of `m[a][b]`), + /// which is set in turn (IEEE 1800-2023 7.4.5). + fn container_write_back( + &mut self, + receiver: &sv::ir::Expr, + updated: sv::ir::Expr, + ) -> Result<(), sv::AnalyzerError> { + match receiver { + sv::ir::Expr::Ident(name) => { + self.assign(&sv::ir::LValue::Ident(name.clone()), &updated) + } + sv::ir::Expr::Call { + callee: sv::ir::Callee::Object(op), + args, + .. + } if matches!( + **op, + sv::ir::ObjectOp::Container { + op: ContainerOp::Get, + .. + } + ) => + { + let sv::ir::ObjectOp::Container { layout, .. } = **op else { + unreachable!("matched a container read") + }; + let [Some(outer), Some(index)] = args.as_slice() else { + return Err(unsupported("container element receiver")); + }; + self.container_call( + ContainerOp::Set, + layout, + &[Some(outer.clone()), Some(index.clone()), Some(updated)], + )?; + Ok(()) + } + _ => Err(unsupported("container receiver must be a variable")), + } + } + fn container_reduction( &mut self, op: ContainerOp, diff --git a/crates/celox-heap/src/containers.rs b/crates/celox-heap/src/containers.rs index 127528da42a..5ab65599b27 100644 --- a/crates/celox-heap/src/containers.rs +++ b/crates/celox-heap/src/containers.rs @@ -35,7 +35,9 @@ pub const RSORT: u64 = 99; /// The operation parameter encodes the element width (bits 0..6), whether /// it is two-state (7), its handle kind (8..9: none/string/object), container /// kind (10..11: dynamic/queue/associative), queue capacity (12..43, 0 means -/// unbounded), and associative key ordering (44 signed, 45 string). +/// unbounded), associative key ordering (44 signed, 45 string), and whether +/// associative keys are object handles that the collector traces (46). +#[allow(clippy::too_many_arguments)] pub const fn parameter( width: u32, two_state: bool, @@ -44,6 +46,7 @@ pub const fn parameter( capacity: u32, signed_key: bool, string_key: bool, + object_key: bool, ) -> u64 { width as u64 | (two_state as u64) << 7 @@ -52,6 +55,7 @@ pub const fn parameter( | (capacity as u64) << 12 | (signed_key as u64) << 44 | (string_key as u64) << 45 + | (object_key as u64) << 46 } #[derive(Clone, Copy)] @@ -171,19 +175,33 @@ impl Heap { let Some(container) = self.containers.get(&handle) else { return Vec::new(); }; + let mut roots = Vec::new(); + // Object keys of an associative array keep their objects alive. + if container.layout & (1 << 46) != 0 + && let Contents::Associative(v) = &container.contents + { + roots.extend(v.keys().filter_map(|key| match key { + Key::Integer(handle) => Some(Root { + kind: crate::HandleKind::Object, + handle: *handle as Handle, + }), + Key::String(_) => None, + })); + } let kind = match (container.layout >> 8) & 3 { 1 => crate::HandleKind::String, 2 => crate::HandleKind::Object, - _ => return Vec::new(), + _ => return roots, }; let root = |element: &Element| Root { kind, handle: element.value as Handle, }; match &container.contents { - Contents::Sequence(v) => v.iter().map(root).collect(), - Contents::Associative(v) => v.values().map(root).collect(), + Contents::Sequence(v) => roots.extend(v.iter().map(root)), + Contents::Associative(v) => roots.extend(v.values().map(root)), } + roots } /// Execute a container helper. Indices have already undergone language /// conversion; invalid four-state indices use an out-of-range sentinel. @@ -435,7 +453,7 @@ mod tests { #[test] fn completed_updates_intern_values_and_collection_releases_lookup_entries() { let mut heap = Heap::new(); - let p = parameter(8, true, 0, 0, 0, false, false); + let p = parameter(8, true, 0, 0, 0, false, false, false); let a = call(&mut heap, NEW, p, 2, 0, 0); let b = call(&mut heap, SET, p, a, 0, 7); let b = call(&mut heap, SET_MASK, p, b, 0, 0); @@ -454,7 +472,7 @@ mod tests { #[test] fn resize_copy_delete_and_four_state_defaults() { let mut heap = Heap::new(); - let p = parameter(32, false, 0, 0, 0, false, false); + let p = parameter(32, false, 0, 0, 0, false, false, false); let a = call(&mut heap, NEW, p, 2, 0, 0); assert_eq!(call(&mut heap, GET_MASK, p, a, 0, 0), u32::MAX as u64); let b = call(&mut heap, SET, p, a, 0, 42); @@ -470,7 +488,7 @@ mod tests { #[test] fn bounded_queue_insert_and_value_copies() { let mut heap = Heap::new(); - let p = parameter(8, true, 0, 1, 2, false, false); + let p = parameter(8, true, 0, 1, 2, false, false, false); let a = call(&mut heap, INSERT, p, 0, 0, 10); let b = call(&mut heap, INSERT, p, a, 0, 20); let c = call(&mut heap, INSERT, p, b, 0, 30); @@ -484,7 +502,7 @@ mod tests { #[test] fn ordering_interns_unchanged_values_and_retains_nested_string_roots() { let mut heap = Heap::new(); - let p = parameter(32, true, 1, 1, 0, false, false); + let p = parameter(32, true, 1, 1, 0, false, false, false); let z = heap.intern(b"z") as u64; let a = heap.intern(b"a") as u64; let first = call(&mut heap, INSERT, p, 0, 0, z); @@ -509,7 +527,7 @@ mod tests { #[test] fn associative_order_and_gc_follow_element_handles() { let mut heap = Heap::new(); - let p = parameter(32, true, 1, 2, 0, true, false); + let p = parameter(32, true, 1, 2, 0, true, false, false); let string = heap.intern(b"live"); let a = call(&mut heap, SET, p, 0, 3, string as u64); let b = call(&mut heap, SET, p, a, (-2i64) as u64, string as u64); diff --git a/crates/celox-sv-analyzer/src/ast/containers.rs b/crates/celox-sv-analyzer/src/ast/containers.rs index 8bea51bc93f..6d4844a95a9 100644 --- a/crates/celox-sv-analyzer/src/ast/containers.rs +++ b/crates/celox-sv-analyzer/src/ast/containers.rs @@ -34,10 +34,17 @@ pub(super) fn with_dimensions( DimensionKind::Index(id) => { let key_type = match &tree.declarations().expression(id).kind { ExprKind::Type(id) => type_binding::bind(*id, tree, context)?, - ExprKind::Name(name) => context - .type_aliases - .get(&instances::normalize_identifier(&name.spelling)) - .cloned(), + ExprKind::Name(name) => { + let name = instances::normalize_identifier(&name.spelling); + match context.type_aliases.get(&name) { + Some(ty) => Some(ty.clone()), + // A class: the index is an object handle (IEEE + // 1800-2023 7.8.5). + None if context.get(&name).is_none() => classes::resolve(tree, &name) + .and_then(|class| classes::handle_type(tree, &class)), + None => None, + } + } _ => None, }; match key_type { @@ -45,21 +52,24 @@ pub(super) fn with_dimensions( Some(ty) => { index_type = Some(ty.clone()); let string = ty.kind() == TypeKind::String; + let object = ty.kind() == TypeKind::Object && ty.container.is_none(); let shape = casts::expr_type_from_type(&tree.state, &ty, &context.const_env) .ok_or_else(|| unsupported("associative index type"))?; if !string + && !object && (!matches!(ty.kind(), TypeKind::Bit | TypeKind::Logic | TypeKind::Reg) || shape.width > 64 || !ty.unpacked_ranges.is_empty()) { return Err(unsupported( - "associative indices require strings or integral types up to 64 bits", + "associative indices require strings, class handles or integral types up to 64 bits", )); } Some(ContainerKind::Associative { key_width: shape.width as u32, - signed: shape.signed, + signed: shape.signed && !object, string, + object, }) } } @@ -73,8 +83,17 @@ pub(super) fn with_dimensions( constant_binding::bind_unpacked_ranges(dims, tree, context)?, )); }; - if dims.len() != 1 || base.container.is_some() || !base.unpacked_ranges.is_empty() { - return Err(unsupported("multidimensional dynamic container")); + // `T a[x][y]`: each element of `a` is a container `T [y]` (IEEE + // 1800-2023 7.4.5, 7.8), held by its handle like any container value. + let base = if dims.len() > 1 { + with_dimensions(base, &dims[1..], tree, context)? + } else { + base + }; + if base.container.is_none() && dims.len() > 1 || !base.unpacked_ranges.is_empty() { + return Err(unsupported( + "dynamic container of fixed-size unpacked arrays", + )); } if matches!(base.kind(), TypeKind::Real | TypeKind::Shortreal) { return Err(unsupported("real dynamic container elements")); @@ -89,8 +108,8 @@ pub(super) fn with_dimensions( return Err(unsupported("dynamic container elements wider than 64 bits")); } let handle = match base.kind() { - // An element in a record is the record's handle. - _ if record.is_some() => Some(HandleProperty::Object), + // An element in a record, or a nested container, is a handle. + _ if record.is_some() || base.container.is_some() => Some(HandleProperty::Object), TypeKind::String => Some(HandleProperty::String), TypeKind::Object => Some(HandleProperty::Object), _ => None, @@ -141,6 +160,40 @@ pub(super) fn native_type( { return Ok(shape.container.clone()); } + // An element popped from a queue of containers. + let callee = match &native + .expression(expression_binding::ungroup(id, native)) + .kind + { + ExprKind::Call { expression, .. } => Some(*expression), + ExprKind::Member { .. } => Some(expression_binding::ungroup(id, native)), + _ => None, + }; + if let Some(callee) = callee + && let ExprKind::Member { + expression, name, .. + } = &native.expression(callee).kind + && matches!(name.spelling.as_str(), "pop_front" | "pop_back") + && let Some(outer) = native_type(*expression, native, tree, dims)? + && let Some(inner) = outer.element.container.clone() + { + return Ok(Some(inner)); + } + // An element of a container of containers, `m[a]` of `m[a][b]`. + if let ExprKind::Select { + expression, + dimension, + } = &native + .expression(expression_binding::ungroup(id, native)) + .kind + && matches!( + dimension.kind, + DimensionKind::Index(_) | DimensionKind::Queue(None) + ) + && let Some(outer) = native_type(*expression, native, tree, dims)? + { + return Ok(outer.element.container.clone()); + } Ok(None) } @@ -248,6 +301,11 @@ fn element_value( target: &ContainerType, ) -> Converted { let native = tree.declarations(); + // An element that is itself a container takes a container value, as an + // assignment to a container variable does. + if let Some(inner) = target.element.container.as_deref() { + return assignment(id, tree, dims, inner); + } if native_type(id, native, tree, dims)?.is_some() { return Err(unsupported("container used as an element")); } @@ -284,6 +342,17 @@ fn index_value( target: &ContainerType, ) -> Converted { let native = tree.declarations(); + // A class index takes handles of its class or a derived one. + if let Some(class) = target.key.as_ref().and_then(|key| key.class()).filter(|_| { + matches!( + target.layout.kind, + ContainerKind::Associative { object: true, .. } + ) + }) { + expression_binding::check_handle_assignment(tree, id, native, dims, class, || { + "associative array index".into() + })?; + } if matches!( target.layout.kind, ContainerKind::Associative { string: true, .. } @@ -375,6 +444,10 @@ pub(super) fn value( "comparison of dynamic containers of unpacked structures", )); } + // The elements are inner containers' handles, not their values. + if target.element.container.is_some() { + return Err(unsupported("comparison of nested dynamic containers")); + } let op = match operator.as_str() { "==" | "!=" => ContainerOp::Equal, "===" | "!==" => ContainerOp::CaseEqual, @@ -567,10 +640,15 @@ pub(super) fn value( let shape = dims .get(&instances::normalize_identifier(&name.spelling)) .ok_or_else(|| unsupported("associative traversal index variable"))?; - if let ContainerKind::Associative { string, .. } = target.layout.kind + // The index variable of a class index is passed by + // reference, so it has the index's class (IEEE 1800-2023 + // 7.9.4). + let key_class = target.key.as_ref().and_then(|key| key.class()); + if let ContainerKind::Associative { string, object, .. } = target.layout.kind && (shape.string != string || shape.container.is_some() - || !shape.unpacked.is_empty()) + || !shape.unpacked.is_empty() + || object && shape.class.as_deref() != key_class) { return Err(unsupported( "incompatible associative traversal index variable", @@ -647,15 +725,23 @@ fn query( if arguments.len() != 1 { return Err(unsupported("dynamic array query arguments")); } + // A container of containers has one unpacked dimension per level. + let mut innermost = target.clone(); + let mut unpacked = 1; + while let Some(inner) = innermost.element.container.clone() { + innermost = inner; + unpacked += 1; + } return Ok(Some(Expr::Literal( if name.spelling == "$unpacked_dimensions" { - 1 + unpacked } else { - 1 + if target.layout.handle.is_some() { - 0 - } else { - target.element.packed_ranges.len() - } + unpacked + + if innermost.layout.handle.is_some() { + 0 + } else { + innermost.element.packed_ranges.len() + } } .to_string(), ))); @@ -797,7 +883,22 @@ mod tests { fn unsupported_container_forms_fail_before_lowering() { for (source, expected) in [ ("module Top; bit[127:0] a[]; endmodule", "wider than 64"), - ("module Top; int a[][]; endmodule", "multidimensional"), + ( + "module Top; int a[][2]; endmodule", + "dynamic container of fixed-size unpacked arrays", + ), + ( + "module Top; int a[][], b[][]; bit x; initial x = a == b; endmodule", + "comparison of nested dynamic containers", + ), + ( + "module Top; class A; endclass class B; endclass int m[A]; B b; initial begin b = new; m[b] = 1; end endmodule", + "associative array index", + ), + ( + "module Top; class A; endclass class B; endclass int m[A]; B k; initial void'(m.first(k)); endmodule", + "incompatible associative traversal index variable", + ), ("module Top; int a[*]; endmodule", "wildcard"), ( "module Top; int a[string]; initial a[123] = 7; endmodule", diff --git a/crates/celox-sv-analyzer/src/ast/procedural/foreach.rs b/crates/celox-sv-analyzer/src/ast/procedural/foreach.rs index 4a780198d6b..89f7e64e879 100644 --- a/crates/celox-sv-analyzer/src/ast/procedural/foreach.rs +++ b/crates/celox-sv-analyzer/src/ast/procedural/foreach.rs @@ -47,9 +47,12 @@ impl BodyBuilder<'_, '_, '_> { key_width, signed, string, + object, } = container.layout.kind { - index_type = if string { + index_type = if object { + container.key.clone().expect("a class index type") + } else if string { type_binding::builtin_type("string", None).expect("string is a builtin type") } else { let mut ty = int_type(); diff --git a/crates/celox-sv-analyzer/src/system_functions.rs b/crates/celox-sv-analyzer/src/system_functions.rs index 2502e6b3ad3..41acaf58a43 100644 --- a/crates/celox-sv-analyzer/src/system_functions.rs +++ b/crates/celox-sv-analyzer/src/system_functions.rs @@ -901,6 +901,8 @@ pub enum ContainerKind { key_width: u32, signed: bool, string: bool, + /// Keys are class handles, which keep their objects alive. + object: bool, }, } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] diff --git a/crates/celox-test-suite/LIMITATIONS.md b/crates/celox-test-suite/LIMITATIONS.md index 5ea627f90fd..106251a144e 100644 --- a/crates/celox-test-suite/LIMITATIONS.md +++ b/crates/celox-test-suite/LIMITATIONS.md @@ -628,6 +628,7 @@ four-state expectations; the assertions remain enabled on all Celox variants. | `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_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. | The `string_format` cases compare `$sformatf`, `$sformat` and `$swrite` with diff --git a/crates/celox-test-suite/src/sv/cases/containers.vtest b/crates/celox-test-suite/src/sv/cases/containers.vtest index 52d1985d914..869b0a22384 100644 --- a/crates/celox-test-suite/src/sv/cases/containers.vtest +++ b/crates/celox-test-suite/src/sv/cases/containers.vtest @@ -957,3 +957,133 @@ endmodule "#) (four_state) (top Top) (run_until 0) (assert_eq flags 255)) + +(case nested_containers_and_class_keys + (source "nested_containers.sv" #" +module Top(output bit done); + class Obj; + string n; + function new(string n); + this.n = n; + endfunction + endclass + typedef enum { NEVER, STARTED, FINISHED } state_e; + typedef enum { DEEP, SHALLOW } policy_e; + typedef struct { state_e state; bit ret_val; } info_t; + class Comparer; + info_t m[Obj][Obj][policy_e]; + state_e s[Obj][Obj]; + function void start(Obj l, Obj r); + m[l][r][DEEP] = '{STARTED, 0}; + endfunction + endclass + initial begin + Comparer c; + Obj a, b, k; + int grid[][]; + c = new; + a = new("a"); + b = new("b"); + c.start(a, b); + $display("%0d %0d %0d", c.m[a][b][DEEP].state, c.m[a][b][DEEP].ret_val, c.m.exists(a)); + c.m[a][b][DEEP] = '{FINISHED, 1}; + c.m[b][a][SHALLOW] = '{STARTED, 1}; + $display("%0d %0d %0d %0d", c.m[a][b][DEEP].state, c.m[a][b][DEEP].ret_val, c.m.num(), + c.m[b][a][SHALLOW].ret_val); + c.s[a][b] = FINISHED; + $display("%0d %0d", c.s[a][b], c.s[b][a]); + if (c.m.first(k)) $display("first %s", k.n); + foreach (c.m[x]) $display("key %s", x.n); + c.m.delete(); + grid = new[2]; + grid[1] = new[3]; + grid[1][2] = 7; + $display("%0d %0d", c.m.num(), grid[1][2]); + done = 1; + end +endmodule +"#) + (top Top) (run_until 0) (assert_eq done 1) + (expect_output "1 0 1\n2 1 2 1\n2 0\nfirst a\nkey a\nkey b\n0 7\n")) + +(case methods_of_nested_container_elements + (source "nested_container_methods.sv" #" +module Top(output bit done); + initial begin + int m[string][int]; + int counts[string][$]; + int grid[][]; + m["a"][1] = 10; + m["a"][2] = 20; + m["b"][3] = 30; + $display("%0d %0d %0d %0d", m.num(), m["a"].num(), m["a"].exists(2), m["b"].exists(2)); + m["a"].delete(1); + $display("%0d %0d", m["a"].num(), m.num()); + counts["x"].push_back(3); + counts["x"].push_back(4); + counts["y"].push_back(5); + $display("%0d %0d %0d %0d", counts["x"].size(), counts["x"][1], counts["y"][0], + counts["z"].size()); + grid = new[2]; + grid[1] = new[3]; + $display("%0d %0d %0d", grid.size(), grid[0].size(), grid[1].size()); + done = 1; + end +endmodule +"#) + (top Top) (run_until 0) (assert_eq done 1) + (expect_output "2 2 1 0\n1 2\n2 4 5 0\n2 0 3\n")) + +(case nested_updates_evaluate_indices_once + (source "nested_updates.sv" #" +module Top(output bit done); + int i; + function automatic int next_index(); + i++; + return i; + endfunction + initial begin + int m[int][$]; + int grid[][]; + m[next_index()].push_back(7); + m[next_index()].push_back(8); + $display("%0d %0d %0d %0d %0d", m.num(), m[1].size(), m[1][0], m[2][0], i); + grid = new[2]; + grid[1] = new[2]; + $display("%0d %0d", $unpacked_dimensions(grid), $dimensions(grid)); + done = 1; + end +endmodule +"#) + (top Top) (run_until 0) (assert_eq done 1) + (expect_output "2 1 7 8 2\n2 3\n")) + +(case class_keys_survive_heap_collections + (source "class_keys.sv" #" +module Top(output int n); + class Obj; + string n; + endclass + logic clk = 0; + always #1 clk = ~clk; + int seen[Obj]; + Obj last; + string number; + always @(posedge clk) begin + Obj o; + o = new; + number.itoa(n); + o.n = number; + seen[o] = n; + n = n + 1; + end + initial begin + #6000; + foreach (seen[k]) if (seen[k] == 2999) last = k; + $display("%0d [%s] %0d", seen.num(), last.n, seen[last]); + end +endmodule +"#) + (top Top) + (run_until 6000) + (expect_output "3000 [2999] 2999\n")) diff --git a/crates/celox-test-suite/verification/repros/sv_icarus_nested_containers.sv b/crates/celox-test-suite/verification/repros/sv_icarus_nested_containers.sv new file mode 100644 index 00000000000..7b08e4e1ef6 --- /dev/null +++ b/crates/celox-test-suite/verification/repros/sv_icarus_nested_containers.sv @@ -0,0 +1,16 @@ +// Icarus 13.0 rejects an associative array whose index type is a type name, +// a class or a typedef ("Type names are not valid expressions here."), which +// IEEE 1800-2023 7.8 and 7.8.5 permit. +module top; + class Obj; + endclass + initial begin + int seen[Obj]; + int m[string][int]; + Obj a; + a = new; + seen[a] = 1; + m["a"][1] = 2; + $display("%0d %0d", seen[a], m["a"][1]); + end +endmodule diff --git a/crates/celox-test-suite/verification/repros/sv_xezim_nested_containers.sv b/crates/celox-test-suite/verification/repros/sv_xezim_nested_containers.sv new file mode 100644 index 00000000000..79c95022f20 --- /dev/null +++ b/crates/celox-test-suite/verification/repros/sv_xezim_nested_containers.sv @@ -0,0 +1,26 @@ +// xezim 0.11.3: first() of a class property that is an associative array of +// associative arrays indexed by class handles reports an empty array, and +// new[] assigned to an element of a dynamic array of dynamic arrays is lost +// (IEEE 1800-2023 7.8.5, 7.9.5, 7.5.1). Expected: "first 1 a" and "3 7". +module top; + class Obj; + string n; + endclass + class Holder; + int m[Obj][Obj]; + endclass + initial begin + Holder h; + int grid[][]; + Obj a, k; + h = new; + a = new; + a.n = "a"; + h.m[a][a] = 1; + $display("first %0d %s", h.m.first(k), k == null ? "-" : k.n); + grid = new[2]; + grid[1] = new[3]; + grid[1][2] = 7; + $display("%0d %0d", grid[1].size(), grid[1][2]); + end +endmodule diff --git a/crates/celox-test-suite/verification/sv/icarus.json b/crates/celox-test-suite/verification/sv/icarus.json index c10f9fe0aeb..b8f59525689 100644 --- a/crates/celox-test-suite/verification/sv/icarus.json +++ b/crates/celox-test-suite/verification/sv/icarus.json @@ -4,6 +4,7 @@ "icarus/always_comb.json", "icarus/class.json", "icarus/concurrent_assertions.json", + "icarus/containers.json", "icarus/fork.json", "icarus/fork_control.json", "icarus/fork_deferred.json", diff --git a/crates/celox-test-suite/verification/sv/icarus/containers.json b/crates/celox-test-suite/verification/sv/icarus/containers.json new file mode 100644 index 00000000000..1cd085b2de7 --- /dev/null +++ b/crates/celox-test-suite/verification/sv/icarus/containers.json @@ -0,0 +1,96 @@ +{ + "cases": [ + { + "category": "Types", + "detail": "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.", + "expectation": "Simulation", + "known_issue": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/repros/sv_icarus_nested_containers.sv", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_icarus_nested_containers", + "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", + "phase": "compile", + "reason": "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.", + "upstream": [] + }, + "name": "containers::class_keys_survive_heap_collections", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "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.", + "expectation": "Simulation", + "known_issue": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/repros/sv_icarus_nested_containers.sv", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_icarus_nested_containers", + "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", + "phase": "compile", + "reason": "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.", + "upstream": [] + }, + "name": "containers::methods_of_nested_container_elements", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "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.", + "expectation": "Simulation", + "known_issue": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/repros/sv_icarus_nested_containers.sv", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_icarus_nested_containers", + "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", + "phase": "compile", + "reason": "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.", + "upstream": [] + }, + "name": "containers::nested_containers_and_class_keys", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "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.", + "expectation": "Simulation", + "known_issue": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/repros/sv_icarus_nested_containers.sv", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_icarus_nested_containers", + "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", + "phase": "compile", + "reason": "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.", + "upstream": [] + }, + "name": "containers::nested_updates_evaluate_indices_once", + "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 b4e804a0208..623ea0723a1 100644 --- a/crates/celox-test-suite/verification/sv/limitations.json +++ b/crates/celox-test-suite/verification/sv/limitations.json @@ -3018,5 +3018,25 @@ "unpacked_structs::assignment_patterns" ] } + }, + { + "id": "sv_icarus_nested_containers", + "category": "simulator_compile_limitation", + "phase": "compile", + "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", + "reason": "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.", + "upstream": [], + "evidence": [ + "verification/repros/sv_icarus_nested_containers.sv", + "LIMITATIONS.md#systemverilog-suite" + ], + "cases": { + "icarus": [ + "containers::class_keys_survive_heap_collections", + "containers::methods_of_nested_container_elements", + "containers::nested_containers_and_class_keys", + "containers::nested_updates_evaluate_indices_once" + ] + } } ] diff --git a/crates/celox-test-suite/verification/sv/xezim.json b/crates/celox-test-suite/verification/sv/xezim.json index ff2b063c499..f3f67567030 100644 --- a/crates/celox-test-suite/verification/sv/xezim.json +++ b/crates/celox-test-suite/verification/sv/xezim.json @@ -5,6 +5,7 @@ "xezim/binary_file_io.json", "xezim/class.json", "xezim/concurrent_assertions.json", + "xezim/containers.json", "xezim/distributions.json", "xezim/edges.json", "xezim/file_core.json", diff --git a/crates/celox-test-suite/verification/sv/xezim/containers.json b/crates/celox-test-suite/verification/sv/xezim/containers.json new file mode 100644 index 00000000000..e24ae9fb382 --- /dev/null +++ b/crates/celox-test-suite/verification/sv/xezim/containers.json @@ -0,0 +1,37 @@ +{ + "cases": [ + { + "category": "Types", + "detail": "containers::methods_of_nested_container_elements at 1035:3: expect_output: expected [50, 32, 50, 32, 49, 32, 48, 10, 49, 32, 50, 10, 50, 32, 52, 32, 53, 32, 48, 10, 50, 32, 48, 32, 51, 10], got [50, 32, 50, 32, 49, 32, 48, 10, 49, 32, 50, 10, 50, 32, 52, 32, 53, 32, 48, 10, 50, 32, 48, 32, 48, 10]", + "expectation": "Simulation", + "name": "containers::methods_of_nested_container_elements", + "phase": "execute", + "status": "mismatch", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "containers::nested_containers_and_class_keys at 1007:3: expect_output: expected [49, 32, 48, 32, 49, 10, 50, 32, 49, 32, 50, 32, 49, 10, 50, 32, 48, 10, 102, 105, 114, 115, 116, 32, 97, 10, 107, 101, 121, 32, 97, 10, 107, 101, 121, 32, 98, 10, 48, 32, 55, 10], got [49, 32, 48, 32, 49, 10, 50, 32, 49, 32, 50, 32, 49, 10, 50, 32, 48, 10, 107, 101, 121, 32, 97, 10, 107, 101, 121, 32, 98, 10, 48, 32, 49, 10]", + "expectation": "Simulation", + "name": "containers::nested_containers_and_class_keys", + "phase": "execute", + "status": "mismatch", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "containers::nested_updates_evaluate_indices_once at 1059:3: expect_output: expected [50, 32, 49, 32, 55, 32, 56, 32, 50, 10, 50, 32, 51, 10], got [50, 32, 48, 32, 48, 32, 48, 32, 54, 10, 49, 32, 50, 10]", + "expectation": "Simulation", + "name": "containers::nested_updates_evaluate_indices_once", + "phase": "execute", + "status": "mismatch", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + } + ] +} diff --git a/crates/celox-test-suite/verification/xezim-review.json b/crates/celox-test-suite/verification/xezim-review.json index 44e8a8d4db5..39f718bd0c6 100644 --- a/crates/celox-test-suite/verification/xezim-review.json +++ b/crates/celox-test-suite/verification/xezim-review.json @@ -794,6 +794,18 @@ "sv_rest-X89": { "title": "A whole class property of unpacked structure type is assigned member by member: a pattern reading the property sees members already written, and a receiver with a side-effecting index is evaluated per member", "standard": "IEEE 1800-2023 7.2, 10.9.2, 11.4.1" + }, + "sv_rest-X86": { + "title": "first() of a class property that is an associative array of associative arrays indexed by class handles reports an empty array", + "standard": "IEEE 1800-2023 7.8.5, 7.9.5" + }, + "sv_rest-X87": { + "title": "new[] assigned to an element of a dynamic array of dynamic arrays is lost", + "standard": "IEEE 1800-2023 7.5.1, 7.4.5" + }, + "sv_rest-X90": { + "title": "An update of an element of a nested container evaluates the outer index expression again, and $unpacked_dimensions/$dimensions of a dynamic array of dynamic arrays count one level", + "standard": "IEEE 1800-2023 7.4.5, 11.4.1, 20.7" } }, "cases": [ @@ -4651,6 +4663,30 @@ "classification": "xezim_bug", "bug": "sv_rest-X89", "note": "h.p = '{h.p.b, h.p.a} prints \"2 2\" instead of \"2 1\", and items[next_index()].p = '{7, 8} calls next_index() once per member, writing items[1].p.a and items[2].p.b, with i = 3 instead of 1." + }, + { + "suite": "sv", + "name": "containers::nested_containers_and_class_keys", + "status": "mismatch", + "classification": "xezim_bug", + "bug": "sv_rest-X86", + "note": "c.m.first(k) on the Obj-indexed property returns 0, so \"first a\" is missing; grid[1] = new[3] is also lost (sv_rest-X87), so grid[1][2] reads 1 instead of 7. Reproduced by verification/repros/sv_xezim_nested_containers.sv." + }, + { + "suite": "sv", + "name": "containers::methods_of_nested_container_elements", + "status": "mismatch", + "classification": "xezim_bug", + "bug": "sv_rest-X87", + "note": "grid[1] = new[3] leaves grid[1] empty, so grid[1].size() prints 0 instead of 3. Reproduced by verification/repros/sv_xezim_nested_containers.sv." + }, + { + "suite": "sv", + "name": "containers::nested_updates_evaluate_indices_once", + "status": "mismatch", + "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." } ] } diff --git a/crates/celox/tests/frontends/systemverilog/containers.rs b/crates/celox/tests/frontends/systemverilog/containers.rs index b9c99830c6d..343428e4ace 100644 --- a/crates/celox/tests/frontends/systemverilog/containers.rs +++ b/crates/celox/tests/frontends/systemverilog/containers.rs @@ -2,6 +2,10 @@ use super::*; sv_backends! { fn class_container_inheritance_static(sim) { @case "containers::class_container_inheritance_static"; } + fn nested_containers_and_class_keys(sim) { @case "containers::nested_containers_and_class_keys"; } + fn methods_of_nested_container_elements(sim) { @case "containers::methods_of_nested_container_elements"; } + fn nested_updates_evaluate_indices_once(sim) { @case "containers::nested_updates_evaluate_indices_once"; } + fn class_keys_survive_heap_collections(sim) { @case "containers::class_keys_survive_heap_collections"; } fn class_container_receiver_evaluation(sim) { @case "containers::class_container_receiver_evaluation"; } fn class_container_properties(sim) { @case "containers::class_container_properties"; } fn class_container_queue_pool(sim) { @case "containers::class_container_queue_pool"; } @@ -41,6 +45,29 @@ sv_backends! { fn declaration_initializers_and_locals(sim) { @case "containers::declaration_initializers_and_locals"; } } +sv_backends! { + fn popped_nested_queue_elements_are_containers(sim) { + @setup { + let source = r#"module Top(output int value); + initial begin + int q[$][$]; + int row[$]; + row.push_back(4); + row.push_back(2); + q.push_back(row); + row = '{}; + row = q.pop_front(); + value = row.size() * 100 + row[0] * 10 + q.size(); + end + endmodule"#; + } + @build celox::Simulation::from_sv_sources(vec![(source, Path::new("nested.sv"))], "Top"); + sim.run_until(0).unwrap(); + let value = sim.signal("value"); + assert_eq!(sim.get(value), BigUint::from(240u8)); + } +} + sv_backends! { fn container_checkpoints_restore_all_three_kinds(sim) { @setup { diff --git a/docs/guide/systemverilog-reference.md b/docs/guide/systemverilog-reference.md index 5c603abfd30..9f7812ef13b 100644 --- a/docs/guide/systemverilog-reference.md +++ b/docs/guide/systemverilog-reference.md @@ -31,7 +31,7 @@ synthesis and is tested at the design level. | Expressions | arithmetic including `**`, logic, shift, comparison, reduction, concatenation and replication, `?:`, `inside`, `==?` / `!=?`, casts (`N'(x)`, `signed'(x)`, `T'(x)`), `$signed` / `$unsigned` | | Selects | constant and run-time bit selects and indexed part-selects (`[i]`, `[i +: W]`, `[i -: W]`), in reads and writes, in either declaration direction | | Patterns | assignment patterns for packed and unpacked structs, packed arrays and unpacked arrays (`'{a, b}`, `'{x: a, default: 0}`, `'{n{a}}`, `T'{...}`) | -| Dynamic containers | one-dimensional dynamic arrays, queues (including bounded queues), and associative arrays with integral or string keys; element access, value assignment, equality, `foreach` and built-in container methods. See [dynamic containers](#dynamic-containers) | +| Dynamic containers | dynamic arrays, queues (including bounded queues), and associative arrays with integral, string or class handle keys, also nested (`int m[string][$]`, `T m[C][C][E]`); element access, value assignment, equality, `foreach` and built-in container methods. See [dynamic containers](#dynamic-containers) | | Strings | `string` variables, function arguments and results: assignment of strings, string literals and casts (`string'(x)`), `==`, `!=` and ordering comparisons, concatenation and replication (with a run-time count), character reads and writes (`s[i]`), and the methods `len`, `getc`, `putc`, `toupper`, `tolower`, `compare`, `icompare`, `substr`, `atoi` / `atohex` / `atooct` / `atobin` and `itoa` / `hextoa` / `octtoa` / `bintoa`; `%s` and format-less display of string values; text formatted by `$sformatf` / `$sformat` / `$swrite`. See [strings](#strings) | | Classes | classes declared in a module, a package or the compilation unit: properties of 2-state and 4-state integral types up to 64 bits (4-state properties start as X and keep X/Z bits), `string` and class handle types, unpacked structures of those types (see [unpacked structures](#unpacked-structures)), plus dynamic arrays, queues and associative arrays, with initializers; `new` with and without arguments, implicit and explicit constructors; methods (`function` and `task`, also `extern` with an out-of-block body) called through a handle or unqualified inside the class; `this`, `null`, handle assignment and comparison; inheritance of properties and methods, with base constructors called by `super.new(...)` or `extends Base(...)`; `super.` members; virtual methods, abstract (`virtual`) classes and pure virtual methods; classes that implement interface classes and method calls through interface class handles; `$cast` of class handles, as a function and as a task; static properties and methods; `C::` scope resolution of static members and `C::new`; arrays of handles; parameterized classes with value and type parameters, parameters read through a handle or `C#(...)::`, typedefs of classes and interface classes and `C::T`; named constructor arguments; shallow copies (`new h`). See [classes](#classes) | | Parameters | integral parameters and overrides preserving widths beyond 128 bits and X/Z values, and parameters of unpacked array or packed struct type given by an assignment pattern (constant tables), including unpacked-array pattern overrides | @@ -462,9 +462,14 @@ Dynamic arrays (`T a[]`) support `new[n]`, `new[n](a)`, `size()` and `delete()` (IEEE 1800-2023 7.5). Queues (`T q[$]`, `T q[$:N]`) support `size`, `insert`, `delete`, `push_front`, `push_back`, `pop_front` and `pop_back`. Queue indices may use `$` and `$+1`. -Associative arrays support integral keys up to 64 bits or `string` keys, -`num` / `size`, `exists`, `delete`, and `first` / `last` / `next` / `prev` -(7.8–7.10). Traversal leaves its index unchanged when no key is found. +Associative arrays support integral keys up to 64 bits, `string` keys or +class handle keys (7.8.5), which keep their objects alive; `num` / `size`, +`exists`, `delete`, and `first` / `last` / `next` / `prev` (7.8–7.10). +Traversal leaves its index unchanged when no key is found. A container +declared with several dynamic dimensions, `T m[a][b]`, holds containers as +elements: `m[a][b] = v` updates the inner container of `m[a]`, which reads as +empty when absent, and methods apply to an element (`m[a].exists(b)`). +`foreach` iterates one dimension at a time. The empty parentheses on zero-argument container methods are optional: `a.size`, `q.pop_front`, `map.num` and `map.delete` have the same behavior as