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
62 changes: 48 additions & 14 deletions crates/celox-sv-analyzer/src/system_functions.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! The system tasks and functions Celox knows (IEEE 1800-2023 clauses 20 and
//! 21), and where the SystemVerilog frontend supports each one.
//! The system tasks and functions Celox knows (those IEEE 1800-2023 defines,
//! mostly in clauses 20 and 21, and the optional ones of its Annex D), and
//! where the SystemVerilog frontend supports each one.
//!
//! The analyzer checks each call against this catalog where it converts the
//! call, with the context it converts it in ([`CallSite`]), so a name the
Expand Down Expand Up @@ -49,7 +50,7 @@ pub enum SystemFunction {
Onehot0,
/// `$isunknown` (20.9).
Isunknown,
/// `$urandom` (18.13.1, 20.15.2).
/// `$urandom` (18.13.1).
Urandom,
}

Expand Down Expand Up @@ -416,7 +417,8 @@ const fn function(function: SystemFunction, min_args: usize, max_args: Option<us
}
}

/// The catalog, in the order of IEEE 1800-2023 clauses 20 and 21.
/// The catalog: IEEE 1800-2023 clauses 20 and 21 in order, then the names
/// other clauses define, then Annex D.
pub const SYSTEM_TFS: &[SystemTf] = &[
// 20.2 Simulation control system tasks
task(SystemTask::Finish, ProceduralAndInitial, 0, Some(1)),
Expand Down Expand Up @@ -489,7 +491,8 @@ pub const SYSTEM_TFS: &[SystemTf] = &[
function(SystemFunction::Onehot, 1, Some(1)),
function(SystemFunction::Onehot0, 1, Some(1)),
function(SystemFunction::Isunknown, 1, Some(1)),
// 20.10 Severity tasks (and 20.11 elaboration system tasks)
// 20.10 Severity system tasks (and 20.10.1 elaboration severity system
// tasks)
task(SystemTask::Fatal, ProceduralAndInitial, 0, None),
task(
SystemTask::Severity(Severity::Error),
Expand All @@ -509,7 +512,7 @@ pub const SYSTEM_TFS: &[SystemTf] = &[
0,
None,
),
// 20.12 Assertion control system tasks
// 20.11 Assertion control system tasks
unsupported("$asserton", Task),
unsupported("$assertoff", Task),
unsupported("$assertkill", Task),
Expand All @@ -520,7 +523,7 @@ pub const SYSTEM_TFS: &[SystemTf] = &[
unsupported("$assertnonvacuouson", Task),
unsupported("$assertvacuousoff", Task),
unsupported("$assertcontrol", Task),
// 20.13 Sampled value system functions
// 20.12 Sampled value system functions
unsupported("$sampled", Function),
unsupported("$rose", Function),
unsupported("$fell", Function),
Expand All @@ -537,7 +540,7 @@ pub const SYSTEM_TFS: &[SystemTf] = &[
unsupported("$falling_gclk", Function),
unsupported("$steady_gclk", Function),
unsupported("$changing_gclk", Function),
// 20.14 Coverage control functions
// 20.13 Coverage system functions
unsupported("$coverage_control", Function),
unsupported("$coverage_get_max", Function),
unsupported("$coverage_get", Function),
Expand All @@ -546,24 +549,22 @@ pub const SYSTEM_TFS: &[SystemTf] = &[
unsupported("$get_coverage", Function),
unsupported("$set_coverage_db_name", Task),
unsupported("$load_coverage_db", Task),
// 20.15 Probabilistic distribution functions
// 20.14 Probabilistic distribution functions
unsupported("$random", Function),
function(SystemFunction::Urandom, 0, Some(1)),
unsupported("$urandom_range", Function),
unsupported("$dist_uniform", Function),
unsupported("$dist_normal", Function),
unsupported("$dist_exponential", Function),
unsupported("$dist_poisson", Function),
unsupported("$dist_chi_square", Function),
unsupported("$dist_t", Function),
unsupported("$dist_erlang", Function),
// 20.16 Stochastic analysis tasks and functions
// 20.15 Stochastic analysis tasks and functions
unsupported("$q_initialize", Task),
unsupported("$q_add", Task),
unsupported("$q_remove", Task),
unsupported("$q_full", Function),
unsupported("$q_exam", Task),
// 20.17 Programmable logic array modeling system tasks
// 20.16 Programmable logic array modeling system tasks
unsupported("$async$and$array", Task),
unsupported("$async$nand$array", Task),
unsupported("$async$or$array", Task),
Expand All @@ -580,8 +581,9 @@ pub const SYSTEM_TFS: &[SystemTf] = &[
unsupported("$sync$nand$plane", Task),
unsupported("$sync$or$plane", Task),
unsupported("$sync$nor$plane", Task),
// 20.18 Miscellaneous tasks and functions
// 20.17 Miscellaneous tasks and functions
unsupported("$system", TaskOrFunction),
unsupported("$stacktrace", TaskOrFunction),
// 21.2 Display system tasks
task(
SystemTask::Display(Radix::Decimal),
Expand Down Expand Up @@ -711,6 +713,38 @@ pub const SYSTEM_TFS: &[SystemTf] = &[
unsupported("$dumpportsall", Task),
unsupported("$dumpportslimit", Task),
unsupported("$dumpportsflush", Task),
// 14.14 Global clocking
unsupported("$global_clock", Function),
// 16.14.7 Inferred clocking and disable functions
unsupported("$inferred_clock", Function),
unsupported("$inferred_disable", Function),
// 18.13 Random number system functions and methods
function(SystemFunction::Urandom, 0, Some(1)),
unsupported("$urandom_range", Function),
// 32.9 Loading timing data from an SDF file
unsupported("$sdf_annotate", Task),
// Annex D Optional system tasks and system functions, which the standard
// describes for information only
unsupported("$countdrivers", Function),
unsupported("$getpattern", Function),
unsupported("$input", Task),
unsupported("$key", Task),
unsupported("$nokey", Task),
unsupported("$list", Task),
unsupported("$log", Task),
unsupported("$nolog", Task),
unsupported("$reset", Task),
unsupported("$reset_count", Function),
unsupported("$reset_value", Function),
unsupported("$save", Task),
unsupported("$restart", Task),
unsupported("$incsave", Task),
unsupported("$scale", Function),
unsupported("$scope", Task),
unsupported("$showscopes", Task),
unsupported("$showvars", Task),
unsupported("$sreadmemb", Task),
unsupported("$sreadmemh", Task),
// Veryl's immediate assertions, emitted into SystemVerilog as calls of
// these names: `$assert(condition, message...)` ends the simulation when
// the condition fails and `$assert_continue` reports and continues.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1354,6 +1354,14 @@ fn reports_where_a_known_system_function_is_not_supported() {
"system task `$stop`",
"module Top(output logic y); initial $stop; assign y = 0; endmodule",
),
(
"system task `$stacktrace`",
"module Top(output logic y); initial $stacktrace; assign y = 0; endmodule",
),
(
"system function `$countdrivers` in an expression",
"module Top(input logic a, output logic y); assign y = $countdrivers(a); endmodule",
),
];
for (expected, source) in cases {
let error = build_error(source);
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/systemverilog.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ constructs without a dedicated issue point to the frontend roadmap, [#88](https:
- Expressions: streaming concatenations ([#447](https://github.com/celox-sim/celox/issues/447)), reduction operators in parameter expressions
([#456](https://github.com/celox-sim/celox/issues/456)), and parameter overrides that are not plain integers, such as X/Z
values or values wider than 128 bits ([#461](https://github.com/celox-sim/celox/issues/461)).
- System tasks and functions: Celox knows every name of IEEE 1800-2023
clauses 20 and 21. One it does not support where it is called, such as
- System tasks and functions: Celox knows every name IEEE 1800-2023
defines, including the optional ones of its Annex D. One it does not support where it is called, such as
`$time` in an expression or `$fopen`, is
reported with its name wherever it is written, including in an unused
parameter and in a function body. A `$` name that is not a system task or
Expand Down
4 changes: 2 additions & 2 deletions docs/ja/guide/systemverilog.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ package・interface の手続きは宣言元の時間単位と精度を保持し
- 式:ストリーミング連結([#447](https://github.com/celox-sim/celox/issues/447))、パラメータ式での
リダクション演算子([#456](https://github.com/celox-sim/celox/issues/456))、X/Z を含む値や 128 ビットを超える値など、単純な整数で
ないパラメータ上書き([#461](https://github.com/celox-sim/celox/issues/461))。
- システムタスクとシステム関数:Celox は IEEE 1800-2023 第 20・21 章のすべての名前を
知っています。呼び出した位置で対応していないもの(式の中の `$time`、`$fopen` など)は、
- システムタスクとシステム関数:Celox は IEEE 1800-2023 が定義するすべての名前を、
附属書 D の任意のものも含めて知っています。呼び出した位置で対応していないもの(式の中の `$time`、`$fopen` など)は、
使われていないパラメータや関数本体の中を含め、書かれた
場所にかかわらず名前を示して報告します。システムタスクでもシステム関数でもない `$` 名、
引数の数が誤っている呼び出し、既定値のない引数の省略、値として使ったタスクはエラーです。
Expand Down
3 changes: 2 additions & 1 deletion scripts/ci-changes.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ function changedFiles(base, head) {
try {
const output = execFileSync(
"git",
["diff", "--name-only", "-z", base, head],
// Diff from the merge base: a PR's base.sha is the current base tip.
["diff", "--name-only", "-z", `${base}...${head}`],
{ encoding: "utf8" },
);
return output.split("\0").filter(Boolean);
Expand Down
30 changes: 29 additions & 1 deletion scripts/ci-changes.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { dirname, join, relative } from "node:path";
import test from "node:test";
import { fileURLToPath } from "node:url";

import { changedFilesBetween } from "./ci-rust-scope.mjs";
import {
affectsHeliodorArm64,
classifyFiles,
Expand Down Expand Up @@ -161,7 +162,7 @@ const MASTER_GROUP = {

const classifier = fileURLToPath(new URL("./ci-changes.mjs", import.meta.url));

// The classifier diffs base..head in the repository at cwd.
// The classifier diffs base...head in the repository at cwd.
function runClassifier(
base,
head,
Expand Down Expand Up @@ -506,3 +507,30 @@ test("queue configuration runs script checks without rebuilding the product", ()
});
assert.deepEqual(classifyFiles([".mergify.yml", "unknown/new-source"]), all);
});

test("PR branches behind their base ignore unmerged base changes", (t) => {
const repository = mkdtempSync(join(tmpdir(), "celox-ci-changes-"));
t.after(() => rmSync(repository, { recursive: true, force: true }));
const git = (...args) =>
execFileSync("git", args, { cwd: repository, encoding: "utf8" }).trim();
const commit = (path) => {
writeFileSync(join(repository, path), `${path}\n`);
git("add", path);
git("commit", "--quiet", "-m", path);
return git("rev-parse", "HEAD");
};
git("init", "--quiet");
git("config", "user.name", "test");
git("config", "user.email", "test@example.com");
git("config", "commit.gpgsign", "false");
const fork = commit("README.md");
git("checkout", "--quiet", "-b", "pr");
const head = commit("CONTRIBUTING.md");
git("checkout", "--quiet", fork);
const base = commit("unknown-base-change.xyz");
assert.deepEqual(changedFilesBetween(base, head, repository), ["CONTRIBUTING.md"]);
assert.deepEqual(
runClassifier(base, head, { GITHUB_EVENT_NAME: "pull_request" }, repository),
{ ...none, docs: true, heliodor_arm64: false, release: false },
);
});
11 changes: 8 additions & 3 deletions scripts/ci-rust-scope.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,17 @@ export function rustTestScope(files, packages) {
};
}

/** Changed files between two commits, or null when they cannot be compared. */
export function changedFilesBetween(base, head) {
/**
* Files changed on head since it forked from base, or null when they cannot be
* compared. A PR's base.sha is the current base tip, so a two-point diff would
* also report base changes that the PR branch has not merged yet.
*/
export function changedFilesBetween(base, head, cwd = undefined) {
const sha = /^[0-9a-f]{40,64}$/i;
if (!sha.test(base) || !sha.test(head) || /^0+$/.test(base)) return null;
try {
return execFileSync("git", ["diff", "--name-only", "-z", base, head], {
return execFileSync("git", ["diff", "--name-only", "-z", `${base}...${head}`], {
cwd,
encoding: "utf8",
})
.split("\0")
Expand Down
Loading