Skip to content

Read a select past an associative array's dimensions from the element (§7.8, §11.5.1, #956) - #957

Closed
chuanseng-ng wants to merge 3 commits into
aionhw:mainfrom
chuanseng-ng:fix/assoc-elem-bit-read
Closed

chuanseng-ng wants to merge 3 commits into
aionhw:mainfrom
chuanseng-ng:fix/assoc-elem-bit-read

Conversation

@chuanseng-ng

@chuanseng-ng chuanseng-ng commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #956.

A select past the unpacked dimensions of an associative array selects into the element (§7.8, §7.4.6, §11.5.1). a[7][3] on logic [31:0] a [int] read the absent element a[7][3] instead of bit 3 of a[7], so it read the element default at the element's width (X for 4-state, 0 for 2-state).

Change. assoc_elem_select_read (src/compiler/simulator/collections.rs) runs in the Index read arm of eval_expr before the associative-key handlers. When the selects already reach the array's declared associative depth (one for a[int], the registered shape for ab[int][string]), it reads the element and applies the next select to it: a bit select for a one-dimensional packed element, or the packed slice for a multi-dimensional one. It mirrors assoc_elem_bit_write on the write path. Rows of multidimensional associative arrays, dynamic arrays and queues are left to the existing handlers. The check is skipped when the module has no associative arrays.

Result (ticket reproducer):

Output
the reference simulator a=1 ab=1 miss=0 m=1
xezim 343b6d75 a=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ab=0000000000000000 miss=00000000 m=xxxxxxxxxxxxxxxx
this branch a=1 ab=1 miss=0 m=1

Tests. tests/collections/assoc_elem_select_read.rs, 10 tests: each key type (int, typedef, string, [*]), variable key and bit, a generate block, a packed struct element, past a two-dimensional associative array, an absent element, a bit write then read, and guards for part-selects, whole-element reads and rows of multidimensional associative arrays and queues. 8 of 10 fail without the fix; the two guards pass on both.

Suite. Rebased on 5ca27d9e (pinned core 5b0b02e); the only conflict was the test list in tests/collections.rs. Full suite on the head of #959, which contains this branch: 6348 passed, 0 failed, 1 ignored. Before the rebase, on this branch alone (base 343b6d75, core 60e6508): 6322 passed, 0 failed, 1 ignored. No new clippy or rustfmt findings on the changed lines.

Notes and caches. The third commit adds the NOTES.md entry. The change is in the interpreter (src/compiler/simulator/); compiled-method instructions and the admit/decline decision are unchanged, so METHOD_CACHE_COMPILER_SALT stays.

Performance. perf is not available on my machine (perf_event_paranoid=4), so no profile. On the read path the added cost is one is_empty() check for modules without associative arrays; for modules with them, one walk of the Index chain and a map lookup before the existing handlers.

Not in this PR: an associative element whose packed type is multi-dimensional, offset or ascending (logic [3:0][7:0] p [int], logic [8:1] r [int], logic [0:7] u [int]) is not stored correctly. That has a separate cause and will be its own ticket and PR.

@aionhw

aionhw commented Nov 9, 2026

Copy link
Copy Markdown
Owner

Integrated as part of #959, which contains these two commits unchanged: f33558ea and the tests 434a7be0, with @chuanseng-ng's authorship preserved.

Published in xezim 603c9bf3 with xezim-core 212dde0.
Validation: the full xezim suite passes (6610 tests, 0 failed, 1 ignored), with xezim-core 514 and parser 233 tests, the JIT smoke and DPI fallback tests, and a 1.92 MSRV check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A bit select of an associative array element reads X: a[7][3] on logic [31:0] a [int] (§7.8, §11.5.1)

2 participants