diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d8b2cbce565..0ef49c3e082 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -152,7 +152,8 @@ See [Mergify priorities](https://docs.mergify.com/merge-queue/priority/) and [Mergify stacks](https://docs.mergify.com/merge-queue/stacks/) (`stack/*` heads pushed by `mergify stack push --no-github-native`) use the `changes` queue. A member above the bottom targets the branch below it and carries a -`Depends-On: #N` marker; the queue accepts it on that basis and lands the whole +`Depends-On: #N` or same-repository `Depends-On: https://github.com/OWNER/REPO/pull/N` +marker; the queue accepts it on that basis and lands the whole chain on the stack root, bottom-up. Queueing the top member queues every member below it. The batch validator resolves each member's root through the same marker chain, so a stack branch without it is still refused. diff --git a/crates/celox-frontend-veryl/src/lowering/bitaccess.rs b/crates/celox-frontend-veryl/src/lowering/bitaccess.rs index 115e10a14b3..3f6ee374de7 100644 --- a/crates/celox-frontend-veryl/src/lowering/bitaccess.rs +++ b/crates/celox-frontend-veryl/src/lowering/bitaccess.rs @@ -225,12 +225,12 @@ fn collect_dims(module: &Module, var_id: VarId) -> Result, ParserErro "array", &mut dims, )?; - // For enum-typed variables, the width Shape is empty but the actual - // bit width is encoded in the TypeKind. Use kind.width() as the - // base scalar width when the explicit width shape is absent. + // Enums and aggregates encode their packed width in TypeKind rather + // than the width Shape. Even a one-bit struct/union needs that dimension: + // Veryl represents member access as a select into the packed aggregate. if width.is_empty() { if let Some(kind_width) = var_type.kind.width() - && kind_width > 1 + && (kind_width > 1 || (kind_width == 1 && var_type.is_struct_union())) { dims.push(kind_width); } diff --git a/crates/celox-test-suite/src/veryl/cases/struct_constructor.vtest b/crates/celox-test-suite/src/veryl/cases/struct_constructor.vtest index 1ff32fbb1b2..34ceec524bd 100644 --- a/crates/celox-test-suite/src/veryl/cases/struct_constructor.vtest +++ b/crates/celox-test-suite/src/veryl/cases/struct_constructor.vtest @@ -53,3 +53,63 @@ o_cut = Cut'{y: wide}; (assert_eq o_pad 0x0B) ; wide(8bit) -> member logic<4> should keep lower 4 bits. (assert_eq o_cut 0xB)) + +(case test_single_bit_aggregate_members + (source "test.veryl" #" +module Top ( + i: input logic, + rst: input reset_sync_low, + members: output logic<3>, + reset_member: output logic, +) { + struct Single { value: logic, } + struct Nested { inner: Single, } + struct Reset { value: reset_sync_low, } + union Overlay { value: logic, other: logic, } + var single: Single; + var nested: Nested; + var reset_pair: Reset; + var overlay: Overlay; + assign single.value = i; + assign nested.inner.value = i; + assign reset_pair.value = rst; + assign overlay.value = i; + assign members = {single.value, nested.inner.value, overlay.other}; + assign reset_member = reset_pair.value; +} +"#) + (top Top) + (modify (set i 0) (set rst 1)) + (assert_eq members 0) + (assert_eq reset_member 1) + (modify (set i 1) (set rst 0)) + (assert_eq members 7) + (assert_eq reset_member 0)) + +(case test_single_bit_struct_ff + (source "test.veryl" #" +module Top ( + clk: input clock, + rst: input reset, + i: input logic, + o: output logic, +) { + struct Single { value: logic, } + var registered: Single; + always_ff (clk, rst) { + if_reset { registered.value = 1'b0; } + else { registered.value = i; } + } + assign o = registered.value; +} +"#) + (top Top) + (modify (set rst 0) (set i 1)) + (tick clk) + (assert_eq o 0) + (modify (set rst 1)) + (tick clk) + (assert_eq o 1) + (modify (set i 0)) + (tick clk) + (assert_eq o 0)) diff --git a/crates/celox/tests/struct_constructor.rs b/crates/celox/tests/struct_constructor.rs index 359538e8a76..a547523e541 100644 --- a/crates/celox/tests/struct_constructor.rs +++ b/crates/celox/tests/struct_constructor.rs @@ -3,6 +3,13 @@ mod test_utils; all_backends! { + fn test_single_bit_aggregate_members(sim) { + @case "struct_constructor::test_single_bit_aggregate_members"; + } + + fn test_single_bit_struct_ff(sim) { + @case "struct_constructor::test_single_bit_struct_ff"; + } fn test_struct_constructor_comb_assignment(sim) { @case "struct_constructor::test_struct_constructor_comb_assignment"; diff --git a/flake.lock b/flake.lock index 60c6320088b..df9a372e0e9 100644 --- a/flake.lock +++ b/flake.lock @@ -7,11 +7,11 @@ ] }, "locked": { - "lastModified": 1792195366, - "narHash": "sha256-kqOyKz1zB7CB60DYPWx3fwFnL0R58A6Zzdmgiv15o7Y=", + "lastModified": 1792488653, + "narHash": "sha256-6mDIj7DP6kHQAdT0B7N8QpC3KBrY6W8LEenKg3GGfM0=", "owner": "tignear", "repo": "nix-packages", - "rev": "433f006183bab18dfcaa0a3104ec1c7c9bc907af", + "rev": "683234e1ef474a6fbb653ce7ec11aa4657d49975", "type": "github" }, "original": { diff --git a/scripts/check-mergify-batch.mjs b/scripts/check-mergify-batch.mjs index 3cff129ee86..0bea49aafeb 100644 --- a/scripts/check-mergify-batch.mjs +++ b/scripts/check-mergify-batch.mjs @@ -26,12 +26,24 @@ export function batchPullRequestNumbers(metadata) { // Mergify's queue lands stack members on the stack root, while each member // targets the head branch of the member below it. Resolve that root through // the `Depends-On:` chain, matching the queue's own stack recognition. +export function stackDependency(repository, body) { + const marker = + /^Depends-On: (?:#([1-9]\d*)|https:\/\/github\.com\/([^/\s]+\/[^/\s]+)\/pull\/([1-9]\d*))\s*$/m.exec(body ?? ""); + if ( + !marker || + (marker[2] && marker[2].toLowerCase() !== repository.toLowerCase()) + ) + return null; + const number = Number(marker[1] ?? marker[3]); + return Number.isSafeInteger(number) ? number : null; +} + export async function stackRootRef(repository, pull, api = githubJson) { for (let depth = 0; depth < 20; depth++) { const ref = pull.base?.ref; - const below = /^Depends-On: #(\d+)\s*$/m.exec(pull.body ?? ""); + const below = stackDependency(repository, pull.body); if (!ref?.startsWith("stack/") || !below) return ref; - pull = await api(`/repos/${repository}/pulls/${below[1]}`); + pull = await api(`/repos/${repository}/pulls/${below}`); if (pull.head?.ref !== ref || pull.head?.repo?.full_name !== repository) return ref; } diff --git a/scripts/check-mergify-batch.test.mjs b/scripts/check-mergify-batch.test.mjs index ea937633bc0..bd0f701f5c6 100644 --- a/scripts/check-mergify-batch.test.mjs +++ b/scripts/check-mergify-batch.test.mjs @@ -2,6 +2,7 @@ import assert from "node:assert/strict"; import test from "node:test"; import { batchPullRequestNumbers, + stackDependency, validateBatch, } from "./check-mergify-batch.mjs"; @@ -103,37 +104,58 @@ test("rejects source PRs with invalid titles or another target branch", async () } }); -test("stack members are validated against the stack root", async () => { - const f = fixture(); - const top = { - ...f.source, - head: { - sha: sourceSha, - ref: "stack/u/feat/b--2", - repo: { full_name: "o/r" }, - }, - base: { ref: "stack/u/feat/a--1" }, - body: "Adds b.\n\nDepends-On: #12\n", - }; - const bottom = { - ...f.source, - head: { - sha: sourceSha, - ref: "stack/u/feat/a--1", - repo: { full_name: "o/r" }, - }, - }; - const api = async (path) => { - if (path === "/repos/o/r/pulls/12") return bottom; - if (path === "/repos/o/r/pulls/13") return top; - return f.api(path); - }; - assert.deepEqual( - await validateBatch(f.input, api, f.commits, f.policy), - [12, 13], - ); +test("stack dependencies accept local shorthand and same-repository GitHub URLs", () => { + for (const body of [ + "Depends-On: #12", + "Text\n\nDepends-On: https://github.com/o/r/pull/12\r\n", + "Depends-On: https://github.com/O/R/pull/12", + ]) + assert.equal(stackDependency("o/r", body), 12); + for (const body of [ + undefined, + "Depends-On: #0", + "Depends-On: #9007199254740992", + "Depends-On: https://github.com/other/r/pull/12", + "Depends-On: https://github.com/o/r/pull/12/extra", + "Depends-On: https://github.com.evil/o/r/pull/12", + "Depends-On: http://github.com/o/r/pull/12", + "Depends-On: #12 extra", + ]) + assert.equal(stackDependency("o/r", body), null); }); +for (const dependency of ["#12", "https://github.com/o/r/pull/12"]) + test(`stack members with ${dependency} are validated against the stack root`, async () => { + const f = fixture(); + const top = { + ...f.source, + head: { + sha: sourceSha, + ref: "stack/u/feat/b--2", + repo: { full_name: "o/r" }, + }, + base: { ref: "stack/u/feat/a--1" }, + body: `Adds b.\n\nDepends-On: ${dependency}\n`, + }; + const bottom = { + ...f.source, + head: { + sha: sourceSha, + ref: "stack/u/feat/a--1", + repo: { full_name: "o/r" }, + }, + }; + const api = async (path) => { + if (path === "/repos/o/r/pulls/12") return bottom; + if (path === "/repos/o/r/pulls/13") return top; + return f.api(path); + }; + assert.deepEqual( + await validateBatch(f.input, api, f.commits, f.policy), + [12, 13], + ); + }); + test("rejects stack-like PRs whose chain does not reach the batch base", async () => { for (const [body, below] of [ // No marker: the queue keeps the literal stack branch as the target.