Repository navigation
fix(sv): keep task arguments read before a suspending call - #2089
Conversation
Closes #2071 Change-Id: I74cd699fd95a0ea315260ab27817672e3135690b
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Queued — the merge queue status continues in this comment ↓. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e37230af7f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| *expr = if self.m.calls(expr) { | ||
| self.hoist(expr)? |
There was a problem hiding this comment.
Capture the complete argument after hoisting its calls
When an argument contains a call, hoist only captures the call results; it leaves surrounding variable reads unevaluated. Moving all hoisting before the evaluation loop therefore lets later arguments change the value of an earlier argument. For example, with i = 3, a function f() returning zero, and a function g() setting i = 7, $display("%0d %0d", i + f(), g()) now evaluates the first argument using i == 7, whereas the previous implementation captured it before executing g(). Capture the complete hoisted expression in a temporary at this point, before processing subsequent arguments, to preserve the intended left-to-right argument evaluation.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed and fixed in 2051911. Every argument before the last one with a call is now evaluated whole into a temporary at its place: its calls are hoisted first, and then keep_argument evaluates the hoisted expression. That last argument only has its calls run before its own reads, as any expression does. Arguments after it are read as before.
New test ordered_arguments_{interpreter,compiled,native} (sv_plusargs.rs), on your example plus a host request: with i = 3, f() returning 0 and g() setting i = 7 and returning 5, $display("%0d %0d %0d %0d", i + f(), $test$plusargs("verbose"), g(), i) prints 3 1 5 7. Icarus prints the same. Verilator 5.052 prints 7 5 7 for the variant without the host request, because it runs the calls before reading i. The test fails on the previous head with 7 1 5 7.
cargo nextest run -p celox -p celox-frontend-sv with CI's features: 14755 passed. sv-tests conformance (official runner, pinned revision, both modes) is unchanged against expected.tsv.
Hoisting an argument's calls left its other reads for later, so a later argument's call could change them: $display("%0d %0d", i + f(), g()) with g() writing i printed the new i.
Change-Id: I21d256f4b87659330d009ec7cba06314ac2ff1d8
Merge Queue Status
This pull request spent 45 minutes 14 seconds in the queue, including 43 minutes 36 seconds running CI. Required conditions to merge
|
Closes #2071.
Summary
A system task such as
$displayevaluated its arguments one by one. A plain argument became a register, and a later argument's call (a plusargs query, file I/O, a distribution) was hoisted after it. When that call is a host request, the process suspends and resumes in a block entered from the kernel dispatch. The earlier register is used after the resume, where its definition does not dominate:Arguments are still evaluated left to right, which
veryl_assert_continue_ff_captures_arguments_before_reportingrelies on. Every argument up to the last one that contains a call is now handled in order:keep_argument) at its place in the order. Memory survives the suspension, and the temporary keeps the argument's signedness, real precision and string-handle kind.Literals and the arguments after the last call are read as before, so a task without calls in its arguments lowers exactly as before.
Tests
display_of_plusargs_{interpreter,compiled,native}(sv_plusargs.rs):$display("%0d %0d %0d %0d", i, $test$plusargs("verbose"), $value$plusargs("v=%d", v), v)prints3 1 1 7. All three fail on master with the issue's error.cargo nextest run -p celox -p celox-frontend-svwith CI's features: 14752 passed. A first version that hoisted all calls before any read broke the argument-order test above, and this version keeps the order.--state-mode both) matchesexpected.tsvwith no changes (1064/1650 two-state, 1075/1650 four-state).