Skip to content
Closed
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
65 changes: 65 additions & 0 deletions crates/celox-frontend-sv/src/lowering/ff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7244,6 +7244,11 @@ impl Ff<'_, '_> {
}) {
return Err(unsupported("wait condition reading a static task argument"));
}
// A write of a class property does not wake a waiting process yet, so
// a condition that reads one would never be checked again.
if let Some(op) = heap_read(self.m, condition) {
return Err(unsupported(format!("{op} in a wait condition")));
}
let mut ids: Vec<_> = names
.iter()
.filter_map(|name| self.m.id(name))
Expand Down Expand Up @@ -7471,6 +7476,66 @@ fn subroutine_reads(pm: &ProcModule<'_>, expr: &sv::ir::Expr, names: &mut HashSe
}
}

/// The name of an operation in `expr` that reads the class object heap,
/// directly or through the functions it calls: a class property, or the
/// random mode of one. Container contents are values of their handles. The
/// default of an argument counts only where a call omits the argument.
fn heap_read(pm: &ProcModule<'_>, expr: &sv::ir::Expr) -> Option<String> {
let mut pending = vec![expr.clone()];
let mut calls = Vec::new();
let mut visited = HashSet::default();
let mut defaults = HashSet::default();
loop {
while let Some(expr) = pending.pop() {
let found = std::cell::RefCell::new(None);
expr_calls(&expr, &|callee| {
if let sv::ir::Callee::Object(op) = callee
&& matches!(
**op,
sv::ir::ObjectOp::Load(_)
| sv::ir::ObjectOp::ModeGet(..)
| sv::ir::ObjectOp::ConstraintModeGet(_)
)
{
found.borrow_mut().get_or_insert(op.to_string());
}
false
});
if let Some(op) = found.into_inner() {
return Some(op);
}
collect_calls(&expr, &mut calls);
}
let (callee, args) = calls.pop()?;
let sv::ir::Callee::Subroutine(name) = callee else {
continue;
};
let Some(subroutine) = pm.subroutine(&name) else {
continue;
};
for (position, param) in subroutine.params.iter().enumerate() {
if matches!(args.get(position), None | Some(None))
&& let Some(default) = &param.default
&& defaults.insert((name.clone(), position))
{
pending.push(default.clone());
}
}
if !visited.insert(name) {
continue;
}
for stmt in &subroutine.body {
let mut stmt = stmt.clone();
stmt.walk(&mut |stmt| stmt_calls(stmt, &mut calls));
stmt.visit_mut(
&mut |expr| pending.push(expr.clone()),
&mut |_| {},
&mut |_| {},
);
}
}
}

/// The name of a call in `expr` that has an effect or reads the state of the
/// simulation, directly or through the functions it calls: an event
/// expression must be a value of the variables it reads.
Expand Down
1 change: 1 addition & 0 deletions crates/celox-test-suite/LIMITATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,7 @@ four-state expectations; the assertions remain enabled on all Celox variants.
| `sv_verilator_program_exit` | execute | verilator | 1 | Verilator 5.052 continues after `$exit` and keeps the program's other `initial` procedures (24.7). Icarus does not run the case; xezim 0.11.3 agrees with the expected output. |
| `sv_verilator_program_items` | compile | verilator | 2 | Verilator 5.052 rejects an `always` procedure and a module instance in a program with syntax errors, which the run cannot count as language rejections. Both are illegal (IEEE 1800-2023 24.3); Icarus 13.0 rejects them with diagnostics that name the rule. |
| `sv_icarus_iff_event_controls` | compile | icarus | 15 | Icarus 13.0 rejects `iff` in an event control with "syntax error" and "Malformed event control expression." IEEE 1800-2023 9.4.2.3 and A.6.5 permit `@(posedge clk iff en)`; [Standalone probe](verification/repros/sv_iff_event_controls_icarus.json); Verilator 5.052 runs the cases and gives the asserted counts. |
| `sv_icarus_static_property_wait` | execute | icarus | 1 | Icarus 13.0 compiles a `wait` on a static class property in a class task but vvp cannot load the result ("unresolved vvp_net reference", "Program not runnable"); IEEE 1800-2023 8.9 and 9.4.3 make the property one variable that the wait watches. [Standalone probe](verification/repros/sv_static_property_wait_icarus.json); Verilator 5.052 and xezim 0.11.3 pass the case. |
| `sv_verilator_iff_late_conditions` | execute | verilator | 4 | Verilator 5.052 judges an `iff` condition after the process that writes the event signal suspends, not at the write: with `clk = 1; en = 0;` from en = 1 it counts no event, with nonblocking updates `clk <= 1; en <= 0;` from en = 1 it counts none either, and an always_comb that writes `en = a; clk = a; en = 0;` gives no event of its `clk` write while `en` is 1. IEEE 1800-2023 9.4.2.3 judges the condition when the event occurs, and 10.4.2 applies nonblocking updates in issue order, so all three are events. [Standalone probes](verification/repros/sv_iff_late_conditions_verilator.json) print n=0, n=1 and n=0 in Verilator where the spec gives 1, 2 and 1; Icarus 13.0 rejects `iff` in event controls. |

The [system-function edge-case evidence](verification/repros/system_function_edge_cases.json)
Expand Down
25 changes: 25 additions & 0 deletions crates/celox-test-suite/src/sv/cases/class.vtest
Original file line number Diff line number Diff line change
Expand Up @@ -2806,3 +2806,28 @@ module Top(output int a, output int b);
endmodule
"#)
(top Top) (run_until 0) (assert_eq a 8) (assert_eq b 8))

(case waits_on_static_properties
; A static property is a variable of the declaring scope, so a wait in a
; method wakes when another process writes it (IEEE 1800-2023 8.9, 9.4.3).
(source "class.sv" #"
class C;
static int s_state;
task wait_for(int s);
wait (s_state >= s);
$display("reached %0d at %0d", s, $time);
endtask
endclass
module Top;
C c;
initial begin
c = new;
fork
c.wait_for(2);
begin #1 c.s_state = 1; #1 c.s_state = 2; end
join
end
endmodule
"#)
(top Top) (run_until 5)
(expect_output "reached 2 at 2\n"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"tool": "icarus",
"version": "Icarus Verilog version 13.0 (stable) (v13_0)",
"source": "sv_static_property_wait_icarus.sv",
"standard": "IEEE 1800-2023 8.9, 9.4.3",
"command": "iverilog -g2012 -s Top -o sp.vvp sv_static_property_wait_icarus.sv && vvp sp.vvp",
"expected_output": "reached 2 at 2",
"observations": [
{
"build_exit_code": 0,
"exit_code": 2,
"output": "unresolved vvp_net reference: v0x5555558f2f70_0\nunresolved vvp_net reference: v0x5555558f3050_0\ncompile_cleanup: 2 unresolved items\nsp.vvp: Program not runnable, 2 errors.\n"
}
],
"note": "A task of a class waits on a static property of the class, which another process writes through a handle. Icarus 13.0 compiles the design but vvp cannot load it (unresolved nets). Verilator 5.052, xezim 0.11.3 and Celox print reached 2 at 2."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class C;
static int s_state;
task wait_for(int s);
wait (s_state >= s);
$display("reached %0d at %0d", s, $time);
endtask
endclass
module Top;
C c;
initial begin
c = new;
fork
c.wait_for(2);
begin #1 c.s_state = 1; #1 c.s_state = 2; end
join
end
endmodule
23 changes: 23 additions & 0 deletions crates/celox-test-suite/verification/sv/icarus/class.json
Original file line number Diff line number Diff line change
Expand Up @@ -1692,6 +1692,29 @@
"stronger_than_sv": false,
"tag_reasons": {},
"tags": []
},
{
"category": "Types",
"detail": "Icarus 13.0 compiles a `wait` on a static class property in a class task but vvp cannot load the result (\"unresolved vvp_net reference\", \"Program not runnable\"). IEEE 1800-2023 8.9 and 9.4.3 make the property one variable that the wait watches. Verilator 5.052 and xezim 0.11.3 pass the case.",
"expectation": "Simulation",
"known_issue": {
"id": "sv_icarus_static_property_wait",
"category": "simulator_runtime_limitation",
"phase": "execute",
"observed_version": "Icarus Verilog version 13.0 (stable) (v13_0)",
"reason": "Icarus 13.0 compiles a `wait` on a static class property in a class task but vvp cannot load the result (\"unresolved vvp_net reference\", \"Program not runnable\"). IEEE 1800-2023 8.9 and 9.4.3 make the property one variable that the wait watches. Verilator 5.052 and xezim 0.11.3 pass the case.",
"upstream": [],
"evidence": [
"verification/repros/sv_static_property_wait_icarus.json",
"LIMITATIONS.md#systemverilog-suite"
]
},
"name": "class::waits_on_static_properties",
"phase": "skip",
"status": "ignored",
"stronger_than_sv": false,
"tag_reasons": {},
"tags": []
}
]
}
17 changes: 17 additions & 0 deletions crates/celox-test-suite/verification/sv/limitations.json
Original file line number Diff line number Diff line change
Expand Up @@ -2769,6 +2769,23 @@
]
}
},
{
"id": "sv_icarus_static_property_wait",
"category": "simulator_runtime_limitation",
"phase": "execute",
"observed_version": "Icarus Verilog version 13.0 (stable) (v13_0)",
"reason": "Icarus 13.0 compiles a `wait` on a static class property in a class task but vvp cannot load the result (\"unresolved vvp_net reference\", \"Program not runnable\"). IEEE 1800-2023 8.9 and 9.4.3 make the property one variable that the wait watches. Verilator 5.052 and xezim 0.11.3 pass the case.",
"upstream": [],
"evidence": [
"verification/repros/sv_static_property_wait_icarus.json",
"LIMITATIONS.md#systemverilog-suite"
],
"cases": {
"icarus": [
"class::waits_on_static_properties"
]
}
},
{
"id": "sv_verilator_iff_late_conditions",
"category": "simulator_disagreement",
Expand Down
11 changes: 11 additions & 0 deletions crates/celox-test-suite/verification/sv/verilator/class.json
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,17 @@
"stronger_than_sv": false,
"tag_reasons": {},
"tags": []
},
{
"category": "Types",
"detail": "",
"expectation": "Simulation",
"name": "class::waits_on_static_properties",
"phase": "execute",
"status": "passed",
"stronger_than_sv": false,
"tag_reasons": {},
"tags": []
}
]
}
11 changes: 11 additions & 0 deletions crates/celox-test-suite/verification/sv/xezim/class.json
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,17 @@
"stronger_than_sv": false,
"tag_reasons": {},
"tags": []
},
{
"category": "Types",
"detail": "",
"expectation": "Simulation",
"name": "class::waits_on_static_properties",
"phase": "execute",
"status": "passed",
"stronger_than_sv": false,
"tag_reasons": {},
"tags": []
}
]
}
98 changes: 98 additions & 0 deletions crates/celox/tests/frontends/systemverilog/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ sv_backends! {
fn class_imported_member_type_dimensions(sim) { @case "class::imported_member_type_dimensions"; }
fn class_imported_member_type_inheritance(sim) { @case "class::imported_member_type_inheritance"; }
fn class_package_constant_class_defaults(sim) { @case "class::package_constant_class_defaults"; }
fn class_waits_on_static_properties(sim) { @case "class::waits_on_static_properties"; }
fn class_package_constant_type_arguments(sim) { @case "class::package_constant_type_arguments"; }
fn class_named_aggregate_type_arguments(sim) { @case "class::named_aggregate_type_arguments"; }
fn class_generate_scope_enum_type_arguments(sim) { @case "class::generate_scope_enum_type_arguments"; }
Expand Down Expand Up @@ -211,6 +212,103 @@ sv_backends! {
}
}

/// A write of a class property does not wake a process waiting on it, so a
/// wait whose condition reads one is rejected instead of never waking. The
/// condition reads it in a method through `this`, through a handle, through
/// a queue held in a property and through a function.
#[test]
fn waits_on_class_properties_are_unsupported() {
let waits = [
"wait (m_state >= s);",
"wait (other.m_state >= s);",
"wait (q.size() != 0);",
"wait (reached(s));",
];
for wait in waits {
let source = format!(
"class C;
int m_state;
int q[$];
C other;
function bit reached(int s); return m_state >= s; endfunction
task wait_for(int s); {wait} $display(\"reached %0d at %0d\", s, $time); endtask
endclass
module Top;
initial begin
automatic C c = new;
c.other = c;
fork
c.wait_for(2);
begin #1 c.m_state = 1; #1 c.m_state = 2; c.q.push_back(1); end
join
end
endmodule"
);
for four_state in [false, true] {
let builder = || {
celox::Simulation::from_sv_sources(
vec![(source.as_str(), Path::new("class.sv"))],
"Top",
)
.four_state(four_state)
};
let errors = [
builder().build_native().err(),
builder().build_cranelift().err(),
builder().build_wasm().err(),
builder().build_interpreter().err(),
];
for error in errors {
let error = error
.unwrap_or_else(|| panic!("{wait} must be rejected"))
.to_string();
assert!(error.contains("in a wait condition"), "{wait}: {error}");
}
}
}
}

/// The default of an argument is read only where a call omits the argument,
/// so a property-reading default does not reject a wait that supplies it.
#[test]
fn waits_read_property_defaults_only_when_omitted() {
let source = |call: &str| {
format!(
"`timescale 1ns/1ns
class C; int state; endclass
module Top(output int seen);
C c;
int signal;
function automatic bit ready(int x = c.state); return x != 0; endfunction
initial begin
c = new;
fork
begin wait ({call}); seen = $time; end
begin #2 signal = 1; end
join
end
endmodule"
)
};
let supplied = source("ready(signal)");
let mut sim =
celox::Simulation::from_sv_sources(vec![(supplied.as_str(), Path::new("class.sv"))], "Top")
.build_interpreter()
.unwrap();
sim.run_until(5).unwrap();
let seen = sim.signal("seen");
assert_eq!(sim.get(seen), BigUint::from(2u8));
let omitted = source("ready()");
let Err(error) =
celox::Simulation::from_sv_sources(vec![(omitted.as_str(), Path::new("class.sv"))], "Top")
.build_interpreter()
else {
panic!("a wait reading a property through a default is rejected");
};
let error = error.to_string();
assert!(error.contains("in a wait condition"), "{error}");
}

#[test]
fn randomizing_four_state_properties_is_rejected() {
for (body, want) in [
Expand Down
8 changes: 6 additions & 2 deletions docs/guide/systemverilog-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,12 @@ constructs without a dedicated issue point to the frontend roadmap, [#88](https:
- Behavioral and verification constructs: intra-assignment timing controls (`a = #1 b`),
delayed continuous assignments ([#444](https://github.com/celox-sim/celox/issues/444)),
named events and `->`, `wait fork` / `disable fork`, temporal concurrent assertions beyond the Boolean subset below, `force` / `release`.
- Timing controls in processes: impure function calls in event expressions, and
`wait` or event expressions reading a static task argument.
- Timing controls in processes: impure function calls in event expressions,
`wait` or event expressions reading a static task argument, and `wait`
conditions or event expressions reading a class property (directly, through
a handle or a function, or a container held in one), since a write of the
property does not wake the waiting process. Static class properties are
module variables and may be waited on.
- Nonblocking assignments inside `always_latch` ([#431](https://github.com/celox-sim/celox/issues/431)); use blocking assignments for the supported latch subset.
- Inferred latches inside `always_comb` are rejected by default. Set `inferred_latch = "warn"` or `"allow"` in `celox.toml` under `[diagnostics]` to permit retained blocking assignments. Ordinary `always @*` and explicit `always_latch` do not require this option.
- Ports and instances: non-ANSI port expressions such as `module m({a, b}, c[3:0], .p(d))` ([#1953](https://github.com/celox-sim/celox/issues/1953)), `ref` ports
Expand Down
4 changes: 3 additions & 1 deletion docs/ja/guide/systemverilog-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,9 @@ SystemVerilog に対しても、共有の Veryl 適合性スイートを実行
- 振る舞い記述・検証向けの構文:`final`、代入内のタイミング制御(`a = #1 b`)、遅延付き継続代入([#444](https://github.com/celox-sim/celox/issues/444))、
named event と `->`、`fork` / `join`、`wait fork` / `disable fork`、下記のBoolean部分集合を超える並行アサーション、`force` / `release`。
- プロセス内のタイミング制御:イベント式と `iff` 条件内の impure な関数呼び出し、
static task 引数を読む `wait` 条件、イベント式、`iff` 条件。
static task 引数を読む `wait` 条件、イベント式、`iff` 条件。クラスのプロパティを(直接、ハンドルや関数を通じて、
またはプロパティが持つコンテナとして)読む `wait` 条件とイベント式。プロパティへの書き込みで待機中のプロセスが
起きないためです。static プロパティはモジュールの変数なので待機できます。
- `always_latch` 内のノンブロッキング代入([#431](https://github.com/celox-sim/celox/issues/431))。対応するラッチではブロッキング代入を使用してください。
- `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))、
Expand Down
Loading