diff --git a/crates/celox-frontend-core/src/symbolic/assembly.rs b/crates/celox-frontend-core/src/symbolic/assembly.rs index c41124ec1a4..1b720f15176 100644 --- a/crates/celox-frontend-core/src/symbolic/assembly.rs +++ b/crates/celox-frontend-core/src/symbolic/assembly.rs @@ -375,9 +375,10 @@ impl PackageBindings { } } -/// Reject a package variable that two flip-flop processes write, that the -/// initial writes of two instances write, or that a continuous driver and -/// any other process write. Instances of one module are separate drivers. +/// Reject a package variable that two flip-flop processes write, that a +/// continuous driver and any other process write, or that an `always_ff`, +/// `always_comb` or `always_latch` run as a process and any other process +/// write. Instances of one module are separate drivers. /// Overlapping continuous drivers are rejected by the scheduler. fn check_package_variable_drivers( bindings: &PackageBindings, @@ -455,6 +456,9 @@ fn check_package_variable_drivers( // values, and initial processes. The package's own declaration // initializers are not drivers. let mut initial_writes: Vec<((InstanceId, usize), AbsoluteAddr, BitAccess)> = Vec::new(); + // The writes of processes that must be the only writers of what they + // write (IEEE 1800-2023 9.2.2.2 to 9.2.2.4). + let mut restricted_writes: Vec<((InstanceId, usize), AbsoluteAddr, BitAccess)> = Vec::new(); for (&instance, module_id) in instance_modules { let module = &modules[module_id]; if package_instances.contains_key(module_id) { @@ -485,17 +489,34 @@ fn check_package_variable_drivers( } } for (index, process) in module.processes.iter().enumerate() { + let restricted = matches!( + process.origin.construct.as_str(), + "always_ff" | "always_comb" | "always_latch" + ); for block in process.kernel.blocks.values() { for instruction in &block.instructions { - let (SIRInstruction::Store(address, ..) - | SIRInstruction::Commit(_, address, ..)) = instruction + let (SIRInstruction::Store(address, offset, bits, ..) + | SIRInstruction::Commit(_, address, offset, bits, _)) = instruction else { continue; }; let address = bindings.locate(instance, address.var_id); if packages.contains(&address) { - let access = BitAccess::new(0, width(&address).saturating_sub(1)); + // The bits the store writes, as for flip-flop + // writes, so disjoint writers are not rejected. + let access = offset + .constant_bit_offset() + .zip(bits.checked_sub(1)) + .and_then(|(lsb, tail)| { + Some(BitAccess::new(lsb, lsb.checked_add(tail)?)) + }) + .unwrap_or_else(|| { + BitAccess::new(0, width(&address).saturating_sub(1)) + }); initial_writes.push(((instance, index), address, access)); + if restricted { + restricted_writes.push(((instance, index), address, access)); + } } } } @@ -518,12 +539,28 @@ fn check_package_variable_drivers( .then_some(*address) }) }; - // Two flip-flop processes, or initial writes of two instances, race. + // Two flip-flop processes race. Initial writes and processes of several + // instances may write one package variable, as any processes may write + // a variable (IEEE 1800-2023 6.5). if let Some(address) = conflict(&ff_writes, &|left, right| left != right) { return Err(error(&address)); } - if let Some(address) = conflict(&initial_writes, &|left, right| left.0 != right.0) { - return Err(error(&address)); + // A restricted process overlaps every write of another process. + for (writer, address, access) in &restricted_writes { + let overlaps = |(other, other_address, other_access): &( + (InstanceId, usize), + AbsoluteAddr, + BitAccess, + )| { + other_address == address && other_access.overlaps(access) && other != writer + }; + if initial_writes.iter().any(overlaps) + || ff_writes.iter().any(|(_, other_address, other_access)| { + other_address == address && other_access.overlaps(access) + }) + { + return Err(error(address)); + } } // A continuous driver overlaps every other write. for path in comb_blocks { diff --git a/crates/celox-frontend-sv/src/lowering.rs b/crates/celox-frontend-sv/src/lowering.rs index fa54240afe6..b5b0d177f4c 100644 --- a/crates/celox-frontend-sv/src/lowering.rs +++ b/crates/celox-frontend-sv/src/lowering.rs @@ -1043,11 +1043,25 @@ fn validate_package_variable_drivers<'a>( for root in roots { count(root, 1, module_ids, modules, &mut instances); } - // A driver is one process or child output of one instance; a process may - // assign the variable several times. - type Driver = (ModuleId, usize, bool, usize); - let mut drivers: HashMap<(String, String), Vec<(Driver, Option<(i128, i128)>)>> = - HashMap::default(); + // A driver is one process, child output or initial block of one + // instance; a process may assign the variable several times. + #[derive(Clone, Copy, PartialEq)] + enum Source { + Process, + Child, + Initial, + } + type Driver = (ModuleId, usize, Source, usize); + struct Writer { + driver: Driver, + range: Option<(i128, i128)>, + /// Treated as the only writer of what it writes. + exclusive: bool, + /// The only writer the standard allows, which an initial block + /// must not write either. + restricted: bool, + } + let mut drivers: HashMap<(String, String), Vec> = HashMap::default(); for (&module_id, module) in modules { let multiplicity = instances.get(&module_id).copied().unwrap_or(0); if module.package_variables.is_empty() { @@ -1060,24 +1074,62 @@ fn validate_package_variable_drivers<'a>( let name = &module.variables[var_id].path[0]; let local = module_drivers.local(name); let children = child_output_driver_ranges(module, &child_drivers, name); + // One-shot initial blocks; repeating ones are among `local`. + let initial = module_drivers + .initial(name) + .into_iter() + .filter(|(driver, _)| !module.source.initial_processes()[*driver].repeats()) + .collect::>(); let entry = drivers .entry((package.clone(), variable.clone())) .or_default(); for copy in 0..multiplicity { for &(driver, range) in &local { - entry.push(((module_id, copy, false, driver), range)); + entry.push(Writer { + driver: (module_id, copy, Source::Process, driver), + range, + exclusive: exclusive_driver(&module.source, driver), + restricted: restricted_driver(&module.source, driver), + }); } for &(driver, range) in &children { - entry.push(((module_id, copy, true, driver), range)); + entry.push(Writer { + driver: (module_id, copy, Source::Child, driver), + range, + exclusive: true, + restricted: true, + }); + } + for &(driver, range) in &initial { + entry.push(Writer { + driver: (module_id, copy, Source::Initial, driver), + range, + exclusive: false, + restricted: false, + }); } } } } - for ((package, variable), ranges) in drivers { - let overlap = ranges.iter().enumerate().any(|(index, (driver, range))| { - ranges[index + 1..].iter().any(|(other, other_range)| { - other != driver && net_driver_ranges_overlap(*range, *other_range) - }) + // Processes of several instances may write a package variable, as any + // processes may write a variable, unless one of them must be its only + // writer (IEEE 1800-2023 6.5, 9.2.2); an initial block conflicts only + // with a writer the standard restricts. + for ((package, variable), writers) in drivers { + let conflict = |left: &Writer, right: &Writer| { + let initial = left.driver.2 == Source::Initial || right.driver.2 == Source::Initial; + left.driver != right.driver + && if initial { + left.restricted || right.restricted + } else { + left.exclusive || right.exclusive + } + && net_driver_ranges_overlap(left.range, right.range) + }; + let overlap = writers.iter().enumerate().any(|(index, left)| { + writers[index + 1..] + .iter() + .any(|right| conflict(left, right)) }); if overlap { return Err(sv::AnalyzerError::Unsupported(format!( @@ -1803,6 +1855,49 @@ impl ModuleDrivers { } } +/// Whether process `driver` of [`ModuleDrivers::local`] must be the only writer of +/// the variables it writes: an `always_comb` or continuous assignment, an +/// edge procedure, or an `always_ff` run as a process, but not another +/// ordinary `always` process (IEEE 1800-2023 6.5, 9.2.2). +fn exclusive_driver(module: &sv::ir::Module, driver: usize) -> bool { + let edge = module.comb_processes().len() + module.ff_processes().len(); + driver < edge || { + let process = module + .initial_processes() + .iter() + .filter(|process| process.repeats()) + .nth(driver - edge); + process.is_some_and(|process| { + process.is_scheduled_edge() + || process + .site() + .is_some_and(|site| site.construct == "always_ff") + }) + } +} + +/// Whether process `driver` of [`ModuleDrivers::local`] is one the standard lets +/// no other process write to the variables it writes: `always_comb`, +/// `always_latch`, `always_ff` or a continuous assignment (IEEE 1800-2023 +/// 6.5, 9.2.2). +fn restricted_driver(module: &sv::ir::Module, driver: usize) -> bool { + let combinational = module.comb_processes().len(); + let edge = combinational + module.ff_processes().len(); + if let Some(process) = module.comb_processes().get(driver) { + return process.kind() != sv::ir::CombProcessKind::AlwaysStar; + } + if driver < edge { + return module.ff_processes()[driver - combinational].is_always_ff(); + } + module + .initial_processes() + .iter() + .filter(|process| process.repeats()) + .nth(driver - edge) + .and_then(|process| process.site()) + .is_some_and(|site| matches!(site.construct, "always_ff" | "always_comb" | "always_latch")) +} + fn net_lvalue_range( lvalue: &sv::ir::LValue, constants: &HashMap, diff --git a/crates/celox/tests/frontends/systemverilog/class.rs b/crates/celox/tests/frontends/systemverilog/class.rs index 90b5b974c1e..b3243686b6b 100644 --- a/crates/celox/tests/frontends/systemverilog/class.rs +++ b/crates/celox/tests/frontends/systemverilog/class.rs @@ -580,31 +580,19 @@ fn classes_of_packages_in_other_sources_are_used_through_their_layouts() { } #[test] -fn misused_classes_of_other_scopes_are_rejected() { - for (source, want) in [ - ( - "package p; class Box #(int N = 2); endclass endpackage - module Top; import p::*; Box #(3) box; endmodule", - "specialization of parameterized class `p::Box` outside the scope that declares it", - ), - // A package variable has one writing instance (#1146), static - // properties of package classes too. - ( - "package p; class C; static int n; function new(); n++; endfunction endclass endpackage - module W; p::C c; initial c = new; endmodule - module Top; W a(); W b(); endmodule", - "multiple drivers of package", - ), - ] { - let Err(error) = - celox::Simulation::from_sv_sources(vec![(source, Path::new("class.sv"))], "Top") - .build() - else { - panic!("`{source}` is rejected"); - }; - let error = error.to_string(); - assert!(error.contains(want), "{error}"); - } +fn specializations_of_classes_of_other_scopes_are_rejected() { + let source = "package p; class Box #(int N = 2); endclass endpackage + module Top; import p::*; Box #(3) box; endmodule"; + let Err(error) = + celox::Simulation::from_sv_sources(vec![(source, Path::new("class.sv"))], "Top").build() + else { + panic!("`{source}` is rejected"); + }; + let error = error.to_string(); + assert!( + error.contains("outside the scope that declares it"), + "{error}" + ); } #[test] @@ -618,6 +606,28 @@ fn a_class_of_another_module_does_not_hide_a_package() { assert_eq!(sim.get(sim.signal("bits")), 3u32.into()); } +#[test] +fn processes_of_several_instances_share_the_static_properties_of_a_package_class() { + let source = "`timescale 1ns/1ns + package p; + class C; + static int made; + function new(); made++; endfunction + endclass + endpackage + module W; p::C c; initial c = new; endmodule + module Top(output int made); + W first(); + W second(); + initial #1 made = p::C::made; + endmodule"; + let mut sim = celox::Simulation::from_sv_sources(vec![(source, Path::new("class.sv"))], "Top") + .build() + .unwrap(); + sim.run_until(1).unwrap(); + assert_eq!(sim.get(sim.signal("made")), 2u32.into()); +} + #[test] fn type_arguments_keep_their_dimensions_scopes_and_class_scoped_types() { let source = "module Top(output int defs, output int narrow, output int wide); diff --git a/crates/celox/tests/frontends/systemverilog/review_regressions.rs b/crates/celox/tests/frontends/systemverilog/review_regressions.rs index 5ad82945518..e34c6124f7a 100644 --- a/crates/celox/tests/frontends/systemverilog/review_regressions.rs +++ b/crates/celox/tests/frontends/systemverilog/review_regressions.rs @@ -8729,9 +8729,12 @@ fn timed_task_edge_drivers_are_checked_against_child_outputs() { } #[test] -fn timed_task_edge_drivers_of_package_variables_are_checked_across_instances() { - let error = cranelift_build_error( - r#" +fn timed_task_edge_processes_of_several_instances_may_write_a_package_variable() { + // `always` processes, unlike `always_ff`, may share their variables + // (IEEE 1800-2023 6.5, 9.2.2.4). + celox::Simulation::from_sv_sources( + vec![( + r#" package p; bit q; endpackage module Child(input bit clk); task automatic pause; #1; endtask @@ -8741,11 +8744,12 @@ fn timed_task_edge_drivers_of_package_variables_are_checked_across_instances() { Child first(clk), second(clk); endmodule "#, - ); - assert!( - error.contains("multiple drivers of package variable `p::q`"), - "{error}" - ); + Path::new("timed_task_package_writers.sv"), + )], + "Top", + ) + .build() + .unwrap_or_else(|error| panic!("{error}")); } mod aggregate_regressions { diff --git a/crates/celox/tests/sv_packages.rs b/crates/celox/tests/sv_packages.rs index 4a0093a21ba..306977bab5e 100644 --- a/crates/celox/tests/sv_packages.rs +++ b/crates/celox/tests/sv_packages.rs @@ -739,7 +739,7 @@ fn rejects_unsupported_package_state() { } #[test] -fn veryl_instances_of_one_initializer_are_several_drivers() { +fn veryl_instances_may_initialize_one_package_variable() { let sv = "package p; logic [7:0] shared; endpackage module W(input logic [7:0] a); initial p::shared = 8'd1; endmodule"; let veryl = r#" @@ -753,12 +753,42 @@ module Top ( assign y = a; } "#; - let error = Simulator::builder(veryl, "Top") + // Initial blocks of several instances may write one package variable, + // as any processes may write a variable (IEEE 1800-2023 6.5). + Simulator::builder(veryl, "Top") .with_sv_sources(vec![(sv, std::path::Path::new("initial.sv"))]) .build() - .expect_err("two instances initializing one package variable"); + .unwrap_or_else(|error| panic!("{error}")); +} + +#[test] +fn veryl_instances_do_not_share_a_package_variable_from_always_ff() { + // `always_ff` must be the only writer of its variables (IEEE 1800-2023 + // 9.2.2.4), also when a host request runs it as a process and a Veryl + // module instantiates it twice. Nonblocking writes of processes are not + // seen by the assembly check yet (#1969). + let sv = r#"package p; logic [7:0] shared; endpackage + module W(input logic clk, input logic [7:0] a); + always_ff @(posedge clk) begin p::shared = a; $fwrite(1, "host"); end + endmodule"#; + let veryl = r#" +module Top ( + clk: input clock, + y: output logic<8>, +) { + var a: logic<8>; + assign a = 8'd7; + inst w1: $sv::W (clk, a); + inst w2: $sv::W (clk, a); + assign y = a; +} +"#; + let error = celox::Simulation::builder(veryl, "Top") + .with_sv_sources(vec![(sv, std::path::Path::new("always_ff.sv"))]) + .build() + .expect_err("two always_ff instances writing one package variable"); assert!( - format!("{error:?}").contains("multiple drivers of package variable `p::shared`"), + format!("{error:?}").contains("multiple drivers of package variable"), "{error:?}" ); } @@ -1581,3 +1611,83 @@ fn nested_generate_block_imports_restore_the_module_binding() { ); } } + +#[test] +fn ordinary_processes_do_not_share_a_package_variable_with_always_ff() { + // `always_ff` must be the only writer of its variables (IEEE 1800-2023 + // 9.2.2.4), also when another instance writes it from an `always`. + let error = celox::Simulation::from_sv_sources( + vec![( + "package p; logic q; endpackage + module F(input logic clk, input logic d); always_ff @(posedge clk) p::q <= d; endmodule + module T; always #1 p::q = 0; endmodule + module Top(input logic clk); F f(.clk(clk), .d(1'b1)); T t(); endmodule", + std::path::Path::new("exclusive.sv"), + )], + "Top", + ) + .build() + .expect_err("an always and an always_ff writing one package variable"); + assert!( + format!("{error:?}").contains("multiple drivers of package variable `p::q`"), + "{error:?}" + ); +} + +#[test] +fn initial_blocks_do_not_share_a_package_variable_with_always_ff() { + // An initial block is another process too (IEEE 1800-2023 9.2.2.4), + // also when the always_ff runs as a process for its host request. + let error = celox::Simulation::from_sv_sources( + vec![( + r#"package p; logic q; endpackage + module F(input logic clk); always_ff @(posedge clk) begin p::q <= 1; $display("host"); end endmodule + module I; initial p::q = 0; endmodule + module Top(input logic clk); F f(.clk(clk)); I i(); endmodule"#, + std::path::Path::new("initial.sv"), + )], + "Top", + ) + .build() + .expect_err("an initial block and an always_ff writing one package variable"); + assert!( + format!("{error:?}").contains("multiple drivers of package variable `p::q`"), + "{error:?}" + ); + // An ordinary edge procedure has no such restriction. + celox::Simulation::from_sv_sources( + vec![( + "package p; logic q; endpackage + module F(input logic clk); always @(posedge clk) p::q <= 1; endmodule + module I; initial p::q = 0; endmodule + module Top(input logic clk); F f(.clk(clk)); I i(); endmodule", + std::path::Path::new("ordinary.sv"), + )], + "Top", + ) + .build() + .unwrap_or_else(|error| panic!("{error}")); +} + +#[test] +fn restricted_processes_may_share_disjoint_package_slices() { + // An `always_ff` run as a process writes only the bits it assigns, so + // an initial block may write the other bits (IEEE 1800-2023 9.2.2.4). + let mut sim = celox::Simulation::from_sv_sources( + vec![( + r#"`timescale 1ns/1ns + package p; logic [7:0] q; endpackage + module Top(input logic clk, input logic [3:0] d, output logic [7:0] y); + initial begin #1 p::q[7:4] = 4'h5; end + always_ff @(posedge clk) begin p::q[3:0] = d; $fwrite(1, "host"); end + assign y = p::q; + endmodule"#, + std::path::Path::new("slices.sv"), + )], + "Top", + ) + .build() + .unwrap_or_else(|error| panic!("{error}")); + sim.run_until(1).unwrap(); + assert_eq!(sim.get(sim.signal("y")) >> 4u32, 5u32.into()); +} diff --git a/docs/guide/systemverilog-reference.md b/docs/guide/systemverilog-reference.md index 3b3b3796d19..ced3e927699 100644 --- a/docs/guide/systemverilog-reference.md +++ b/docs/guide/systemverilog-reference.md @@ -187,7 +187,7 @@ Celox reports an `Unsupported` error naming the construct instead of ignoring it. The error carries the number of the issue that tracks the construct; constructs without a dedicated issue point to the frontend roadmap, [#88](https://github.com/celox-sim/celox/issues/88). -- Class features beyond those [listed](#classes): `$cast` to a variable that is not a class handle, enumeration constants declared in a class, enumeration, struct and union types and named four-state or string constants as class parameter values, specializations of a parameterized class outside the package or compilation unit that declares it, a static property of a package or compilation-unit class that processes of two module instances write (see [packages](#packages)), and properties that are 4-state, `real`, arrays or wider than 64 bits. Timed tasks with static local declarations, recursive calls and `ref` arguments remain unsupported. +- Class features beyond those [listed](#classes): `$cast` to a variable that is not a class handle, enumeration constants declared in a class, enumeration, struct and union types and named four-state or string constants as class parameter values, specializations of a parameterized class outside the package or compilation unit that declares it, and properties that are 4-state, `real`, arrays or wider than 64 bits. Timed tasks with static local declarations, recursive calls and `ref` arguments remain unsupported. - Behavioral and verification constructs: `final`, intra-assignment timing controls (`a = #1 b`), delayed continuous assignments ([#444](https://github.com/celox-sim/celox/issues/444)), named events and `->`, `fork` / `join`, `wait fork` / `disable fork`, concurrent assertions, `force` / `release`. @@ -346,8 +346,8 @@ A class declared in a package or the compilation unit is laid out and its methods are lowered where it is declared, once (IEEE 1800-2023 3.12.1, 26.3): a module uses it through an import, as `p::C`, or by its name when the compilation unit declares it, also from another source file. Its static -properties are variables of the package, so their writers follow the rules of -package variables. A module class may extend it and override its virtual +properties are variables of the package, shared by every module that uses +the class. A module class may extend it and override its virtual methods; calls of those methods through handles in the module then also reach the overrides of the module's classes. A specialization of a parameterized class is made where the class is declared, so outside that scope only the @@ -388,8 +388,10 @@ An import in a generate block makes names visible in that block (and the blocks inside it), ahead of the module's own declarations and imports. A package variable is one object shared by every module that uses it, including SystemVerilog modules instantiated from Veryl, and keeps its -initializer. `sim.signal("p::v")` names it. Several drivers of one package -variable are rejected, counting every instance of a module that writes it. +initializer. `sim.signal("p::v")` names it. Any processes may write it, also +those of several instances; a continuous assignment, `always_comb` or +`always_ff` that writes it must be its only writer (IEEE 1800-2023 6.5, 9.2.2), +counting every instance of the module that holds it. A package variable cannot be a clock or reset yet, and its initializer must be constant. `export` declarations (26.6) make imported declarations visible to the importers of a package: `export p::*;` exports only the @@ -558,8 +560,8 @@ initialization process. Constant function calls use fresh values and do not affect runtime storage (13.4.3). Task locals that keep their values and nonconstant static initializers remain -unsupported; declare those locals `automatic`. Package function state follows -the existing package-variable restrictions on multiple procedural drivers. +unsupported; declare those locals `automatic`. Package function state is a +package variable, which the processes of every instance may write. An interface whose default lifetime (`interface automatic`) differs from that of the module it is used in is rejected. diff --git a/docs/ja/guide/systemverilog-reference.md b/docs/ja/guide/systemverilog-reference.md index da84f4d8c8d..11956d111ea 100644 --- a/docs/ja/guide/systemverilog-reference.md +++ b/docs/ja/guide/systemverilog-reference.md @@ -163,7 +163,7 @@ SystemVerilog に対しても、共有の Veryl 適合性スイートを実行 その構文を追跡する issue の番号が含まれます。専用の issue がない構文は、フロントエンドの ロードマップ [#88](https://github.com/celox-sim/celox/issues/88) を指します。 -- [対応範囲](#classes)外のクラスの機能:クラスハンドル以外の変数への `$cast`、クラス内で宣言した列挙定数、クラスパラメータの値としての列挙型・構造体型・共用体型と名前付きの 4 値・文字列定数、宣言した package やコンパイル単位の外でのパラメータ付きクラスの特殊化、2 つのモジュールインスタンスのプロセスが書き込む package・コンパイル単位のクラスの static プロパティ、4 値・`real`・配列・64 ビットを超えるプロパティ。時間待ちを含む task の static ローカル宣言、再帰呼び出し、`ref` 引数。 +- [対応範囲](#classes)外のクラスの機能:クラスハンドル以外の変数への `$cast`、クラス内で宣言した列挙定数、クラスパラメータの値としての列挙型・構造体型・共用体型と名前付きの 4 値・文字列定数、宣言した package やコンパイル単位の外でのパラメータ付きクラスの特殊化、4 値・`real`・配列・64 ビットを超えるプロパティ。時間待ちを含む task の static ローカル宣言、再帰呼び出し、`ref` 引数。 - interface のポート、`inout` / `ref` / 式を使う modport、virtual interface など。 interface 自体と入れ子の interface は対応しています。型パラメータはインスタンスごとに解決し、modport ポート経由でも伝搬します。 再帰する特殊化と64段を超える入れ子は拒否します。細かな制約は[英語版の一覧](/guide/systemverilog-reference#interface-restrictions)を参照してください。 @@ -216,7 +216,7 @@ SystemVerilog に対しても、共有の Veryl 適合性スイートを実行 パラメータ付きクラスでは、パラメータの値と型の組ごとに 1 つの特殊化があり、それぞれが独立したクラスとして static プロパティを持ちます(IEEE 1800-2023 8.25)。`C#(2, int)` と `C#(.T(int), .N(2))` は同じ特殊化で、`C#(2)` のハンドルは `C#(3)` の変数に代入できません。パラメータ値の割り当ては書いた場所で評価するので、モジュールのパラメータに依存してもかまいません。型としてのクラス名だけはクラスの中でもデフォルトの特殊化 `C#()` を表します。`::` の前に置いたクラス名は、クラスの中と extern メソッドの本体では宣言中の特殊化を指し、それ以外の場所では `C#()::` と書く必要があります(8.25.1)。interface クラスは継承する interface クラスのパラメータと typedef を引き継ぎ、異なる interface クラスや特殊化から同じ名前を引き継ぐ場合は自分で宣言し直す必要があります(8.26.6.2、8.26.6.3)。Celox はモジュールの型とスコープが参照する特殊化を実行前にすべて作り、generate ブロック内の割り当てはそのインスタンスごとに評価します。 -package やコンパイル単位で宣言したクラスは、宣言した場所で一度だけレイアウトを決めてメソッドを下ろします(IEEE 1800-2023 3.12.1、26.3)。モジュールは import や `p::C` で、コンパイル単位のクラスなら名前で、別のソースファイルからでも使えます。static プロパティは package の変数なので、書き込みは package 変数の規則に従います。モジュールのクラスはこれを継承して virtual メソッドをオーバーライドでき、そのモジュールのハンドルを通した呼び出しはモジュールのクラスのオーバーライドにも届きます。パラメータ付きクラスの特殊化はクラスを宣言した場所で作るので、そのスコープの外ではそこで名前を挙げた特殊化だけを使えます。package とコンパイル単位の要素だけのソースは、それらのスコープをエラボレーションします。 +package やコンパイル単位で宣言したクラスは、宣言した場所で一度だけレイアウトを決めてメソッドを下ろします(IEEE 1800-2023 3.12.1、26.3)。モジュールは import や `p::C` で、コンパイル単位のクラスなら名前で、別のソースファイルからでも使えます。static プロパティは package の変数で、クラスを使うすべてのモジュールが共有します。モジュールのクラスはこれを継承して virtual メソッドをオーバーライドでき、そのモジュールのハンドルを通した呼び出しはモジュールのクラスのオーバーライドにも届きます。パラメータ付きクラスの特殊化はクラスを宣言した場所で作るので、そのスコープの外ではそこで名前を挙げた特殊化だけを使えます。package とコンパイル単位の要素だけのソースは、それらのスコープをエラボレーションします。 チェックポイントはオブジェクトを保持します。状態ファイルは文字列を記録しますがオブジェクトは記録しないため、オブジェクトを持つ変数があると状態ファイルの保存は失敗します。 @@ -251,8 +251,9 @@ package はそれぞれ独立したスコープとして 1 回だけ解析し、 (と内側のブロック)でだけ名前を見えるようにし、モジュール自身の宣言や import より優先されます。package の関数の中の名前は package の中で解決します。package の変数は、それを使うすべてのモジュール(Veryl からインスタンス化した SystemVerilog モジュールを含む)で共有される 1 つのオブジェクトで、初期化子も反映します。 -`sim.signal("p::v")` で参照できます。1 つの package 変数を複数のドライバが書く設計は、書き込む -モジュールのインスタンスをすべて数えて拒否します。package 変数のクロック・リセットとしての使用、定数でない package 変数の初期化子、 +`sim.signal("p::v")` で参照できます。どのプロセスも、複数のインスタンスのものでも書き込めますが、 +継続代入・`always_comb`・`always_ff` が書き込む場合はそれだけが書き込むものでなければならず、書き込む +モジュールのインスタンスをすべて数えて確認します(IEEE 1800-2023 6.5、9.2.2)。package 変数のクロック・リセットとしての使用、定数でない package 変数の初期化子、 package の net は未対応です([#1146](https://github.com/celox-sim/celox/issues/1146))。`export` 宣言(26.6)は、import した宣言をその package を import する側から見えるようにします。`export p::*;` が export するのは package が `p` から実際に import した名前だけです。export を経由した import は元の宣言を指すため、 @@ -376,8 +377,8 @@ static な output 引数も、代入しない経路では以前の値を保持 毎回新しい値を使い、実行時の状態に影響しません(13.4.3)。 値を保持する task ローカル変数と、定数でない static 初期化子は引き続き未対応です。 -これらには `automatic` を指定してください。package 関数の状態には、複数の手続きドライバーに関する -既存の package 変数の制約が適用されます。既定の寿命(`interface automatic`)が +これらには `automatic` を指定してください。package 関数の状態は package 変数で、 +すべてのインスタンスのプロセスが書き込めます。既定の寿命(`interface automatic`)が 使用先のモジュールと異なる interface は拒否します。 ### 実行時のループ