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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions conformance/sv-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
64 changes: 32 additions & 32 deletions conformance/sv-tests/expected.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
60 changes: 55 additions & 5 deletions crates/celox-sv-analyzer/src/ast/containers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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:?}"
);
}
}
}
23 changes: 23 additions & 0 deletions crates/celox-sv-analyzer/src/ast/dimensions/query_binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
7 changes: 7 additions & 0 deletions crates/celox-sv-analyzer/src/ast/procedural.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down
95 changes: 95 additions & 0 deletions crates/celox-test-suite/src/sv/cases/containers.vtest
Original file line number Diff line number Diff line change
Expand Up @@ -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))
4 changes: 4 additions & 0 deletions crates/celox/tests/frontends/systemverilog/containers.rs
Original file line number Diff line number Diff line change
@@ -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"; }
Expand Down
Loading
Loading