From 571727cc54630089868d90ba1731450db769a8fc Mon Sep 17 00:00:00 2001 From: tignear Date: Tue, 27 Oct 2026 02:22:47 +0900 Subject: [PATCH] fix(sv): allow bare zero-argument container methods Calls such as q.size, q.pop_front and map.delete now bind through the same argument and void-result checks as their parenthesized forms. Handle void-cast statements that discard pop results, including string and class handles. Preserve the declared element type when querying an integral pop result, including packed rank and authored bounds. Type queries validate without executing the pop. Reject unsupported queries on nonintegral pop results instead of treating string/class handles as packed integer values. The upstream queue and associative examples are narrow: all 28 initially selected official case/mode checks passed while a packed-result query still failed on every Celox backend. Add that counterexample alongside ordinary, four-state/default, side-effect, discarded-return and required-argument checks. The fixed packed-result case also passes Verilator. The official runner checked 36 pinned upstream cases containing bare method names in both state modes (72 verdicts). Sixteen simulation cases improve from fail to pass in both modes, including associative allocation and nonexistent reads beyond the initial selection. Update exactly those 32 expectations; preserve the other 3,268 rows. No previously passing candidate regresses. This was a focused run, not a full-corpus conformance measurement. Validation: - Common SV suite: 5,679 passed, 20 existing ignored. Latest container suite: 108 passed, including four new shared cases across five configurations. - Analyzer/frontend units: 833 and 7 passed, with 3 existing analyzer ignores. - Debug NAPI build and JS integration: 435 passed across 16 files. - Affected-crate all-targets Clippy with -D warnings, formatting, diff checks and the five sv-tests aggregate tests passed. Independent checks retain their original assertions and exclusions: - Verilator 5.052: 3 passes, 1 four-state adapter unsupported. - Icarus 13.0: 1 pass, 2 compile errors for unsupported associative arrays and 1 mismatch in the packed-result dimension/bound queries. - xezim 0.11.3: all four compile but mismatch. Standalone probes reproduce queue mutation inside $bits/$size, zero instead of X from an empty logic queue pop, and receiver capture before a nested pop argument. Queue slicing, queue concatenation operands, element-reference persistence, warning diagnostics and nonintegral pop result queries remain outside this change's support contract. Change-Id: Ie020842652d298a923ebb251ce8d4775b3249082 --- conformance/sv-tests/README.md | 20 ++++ conformance/sv-tests/expected.tsv | 64 ++++++------- .../celox-sv-analyzer/src/ast/containers.rs | 60 +++++++++++- .../src/ast/dimensions/query_binding.rs | 23 +++++ .../celox-sv-analyzer/src/ast/procedural.rs | 7 ++ .../src/sv/cases/containers.vtest | 95 +++++++++++++++++++ .../frontends/systemverilog/containers.rs | 4 + docs/guide/systemverilog-reference.md | 10 +- 8 files changed, 245 insertions(+), 38 deletions(-) diff --git a/conformance/sv-tests/README.md b/conformance/sv-tests/README.md index aeb7df2da7b..fec41b659ee 100644 --- a/conformance/sv-tests/README.md +++ b/conformance/sv-tests/README.md @@ -145,6 +145,26 @@ contains 3,300 case/mode verdicts at the pinned revision. These are its only changed rows, with no passing case regressing: 1,201 cases pass in 2state and 1,212 in 4state. Only these reviewed expectations are updated. +Zero-argument dynamic-container methods accept omitted parentheses, including +`size`, associative `num`, `delete`, and queue `pop_front` / `pop_back` +(7.5.2–7.5.3, 7.9, 7.10.2). Sixteen unmodified upstream simulation cases pass +the official runner in both state modes at the pinned revision: dynamic +`op-delete` / `op-size`, associative `alloc`, `nonexistent`, `delete`, `num`, +and `size`, and queue +`bounded`, `delete`, `insert`, `max-size`, `pop_back`, `pop_front`, `push_back`, +`push_front` and `size`. Only these 32 expectations change from `fail` to `pass`. +The focused runner checked 36 pinned case files containing these bare +method names (72 case/mode verdicts), with no passing candidate regressing. +This does not establish full dynamic-container conformance. +Shared regressions additionally cover discarded pop results, string/class +handles, four-state values and empty-pop defaults, and unevaluated type queries +that preserve packed result dimensions and authored bounds. The packed-result +query regression failed on all five Celox backend configurations even after +the initial 28 upstream checks passed. Arity and void-result rejection remain checked. +Queue slices, queue operands in concatenations, element-reference persistence, +warning diagnostics, and queries on nonintegral pop results remain outside +this change's support contract. + ## Running locally Use the locked development shell and install the pinned [`requirements.txt`](requirements.txt) in a Python environment. diff --git a/conformance/sv-tests/expected.tsv b/conformance/sv-tests/expected.tsv index b9bae1143b3..547a5dcf84c 100644 --- a/conformance/sv-tests/expected.tsv +++ b/conformance/sv-tests/expected.tsv @@ -1255,8 +1255,8 @@ chapter-6/6.9.2--vector_vectored.sv 2state fail chapter-6/6.9.2--vector_vectored.sv 4state fail chapter-6/6.9.2--vector_vectored_inv.sv 2state pass chapter-6/6.9.2--vector_vectored_inv.sv 4state pass -chapter-7/arrays/associative/alloc.sv 2state fail -chapter-7/arrays/associative/alloc.sv 4state fail +chapter-7/arrays/associative/alloc.sv 2state pass +chapter-7/arrays/associative/alloc.sv 4state pass chapter-7/arrays/associative/arguments.sv 2state fail chapter-7/arrays/associative/arguments.sv 4state fail chapter-7/arrays/associative/assignment.sv 2state pass @@ -1287,8 +1287,8 @@ chapter-7/arrays/associative/locator-methods/unique-index.sv 2state fail chapter-7/arrays/associative/locator-methods/unique-index.sv 4state fail chapter-7/arrays/associative/locator-methods/unique.sv 2state fail chapter-7/arrays/associative/locator-methods/unique.sv 4state fail -chapter-7/arrays/associative/methods/delete.sv 2state fail -chapter-7/arrays/associative/methods/delete.sv 4state fail +chapter-7/arrays/associative/methods/delete.sv 2state pass +chapter-7/arrays/associative/methods/delete.sv 4state pass chapter-7/arrays/associative/methods/exists.sv 2state pass chapter-7/arrays/associative/methods/exists.sv 4state pass chapter-7/arrays/associative/methods/first.sv 2state pass @@ -1297,16 +1297,16 @@ chapter-7/arrays/associative/methods/last.sv 2state pass chapter-7/arrays/associative/methods/last.sv 4state pass chapter-7/arrays/associative/methods/next.sv 2state pass chapter-7/arrays/associative/methods/next.sv 4state pass -chapter-7/arrays/associative/methods/num.sv 2state fail -chapter-7/arrays/associative/methods/num.sv 4state fail +chapter-7/arrays/associative/methods/num.sv 2state pass +chapter-7/arrays/associative/methods/num.sv 4state pass chapter-7/arrays/associative/methods/prev.sv 2state pass chapter-7/arrays/associative/methods/prev.sv 4state pass -chapter-7/arrays/associative/methods/size.sv 2state fail -chapter-7/arrays/associative/methods/size.sv 4state fail +chapter-7/arrays/associative/methods/size.sv 2state pass +chapter-7/arrays/associative/methods/size.sv 4state pass chapter-7/arrays/associative/methods/traversal.sv 2state pass chapter-7/arrays/associative/methods/traversal.sv 4state pass -chapter-7/arrays/associative/nonexistent.sv 2state fail -chapter-7/arrays/associative/nonexistent.sv 4state fail +chapter-7/arrays/associative/nonexistent.sv 2state pass +chapter-7/arrays/associative/nonexistent.sv 4state pass chapter-7/arrays/associative/other.sv 2state fail chapter-7/arrays/associative/other.sv 4state fail chapter-7/arrays/associative/string.sv 2state pass @@ -1315,12 +1315,12 @@ chapter-7/arrays/associative/wildcard.sv 2state fail chapter-7/arrays/associative/wildcard.sv 4state fail chapter-7/arrays/dynamic/basic.sv 2state pass chapter-7/arrays/dynamic/basic.sv 4state pass -chapter-7/arrays/dynamic/op-delete.sv 2state fail -chapter-7/arrays/dynamic/op-delete.sv 4state fail +chapter-7/arrays/dynamic/op-delete.sv 2state pass +chapter-7/arrays/dynamic/op-delete.sv 4state pass chapter-7/arrays/dynamic/op-new.sv 2state pass chapter-7/arrays/dynamic/op-new.sv 4state pass -chapter-7/arrays/dynamic/op-size.sv 2state fail -chapter-7/arrays/dynamic/op-size.sv 4state fail +chapter-7/arrays/dynamic/op-size.sv 2state pass +chapter-7/arrays/dynamic/op-size.sv 4state pass chapter-7/arrays/multidimensional/basic.sv 2state pass chapter-7/arrays/multidimensional/basic.sv 4state pass chapter-7/arrays/multidimensional/copy.sv 2state pass @@ -1409,38 +1409,38 @@ chapter-7/memories/read-write.sv 2state pass chapter-7/memories/read-write.sv 4state pass chapter-7/queues/basic.sv 2state pass chapter-7/queues/basic.sv 4state pass -chapter-7/queues/bounded.sv 2state fail -chapter-7/queues/bounded.sv 4state fail -chapter-7/queues/delete.sv 2state fail -chapter-7/queues/delete.sv 4state fail +chapter-7/queues/bounded.sv 2state pass +chapter-7/queues/bounded.sv 4state pass +chapter-7/queues/delete.sv 2state pass +chapter-7/queues/delete.sv 4state pass chapter-7/queues/delete_assign.sv 2state fail chapter-7/queues/delete_assign.sv 4state fail -chapter-7/queues/insert.sv 2state fail -chapter-7/queues/insert.sv 4state fail +chapter-7/queues/insert.sv 2state pass +chapter-7/queues/insert.sv 4state pass chapter-7/queues/insert_assign.sv 2state fail chapter-7/queues/insert_assign.sv 4state fail -chapter-7/queues/max-size.sv 2state fail -chapter-7/queues/max-size.sv 4state fail +chapter-7/queues/max-size.sv 2state pass +chapter-7/queues/max-size.sv 4state pass chapter-7/queues/persistence.sv 2state fail chapter-7/queues/persistence.sv 4state fail -chapter-7/queues/pop_back.sv 2state fail -chapter-7/queues/pop_back.sv 4state fail +chapter-7/queues/pop_back.sv 2state pass +chapter-7/queues/pop_back.sv 4state pass chapter-7/queues/pop_back_assing.sv 2state fail chapter-7/queues/pop_back_assing.sv 4state fail -chapter-7/queues/pop_front.sv 2state fail -chapter-7/queues/pop_front.sv 4state fail +chapter-7/queues/pop_front.sv 2state pass +chapter-7/queues/pop_front.sv 4state pass chapter-7/queues/pop_front_assign.sv 2state fail chapter-7/queues/pop_front_assign.sv 4state fail -chapter-7/queues/push_back.sv 2state fail -chapter-7/queues/push_back.sv 4state fail +chapter-7/queues/push_back.sv 2state pass +chapter-7/queues/push_back.sv 4state pass chapter-7/queues/push_back_assign.sv 2state fail chapter-7/queues/push_back_assign.sv 4state fail -chapter-7/queues/push_front.sv 2state fail -chapter-7/queues/push_front.sv 4state fail +chapter-7/queues/push_front.sv 2state pass +chapter-7/queues/push_front.sv 4state pass chapter-7/queues/push_front_assign.sv 2state fail chapter-7/queues/push_front_assign.sv 4state fail -chapter-7/queues/size.sv 2state fail -chapter-7/queues/size.sv 4state fail +chapter-7/queues/size.sv 2state pass +chapter-7/queues/size.sv 4state pass chapter-7/queues/slice.sv 2state fail chapter-7/queues/slice.sv 4state fail chapter-7/structures/packed/basic.sv 2state pass diff --git a/crates/celox-sv-analyzer/src/ast/containers.rs b/crates/celox-sv-analyzer/src/ast/containers.rs index f30930ee12f..e8acce08883 100644 --- a/crates/celox-sv-analyzer/src/ast/containers.rs +++ b/crates/celox-sv-analyzer/src/ast/containers.rs @@ -399,15 +399,21 @@ pub(super) fn value( ], ))) } - ExprKind::Call { - expression, - arguments, - } => { + ExprKind::Call { .. } | ExprKind::Member { .. } => { + // No-argument built-in methods also permit the bare member form, + // e.g. q.size, q.pop_front and map.delete (clauses 7.9 and 7.10). + let (expression, arguments) = match &native.expression(id).kind { + ExprKind::Call { + expression, + arguments, + } => (*expression, arguments.as_slice()), + _ => (id, &[][..]), + }; let ExprKind::Member { expression: base, separator, name, - } = &native.expression(*expression).kind + } = &native.expression(expression).kind else { return Ok(None); }; @@ -476,6 +482,12 @@ pub(super) fn value( name.spelling ))); } + if dims.type_query + && matches!(op, ContainerOp::PopFront | ContainerOp::PopBack) + && target.layout.handle.is_some() + { + return Err(unsupported("type queries on nonintegral queue pop results")); + } let mut args = vec![expression_binding::value(*base, native, tree, dims)?]; for (index, arg) in arguments.iter().enumerate() { let id = arg.value.unwrap(); @@ -727,3 +739,41 @@ mod tests { Source::from_syntax(&tree).unwrap(); } } + +#[cfg(test)] +mod method_call_tests { + use super::*; + + #[test] + fn bare_methods_keep_argument_and_void_result_checks() { + for statement in [ + "q.push_back;", + "q.push_front;", + "q.insert;", + "map.exists;", + "map.first;", + "map.last;", + "map.next;", + "map.prev;", + "value = q.delete;", + "value = a.delete;", + "value = map.delete;", + "value = q.num;", + "value = $bits(strings.pop_front);", + "value = $dimensions(strings.pop_back());", + "value = $bits(objects.pop_front());", + "value = $dimensions(objects.pop_back);", + ] { + let source = format!( + "module Top; int q[$], a[], map[int], value; string strings[$]; + class Cell; int n; endclass Cell objects[$]; + initial begin {statement} end endmodule" + ); + let result = crate::analyze_source(&source, Path::new("bare-container-method.sv")); + assert!( + matches!(result, Err(AnalyzerError::Unsupported(_))), + "{statement}: {result:?}" + ); + } + } +} diff --git a/crates/celox-sv-analyzer/src/ast/dimensions/query_binding.rs b/crates/celox-sv-analyzer/src/ast/dimensions/query_binding.rs index 353055ff483..8a314d56c71 100644 --- a/crates/celox-sv-analyzer/src/ast/dimensions/query_binding.rs +++ b/crates/celox-sv-analyzer/src/ast/dimensions/query_binding.rs @@ -690,6 +690,29 @@ pub(in crate::ast) fn shape( while let Some(job) = jobs.pop() { match job { Job::Enter(id) => { + let callee = match native.expression(id).kind { + ExprKind::Call { expression, .. } => expression, + _ => id, + }; + if let ExprKind::Member { + expression, name, .. + } = &native.expression(callee).kind + && let Some(container) = containers::native_type(*expression, native, context) + { + // Validate the call without executing it. Pop returns the + // declared element type, including packed dimensions and + // authored bounds, rather than a flattened bit vector. + let value = expression_binding::bind(id, tree, context)?; + let shape = if matches!(name.spelling.as_str(), "pop_front" | "pop_back") { + procedural::dimensions_from_type(&container.element) + } else { + let ty = bound_bits_type(&tree.state, &value, context) + .ok_or_else(|| unsupported("container method result type"))?; + scalar(ty.width, ty.signed, ty.width > 1) + }; + values.push(shape); + continue; + } if let Some((name, dimensions)) = type_binding::argument_alias(id, native) && dimensions.is_empty() { diff --git a/crates/celox-sv-analyzer/src/ast/procedural.rs b/crates/celox-sv-analyzer/src/ast/procedural.rs index 594ed4bed04..ebd7f92adcb 100644 --- a/crates/celox-sv-analyzer/src/ast/procedural.rs +++ b/crates/celox-sv-analyzer/src/ast/procedural.rs @@ -1236,6 +1236,13 @@ impl<'s, 't, 'a> BodyBuilder<'s, 't, 'a> { { let query_root = expression_binding::call_statement_root(root, discarded, self.tree.declarations())?; + if discarded + && let Some(mut value) = + containers::value(query_root, native, self.tree, &self.dims, true)? + { + self.rename_expr(&mut value); + return Ok(vec![Stmt::Eval(value)]); + } if let Some(call) = self.method_call_statement(query_root)? { return Ok(vec![call]); } diff --git a/crates/celox-test-suite/src/sv/cases/containers.vtest b/crates/celox-test-suite/src/sv/cases/containers.vtest index ef81766ee8d..5a1010c002f 100644 --- a/crates/celox-test-suite/src/sv/cases/containers.vtest +++ b/crates/celox-test-suite/src/sv/cases/containers.vtest @@ -386,3 +386,98 @@ module Top(output bit [2:0] flags); endmodule "#) (top Top) (run_until 0) (assert_eq flags 7)) + +(case optional_parentheses + (source "optional_parentheses.sv" #" +module Top(output bit [14:0] flags); + int a[], q[$], numbers[int], words[string], value; + string strings[$], text; + class Cell; int n; endclass + Cell objects[$], original, popped; + initial begin + flags[0] = a.size == 0 && q.size == 0 && numbers.num == 0 && words.size == 0; + a = new[3]; + flags[1] = a.size == 3 && a.size() == a.size; + a.delete; + flags[2] = a.size == 0; + q = {2, 3, 4}; value = q.pop_front; + flags[3] = value == 2 && q.size == 2 && q[0] == 3; + value = q.pop_back; + flags[4] = value == 4 && q.size == 1; + q.pop_front; + flags[5] = q.size == 0; + q = {5, 6}; void'(q.pop_front); void'(q.pop_back()); + flags[6] = q.size == 0; + q = {1, 2}; q.push_back(q.pop_front); + flags[7] = q.size == 2 && q[0] == 2 && q[1] == 1; + q.delete; + flags[8] = q.size == 0; + numbers[-1] = 10; numbers[5] = 20; + flags[9] = numbers.size == 2 && numbers.num == 2; + words["first"] = 10; words["second"] = 20; words.delete("first"); + flags[10] = words.size == 1 && words.num == 1 && words["second"] == 20; + numbers.delete; words.delete; q.size; + flags[11] = numbers.num == 0 && words.size == 0; + strings = {"first", "last"}; text = strings.pop_front; + flags[12] = text == "first" && strings.size == 1; + text = strings.pop_back; + flags[13] = text == "last" && strings.size == 0; + original = new; original.n = 9; objects.push_back(original); popped = objects.pop_front; + flags[14] = popped == original && popped.n == 9 && objects.size == 0; + end +endmodule +"#) + (top Top) (run_until 0) (assert_eq flags 32767)) + +(case optional_parentheses_queries + (source "optional_parentheses.sv" #" +module Top(output bit [3:0] flags); + logic [3:0] q[$]; + int a[], map[int]; + initial begin + q = {4'h5, 4'h6}; + flags[0] = $bits(q.pop_front) == 4 && $size(q.pop_back) == 4 && q.size == 2; + flags[1] = $bits(a.size) == 32 && $bits(map.num) == 32; + flags[2] = $dimensions(q.pop_front) == 1 && $unpacked_dimensions(q.pop_back) == 0 && q.size == 2; + flags[3] = q.pop_back == 6 && q.pop_front == 5 && q.size == 0; + end +endmodule +"#) + (top Top) (run_until 0) (assert_eq flags 15)) + +(case optional_parentheses_four_state + (source "optional_parentheses.sv" #" +module Top(output bit [3:0] flags); + logic [3:0] q[$], value; + initial begin + q = {4'b1xz0, 4'bz01x}; + value = q.pop_front; + flags[0] = value === 4'b1xz0 && q.size == 1; + value = q.pop_back; + flags[1] = value === 4'bz01x && q.size == 0; + value = q.pop_front; + flags[2] = value === 4'bxxxx && q.size == 0; + q = {4'bxzxz}; void'(q.pop_back); + flags[3] = q.size == 0; + end +endmodule +"#) + (four_state) + (top Top) (run_until 0) (assert_eq flags 15)) + +(case optional_parentheses_packed_result + (source "optional_parentheses.sv" #" +module Top(output bit [4:0] flags); + logic [2:1][7:4] q[$]; + initial begin + q = {8'h12, 8'h34}; + flags[0] = $bits(q.pop_front) == 8 && $bits(q.pop_back()) == 8; + flags[1] = $dimensions(q.pop_front) == 2 && $dimensions(q.pop_back()) == 2; + flags[2] = $size(q.pop_front, 1) == 2 && $size(q.pop_back(), 2) == 4; + flags[3] = $left(q.pop_front, 1) == 2 && $right(q.pop_back(), 1) == 1 + && $left(q.pop_front(), 2) == 7 && $right(q.pop_back, 2) == 4; + flags[4] = q.size == 2 && q.pop_back == 8'h34 && q.pop_front == 8'h12 && q.size == 0; + end +endmodule +"#) + (top Top) (run_until 0) (assert_eq flags 31)) diff --git a/crates/celox/tests/frontends/systemverilog/containers.rs b/crates/celox/tests/frontends/systemverilog/containers.rs index 693181a3894..b00caad9ff0 100644 --- a/crates/celox/tests/frontends/systemverilog/containers.rs +++ b/crates/celox/tests/frontends/systemverilog/containers.rs @@ -1,6 +1,10 @@ use super::*; sv_backends! { + fn optional_parentheses_packed_result(sim) { @case "containers::optional_parentheses_packed_result"; } + fn optional_parentheses(sim) { @case "containers::optional_parentheses"; } + fn optional_parentheses_queries(sim) { @case "containers::optional_parentheses_queries"; } + fn optional_parentheses_four_state(sim) { @case "containers::optional_parentheses_four_state"; } fn queue_argument_side_effects(sim) { @case "containers::queue_argument_side_effects"; } fn queue_argument_four_state(sim) { @case "containers::queue_argument_four_state"; } fn string_associative_foreach(sim) { @case "containers::string_associative_foreach"; } diff --git a/docs/guide/systemverilog-reference.md b/docs/guide/systemverilog-reference.md index ea7c9387bfb..7eefdc84c57 100644 --- a/docs/guide/systemverilog-reference.md +++ b/docs/guide/systemverilog-reference.md @@ -356,11 +356,19 @@ VCD output and the TypeScript API. 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`, with parentheses. Queue indices may use `$` and `$+1`. +`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. +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 +their parenthesized forms. A bare `delete` clears the container. Queue pop +results may be discarded with `void'(...)`; type queries such as +`$bits(q.pop_front)` inspect the result without removing an element. +Integral pop result queries preserve the element's packed dimensions and +declared bounds. Queries on string- or class-valued pop results remain unsupported. + Elements may be packed integral values up to 64 bits, strings or class handles. Positional assignment patterns and element concatenations construct sequences; assignments between dynamic arrays and queues copy values and