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
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions crates/celox-frontend-veryl/src/lowering/bitaccess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,12 @@ fn collect_dims(module: &Module, var_id: VarId) -> Result<Vec<usize>, 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);
}
Expand Down
60 changes: 60 additions & 0 deletions crates/celox-test-suite/src/veryl/cases/struct_constructor.vtest
Original file line number Diff line number Diff line change
Expand Up @@ -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))
7 changes: 7 additions & 0 deletions crates/celox/tests/struct_constructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions scripts/check-mergify-batch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
80 changes: 51 additions & 29 deletions scripts/check-mergify-batch.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import assert from "node:assert/strict";
import test from "node:test";
import {
batchPullRequestNumbers,
stackDependency,
validateBatch,
} from "./check-mergify-batch.mjs";

Expand Down Expand Up @@ -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.
Expand Down
Loading