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.

2 changes: 1 addition & 1 deletion packages/playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"preview": "vite preview",
"test": "vitest run",
"typecheck": "node test/generate-sidecars.mjs && tsc -p .",
"test:vite-components": "vitest run test/vite-plugin-cache.test.ts test/generated-dts.test.ts test/vite-assertion-bytes.test.ts test/vite-plugin-cache-real.test.ts test/vite-plugin-watch.test.ts test/sidecar-orphans.test.ts test/sidecar-lock.test.ts && vitest run --config test/fixtures/injected-components/vitest.config.ts && node test/fixtures/injected-components/dependency-e2e.mjs && node test/fixtures/source-watch/watch-e2e.mjs && node test/fixtures/source-watch/build-watch-e2e.mjs && node test/fixtures/source-watch/component-watch-e2e.mjs",
"test:vite-components": "vitest run test/vite-plugin-cache.test.ts test/generated-dts.test.ts test/vite-assertion-bytes.test.ts test/vite-plugin-cache-real.test.ts test/vite-plugin-watch.test.ts test/sidecar-orphans.test.ts test/sidecar-lock.test.ts && node test/fixtures/injected-components/cache-e2e.mjs && node test/fixtures/injected-components/dependency-e2e.mjs && node test/fixtures/source-watch/watch-e2e.mjs && node test/fixtures/source-watch/build-watch-e2e.mjs && node test/fixtures/source-watch/component-watch-e2e.mjs",
"test:lsp-components": "pnpm run test:vite-components && node test/fixtures/injected-components/lsp-e2e.mjs",
"test:e2e": "pnpm run build && playwright test",
"test:watch": "vitest",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import assert from "node:assert/strict";
import { spawnSync } from "node:child_process";
import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";

const vitest = join(
dirname(fileURLToPath(import.meta.resolve("vitest/package.json"))),
"vitest.mjs",
);
for (const layout of ["internal", "external"]) {
const cache = mkdtempSync(join(tmpdir(), "celox-vitest-cache-"));
const client =
layout === "external"
? mkdtempSync(join(import.meta.dirname, ".cache-client-"))
: undefined;
try {
for (const phase of ["cold", "warm"]) {
const result = spawnSync(
process.execPath,
[
vitest,
"run",
"--config",
join(import.meta.dirname, "vitest.config.ts"),
"--fsModuleCachePath",
cache,
],
{
cwd: import.meta.dirname,
env: { ...process.env, CELOX_TEST_EXTERNAL_VITE_ROOT: client ?? "" },
encoding: "utf8",
timeout: 120_000,
},
);
process.stdout.write(result.stdout ?? "");
process.stderr.write(result.stderr ?? "");
assert.ifError(result.error);
assert.equal(
result.status,
0,
`${layout} ${phase} module-cache run failed`,
);
}
} finally {
rmSync(cache, { recursive: true, force: true });
if (client) rmSync(client, { recursive: true, force: true });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const virtualTbStep: Plugin = {
};

export default defineConfig({
root: import.meta.dirname,
root: process.env.CELOX_TEST_EXTERNAL_VITE_ROOT || import.meta.dirname,
resolve: {
alias: {
"@fixture/tb-helper": resolve(
Expand All @@ -26,8 +26,9 @@ export default defineConfig({
plugins: [
virtualTbStep,
celox({
projectRoot: import.meta.dirname,
testbenchComponents: "./tb-components.ts",
}),
],
test: { include: ["entry.test.ts"] },
test: { include: [resolve(import.meta.dirname, "entry.test.ts")] },
});
148 changes: 147 additions & 1 deletion packages/playground/test/vite-plugin-watch.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { EventEmitter } from "node:events";
import { mkdtempSync, rmSync, utimesSync, writeFileSync } from "node:fs";
import {
mkdirSync,
mkdtempSync,
rmSync,
utimesSync,
writeFileSync,
} from "node:fs";
import { tmpdir } from "node:os";
import { dirname, join } from "node:path";
import { normalizePath } from "vite";
Expand Down Expand Up @@ -1045,3 +1051,143 @@ test.each([true, false])(
expect(watcher.add).not.toHaveBeenCalled();
},
);

// Vitest's persistent module cache replays imports as URLs rooted at Vite's
// root, rather than their original paths relative to the importer.
test("cached root-relative imports retain their generated module identity", async () => {
const root = mkdtempSync(join(tmpdir(), "celox-cached-import-"));
roots.push(root);
mkdirSync(join(root, "src"));
writeFileSync(join(root, "src", "Main.veryl"), "module Main {}\n");
writeFileSync(join(root, "Veryl.toml"), "[project]\nname = 'test'\n");
const { plugin, context } = await initialize(root);
for (const [url, file] of [
["/src/Main.veryl", join(root, "src", "Main.veryl")],
[
"/src/Main.veryl?dse=preserveAllPorts",
`${join(root, "src", "Main.veryl")}?dse=preserveAllPorts`,
],
["/Veryl.toml?celox-project", `${join(root, "Veryl.toml")}?celox-project`],
[
"/src/Main.veryl?celox-watch",
`${join(root, "src", "Main.veryl")}?celox-watch`,
],
]) {
const id = (plugin.resolveId as Function)(url, join(root, "index.html"));
expect(id).toBe(normalizePath(file!));
expect((plugin.load as Function).call(context, id)).toBeTypeOf("string");
}
expect((plugin.resolveId as Function)("/missing.veryl")).toBeUndefined();
});

// A project outside Vite's root is replayed through the /@fs/ URL namespace.
test("cached external project imports retain their generated module identity", async () => {
const root = mkdtempSync(join(tmpdir(), "celox-external-cache-"));
const client = mkdtempSync(join(tmpdir(), "celox-external-client-"));
roots.push(root, client);
writeFileSync(join(root, "Main.veryl"), "module Main {}\n");
writeFileSync(join(root, "Veryl.toml"), "[project]\nname = 'test'\n");
const plugin = celox({ projectRoot: root });
const context = { addWatchFile: vi.fn(), warn: vi.fn() };
await (plugin.configResolved as Function)({ root: client });
await (plugin.buildStart as Function).call(context);
for (const query of ["", "?dse=preserveAllPorts", "?celox-watch"]) {
const file = normalizePath(join(root, "Main.veryl")) + query;
const id = (plugin.resolveId as Function)(
`/@fs/${file.replace(/^\//, "")}`,
join(client, "index.html"),
);
expect(id).toBe(file);
expect((plugin.load as Function).call(context, id)).toBeTypeOf("string");
}
const project = `${normalizePath(join(root, "Veryl.toml"))}?celox-project`;
const id = (plugin.resolveId as Function)(
`/@fs/${project.replace(/^\//, "")}`,
);
expect(id).toBe(project);
expect((plugin.load as Function).call(context, id)).toBeTypeOf("string");
});

// Both the host-absolute and Vite-root-relative paths exist. Their existence
// alone must not let an unrelated host file take over a cached project URL.
test("cached URLs prefer the project over colliding host paths", async () => {
const client = mkdtempSync(join(tmpdir(), "celox-collision-client-"));
const host = mkdtempSync(join(tmpdir(), "celox-collision-host-"));
roots.push(client, host);
const urlRoot = normalizePath(host).replace(/^[A-Z]:/i, "");
const project = join(client, urlRoot.replace(/^\//, ""));
mkdirSync(project, { recursive: true });
for (const dir of [host, project]) {
writeFileSync(join(dir, "Main.veryl"), "module Main {}\n");
writeFileSync(join(dir, "Veryl.toml"), "[project]\nname = 'test'\n");
}
const plugin = celox({ projectRoot: project });
const context = { addWatchFile: vi.fn(), warn: vi.fn() };
await (plugin.configResolved as Function)({ root: client });
await (plugin.buildStart as Function).call(context);
for (const [name, query] of [
["Main.veryl", ""],
["Main.veryl", "?dse=preserveAllPorts"],
["Main.veryl", "?celox-watch"],
["Veryl.toml", "?celox-project"],
]) {
const file = normalizePath(join(project, name!)) + query;
const url = `${urlRoot}/${name}${query}`;
const id = (plugin.resolveId as Function)(url, join(client, "index.html"));
expect(id).toBe(file);
expect((plugin.load as Function).call(context, id)).toBeTypeOf("string");
}

// Canonical absolute project IDs must stay stable even if their root-relative
// lookalikes also exist. Explicit /@fs/ URLs retain their absolute meaning.
const mirror = join(
client,
normalizePath(project)
.replace(/^[A-Z]:/i, "")
.replace(/^\//, ""),
);
mkdirSync(mirror, { recursive: true });
writeFileSync(join(mirror, "Main.veryl"), "module Main {}\n");
writeFileSync(join(mirror, "Veryl.toml"), "[project]\nname = 'other'\n");
for (const name of ["Main.veryl", "Veryl.toml?celox-project"]) {
const file = normalizePath(join(project, name));
expect((plugin.resolveId as Function)(file)).toBe(file);
}
const hostFile = normalizePath(join(host, "Main.veryl"));
expect(
(plugin.resolveId as Function)(`/@fs/${hostFile.replace(/^\//, "")}`),
).toBe(hostFile);
});

test.each([false, true])(
"cached prefix-shaped URLs fall back to the Vite root (filesystem root=%s)",
async (filesystemRoot) => {
const project = mkdtempSync(join(tmpdir(), "celox-prefix-project-"));
roots.push(project);
const client = join(project, "client");
const url = filesystemRoot
? `/celox-prefix-${project.split(/[\\/]/).at(-1)}/Main.veryl`
: normalizePath(join(project, "Main.veryl")).replace(/^[A-Z]:/i, "");
const rooted = join(client, url.replace(/^[A-Z]:/i, "").replace(/^\//, ""));
mkdirSync(dirname(rooted), { recursive: true });
writeFileSync(rooted, "module Main {}\n");
const plugin = celox({ projectRoot: filesystemRoot ? "/" : project });
// Resolution does not need buildStart; do not generate sidecars at '/'.
await (plugin.configResolved as Function)({ root: client });
for (const query of ["", "?dse=preserveAllPorts", "?celox-watch"]) {
expect((plugin.resolveId as Function)(url + query)).toBe(
normalizePath(rooted) + query,
);
}
expect(
(plugin.resolveId as Function)(`/@fs/${url.replace(/^\//, "")}`),
).toBeUndefined();
if (!filesystemRoot) {
// Once the canonical project file exists, keep that identity even though
// the cached-root lookalike exists too.
writeFileSync(join(project, "Main.veryl"), "module Main {}\n");
const canonical = normalizePath(join(project, "Main.veryl"));
expect((plugin.resolveId as Function)(canonical)).toBe(canonical);
}
},
);
Loading
Loading