The clocking wave: eight buckets in one round, 43 -> 11 on opentitan
Clocking signal bindings (the one production the modelled node was missing), default disable iff captured verbatim with six rejection pairs, iff on event-control terms, indexed bare event names (chain-charged), gate drive strengths (the mop-up's amortized skip), program blocks as modules with a different closer, and macros as a concurrent assertion's whole action — where QA caught a real regression (a macro BEGINNING a statement, four UVM-idiom shapes) and the rework moved the decision to the token after the call: at_statement_tail, one line, with the failure asymmetry argued in the doc and attacked by QA against the diff rather than trusted. Chain limit 256 -> 1024 on measured need (567 links in pinmux_reg_top) with PARSE_STACK_SIZE 16 -> 32 MiB restoring the 3.3x margin, a sabotage probe proving it real, and parse_sens_list's uncharged chain loop closed. Whole-tree superset: exactly one output move, ~55 lines of prim_sync_reqack generate code freed from an assertion's opaque bytes. Corpus 860 files byte-identical, 813/820. The 11 remaining: macro fragments (preprocessing decision), vendor non-SV (exclude patterns recommended), three written-up skips. Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
5ad0772475
commit
bc533c6cb1
14 files changed
+2081
-85
No files matched your search
@@ -18,7 +18,7 @@ the parser's limit and needs no counter of its own.
|
||||
## The invariant
|
||||
|
||||
> **No input can make AST depth exceed `MAX_NESTING_DEPTH + MAX_CHAIN_LENGTH`
|
||||
> (64 + 256 = 320 layers) on any root-to-leaf path**, so every recursive walk
|
||||
> (64 + 1024 = 1088 layers) on any root-to-leaf path**, so every recursive walk
|
||||
> over the tree — the formatter's, the `Doc` tree's, and the implicit
|
||||
> recursive `Drop` — is bounded too.
|
||||
|
||||
@@ -29,7 +29,7 @@ finishes:
|
||||
| | counter | limit | charged by |
|
||||
|---|---|---|---|
|
||||
| **Nesting** — one parser recursion per layer | `depth` | `MAX_NESTING_DEPTH` = 64 | the 5 gated `parse_*` functions |
|
||||
| **Chains** — a loop that wraps what it already built | `links` | `MAX_CHAIN_LENGTH` = 256 | postfix segments, binary/`inside` operator chains |
|
||||
| **Chains** — a loop that wraps what it already built | `links` | `MAX_CHAIN_LENGTH` = 1024 | postfix segments, binary/`inside` operator chains, a bare event control's path |
|
||||
|
||||
The chain counter exists because a loop can deepen the AST without deepening
|
||||
the parser: `a.b.b.b…` costs `parse_postfix` a single frame but builds one
|
||||
@@ -39,8 +39,8 @@ landed (QA finding, 2026-08-19).
|
||||
|
||||
Because both counters accumulate along a path rather than per construct,
|
||||
nesting and chains cannot multiply: a chain inside another chain's operand
|
||||
stacks on top of it, so `f(a.b…)(a.b…)…` is bounded by the same 320 layers,
|
||||
not by 64 × 256.
|
||||
stacks on top of it, so `f(a.b…)(a.b…)…` is bounded by the same 1088 layers,
|
||||
not by 64 × 1024.
|
||||
|
||||
## Assumptions
|
||||
|
||||
@@ -86,8 +86,8 @@ not by 64 × 256.
|
||||
|
||||
```
|
||||
MAX_NESTING_DEPTH = 64 (crates/vlog_parser/src/parser.rs)
|
||||
MAX_CHAIN_LENGTH = 256
|
||||
PARSE_STACK_SIZE = 16 MiB
|
||||
MAX_CHAIN_LENGTH = 1024 (was 256 until 2026-08-29)
|
||||
PARSE_STACK_SIZE = 32 MiB (was 16 MiB until 2026-08-29)
|
||||
```
|
||||
|
||||
The first two bound the input. The third bounds nothing — it is what the
|
||||
@@ -100,7 +100,7 @@ Going one past either limit produces an ordinary parse error:
|
||||
|
||||
```
|
||||
error: rtl/deep.sv: parse error: 32:5: nesting too deep (limit 64) (found "clk")
|
||||
error: rtl/chain.sv: parse error: 2:525: expression chain too long (limit 256) (found ".")
|
||||
error: rtl/chain.sv: parse error: 2:525: expression chain too long (limit 1024) (found ".")
|
||||
```
|
||||
|
||||
### Why 64 — measured, not guessed
|
||||
@@ -165,7 +165,7 @@ costs three more levels (the statement plus `parse_ternary`/`parse_unary` for
|
||||
its expression). The parser's own boundary unit tests use the empty-block
|
||||
construction (62/63); `vlog_formatter`'s use the ones with content.
|
||||
|
||||
### Why 256 for chains
|
||||
### Why 256 for chains — superseded 2026-08-29, see "Why 1024" below
|
||||
|
||||
Same method, measuring inputs sized to sit exactly *at* the limits so the
|
||||
formatter really walks them (min surviving thread stack, debug / release):
|
||||
@@ -190,7 +190,67 @@ fits). Charging chain links against `MAX_NESTING_DEPTH` instead would have
|
||||
capped those at ~60 terms and rejected real code; that is why chains get
|
||||
their own, larger budget rather than sharing the nesting one.
|
||||
|
||||
### The stack the limit needs — re-measured 2026-08-28
|
||||
### Why 1024 for chains — 2026-08-29
|
||||
|
||||
**256 was not enough for real code.** OpenTitan's generated register files
|
||||
build one `|` chain per register file, `(addr_hit[N] & (|(PERMIT[N] &
|
||||
~reg_be))) | …`, so the chain length tracks the register count. A high-water
|
||||
probe over all 3,943 files (a scratchpad copy with the limit raised out of the
|
||||
way and `links` recorded; never built inside the repo) says what they need:
|
||||
|
||||
| file | links |
|
||||
|---|---|
|
||||
| `top_earlgrey/ip_autogen/pinmux/rtl/pinmux_reg_top.sv` | **567** |
|
||||
| `top_englishbreakfast/…/pinmux_reg_top.sv` | 519 |
|
||||
| `top_darjeeling/…/pinmux_reg_top.sv` | 502 |
|
||||
| `top_darjeeling/…/alert_handler_reg_top.sv` | 397 |
|
||||
| `top_earlgrey/…/alert_handler_reg_top.sv` | 353 |
|
||||
| `rv_dm/rtl/rv_dm_mem_reg_top.sv` | 280 |
|
||||
| `top_darjeeling/…/rv_core_ibex_cfg_reg_top.sv` | 266 |
|
||||
|
||||
3,932 of the 3,943 files stay under 128; five sit in 257–512 and two pass 512.
|
||||
Seven files were rejected outright at 256, which is the acceptance failure this
|
||||
budget exists to avoid.
|
||||
|
||||
**What a link costs, re-measured at the new sizes** (same method: one trial per
|
||||
subprocess, bisect the smallest surviving thread stack, whole `format_source`;
|
||||
rustc 1.97.1):
|
||||
|
||||
| shape | debug | release |
|
||||
|---|---|---|
|
||||
| postfix chain (`a.b…`), 640 links | 5 911 KiB | 375 KiB |
|
||||
| postfix chain, 768 | 7 079 KiB | 455 KiB |
|
||||
| postfix chain, **1024** | **9 430 KiB** | 615 KiB |
|
||||
| postfix chain, 1280 | 11 798 KiB | 775 KiB |
|
||||
| `+` chain / the real `or_chain` shape, 2048 terms | 567 KiB | 183 KiB |
|
||||
| 28 nested `case` + a 1024-link postfix chain inside | **9 894 KiB** | 727 KiB |
|
||||
| 64 nested `case` (trips depth) + a 1024-link chain inside | 5 959 KiB | 775 KiB |
|
||||
|
||||
Per link, from the slope: **9.20 KiB debug**, 0.63 KiB release — consistent
|
||||
with the ~9 KiB the 2026-08-19 round measured at 256. Binary-operator chains,
|
||||
which is what the generated files actually contain, are ~40× cheaper because
|
||||
`binary_chain` flattens the left spine; the *postfix* chain is what the budget
|
||||
has to be safe for.
|
||||
|
||||
**Two things this changes.**
|
||||
|
||||
1. **Chains now set the global worst case.** At 256 a maximal chain peaked at
|
||||
~2.4 MiB against nesting's ~5.9, which is why both earlier rounds could say
|
||||
"the chain budget does not move the worst case". At 1024 it peaks at
|
||||
~9.4 MiB alone and **9 894 KiB** inside nesting, so that sentence is retired:
|
||||
`PARSE_STACK_SIZE` is now measured against the chain.
|
||||
2. **The additive-composition argument is unchanged, and the measurement shows
|
||||
it directly.** 64 nested `case` *with* a 1024-link chain inside bisects to
|
||||
exactly the same byte as without it (5 959 KiB), because tripping the depth
|
||||
limit peaks in the parser while a chain peaks in the formatter. Nothing
|
||||
multiplies.
|
||||
|
||||
**Why 1024 and not 640.** 640 would clear today's largest file by 13 % — a fit,
|
||||
not a margin, on a number that grows with design size, and this limit has now
|
||||
been outgrown once. 1024 is 1.8× the measured maximum and costs 3.5 MiB of
|
||||
debug stack over 640, which the constant below absorbs.
|
||||
|
||||
### The stack the limit needs — re-measured 2026-08-28, and again 2026-08-29
|
||||
|
||||
Same method as above (subprocess per trial, bisect the smallest thread stack
|
||||
that survives), but over the *whole* consumer pipeline this time —
|
||||
@@ -234,17 +294,21 @@ Three things the same sweep settles:
|
||||
its own; it is two orders of magnitude under the walk that produced the
|
||||
tree. Same for the tolerant recovery: strict and tolerant parses of the
|
||||
same limit-tripping input bisect to the same byte.
|
||||
- **Chains still do not move the worst case.** A 256-link chain alone peaks
|
||||
at 2487 KiB debug (~9 KiB per link); the same chain inside 58 nested `case`
|
||||
measures 5895 KiB — identical to that nesting without any chain, because
|
||||
the two peak in different phases. The additive-composition argument above
|
||||
is unchanged.
|
||||
- **16 MiB is the constant, and it is margin rather than a fit.** 8 MiB —
|
||||
what the CLI's pool used and what a stock main thread happens to have —
|
||||
is 1.33× the debug worst case, and the last two years of this number moving
|
||||
(3.9 → 5.9 MiB, no parser change) say that is not enough room. 16 MiB is
|
||||
2.7×, costs address space rather than memory (thread stacks are committed a
|
||||
page at a time), and is the size the feature's tests already spawned.
|
||||
- ~~**Chains still do not move the worst case.**~~ **Retired 2026-08-29.** It
|
||||
was true at `MAX_CHAIN_LENGTH = 256`: a 256-link chain alone peaked at
|
||||
2487 KiB debug (~9 KiB per link), and the same chain inside 58 nested `case`
|
||||
measured 5895 KiB — identical to that nesting without any chain, because the
|
||||
two peak in different phases. At 1024 the chain peaks at ~9.4 MiB and *is*
|
||||
the worst case. The phase argument still holds; only the ranking changed.
|
||||
- ~~**16 MiB is the constant.**~~ **Superseded 2026-08-29 by 32 MiB**, for the
|
||||
same reason 16 replaced 8: the margin, not the fit, is the point. The
|
||||
measured worst case is now **~9.7 MiB debug** (a maximal chain inside
|
||||
nesting, 9 894 KiB) rather than ~5.9; 16 MiB would be 1.65× of that, below
|
||||
the 2.7× this feature settled on for a failure mode that aborts instead of
|
||||
returning. 32 MiB is **3.3×**, costs address space rather than memory (thread
|
||||
stacks are committed a page at a time), and is what the feature's tests now
|
||||
spawn. The full 2026-08-29 measurement is under "Why 1024 for chains" above
|
||||
and in `docs/features/clocking-wave/README.md`.
|
||||
|
||||
## Where the counters sit
|
||||
|
||||
@@ -294,6 +358,7 @@ missed):
|
||||
|---|---|
|
||||
| `parse_postfix` | `a.b`, `a::b`, `a[i]`, `a[m:l]`, `a(args)`, `a'(x)`, `a++`/`a--` — one link per segment |
|
||||
| `parse_binary` | `a + b + c…` (one link per operator, any precedence) and `a inside {…} inside {…}` |
|
||||
| `parse_bare_event_name` | `@a.b.c`, `@a["k"].b` — the `.name` / `[expr]` segments of a paren-less event control's hierarchical path (added 2026-08-29; the `.name` half of this loop existed un-charged before, which was the last instance of the hole below) |
|
||||
|
||||
Not charged at all, and why:
|
||||
|
||||
@@ -357,7 +422,7 @@ not inflate depth — the output of a max-depth file re-parses inside
|
||||
- **Promised to `vlog_formatter`:** AST depth on any path is bounded by
|
||||
`vlog_parser::parser::MAX_NESTING_DEPTH + MAX_CHAIN_LENGTH` (both public,
|
||||
so tests and any future consumer can reference them instead of hard-coding
|
||||
64 and 256). The formatter may keep its recursive walk as long as every
|
||||
64 and 1024). The formatter may keep its recursive walk as long as every
|
||||
path is a structural descent and no public API accepts an externally built
|
||||
AST.
|
||||
- **Requirement on future `vlog_parser` work:** any new loop that wraps the
|
||||
@@ -464,6 +529,34 @@ Round 3 — the stack the limit needs (2026-08-28, from a QA finding on
|
||||
- [x] `cargo test --workspace` (2425), `cargo clippy --all-targets`,
|
||||
`cargo fmt --check` all clean.
|
||||
|
||||
Round 4 — the chain budget real code outgrew (2026-08-29, from the
|
||||
testbench-syntax wave's round 2; see `docs/features/clocking-wave/README.md`):
|
||||
|
||||
- [x] Measured what real code needs before choosing anything: a per-file
|
||||
high-water probe over all 3,943 OpenTitan files. Longest chain **567**
|
||||
(`pinmux_reg_top.sv`); seven files were rejected at 256.
|
||||
- [x] Re-measured the per-link stack cost across four lengths so the slope is
|
||||
measured rather than assumed: **9.20 KiB per postfix link** in a debug
|
||||
build, 0.63 KiB in release.
|
||||
- [x] `MAX_CHAIN_LENGTH` 256 → **1024** (1.8× the measured maximum), and the
|
||||
invariant restated: 64 + 1024 = **1088 layers**.
|
||||
- [x] `PARSE_STACK_SIZE` 16 → **32 MiB**, from the re-measured worst case
|
||||
(**9 894 KiB** debug: a maximal chain inside statement nesting) at the
|
||||
same 2.7×-or-better margin the 2026-08-28 round argued for.
|
||||
- [x] The "chains do not move the worst case" claim retired with the
|
||||
measurement that retires it; the phase argument that makes the two
|
||||
counters additive re-verified at the new size (64 nested `case` with and
|
||||
without a 1024-link chain bisect to the same byte).
|
||||
- [x] The last un-charged chain loop found and closed:
|
||||
`parse_sens_list`'s paren-less `@a.b.c` path boxed a layer per `.name`
|
||||
without charging `link()`. Now `parse_bare_event_name`, charging both
|
||||
segment kinds and restoring the count it started from, with a test.
|
||||
- [x] `deep_nesting.rs` gained the combined worst case
|
||||
(`a_maximal_chain_inside_deep_nesting_formats`), and its past-the-limit
|
||||
case now spells `MAX_CHAIN_LENGTH + 1` instead of a hard-coded 1500.
|
||||
- [x] `MAX_NESTING_DEPTH` left at 64: nothing in this round changes which
|
||||
nesting a file may use.
|
||||
|
||||
## Work log
|
||||
|
||||
### 2026-08-19 — dev agent
|
||||
@@ -696,6 +789,48 @@ two pre-existing helpers re-pointed at the constant). `cargo clippy
|
||||
`crates/vlog_semantic/tests/deep_nesting.rs` (new),
|
||||
`docs/features/parallel-files/README.md`, `TODO.md`, this README.
|
||||
|
||||
### 2026-08-29 — dev, the chain budget real code outgrew
|
||||
|
||||
Written as part of the testbench wave's round 2; the full narrative, the
|
||||
whole-tree distribution and the probe method are in
|
||||
`docs/features/clocking-wave/README.md`. What matters here:
|
||||
|
||||
- **The trigger was acceptance, not a crash.** Seven real OpenTitan files —
|
||||
generated register tops — were being *rejected* with `expression chain too
|
||||
long (limit 256)`. The 2026-08-19 round chose 256 for exactly this reason
|
||||
("256 covers a 256-term generated sum") against a smaller tree; the tree
|
||||
grew. Measured the whole 3,943-file distribution rather than the seven, so
|
||||
the new number is chosen against the shape of real generated code (max 567,
|
||||
five files in 257–512, two over 512) instead of against the failures.
|
||||
- **Re-measured the slope, did not extrapolate the old number.** Four chain
|
||||
lengths (640/768/1024/1280), debug and release, bisected one trial per
|
||||
subprocess. 9.20 KiB per postfix link debug — close to the ~9 KiB measured at
|
||||
256, so the cost is genuinely linear and 1024 lands where arithmetic says.
|
||||
- **The honest finding: this round breaks one of the feature's own claims.**
|
||||
Both earlier rounds concluded that raising the chain budget is free on the
|
||||
stack, because chains peaked at 2.4 MiB against nesting's 5.9. At 1024 a
|
||||
maximal chain peaks at 9.4 MiB alone and 9.9 MiB inside nesting, so the chain
|
||||
is now the global worst case and the claim is retired above rather than
|
||||
quietly left standing. What survives — and was re-verified, not assumed — is
|
||||
the *reason* it was ever true: the two peak in different phases, so they
|
||||
compose additively. 64 nested `case` with and without a 1024-link chain
|
||||
inside bisect to the identical 5 959 KiB.
|
||||
- **`PARSE_STACK_SIZE` follows the measurement, as designed.** 16 MiB is 1.65×
|
||||
the new worst case; the constant's whole argument is margin over fit, so it
|
||||
moves to 32 MiB (3.3×). No consumer changes: every parse site already spells
|
||||
the constant, which is exactly what round 3 put it there for.
|
||||
- **One un-charged chain loop found while working nearby.**
|
||||
`parse_sens_list`'s paren-less `@a.b.c` path built one `Expr::Member` per
|
||||
segment in a loop without charging `link()` — the `Box::new(previous)` shape
|
||||
this README's Handshakes makes a standing requirement, missed because the
|
||||
loop lives in the event-control code rather than in `parse_postfix`. Lifted
|
||||
into `parse_bare_event_name`, charging both segment kinds and restoring the
|
||||
count it started from; `a_bare_event_control_charges_the_chain_budget` pins
|
||||
it.
|
||||
- Files touched here: `crates/vlog_parser/src/parser.rs` (three doc comments,
|
||||
the two constants, the new chain site),
|
||||
`crates/vlog_formatter/tests/deep_nesting.rs`, this README.
|
||||
|
||||
## QA log
|
||||
|
||||
### 2026-08-19 — QA agent
|
||||
|
||||
Reference in new issue
Block a user