diff --git a/conformance/sv-tests/README.md b/conformance/sv-tests/README.md index 0a2ab9e79e4..1c96cdab5ea 100644 --- a/conformance/sv-tests/README.md +++ b/conformance/sv-tests/README.md @@ -90,6 +90,23 @@ from successful runs still reach the official assertion evaluator. The official runner timeout covers the complete invocation, including all variants. Elaboration/parsing cases do not execute variants. +Parameterized classes update fourteen more rows: both state modes for +`8.5--parameters`, `8.8--typed_constructor_param`, +`8.25--parametrized_class_extend`, `8.25.1--parametrized_class_scope_resolution` +and `8.26.3--type_access_implements` change from fail to pass. Each was +simulated and its displayed values checked, including the parameter that +`par_cls#()::b` reads and the base constructor argument passed by name in +`8.8--typed_constructor_param`. The negative +`8.26.6.2--parameter_type_conflict_unresolved` and +`8.26.6.3--diamond_relationship_parametrized` probes now fail for the reason +they test: an interface class inherits `T` from two different interface +classes or specializations without declaring its own. Full official runs at the +pinned revision report 1080 passing cases in 2state and 1091 in 4state, with no +passing case regressing; `8.25.1--parametrized_class_invalid_scope_resolution` +stays a passing negative case because `par_cls::b` outside the class is +rejected. `8.5--properties_enum` keeps failing because enumeration constants +declared in a class are not supported. + ## Running locally Use the locked development shell and install the pinned [`requirements.txt`](requirements.txt) in a Python environment. diff --git a/conformance/sv-tests/expected.tsv b/conformance/sv-tests/expected.tsv index fd3c5c5909b..bf5592271d7 100644 --- a/conformance/sv-tests/expected.tsv +++ b/conformance/sv-tests/expected.tsv @@ -1503,12 +1503,12 @@ chapter-8/8.23--scope_resolution.sv 2state pass chapter-8/8.23--scope_resolution.sv 4state pass chapter-8/8.24--out_of_block_methods.sv 2state pass chapter-8/8.24--out_of_block_methods.sv 4state pass -chapter-8/8.25--parametrized_class_extend.sv 2state fail -chapter-8/8.25--parametrized_class_extend.sv 4state fail +chapter-8/8.25--parametrized_class_extend.sv 2state pass +chapter-8/8.25--parametrized_class_extend.sv 4state pass chapter-8/8.25.1--parametrized_class_invalid_scope_resolution.sv 2state pass chapter-8/8.25.1--parametrized_class_invalid_scope_resolution.sv 4state pass -chapter-8/8.25.1--parametrized_class_scope_resolution.sv 2state fail -chapter-8/8.25.1--parametrized_class_scope_resolution.sv 4state fail +chapter-8/8.25.1--parametrized_class_scope_resolution.sv 2state pass +chapter-8/8.25.1--parametrized_class_scope_resolution.sv 4state pass chapter-8/8.26.2--implements.sv 2state pass chapter-8/8.26.2--implements.sv 4state pass chapter-8/8.26.2--implements_extends.sv 2state pass @@ -1517,8 +1517,8 @@ chapter-8/8.26.2--implements_multiple.sv 2state pass chapter-8/8.26.2--implements_multiple.sv 4state pass chapter-8/8.26.3--type_access_extends.sv 2state pass chapter-8/8.26.3--type_access_extends.sv 4state pass -chapter-8/8.26.3--type_access_implements.sv 2state fail -chapter-8/8.26.3--type_access_implements.sv 4state fail +chapter-8/8.26.3--type_access_implements.sv 2state pass +chapter-8/8.26.3--type_access_implements.sv 4state pass chapter-8/8.26.3--type_access_implements_invalid.sv 2state pass chapter-8/8.26.3--type_access_implements_invalid.sv 4state pass chapter-8/8.26.4--illegal_forward_def_implements.sv 2state pass @@ -1537,20 +1537,20 @@ chapter-8/8.26.6.1--name_conflict_unresolved.sv 2state pass chapter-8/8.26.6.1--name_conflict_unresolved.sv 4state pass chapter-8/8.26.6.2--parameter_type_conflict.sv 2state pass chapter-8/8.26.6.2--parameter_type_conflict.sv 4state pass -chapter-8/8.26.6.2--parameter_type_conflict_unresolved.sv 2state fail -chapter-8/8.26.6.2--parameter_type_conflict_unresolved.sv 4state fail +chapter-8/8.26.6.2--parameter_type_conflict_unresolved.sv 2state pass +chapter-8/8.26.6.2--parameter_type_conflict_unresolved.sv 4state pass chapter-8/8.26.6.3--diamond_relationship.sv 2state pass chapter-8/8.26.6.3--diamond_relationship.sv 4state pass -chapter-8/8.26.6.3--diamond_relationship_parametrized.sv 2state fail -chapter-8/8.26.6.3--diamond_relationship_parametrized.sv 4state fail +chapter-8/8.26.6.3--diamond_relationship_parametrized.sv 2state pass +chapter-8/8.26.6.3--diamond_relationship_parametrized.sv 4state pass chapter-8/8.26.7--partial_implementation.sv 2state pass chapter-8/8.26.7--partial_implementation.sv 4state pass chapter-8/8.27--forward_declaration.sv 2state pass chapter-8/8.27--forward_declaration.sv 4state pass chapter-8/8.4--instantiation.sv 2state pass chapter-8/8.4--instantiation.sv 4state pass -chapter-8/8.5--parameters.sv 2state fail -chapter-8/8.5--parameters.sv 4state fail +chapter-8/8.5--parameters.sv 2state pass +chapter-8/8.5--parameters.sv 4state pass chapter-8/8.5--properties.sv 2state pass chapter-8/8.5--properties.sv 4state pass chapter-8/8.5--properties_enum.sv 2state fail @@ -1565,8 +1565,8 @@ chapter-8/8.7--constructor_super.sv 2state pass chapter-8/8.7--constructor_super.sv 4state pass chapter-8/8.8--typed_constructor.sv 2state pass chapter-8/8.8--typed_constructor.sv 4state pass -chapter-8/8.8--typed_constructor_param.sv 2state fail -chapter-8/8.8--typed_constructor_param.sv 4state fail +chapter-8/8.8--typed_constructor_param.sv 2state pass +chapter-8/8.8--typed_constructor_param.sv 4state pass chapter-8/8.9--static_properties.sv 2state pass chapter-8/8.9--static_properties.sv 4state pass chapter-9/9.2.1--initial.sv 2state pass diff --git a/crates/celox-sv-analyzer/src/ast.rs b/crates/celox-sv-analyzer/src/ast.rs index 41751f3727f..b80165f580a 100644 --- a/crates/celox-sv-analyzer/src/ast.rs +++ b/crates/celox-sv-analyzer/src/ast.rs @@ -34,6 +34,25 @@ pub(super) struct AnalysisState { generate_items: generate::Memo, /// Classes laid out so far, by name. classes: std::cell::RefCell>>, + /// The constants and types of the scope that declares each class, which + /// its parameter defaults and body see (IEEE 1800-2023 8.25). + class_declaration_scopes: + std::cell::RefCell, HashMap)>>, + /// Set once the class methods of the scope being analyzed have their + /// signatures, after which a new specialization would have none. + class_specializations_frozen: std::cell::Cell, + /// The class specializations being made, which their own declarations + /// may name before they are complete. + class_specializations_building: std::cell::RefCell>, + /// How many class specializations are being made, one inside another. + class_specialization_depth: std::cell::Cell, + /// The specializations of classes made so far, in order. + class_specializations: std::cell::RefCell< + Vec<( + String, + std::rc::Rc, + )>, + >, } /// Syntax and specialization bindings for one scope within an analysis session. @@ -666,6 +685,9 @@ impl Module { export_symbols: bool, header_ports: Option<&port_owners::Selection<'_>>, ) -> Result { + // The scope makes its class specializations until its class methods + // have signatures. + syntax_tree.state.class_specializations_frozen.set(false); let unit = syntax_tree.scope_handle().unit(syntax_tree.declarations()); let is_package = unit.is_none_or(|unit| unit.kind == celox_sv_syntax::UnitKind::Package); let program = unit.is_some_and(|unit| unit.kind == celox_sv_syntax::UnitKind::Program); @@ -772,6 +794,8 @@ impl Module { .iter() .map(|parameter| parameter.name().to_string()) .collect(); + // Class parameter defaults are bound where the class is declared. + classes::specializations::declare_scopes(syntax_tree, &const_env, &type_aliases); let declaration_subroutines = with_imported(const_functions::symbolic_module_constant_functions( syntax_tree, @@ -903,6 +927,12 @@ impl Module { { return Err(AnalyzerError::Unsupported("ref port direction".to_string())); } + // The static properties of each class specialization are variables + // of the module (IEEE 1800-2023 8.9, 8.25). + classes::specializations::collect( + syntax_tree, + &PackedDimensions::new(HashMap::default(), &const_env, &type_aliases), + ); let mut signals = signals_from_scope(syntax_tree, &const_env, &type_aliases)?; signals.extend( array_parameters diff --git a/crates/celox-sv-analyzer/src/ast/classes.rs b/crates/celox-sv-analyzer/src/ast/classes.rs index 4d60ddf1d3c..48585e85f64 100644 --- a/crates/celox-sv-analyzer/src/ast/classes.rs +++ b/crates/celox-sv-analyzer/src/ast/classes.rs @@ -12,6 +12,8 @@ use std::rc::Rc; use super::*; use crate::system_functions::{HandleProperty, ObjectField, ObjectOp}; +pub(super) mod specializations; + /// Bit width of a handle, see `celox_design::HANDLE_WIDTH`. pub(super) const HANDLE_WIDTH: usize = 32; @@ -113,6 +115,10 @@ pub(super) struct Class { pub statics: Vec, /// Methods visible in the class, overrides replacing inherited ones. pub methods: Vec, + /// The parameters and typedefs of an interface class, its own and + /// those it inherits, each with the class that declares it (IEEE + /// 1800-2023 8.26.3). + pub declarations: Vec<(String, String)>, /// Bytes of an object. pub size: u32, pub has_constraints: bool, @@ -193,16 +199,71 @@ impl Class { &self.properties[self.base_properties..] } - /// The number of formals of the constructor, which takes the handle of - /// the object it initializes before them. - pub fn constructor_formals(&self, native: &celox_sv_syntax::Declarations) -> usize { - self.method("new").map_or(0, |method| { + /// The actuals that `arguments` of a constructor call pass to each + /// formal of the constructor, by position or by name (IEEE 1800-2023 + /// 13.5.4), `None` for an omitted one, which takes its default; and the + /// formals in the order their actuals are written, then the rest, which + /// is the order they are evaluated in. + pub fn constructor_arguments( + &self, + native: &celox_sv_syntax::Declarations, + arguments: &[celox_sv_syntax::Argument], + ) -> Converted<(Vec>, Vec)> { + let names = self.method("new").map_or_else(Vec::new, |method| { native .subroutine(method.native) .ports - .as_ref() - .map_or(0, Vec::len) - }) + .iter() + .flatten() + .map(|port| { + port.name + .as_ref() + .map(|name| instances::normalize_identifier(&name.spelling)) + }) + .collect() + }); + let mut actuals = vec![None; names.len()]; + let mut order = Vec::new(); + let mut named = false; + for (index, argument) in arguments.iter().enumerate() { + let index = match &argument.name { + Some(name) => { + named = true; + let name = instances::normalize_identifier(&name.spelling); + names + .iter() + .position(|formal| formal.as_ref() == Some(&name)) + .ok_or_else(|| { + unsupported(format!( + "constructor of class `{}` without an argument `{name}`", + self.name + )) + })? + } + None if named => { + return Err(unsupported("positional argument after named argument")); + } + None => index, + }; + let Some(actual) = actuals.get_mut(index) else { + return Err(unsupported(format!( + "constructor of class `{}` with {} arguments", + self.name, + arguments.len() + ))); + }; + // An omitted actual `.x()` binds its formal too. + if order.contains(&index) { + return Err(unsupported("constructor argument passed twice")); + } + order.push(index); + *actual = argument.value; + } + let unbound = (0..names.len()) + .filter(|index| !order.contains(index)) + .collect::>(); + order.extend(unbound); + Ok((actuals, order)) } /// The subroutine name of `method` of `owner`, and the variable name of @@ -280,23 +341,66 @@ impl Class { } } -/// The declaration of class `name`, if one exists. +/// The declaration of class `name`, or of the class it specializes, if one +/// exists. fn declaration<'a>( tree: &'a AnalysisContext<'_>, name: &str, ) -> Option<&'a celox_sv_syntax::ClassDeclaration> { + let name = specializations::generic(tree, name); tree.declarations() .classes .iter() .find(|class| instances::normalize_identifier(&class.name.spelling) == name) } +/// Whether a class named `name` is declared in the current scope or in the +/// compilation unit, where the scope sees it (IEEE 1800-2023 3.12.1). +pub(super) fn is_visible(tree: &AnalysisContext<'_>, name: &str) -> bool { + let native = tree.declarations(); + let scope = tree.root_unit().ok().map(|unit| unit.tokens); + native.classes.iter().any(|class| { + instances::normalize_identifier(&class.name.spelling) == name && { + let unit = enclosing_unit(native, class.tokens).map(|unit| unit.tokens); + unit.is_none() || unit == scope + } + }) +} + +/// Whether class `name` is declared in the source of the current scope. +pub(super) fn is_declared(tree: &AnalysisContext<'_>, name: &str) -> bool { + declaration(tree, name).is_some() +} + +/// The innermost module, interface, program or package of `native` whose +/// declaration contains `tokens`. +pub(super) fn enclosing_unit( + native: &celox_sv_syntax::Declarations, + tokens: celox_sv_syntax::TokenRange, +) -> Option<&celox_sv_syntax::Unit> { + native + .all_units() + .filter(|unit| unit.tokens.start <= tokens.start && tokens.end <= unit.tokens.end) + .min_by_key(|unit| unit.tokens.end - unit.tokens.start) +} + /// Whether `name` is an interface class (IEEE 1800-2023 8.26). pub(super) fn is_interface(tree: &AnalysisContext<'_>, name: &str) -> bool { declaration(tree, name).is_some_and(|declaration| declaration.interface) } -/// The classes and interface classes that body item `item` declares. +/// Whether `name` is a class declared with a parameter port list (IEEE +/// 1800-2023 8.25). +pub(super) fn is_parameterized(tree: &AnalysisContext<'_>, name: &str) -> bool { + tree.declarations().classes.iter().any(|class| { + class.parameter_ports.is_some() + && instances::normalize_identifier(&class.name.spelling) == name + }) +} + +/// The classes and interface classes that body item `item` declares: of a +/// parameterized class, the specializations made of it (IEEE 1800-2023 +/// 8.25). pub(super) fn item_classes( item: celox_sv_syntax::BodyItemId, tree: &AnalysisContext<'_>, @@ -313,10 +417,24 @@ pub(super) fn item_classes( .filter(|class| { item.tokens.start <= class.tokens.start && class.tokens.end <= item.tokens.end }) - .map(|class| instances::normalize_identifier(&class.name.spelling)) + .flat_map(|class| specializations(tree, class)) .collect() } +/// The specializations of class declaration `declaration`: the class itself +/// when it has no parameter port list. +fn specializations( + tree: &AnalysisContext<'_>, + declaration: &celox_sv_syntax::ClassDeclaration, +) -> Vec { + let name = instances::normalize_identifier(&declaration.name.spelling); + if declaration.parameter_ports.is_some() { + specializations::of(tree, &name) + } else { + vec![name] + } +} + /// The methods that class `name` implements, with their definitions: the /// method itself or, for an `extern` method, its out-of-block definition. /// A pure virtual method has none (IEEE 1800-2023 8.21). Each comes with @@ -339,7 +457,7 @@ pub(super) fn declared_methods( return Ok((method.subroutine, method.qualifiers.is_static)); } let method_name = instances::normalize_identifier(&subroutine.name.spelling); - out_of_block_definition(tree, name, &method_name) + out_of_block_definition(tree, &declaration.name.spelling, &method_name) .map(|id| (id, method.qualifiers.is_static)) .ok_or_else(|| { unsupported(format!( @@ -388,13 +506,18 @@ pub(super) fn base_arguments<'a>( /// The handle type of class `name`, if it is a class. pub(super) fn handle_type(tree: &AnalysisContext<'_>, name: &str) -> Option { declaration(tree, name)?; + Some(handle(name)) +} + +/// The handle type of class `name`. +pub(super) fn handle(name: &str) -> Type { let mut ty = Type::new(TypeKind::Object); ty.packed_ranges.push(PackedRange::new( ConstExpr::Literal((HANDLE_WIDTH - 1).to_string()), ConstExpr::Literal("0".into()), )); ty.class = Some(name.to_owned()); - Some(ty) + ty } /// The class `name`, laid out with its bases. @@ -409,21 +532,46 @@ pub(super) fn class( } let declaration = declaration(tree, name).ok_or_else(|| unsupported(format!("class `{name}`")))?; + let (env, aliases) = specializations::scope(tree, name, env, aliases); + let (env, aliases) = (&env, &aliases); let native = tree.declarations(); - let interfaces = declaration - .interfaces - .iter() - .map(|&interface| interface_name(tree, interface, env, aliases)) - .collect::>>()?; + // The specialization of an interface class named the interface classes + // it extends where its header is, as a class names its base below. + let recorded = declaration + .interface + .then(|| specializations::lookup(tree, name)) + .flatten() + .map(|specialization| specialization.bases.clone()) + .filter(|bases| { + bases.len() == declaration.interfaces.len() + && bases.iter().all(|base| { + self::declaration(tree, base).is_some_and(|declaration| declaration.interface) + }) + }); + let interfaces = match recorded { + Some(bases) => bases, + None => declaration + .interfaces + .iter() + .map(|&interface| interface_name(tree, interface, env, aliases)) + .collect::>>()?, + }; if declaration.interface { return interface_class(tree, name, declaration, interfaces, env, aliases); } let base = match &declaration.base { None => None, Some(base) => { - let ty = type_binding::procedural_type(base.data_type, native, tree, env, aliases)? - .and_then(|ty| ty.class.clone()) - .ok_or_else(|| unsupported("base class type"))?; + // The specialization named its base where the class header is, + // before the declarations it inherits could hide those names. + let recorded = specializations::lookup(tree, name) + .and_then(|specialization| specialization.bases.first().cloned()); + let ty = match recorded { + Some(ty) => ty, + None => type_binding::procedural_type(base.data_type, native, tree, env, aliases)? + .and_then(|ty| ty.class.clone()) + .ok_or_else(|| unsupported("base class type"))?, + }; Some(class(tree, &ty, env, aliases)?) } }; @@ -513,11 +661,13 @@ pub(super) fn class( let native_id = if method.qualifiers.is_pure { method.subroutine } else if subroutine.prototype { - out_of_block_definition(tree, name, &method_name).ok_or_else(|| { - unsupported(format!( - "extern method `{name}::{method_name}` without a body" - )) - })? + out_of_block_definition(tree, &declaration.name.spelling, &method_name).ok_or_else( + || { + unsupported(format!( + "extern method `{name}::{method_name}` without a body" + )) + }, + )? } else { method.subroutine }; @@ -589,6 +739,7 @@ pub(super) fn class( base_properties, statics, methods, + declarations: Vec::new(), size: size.max(1), }); tree.state @@ -630,12 +781,40 @@ fn interface_class( aliases: &HashMap, ) -> Converted> { let native = tree.declarations(); + // The parameters and typedefs it declares hide inherited ones; those it + // inherits from one interface class in several ways are one (8.26.6.3). + let mut declarations = own_declarations(native, declaration) + .into_iter() + .map(|own| (own, name.to_owned())) + .collect::>(); + let own = declarations.len(); let mut methods: Vec = Vec::new(); for interface in &interfaces { - for method in &class(tree, interface, env, aliases)?.methods { + let interface = class(tree, interface, env, aliases)?; + for method in &interface.methods { methods.retain(|known| known.name != method.name); methods.push(method.clone()); } + for (inherited, origin) in &interface.declarations { + if declarations[..own] + .iter() + .any(|(known, _)| known == inherited) + { + continue; + } + match declarations.iter().find(|(known, _)| known == inherited) { + Some((_, first)) if first != origin => { + return Err(AnalyzerError::ConflictingInterfaceClassDeclaration { + class: name.to_owned(), + name: inherited.clone(), + first: first.clone(), + second: origin.clone(), + }); + } + Some(_) => {} + None => declarations.push((inherited.clone(), origin.clone())), + } + } } for method in &declaration.methods { let subroutine = native.subroutine(method.subroutine); @@ -670,6 +849,7 @@ fn interface_class( base_properties: 0, statics: Vec::new(), methods, + declarations, size: 1, }); tree.state @@ -679,6 +859,28 @@ fn interface_class( Ok(class) } +/// The names of the parameters and typedefs that class `declaration` +/// declares. +fn own_declarations( + native: &celox_sv_syntax::Declarations, + declaration: &celox_sv_syntax::ClassDeclaration, +) -> Vec { + let parameters = declaration + .parameter_ports + .iter() + .chain(&declaration.parameters) + .flat_map(|&id| &native.parameter_declaration(id).parameters) + .map(|parameter| ¶meter.name); + let aliases = declaration + .type_aliases + .iter() + .map(|&id| &native.type_alias(id).name); + parameters + .chain(aliases) + .map(|name| instances::normalize_identifier(&name.spelling)) + .collect() +} + /// The return type of subroutine `id`, `None` for a task or `void`. fn return_type( tree: &AnalysisContext<'_>, @@ -700,6 +902,7 @@ fn out_of_block_definition( method: &str, ) -> Option { let native = tree.declarations(); + let class = instances::normalize_identifier(class); native.subroutine_ids().find(|&id| { let subroutine = native.subroutine(id); !subroutine.prototype @@ -763,11 +966,13 @@ fn object_classes( ) -> Converted>> { let mut classes = Vec::new(); let mut ids = HashMap::default(); - for declaration in &tree.declarations().classes { - if declaration.interface || declaration.virtual_class { - continue; - } - let name = instances::normalize_identifier(&declaration.name.spelling); + let names = tree + .declarations() + .classes + .iter() + .filter(|declaration| !declaration.interface && !declaration.virtual_class) + .flat_map(|declaration| specializations(tree, declaration)); + for name in names { // A class that cannot be laid out has no objects. let Ok(class) = class(tree, &name, env, aliases) else { continue; diff --git a/crates/celox-sv-analyzer/src/ast/classes/specializations.rs b/crates/celox-sv-analyzer/src/ast/classes/specializations.rs new file mode 100644 index 00000000000..04003afe908 --- /dev/null +++ b/crates/celox-sv-analyzer/src/ast/classes/specializations.rs @@ -0,0 +1,1029 @@ +//! Parameterized classes (IEEE 1800-2023 8.25). +//! +//! Each unique set of parameter values and types of a parameterized class is +//! a specialization: a class of its own, named by the class and the set, +//! such as `C#(N=4,T=bit)`. A specialization keeps the constants and types +//! its declarations see: the parameters, and the scope `C::`, which inside +//! the class refers to the specialization being declared, while the type +//! `C` is the default specialization there too. A class without parameters +//! is its own only specialization. + +use std::rc::Rc; + +use super::*; +use celox_sv_syntax::{Argument, ExprKind, ParameterKind}; + +/// The parameters of one specialization of a class. +#[derive(Debug)] +pub(in crate::ast) struct Specialization { + /// The name of the class declaration. + pub generic: String, + /// The values of the value parameters, with their markers. + pub env: HashMap, + /// The constants the value parameters hide without a value of their + /// own, as a string or four-state value does. + pub hidden: Vec, + /// The literals that replace the value parameters. + pub literals: HashMap, + /// The type parameters and typedefs, and the class name itself. + pub aliases: HashMap, + /// The class the specialization extends, or the interface classes an + /// interface class extends, whose parameters and typedefs it inherits + /// (IEEE 1800-2023 8.13, 8.26.3). + pub bases: Vec, +} + +/// The types that a scope inside the class declared as `own` sees from +/// specialization `specialization` of its lineage: not the name of an +/// inherited class, which outside that class does not refer to its +/// specialization. +fn inherited<'a>( + own: &'a str, + specialization: &'a Specialization, +) -> impl Iterator + 'a { + specialization + .aliases + .iter() + .filter(move |(key, _)| { + specialization.generic == own || **key != scope_key(&specialization.generic) + }) + .map(|(key, ty)| (key.clone(), ty.clone())) +} + +/// The specialization `name` and the ones it inherits from, each after +/// those it inherits from. +fn lineage(tree: &AnalysisContext<'_>, name: &str) -> Vec> { + let mut lineage: Vec> = Vec::new(); + let mut seen = HashSet::default(); + // A class that extends itself is rejected where it is laid out. + let mut pending = vec![(name.to_owned(), false)]; + while let Some((name, visited)) = pending.pop() { + let Some(specialization) = lookup(tree, &name) else { + continue; + }; + if visited { + lineage.push(specialization); + continue; + } + if !seen.insert(name.clone()) { + continue; + } + pending.push((name, true)); + pending.extend( + specialization + .bases + .iter() + .rev() + .map(|base| (base.clone(), false)), + ); + } + lineage +} + +/// Bound on the specializations of one design, which a class that +/// specializes itself with ever new parameters would exceed. +const MAX_SPECIALIZATIONS: usize = 1024; + +/// Bound on specializations made while making another, which a class that +/// extends a specialization of itself would exceed. +const MAX_NESTING: usize = 64; + +/// A specialization in `class_specializations_building`, which it leaves +/// when dropped. +struct Building<'a>(&'a std::cell::RefCell>); + +impl Drop for Building<'_> { + fn drop(&mut self) { + self.0.borrow_mut().pop(); + } +} + +/// The specialization being made, which [`specialize`] leaves when dropped. +struct Nesting<'a>(&'a std::cell::Cell); + +impl Drop for Nesting<'_> { + fn drop(&mut self) { + self.0.set(self.0.get() - 1); + } +} + +/// The key under which the scope of a class finds the specialization being +/// declared: inside a parameterized class and its out-of-block methods, +/// its name alone as the prefix of `::` refers to it, while as a type the +/// name alone is the default specialization (IEEE 1800-2023 8.25, 8.25.1). +pub(in crate::ast) fn scope_key(generic: &str) -> String { + format!("{generic}::") +} + +/// The specialization `name`, if one has been made. +pub(in crate::ast) fn lookup(tree: &AnalysisContext<'_>, name: &str) -> Option> { + tree.state + .class_specializations + .borrow() + .iter() + .find(|(known, _)| known == name) + .map(|(_, specialization)| specialization.clone()) +} + +/// The class declaration that class `name` specializes. +pub(in crate::ast) fn generic(tree: &AnalysisContext<'_>, name: &str) -> String { + lookup(tree, name).map_or_else( + || name.to_owned(), + |specialization| specialization.generic.clone(), + ) +} + +/// The specializations made of the class declared as `generic`, in the +/// order they were made. +pub(in crate::ast) fn of(tree: &AnalysisContext<'_>, generic: &str) -> Vec { + tree.state + .class_specializations + .borrow() + .iter() + .filter(|(_, specialization)| specialization.generic == generic) + .map(|(name, _)| name.clone()) + .collect() +} + +/// `env` and `aliases` with the parameters of class `name` added: the +/// scope the declarations of the class see. +pub(in crate::ast) fn scope( + tree: &AnalysisContext<'_>, + name: &str, + env: &HashMap, + aliases: &HashMap, +) -> (HashMap, HashMap) { + let mut env = env.clone(); + let mut aliases = aliases.clone(); + let own = generic(tree, name); + for specialization in lineage(tree, name) { + env.extend(specialization.env.clone()); + for key in &specialization.hidden { + env.remove(key); + } + aliases.extend(inherited(&own, &specialization)); + } + (env, aliases) +} + +/// `dimensions` and `literals` with the parameters of class `name` added, +/// for binding the bodies of its methods. +pub(in crate::ast) fn body_scope( + tree: &AnalysisContext<'_>, + name: &str, + dimensions: &PackedDimensions, + literals: &HashMap, +) -> (PackedDimensions, HashMap) { + let mut dimensions = dimensions.clone(); + let mut literals = literals.clone(); + let own = generic(tree, name); + for specialization in lineage(tree, name) { + dimensions.const_env.extend(specialization.env.clone()); + for key in &specialization.hidden { + dimensions.const_env.remove(key); + } + dimensions + .type_aliases + .extend(inherited(&own, &specialization)); + literals.extend(specialization.literals.clone()); + } + (dimensions, literals) +} + +/// The value of parameter `parameter` of class `name`, as a literal. +pub(in crate::ast) fn parameter( + tree: &AnalysisContext<'_>, + name: &str, + parameter: &str, +) -> Option { + lineage(tree, name) + .iter() + .rev() + .find_map(|specialization| specialization.literals.get(parameter).cloned()) +} + +/// The type parameter or typedef `member` of class `name`, declared in it +/// or inherited. +pub(in crate::ast) fn member_type( + tree: &AnalysisContext<'_>, + name: &str, + member: &str, +) -> Option { + let generic = generic(tree, name); + lineage(tree, name).iter().rev().find_map(|specialization| { + // The class name itself is not a member. + (member != scope_key(&specialization.generic) && member != scope_key(&generic)) + .then(|| specialization.aliases.get(member).cloned()) + .flatten() + }) +} + +/// The specialization of class `generic` that `arguments`, bound in +/// `context`, assign its parameters (IEEE 1800-2023 8.25), made if it is new. +pub(in crate::ast) fn specialize( + tree: &AnalysisContext<'_>, + generic: &str, + arguments: &[Argument], + context: &PackedDimensions, +) -> Converted { + let depth = &tree.state.class_specialization_depth; + if depth.get() >= MAX_NESTING { + return Err(unsupported(format!( + "class specializations nested more than {MAX_NESTING} deep, as when class `{generic}` extends a specialization of itself" + ))); + } + depth.set(depth.get() + 1); + let _nesting = Nesting(depth); + let native = tree.declarations(); + let declaration = super::declaration(tree, generic) + .ok_or_else(|| unsupported(format!("class `{generic}`")))?; + // The parameters an assignment may set: those of the parameter port + // list that are not local, in order. + let ports = declaration + .parameter_ports + .iter() + .flat_map(|&id| &native.parameter_declaration(id).parameters) + .filter(|parameter| !parameter.local) + .collect::>(); + let mut values = HashMap::::default(); + let mut types = HashMap::::default(); + // The formals assigned, also by an empty named assignment. + let mut assigned = HashSet::::default(); + let mut named = false; + for (index, argument) in arguments.iter().enumerate() { + let parameter = match &argument.name { + Some(name) => { + named = true; + let name = instances::normalize_identifier(&name.spelling); + ports + .iter() + .find(|parameter| { + instances::normalize_identifier(¶meter.name.spelling) == name + }) + .ok_or_else(|| AnalyzerError::UnknownClassParameter { + class: generic.to_owned(), + name, + })? + } + // An ordered assignment cannot follow a named one (A.1.3). + None if named => { + return Err(unsupported("positional parameter value after a named one")); + } + None => ports.get(index).ok_or_else(|| { + unsupported(format!("more parameter values than class `{generic}` has")) + })?, + }; + let name = instances::normalize_identifier(¶meter.name.spelling); + if !assigned.insert(name.clone()) { + return Err(unsupported(format!( + "duplicate parameter assignment `{name}`" + ))); + } + // An empty named assignment keeps the default. + let Some(value) = argument.value else { + continue; + }; + match parameter.kind { + ParameterKind::Type { .. } => { + types.insert(name, type_argument(tree, value, context)?); + } + ParameterKind::Value { .. } => { + values.insert(name, value_argument(tree, value, context)?); + } + } + } + // The declarations of the class are bound in the scope that declares it, + // the actuals in the scope that names the specialization. + let (mut env, mut aliases) = declaration_scope(tree, generic) + .unwrap_or_else(|| ((*context.const_env).clone(), context.type_aliases.clone())); + let mut parameters = Parameters { + values, + types, + literals: HashMap::default(), + lowered: Vec::new(), + spelled: Vec::new(), + own_env: HashMap::default(), + own_aliases: HashMap::default(), + }; + if let Some(id) = declaration.parameter_ports { + parameters.bind(tree, declaration, id, true, &mut env, &mut aliases)?; + } + if let Some(name) = parameters + .values + .keys() + .chain(parameters.types.keys()) + .next() + { + return Err(unsupported(format!( + "assignment of local parameter `{name}`" + ))); + } + let name = if declaration.parameter_ports.is_some() { + format!("{generic}#({})", parameters.spelled.join(",")) + } else { + generic.to_owned() + }; + // A declaration of the class may name the specialization being made, + // as the type `C` of the default specialization does (8.25). + if lookup(tree, &name).is_some() + || tree + .state + .class_specializations_building + .borrow() + .contains(&name) + { + return Ok(name); + } + if tree.state.class_specializations_frozen.get() { + return Err(unsupported(format!( + "specialization `{name}` that only a procedure names, as with a value of a procedural localparam" + ))); + } + if tree.state.class_specializations.borrow().len() >= MAX_SPECIALIZATIONS { + return Err(unsupported(format!( + "more than {MAX_SPECIALIZATIONS} class specializations" + ))); + } + tree.state + .class_specializations_building + .borrow_mut() + .push(name.clone()); + let _building = Building(&tree.state.class_specializations_building); + // The bases are named in the scope of the parameters; a class does not + // inherit the declarations of the interface classes it implements. + let inherited = match &declaration.base { + Some(base) => vec![base.data_type], + None if declaration.interface => declaration.interfaces.clone(), + None => Vec::new(), + }; + let mut bases = Vec::new(); + for id in inherited { + if let Some(base) = type_binding::procedural_type(id, native, tree, &env, &aliases)? + .and_then(|ty| ty.class.clone()) + { + bases.push(base); + } + } + // The body sees the parameters and types of the bases, hidden by the + // class's own, and the scope of the specialization (8.25.1). + for base in &bases { + (env, aliases) = scope(tree, base, &env, &aliases); + } + for (key, value) in ¶meters.own_env { + match value { + Some(value) => env.insert(key.clone(), *value), + None => env.remove(key), + }; + } + aliases.extend( + parameters + .own_aliases + .iter() + .map(|(key, ty)| (key.clone(), ty.clone())), + ); + aliases.insert(scope_key(generic), super::handle(&name)); + // The body parameters and typedefs in the order the body declares them. + let mut body = declaration + .parameters + .iter() + .map(|&id| (native.parameter_declaration(id).tokens.start, Ok(id))) + .chain( + declaration + .type_aliases + .iter() + .map(|&id| (native.type_alias(id).tokens.start, Err(id))), + ) + .collect::>(); + body.sort_by_key(|(start, _)| *start); + for (_, item) in body { + match item { + Ok(id) => parameters.bind(tree, declaration, id, false, &mut env, &mut aliases)?, + Err(id) => { + let alias = native.type_alias(id); + let celox_sv_syntax::TypeAliasTarget::DataType(target) = alias.target else { + continue; + }; + // The type is fixed in the scope of the parameters. A typedef + // that cannot be bound is left out; a use of it reports the + // type unknown. + let context = PackedDimensions::new(HashMap::default(), &env, &aliases); + let ty = type_binding::procedural_type(target, native, tree, &env, &aliases) + .ok() + .flatten() + .and_then(|ty| { + let ranges = constant_binding::bind_unpacked_ranges( + &alias.dimensions, + tree, + &context, + ) + .ok()?; + type_parameters::resolve( + &tree.state, + types::type_with_unpacked_ranges(ty, ranges), + &env, + ) + }); + if let Some(ty) = ty { + aliases.insert(instances::normalize_identifier(&alias.name.spelling), ty); + } + } + } + } + tree.state.class_specializations.borrow_mut().push(( + name.clone(), + Rc::new(Specialization { + generic: generic.to_owned(), + hidden: parameters + .own_env + .iter() + .filter(|(key, value)| value.is_none() && !env.contains_key(*key)) + .map(|(key, _)| key.clone()) + .collect(), + env, + literals: parameters.literals, + aliases, + bases, + }), + )); + Ok(name) +} + +/// The parameters of a specialization as [`specialize`] binds them. +struct Parameters { + /// The values and types the assignment gives, until they are bound. + values: HashMap, + types: HashMap, + literals: HashMap, + lowered: Vec, + /// The parameters of the port list as the name of the specialization + /// spells them. + spelled: Vec, + /// The constants and types the class declares itself, which hide those + /// of its bases; a constant without a value hides one of a base too. + own_env: HashMap>, + own_aliases: HashMap, +} + +impl Parameters { + /// Bind parameter declaration `id` of class `declaration`, one of its + /// parameter port list when `port`, in `env` and `aliases`. + fn bind( + &mut self, + tree: &AnalysisContext<'_>, + declaration: &celox_sv_syntax::ClassDeclaration, + id: celox_sv_syntax::ParameterDeclarationId, + port: bool, + env: &mut HashMap, + aliases: &mut HashMap, + ) -> Converted<()> { + let native = tree.declarations(); + for parameter in &native.parameter_declaration(id).parameters { + let name = instances::normalize_identifier(¶meter.name.spelling); + // A body parameter of a class with a parameter port list is + // local (8.25, 6.20.1). + let local = parameter.local || !port && declaration.parameter_ports.is_some(); + match parameter.kind { + ParameterKind::Type { default } => { + let ty = match self.types.remove(&name).filter(|_| !local) { + Some(ty) => ty, + None => { + let id = default.ok_or_else(|| { + unsupported(format!("type parameter `{name}` without a type")) + })?; + type_binding::procedural_type(id, native, tree, env, aliases)? + .ok_or_else(|| { + unsupported(format!("type of type parameter `{name}`")) + })? + } + }; + // The type is fixed in the scope that assigns it. + let ty = type_parameters::resolve(&tree.state, ty, env) + .ok_or_else(|| unsupported(format!("type of type parameter `{name}`")))?; + if port { + self.spelled.push(format!("{name}={}", spelling(&ty))); + } + aliases.insert(name.clone(), ty.clone()); + self.own_aliases.insert(name, ty); + } + ParameterKind::Value { .. } => { + // The parameter hides all of a constant of the same + // name, whose value a string or four-state value + // does not replace. + let mut keys = parameters::binding_keys(&name, env, 0); + for key in &keys { + env.remove(key); + } + let mut overrides = HashMap::default(); + if !local && let Some(value) = self.values.remove(&name) { + overrides.insert(name.clone(), value); + } + let first = self.lowered.len(); + parameters::parameters_from_native( + &[parameter], + tree, + &mut self.lowered, + local, + env, + aliases, + &overrides, + )?; + let mut typed = true; + for parameter in self.lowered[first..].iter().cloned() { + typed &= parameter.has_declared_type; + keys.extend(parameters::binding_keys( + &name, + env, + parameter.packed_ranges.len(), + )); + constants::bind_generate_parameter( + &tree.state, + parameter, + env, + &mut self.literals, + ); + } + // A parameter without a type takes the type of its value, + // which tells specializations apart too (6.20.2). A + // string or four-state value has its literal only. + let spelling = match (env.get(&name), self.literals.get(&name)) { + (Some(value), _) if typed => value.to_string(), + (_, Some(Expr::Literal(literal))) => literal.clone(), + (Some(value), _) => value.to_string(), + _ => { + return Err(unsupported(format!( + "class parameter `{name}` without a constant value" + ))); + } + }; + if port { + self.spelled.push(format!("{name}={spelling}")); + } + for key in keys { + let value = env.get(&key).copied(); + self.own_env.insert(key, value); + } + } + } + } + Ok(()) + } +} + +/// Record `env` and `aliases`, those of the current scope, as the scope that +/// declares each class of it, until [`collect`] finds the generate scopes +/// around their declarations: elaborating those scopes binds the types they +/// declare, specializations among them. +pub(in crate::ast) fn declare_scopes( + tree: &AnalysisContext<'_>, + env: &HashMap, + aliases: &HashMap, +) { + let native = tree.declarations(); + let scope = tree.root_unit().ok().map(|unit| unit.tokens); + let mut scopes = tree.state.class_declaration_scopes.borrow_mut(); + for class in &native.classes { + if super::enclosing_unit(native, class.tokens).map(|unit| unit.tokens) == scope { + scopes.insert( + instances::normalize_identifier(&class.name.spelling), + (env.clone(), aliases.clone()), + ); + } + } +} + +/// The constants and types of the scope that declares class `generic`, +/// which [`collect`] records. +fn declaration_scope( + tree: &AnalysisContext<'_>, + generic: &str, +) -> Option<(HashMap, HashMap)> { + tree.state + .class_declaration_scopes + .borrow() + .get(generic) + .cloned() +} + +/// The type that argument `id` of a type parameter names. +fn type_argument( + tree: &AnalysisContext<'_>, + id: celox_sv_syntax::ExprId, + context: &PackedDimensions, +) -> Converted { + let native = tree.declarations(); + let ty = match &native.expression(id).kind { + ExprKind::Type(ty) => type_binding::bind(*ty, tree, context)?, + ExprKind::Name(name) => { + let name = instances::normalize_identifier(&name.spelling); + match context.type_aliases.get(&name) { + Some(ty) => Some(ty.clone()), + None if super::declaration(tree, &name).is_some() => { + let name = specialize(tree, &name, &[], context)?; + Some(super::handle(&name)) + } + None => None, + } + } + ExprKind::Parameterized { + expression, + arguments, + } => match &native.expression(*expression).kind { + ExprKind::Name(name) => { + let name = specialize( + tree, + &instances::normalize_identifier(&name.spelling), + arguments, + context, + )?; + Some(super::handle(&name)) + } + _ => None, + }, + // A type of a class, `C::T` or `C#(...)::T`, or of a package + // (IEEE 1800-2023 8.23, 26.3). + ExprKind::Member { + expression, + separator, + name, + } if separator == "::" => { + let member = instances::normalize_identifier(&name.spelling); + let class = match &native.expression(*expression).kind { + ExprKind::Name(scope) => { + let scope = instances::normalize_identifier(&scope.spelling); + if super::is_visible(tree, &scope) { + // Inside the class, its name refers to the + // specialization being declared (8.25). + match context + .type_aliases + .get(&scope_key(&scope)) + .and_then(|ty| ty.class.clone()) + { + Some(class) => Some(class), + None => Some(specialize(tree, &scope, &[], context)?), + } + } else { + let qualified = scope::qualified_name(&tree.state, &scope, &member); + return finish( + context.type_aliases.get(&qualified).cloned(), + context, + tree, + ); + } + } + ExprKind::Parameterized { + expression, + arguments, + } => match &native.expression(*expression).kind { + ExprKind::Name(scope) => Some(specialize( + tree, + &instances::normalize_identifier(&scope.spelling), + arguments, + context, + )?), + _ => None, + }, + _ => None, + }; + class.and_then(|class| member_type(tree, &class, &member)) + } + _ => None, + }; + finish(ty, context, tree) +} + +/// The type argument `ty`, bound in `context`, fixed there and checked. +fn finish( + ty: Option, + context: &PackedDimensions, + tree: &AnalysisContext<'_>, +) -> Converted { + let ty = ty.ok_or_else(|| unsupported("class type parameter value"))?; + // The bounds are those of the scope that assigns the type. + let ty = type_parameters::resolve(&tree.state, ty, &context.const_env) + .ok_or_else(|| unsupported("class type parameter value"))?; + // Each enumeration declaration is a type of its own, which the bound + // type does not tell apart from another of the same base (6.19). + if ty.is_enum { + return Err(unsupported( + "enumeration type as a class type parameter value", + )); + } + // So is each struct or union declaration (6.22.1), whose identity the + // bound type does not keep either. + if !ty.members.is_empty() { + return Err(unsupported( + "struct or union type as a class type parameter value", + )); + } + Ok(ty) +} + +/// The constant value of argument `id` of a value parameter, as a literal +/// independent of the scope it was written in, with the width and signing +/// of the expression, which a parameter without a type takes (6.20.2). +fn value_argument( + tree: &AnalysisContext<'_>, + id: celox_sv_syntax::ExprId, + context: &PackedDimensions, +) -> Converted { + let expr = constant_binding::bind(id, tree, context)? + .ok_or_else(|| unsupported("class parameter value that is not constant"))?; + // An unbased unsized literal such as `'1` fills the width of the formal, + // which it takes when the parameter is bound (5.7.1). + if let ConstExpr::Literal(literal) = &expr + && literal.len() == 2 + && literal.starts_with('\'') + { + return Ok(expr); + } + let Some(value) = eval_ast_const_expr(&tree.state, &expr, &context.const_env) else { + // A string or four-state value is its literal, and so is the value + // of a real expression. + return match expr { + ConstExpr::Literal(_) => Ok(expr), + _ => match parameters::real_literal( + &expr, + TypeKind::Real, + &context.const_env, + &HashMap::default(), + ) { + Some(Expr::Literal(literal)) => Ok(ConstExpr::Literal(literal)), + _ => Err(unsupported("class parameter value that is not constant")), + }, + }; + }; + let ty = type_binding::expression_type(id, tree, context)? + .ok_or_else(|| unsupported("class parameter value without a type"))?; + Ok(ConstExpr::Literal(format_typed_parameter_literal( + value, ty.width, ty.signed, + ))) +} + +/// A spelling of type `ty` that tells it apart from other types, for the +/// name of a specialization. +fn spelling(ty: &Type) -> String { + let mut spelled = match (ty.class(), ty.kind()) { + (Some(class), _) => class.to_owned(), + (None, TypeKind::Real) => "real".to_owned(), + (None, TypeKind::Shortreal) => "shortreal".to_owned(), + (None, TypeKind::String) => "string".to_owned(), + (None, TypeKind::Object) => "object".to_owned(), + (None, TypeKind::Bit) => "bit".to_owned(), + // `reg` is `logic` (6.11.2). + (None, TypeKind::Logic | TypeKind::Implicit | TypeKind::Reg) => "logic".to_owned(), + }; + let integral = ty.class().is_none() + && !matches!( + ty.kind(), + TypeKind::Real | TypeKind::Shortreal | TypeKind::String | TypeKind::Object + ); + if integral && ty.is_signed() { + spelled.push_str(" signed"); + } + let bound = |expr: &ConstExpr| match expr { + ConstExpr::Literal(literal) => literal.clone(), + expr => format!("{expr:?}"), + }; + if integral { + for range in ty.packed_ranges() { + spelled.push_str(&format!("[{}:{}]", bound(&range.left), bound(&range.right))); + } + // An element of a signed named type is signed although the array + // is not (7.4.1). + if let Some(depth) = ty.signed_element_depth { + spelled.push_str(&format!(" signed@{depth}")); + } + } + // Unpacked dimensions of any element type are part of the type, told + // apart from packed ones; `[2]` is `[0:1]` (7.4.2). + for range in ty.unpacked_ranges() { + spelled.push_str(&format!( + " [{}:{}]", + bound(&range.left), + bound(&range.right) + )); + } + if ty.is_enum || !ty.members.is_empty() { + // An aggregate is told apart by its whole structure. + use std::hash::{Hash, Hasher}; + let mut hasher = fxhash::FxHasher::default(); + ty.hash(&mut hasher); + spelled.push_str(&format!("#{:016x}", hasher.finish())); + } + spelled +} + +/// Make the specializations that the types and class scopes of the current +/// module name, and the default specialization of each parameterized +/// interface class, which is checked even when nothing names it. A name +/// inside a class is bound in each specialization of the class, until no +/// new specialization appears. +pub(in crate::ast) fn collect(tree: &AnalysisContext<'_>, context: &PackedDimensions) { + tree.state.class_specializations_frozen.set(false); + let Ok(unit) = tree.root_unit() else { + return; + }; + let native = tree.declarations(); + let within = |outer: celox_sv_syntax::TokenRange, inner: celox_sv_syntax::TokenRange| { + outer.start <= inner.start && inner.end <= outer.end + }; + let classes = native + .classes + .iter() + .filter(|class| within(unit.tokens, class.tokens)) + .collect::>(); + if classes.is_empty() { + return; + } + let names = classes + .iter() + .map(|class| instances::normalize_identifier(&class.name.spelling)) + .collect::>(); + // The class scopes: each class declaration, and each out-of-block + // method definition, which is in the scope of its class (8.24). + let mut scopes = classes + .iter() + .map(|class| { + ( + class.tokens, + instances::normalize_identifier(&class.name.spelling), + ) + }) + .collect::>(); + for id in native.subroutine_ids() { + let subroutine = native.subroutine(id); + if let [scope] = subroutine.scope.as_slice() + && within(unit.tokens, subroutine.tokens) + { + let class = instances::normalize_identifier(&scope.name.spelling); + if names.contains(&class) { + scopes.push((subroutine.tokens, class)); + } + } + } + // The innermost class scope that contains `tokens`. + let enclosing = |tokens: celox_sv_syntax::TokenRange| { + scopes + .iter() + .filter(|(scope, _)| within(*scope, tokens)) + .min_by_key(|(scope, _)| scope.end - scope.start) + .map(|(_, class)| class.clone()) + }; + let mut references: Vec<( + Option, + String, + &[Argument], + celox_sv_syntax::TokenRange, + )> = Vec::new(); + for class in &classes { + if class.parameter_ports.is_none() || class.interface { + references.push(( + None, + instances::normalize_identifier(&class.name.spelling), + &[], + class.tokens, + )); + } + } + for ty in &native.types { + if !within(unit.tokens, ty.tokens) { + continue; + } + // A class, or the class scope of a type it declares, `C#(...)::T`. + // An unadorned `C::T` names the specialization being declared + // inside `C`, and needs a specialization elsewhere (8.25.1). + if let celox_sv_syntax::DataTypeKind::Named(path) = &ty.kind + && let [segment] | [segment, _] = path.as_slice() + && (path.len() == 1 || segment.arguments.is_some()) + { + let name = instances::normalize_identifier(&segment.name.spelling); + if names.contains(&name) { + references.push(( + enclosing(ty.tokens), + name, + segment.arguments.as_deref().unwrap_or_default(), + ty.tokens, + )); + } + } + } + for expression in &native.expressions { + if !within(unit.tokens, expression.tokens) { + continue; + } + if let ExprKind::Parameterized { + expression: scope, + arguments, + } = &expression.kind + && let ExprKind::Name(name) = &native.expression(*scope).kind + { + let name = instances::normalize_identifier(&name.spelling); + if names.contains(&name) { + references.push(( + enclosing(expression.tokens), + name, + arguments, + expression.tokens, + )); + } + } + } + // Outside classes, an assignment is bound in each generate scope that + // contains it, which may give its genvars different values. + let items = + generate::items(tree, &context.const_env, &context.type_aliases).unwrap_or_default(); + // The scope that declares each class: the innermost generate scope + // around its declaration, or the module. + for class in &classes { + let item = items + .iter() + .filter(|item| within(native.body_item(item.id).tokens, class.tokens)) + .min_by_key(|item| { + let tokens = native.body_item(item.id).tokens; + tokens.end - tokens.start + }); + let scope = match item { + Some(item) => ( + (*item.env).clone(), + item.type_aliases(&context.type_aliases).into_owned(), + ), + None => ((*context.const_env).clone(), context.type_aliases.clone()), + }; + tree.state + .class_declaration_scopes + .borrow_mut() + .insert(instances::normalize_identifier(&class.name.spelling), scope); + } + // Whether `tokens` is in a block of a generate construct. + let generated = |tokens: celox_sv_syntax::TokenRange| { + native.body_items.iter().any(|item| { + let contains = + |id: &celox_sv_syntax::BodyItemId| within(native.body_item(*id).tokens, tokens); + within(unit.tokens, item.tokens) + && match &item.kind { + celox_sv_syntax::BodyItemKind::Conditional { + then_body, + otherwise, + .. + } => contains(then_body) || otherwise.as_ref().is_some_and(contains), + celox_sv_syntax::BodyItemKind::Case { arms, .. } => { + arms.iter().any(|arm| contains(&arm.body)) + } + celox_sv_syntax::BodyItemKind::Loop { body, .. } => contains(body), + _ => false, + } + }) + }; + let module_scopes = |tokens: celox_sv_syntax::TokenRange| { + let mut scopes = items + .iter() + .filter(|item| within(native.body_item(item.id).tokens, tokens)) + .map(|item| { + let mut scope = context.clone(); + scope.const_env = (*item.env).clone().into(); + scope.type_aliases = item.type_aliases(&context.type_aliases).into_owned(); + scope + }) + .collect::>(); + // A name in a generate block that elaboration does not select is + // in no scope (27.5). + if scopes.is_empty() && !generated(tokens) { + scopes.push(context.clone()); + } + scopes + }; + let mut done = HashSet::<(usize, String)>::default(); + loop { + let before = tree.state.class_specializations.borrow().len(); + for (index, (scope, name, arguments, tokens)) in references.iter().enumerate() { + let scopes = match scope { + None => { + if done.insert((index, String::new())) { + for context in module_scopes(*tokens) { + // A specialization that cannot be made reports + // why where it is used. + let _ = specialize(tree, name, arguments, &context); + } + } + continue; + } + Some(scope) => of(tree, scope), + }; + for scope in scopes { + if !done.insert((index, scope.clone())) { + continue; + } + let mut context = context.clone(); + let (env, aliases) = + self::scope(tree, &scope, &context.const_env, &context.type_aliases); + context.const_env = env.into(); + context.type_aliases = aliases; + let _ = specialize(tree, name, arguments, &context); + } + } + let after = tree.state.class_specializations.borrow().len(); + if after == before || after >= MAX_SPECIALIZATIONS { + break; + } + } +} diff --git a/crates/celox-sv-analyzer/src/ast/dimensions/discovery.rs b/crates/celox-sv-analyzer/src/ast/dimensions/discovery.rs index 20a1d7b4f05..2d68af1269e 100644 --- a/crates/celox-sv-analyzer/src/ast/dimensions/discovery.rs +++ b/crates/celox-sv-analyzer/src/ast/dimensions/discovery.rs @@ -423,13 +423,23 @@ fn return_type( /// initialized it (IEEE 1800-2023 8.6, 8.7, 8.10). fn class_signatures( class: &celox_sv_syntax::ClassDeclaration, + class_name: &str, tree: &AnalysisContext<'_>, context: &mut PackedDimensions, ) -> Converted<()> { - let class_name = name(&class.name); - let Some(handle) = classes::handle_type(tree, &class_name) else { + let Some(handle) = classes::handle_type(tree, class_name) else { return Ok(()); }; + // Formals and results are bound in the scope of the specialization. + let mut scope = context.clone(); + let (env, aliases) = classes::specializations::scope( + tree, + class_name, + &context.const_env, + &context.type_aliases, + ); + scope.const_env = env.into(); + scope.type_aliases = aliases; let this = ( FunctionArgumentMetadata { name: classes::THIS.into(), @@ -441,7 +451,7 @@ fn class_signatures( let mut constructor = false; for method in &class.methods { let subroutine = tree.declarations().subroutine(method.subroutine); - let mut formals = formal_types(subroutine, tree, context)?; + let mut formals = formal_types(subroutine, tree, &scope)?; if !method.qualifiers.is_static { formals.insert(0, this.clone()); } @@ -449,12 +459,12 @@ fn class_signatures( constructor = true; Some(Some(handle.clone())) } else { - return_type(subroutine, tree, context)? + return_type(subroutine, tree, &scope)? }; // A method that may be virtual also has a dispatcher (8.20). if !method.qualifiers.is_static && subroutine.kind != SubroutineKind::Constructor { publish_signature( - classes::Class::dispatcher_name(&class_name, &name(&subroutine.name)), + classes::Class::dispatcher_name(class_name, &name(&subroutine.name)), formals.clone(), result.clone(), tree, @@ -462,7 +472,7 @@ fn class_signatures( ); } publish_signature( - classes::Class::subroutine_name(&class_name, &name(&subroutine.name)), + classes::Class::subroutine_name(class_name, &name(&subroutine.name)), formals, result, tree, @@ -484,7 +494,7 @@ fn class_signatures( // Signature discovery must not require an otherwise unused class // to have a supported layout. A call validates the layout before // using this selection formal; lowering reports layout errors. - classes::class(tree, &class_name, &context.const_env, &context.type_aliases) + classes::class(tree, class_name, &context.const_env, &context.type_aliases) .map_or_else( |_| classes::unsigned_type(1), |layout| layout.selection_type(), @@ -502,7 +512,7 @@ fn class_signatures( ty, )); publish_signature( - classes::Class::subroutine_name(&class_name, method), + classes::Class::subroutine_name(class_name, method), formals, Some((method == "randomize").then(procedural::int_type)), tree, @@ -511,7 +521,7 @@ fn class_signatures( } if !constructor && !class.interface { publish_signature( - classes::Class::subroutine_name(&class_name, "new"), + classes::Class::subroutine_name(class_name, "new"), vec![this], Some(Some(handle.clone())), tree, @@ -530,7 +540,7 @@ fn class_signatures( ) }; publish_signature( - classes::Class::cast_name(&class_name), + classes::Class::cast_name(class_name), vec![ formal(procedural::CAST_DESTINATION, ParamDirection::Inout), formal(procedural::CAST_SOURCE, ParamDirection::Input), @@ -541,14 +551,26 @@ fn class_signatures( ); Ok(()) } -/// Publish the signatures of the methods of every class in the source. +/// Publish the signatures of the methods of every class in the source, of +/// each specialization of a parameterized class that the current module +/// names (IEEE 1800-2023 8.25). pub(in crate::ast) fn all_class_signatures( tree: &AnalysisContext<'_>, context: &mut PackedDimensions, ) { + classes::specializations::collect(tree, context); for class in &tree.declarations().classes { - let _ = class_signatures(class, tree, context); + let generic = name(&class.name); + let names = if class.parameter_ports.is_some() { + classes::specializations::of(tree, &generic) + } else { + vec![generic] + }; + for class_name in names { + let _ = class_signatures(class, &class_name, tree, context); + } } + tree.state.class_specializations_frozen.set(true); } fn publish_signature( n: String, diff --git a/crates/celox-sv-analyzer/src/ast/expression_binding/direct.rs b/crates/celox-sv-analyzer/src/ast/expression_binding/direct.rs index 1f6ddd9a74a..41d24194d86 100644 --- a/crates/celox-sv-analyzer/src/ast/expression_binding/direct.rs +++ b/crates/celox-sv-analyzer/src/ast/expression_binding/direct.rs @@ -800,6 +800,15 @@ pub(in crate::ast) fn bind_value( vec![(*expression, None), (index, None)], ) } + ExprKind::Member { .. } + if objects::class_parameter(tree, id, native, dimensions)?.is_some() => + { + values.push( + objects::class_parameter(tree, id, native, dimensions)? + .expect("checked by the guard"), + ); + continue; + } ExprKind::Member { .. } if objects::property(tree, id, native, dimensions)?.is_some() => { diff --git a/crates/celox-sv-analyzer/src/ast/expression_binding/objects.rs b/crates/celox-sv-analyzer/src/ast/expression_binding/objects.rs index c5417adf83e..1d4cfbf810c 100644 --- a/crates/celox-sv-analyzer/src/ast/expression_binding/objects.rs +++ b/crates/celox-sv-analyzer/src/ast/expression_binding/objects.rs @@ -108,18 +108,88 @@ fn is_super(id: ExprId, native: &Declarations) -> bool { ExprKind::Name(name) if name.spelling == "super") } -/// The class that native expression `id` names, as the scope of `C::name`. +/// The class that native expression `id` names, as the scope of `C::name`: +/// a class, or the specialization that a parameter value assignment or the +/// defaults of a parameterized class make (IEEE 1800-2023 8.25.1). fn named_class( tree: &AnalysisContext<'_>, id: ExprId, native: &Declarations, dimensions: &PackedDimensions, -) -> Option { - let ExprKind::Name(name) = &native.expression(ungroup(id, native)).kind else { - return None; +) -> Converted> { + let (name, arguments) = match &native.expression(ungroup(id, native)).kind { + ExprKind::Name(name) => (name, None), + ExprKind::Parameterized { + expression, + arguments, + } => match &native.expression(*expression).kind { + ExprKind::Name(name) => (name, Some(&arguments[..])), + _ => return Ok(None), + }, + _ => return Ok(None), }; let name = instances::normalize_identifier(&name.spelling); - (dimensions.get(&name).is_none() && classes::handle_type(tree, &name).is_some()).then_some(name) + if dimensions.get(&name).is_some() { + return Ok(None); + } + // Inside a parameterized class and its out-of-block methods, its name + // alone refers to the specialization. + if arguments.is_none() + && let Some(class) = dimensions + .type_aliases + .get(&classes::specializations::scope_key(&name)) + .or_else(|| dimensions.type_aliases.get(&name)) + .and_then(|ty| ty.class.clone()) + { + return Ok(Some(class)); + } + if !classes::is_visible(tree, &name) { + return Ok(None); + } + if !classes::is_parameterized(tree, &name) { + if arguments.is_some_and(|arguments| !arguments.is_empty()) { + return Err(unsupported(format!( + "parameter value assignment of class `{name}`, which has no parameters" + ))); + } + return Ok(Some(name)); + } + // Elsewhere a parameterized class needs a specialization, `C#()` for + // the default one. + let Some(arguments) = arguments else { + return Err(AnalyzerError::UnspecializedClassScope { class: name }); + }; + classes::specializations::specialize(tree, &name, arguments, dimensions).map(Some) +} + +/// The value of the class parameter that native expression `id` names, +/// `h.p` or `C::p` (IEEE 1800-2023 8.25), as a literal. +pub(in crate::ast) fn class_parameter( + tree: &AnalysisContext<'_>, + id: ExprId, + native: &Declarations, + dimensions: &PackedDimensions, +) -> Converted> { + let ExprKind::Member { + expression, + separator, + name, + } = &native.expression(ungroup(id, native)).kind + else { + return Ok(None); + }; + let class = match separator.as_str() { + "." => native_class(tree, *expression, native, dimensions), + "::" => named_class(tree, *expression, native, dimensions)?, + _ => None, + }; + Ok(class.and_then(|class| { + classes::specializations::parameter( + tree, + &class, + &instances::normalize_identifier(&name.spelling), + ) + })) } /// The variable of the static property that native expression `id` names: @@ -141,7 +211,7 @@ pub(in crate::ast) fn static_property( }; let class_name = match separator.as_str() { "." => native_class(tree, *expression, native, dimensions), - "::" => named_class(tree, *expression, native, dimensions), + "::" => named_class(tree, *expression, native, dimensions)?, _ => None, }; let Some(class_name) = class_name else { @@ -333,7 +403,7 @@ pub(in crate::ast) fn method( expression, separator, name, - } if separator == "::" => match named_class(tree, *expression, native, dimensions) { + } if separator == "::" => match named_class(tree, *expression, native, dimensions)? { Some(class) => (class, name, Receiver::Static), None => return Ok(None), }, @@ -556,7 +626,7 @@ pub(in crate::ast) fn constructor( separator, name, } if separator == "::" && name.spelling == "new" => { - match named_class(tree, *expression, native, dimensions) { + match named_class(tree, *expression, native, dimensions)? { Some(class) => { if !derives_from(tree, dimensions, &class, class_name)? { return Err(AnalyzerError::IncompatibleClassHandle { @@ -588,30 +658,23 @@ pub(in crate::ast) fn constructor( "object of abstract class `{class_name}`" ))); } - let formals = class.constructor_formals(native); let mut args = vec![Some(class.allocation())]; - for argument in arguments { - if argument.name.is_some() { - return Err(unsupported("named constructor argument")); - } + let (actuals, order) = class.constructor_arguments(native, arguments)?; + for actual in actuals { args.push( - argument - .value + actual .map(|value| bind_value(value, native, tree, dimensions, None)) .transpose()?, ); } - if args.len() > formals + 1 { - return Err(unsupported(format!( - "constructor of class `{class_name}` with {} arguments", - args.len() - 1 - ))); - } - args.resize(formals + 1, None); Ok(Some(Expr::Call { callee: Callee::Subroutine(Class::subroutine_name(&class_name, "new")), args, - arg_order: Vec::new(), + // The allocation is passed first; the actuals are evaluated in the + // order they are written (13.5.4). + arg_order: std::iter::once(0) + .chain(order.into_iter().map(|index| index + 1)) + .collect(), })) } diff --git a/crates/celox-sv-analyzer/src/ast/imports.rs b/crates/celox-sv-analyzer/src/ast/imports.rs index 84ce4d53c4e..692c476ff37 100644 --- a/crates/celox-sv-analyzer/src/ast/imports.rs +++ b/crates/celox-sv-analyzer/src/ast/imports.rs @@ -124,11 +124,7 @@ impl ScopeImports { continue; } // `C::name` names a member of class `C` (IEEE 1800-2023 8.23). - if native - .classes - .iter() - .any(|class| normalize_identifier(&class.name.spelling) == package) - { + if visible_class(tree, &package) { continue; } if !nested.iter().any(|(start, end, names)| { @@ -145,6 +141,8 @@ impl ScopeImports { if in_ranges(ty.tokens.start, &ranges) && let celox_sv_syntax::DataTypeKind::Named(path) = &ty.kind && let [package, name] = path.as_slice() + // `C::T` names a type of class `C` (IEEE 1800-2023 8.23). + && !visible_class(tree, &normalize_identifier(&package.name.spelling)) { imports.qualified.push(( normalize_identifier(&package.name.spelling), @@ -165,6 +163,19 @@ impl ScopeImports { } } +/// Whether a class named `name` is declared in the current scope or in the +/// compilation unit, where the scope sees it (IEEE 1800-2023 3.12.1). +fn visible_class(tree: &SyntaxTree, name: &str) -> bool { + let native = tree.declarations(); + let scope = tree.root_unit().ok().map(|unit| unit.tokens); + native.classes.iter().any(|class| { + normalize_identifier(&class.name.spelling) == name && { + let unit = super::classes::enclosing_unit(native, class.tokens).map(|unit| unit.tokens); + unit.is_none() || unit == scope + } + }) +} + /// The names declared directly in a module or package scope: its ports and /// parameters, and the declarations and instances of its items. Names /// declared in nested scopes, such as structure members, function locals diff --git a/crates/celox-sv-analyzer/src/ast/procedural.rs b/crates/celox-sv-analyzer/src/ast/procedural.rs index ec9374ac1a0..6f69399da3c 100644 --- a/crates/celox-sv-analyzer/src/ast/procedural.rs +++ b/crates/celox-sv-analyzer/src/ast/procedural.rs @@ -1748,6 +1748,8 @@ pub(super) fn subroutine_argument_names( for class in classes::item_classes(item.id, tree) { let _constant_functions = item.enter(); let aliases = item.type_aliases(type_aliases); + // A specialization's methods see its parameters (8.25). + let (env, aliases) = classes::specializations::scope(tree, &class, &item.env, &aliases); let handle = classes::handle_type(tree, &class) .ok_or_else(|| unsupported(format!("class `{class}`")))?; let mut constructor = false; @@ -1772,7 +1774,7 @@ pub(super) fn subroutine_argument_names( .collect::>(); // A class that cannot be laid out reports why where it is // lowered. - let layout = classes::class(tree, &class, &item.env, &aliases).ok(); + let layout = classes::class(tree, &class, &env, &aliases).ok(); if let Some(layout) = &layout { methods.extend(layout.dispatched_methods().map(|method| { ( @@ -1784,7 +1786,7 @@ pub(super) fn subroutine_argument_names( } for (name, native_id, is_static) in methods { let native = tree.declarations().subroutine(native_id); - let mut params = subroutine_param_declarations(native, tree, &item.env, &aliases)?; + let mut params = subroutine_param_declarations(native, tree, &env, &aliases)?; constructor |= native.kind == celox_sv_syntax::SubroutineKind::Constructor; if !is_static { params.insert(0, this.clone()); @@ -1799,7 +1801,7 @@ pub(super) fn subroutine_argument_names( params .iter() .map(|(_, _, r#type, _)| { - dimensions_from_type(&scoped_type(r#type.clone(), &item.env)) + dimensions_from_type(&scoped_type(r#type.clone(), &env)) }) .collect(), ); @@ -1832,7 +1834,7 @@ pub(super) fn subroutine_argument_names( shapes.insert(qualified.clone(), param_shapes); names.insert(qualified, param_names); } - let handle = dimensions_from_type(&scoped_type(handle, &item.env)); + let handle = dimensions_from_type(&scoped_type(handle, &env)); if !constructor && !layout.is_some_and(|layout| layout.is_interface) { let qualified = item.name(&classes::Class::subroutine_name(&class, "new")); directions.insert(qualified.clone(), vec![ParamDirection::Input]); @@ -2483,22 +2485,11 @@ impl BodyBuilder<'_, '_, '_> { method.qualifiers.protected, )?; } - let formals = base.constructor_formals(native); - if arguments.len() > formals { - return Err(unsupported(format!( - "constructor of class `{}` with {} arguments", - base.name, - arguments.len() - ))); - } let mut args = vec![Some(Expr::Ident(this.to_owned()))]; - for argument in arguments { - if argument.name.is_some() { - return Err(unsupported("named constructor argument")); - } + let (actuals, order) = base.constructor_arguments(native, arguments)?; + for actual in actuals { args.push( - argument - .value + actual .map(|value| { let mut value = expression_binding::value(value, native, self.tree, &self.dims)?; @@ -2508,11 +2499,12 @@ impl BodyBuilder<'_, '_, '_> { .transpose()?, ); } - args.resize(formals + 1, None); body.push(Stmt::Call { name: classes::Class::subroutine_name(&base.name, "new"), args, - arg_order: Vec::new(), + arg_order: std::iter::once(0) + .chain(order.into_iter().map(|index| index + 1)) + .collect(), }); } for property in class.own_properties() { @@ -2565,11 +2557,20 @@ fn lower_class( state: &mut BodyState<'_>, item: &generate::Item, ) -> Converted> { + // A specialization's methods see its parameters (IEEE 1800-2023 8.25). + let (declaration_env, type_aliases) = + classes::specializations::scope(tree, name, declaration_env, type_aliases); + let (item_dimensions, literals) = + classes::specializations::body_scope(tree, name, item_dimensions, literals); + let (declaration_env, type_aliases, item_dimensions, literals) = + (&declaration_env, &type_aliases, &item_dimensions, &literals); let class = match classes::class(tree, name, declaration_env, type_aliases) { Ok(class) => class, // An interface class that cannot be laid out has no subroutines; a // use of its handles reports why (IEEE 1800-2023 8.26). - Err(_) if classes::is_interface(tree, name) => return Ok(Vec::new()), + Err(AnalyzerError::Unsupported(_)) if classes::is_interface(tree, name) => { + return Ok(Vec::new()); + } Err(error) => return Err(error), }; let mut subroutines = Vec::new(); @@ -2862,20 +2863,29 @@ pub(super) fn initial_processes_from_scope( assignments.push(( instances::normalize_identifier(&variable.name.spelling), value, + None, )); } } } - // Static class properties are initialized like variables. + // Static class properties are initialized like variables, in the + // scope of the class that declares them (IEEE 1800-2023 8.9, 8.25). for property in classes::item_statics(item.id, tree, &item.env, &type_aliases) { if let Some(value) = property.initializer { - assignments.push((property.variable, value)); + assignments.push((property.variable, value, Some(property.owner))); } } if !assignments.is_empty() { let (item_dimensions, literals) = views.get(item); let mut body = Vec::new(); - for (name, native) in assignments { + for (name, native, owner) in assignments { + let scoped = owner.map(|owner| { + classes::specializations::body_scope(tree, &owner, item_dimensions, literals) + }); + let (item_dimensions, literals) = match &scoped { + Some((dimensions, literals)) => (dimensions, literals), + None => (item_dimensions, &**literals), + }; if let Some(target) = selected_unpacked_shape(&name, 0, item_dimensions) { let id = native; array_compatibility::check_native_unpacked_assignment( @@ -2895,12 +2905,23 @@ pub(super) fn initial_processes_from_scope( tree, item_dimensions, )?; - body.push(Stmt::Assign { + let mut stmt = Stmt::Assign { lhs, rhs, nonblocking: false, - }); + }; + // The parameters of the class are its own constants. + if scoped.is_some() { + substitute_stmt_constants( + &tree.state, + &mut stmt, + &item_dimensions.const_env, + literals, + ); + } + body.push(stmt); } + let (_, literals) = views.get(item); for stmt in &mut body { substitute_stmt_constants(&tree.state, stmt, &item.env, literals); qualify_stmt(item, stmt); diff --git a/crates/celox-sv-analyzer/src/ast/type_binding/binding.rs b/crates/celox-sv-analyzer/src/ast/type_binding/binding.rs index 9f0fe4aa2be..fed2fc06737 100644 --- a/crates/celox-sv-analyzer/src/ast/type_binding/binding.rs +++ b/crates/celox-sv-analyzer/src/ast/type_binding/binding.rs @@ -81,6 +81,40 @@ fn bind_in_with_validation( values.push(ty); } DataTypeKind::Named(path) => { + // A class with a parameter value assignment, or one + // whose defaults the name alone refers to (IEEE + // 1800-2023 8.25). + if let [part] = path.as_slice() { + let name = normalize_identifier(&part.name.spelling); + if (part.arguments.is_some() + || !context.type_aliases.contains_key(&name)) + && super::super::classes::is_parameterized(tree, &name) + { + let name = super::super::classes::specializations::specialize( + tree, + &name, + part.arguments.as_deref().unwrap_or_default(), + context, + )?; + values.push(super::super::classes::handle(&name)); + continue; + } + } + // A type that a class declares, `C::T` (IEEE 1800-2023 + // 8.23, 8.25.1). + if let [scope, member] = path.as_slice() + && let Some(class) = class_scope(scope, tree, context)? + { + let member = normalize_identifier(&member.name.spelling); + let ty = super::super::classes::specializations::member_type( + tree, &class, &member, + ) + .ok_or_else(|| { + unsupported(format!("type `{member}` of class `{class}`")) + })?; + values.push(types::enclose_aliased_packed_type(ty, ranges)); + continue; + } if path.iter().any(|part| part.arguments.is_some()) { return Ok(None); } @@ -310,6 +344,52 @@ fn bind_ranges( Ok(result) } +/// The class that `scope` of a class-scoped type `C::T` names: inside a +/// parameterized class its name alone refers to the specialization, and +/// elsewhere a parameterized class needs one (IEEE 1800-2023 8.25.1). +fn class_scope( + scope: &celox_sv_syntax::TypeSegment, + tree: &AnalysisContext<'_>, + context: &PackedDimensions, +) -> Converted> { + let name = normalize_identifier(&scope.name.spelling); + if scope.arguments.is_none() + && let Some(class) = context + .type_aliases + .get(&super::super::classes::specializations::scope_key(&name)) + .or_else(|| context.type_aliases.get(&name)) + .and_then(|ty| ty.class.clone()) + { + return Ok(Some(class)); + } + if !super::super::classes::is_visible(tree, &name) { + return Ok(None); + } + if !super::super::classes::is_parameterized(tree, &name) { + if scope + .arguments + .as_ref() + .is_some_and(|arguments| !arguments.is_empty()) + { + return Err(unsupported(format!( + "parameter value assignment of class `{name}`, which has no parameters" + ))); + } + // Its members are those of its one specialization. + if super::super::classes::handle_type(tree, &name).is_some() + && super::super::classes::specializations::lookup(tree, &name).is_none() + && super::super::classes::is_declared(tree, &name) + { + super::super::classes::specializations::specialize(tree, &name, &[], context)?; + } + return Ok(Some(name)); + } + let Some(arguments) = &scope.arguments else { + return Err(AnalyzerError::UnspecializedClassScope { class: name }); + }; + super::super::classes::specializations::specialize(tree, &name, arguments, context).map(Some) +} + pub(in crate::ast) fn expression_type( root: ExprId, tree: &AnalysisContext<'_>, diff --git a/crates/celox-sv-analyzer/src/lib.rs b/crates/celox-sv-analyzer/src/lib.rs index 09e54787e5b..07f42be06d6 100644 --- a/crates/celox-sv-analyzer/src/lib.rs +++ b/crates/celox-sv-analyzer/src/lib.rs @@ -179,6 +179,30 @@ pub enum AnalyzerError { /// 1800-2023 24.3). #[error("{item} in program `{program}`: a program shall not contain it (IEEE 1800-2023 24.3)")] IllegalProgramItem { program: String, item: String }, + /// An interface class that inherits parameters or typedefs named `name` + /// from two different interface classes or specializations without + /// declaring its own `name` (IEEE 1800-2023 8.26.6.2, 8.26.6.3). + #[error( + "interface class `{class}` inherits `{name}` from both `{first}` and `{second}` and must declare its own `{name}`" + )] + ConflictingInterfaceClassDeclaration { + class: String, + name: String, + first: String, + second: String, + }, + /// The unadorned name of a parameterized class as the prefix of `::` + /// outside the class and its out-of-block methods, where a + /// specialization such as `C#()` is required (IEEE 1800-2023 8.25.1). + #[error( + "`{class}::` outside class `{class}`: a parameterized class needs a specialization such as `{class}#()::`" + )] + UnspecializedClassScope { class: String }, + /// A parameter value assignment of a class names a parameter that the + /// parameter port list of the class does not declare, or declares local + /// (IEEE 1800-2023 8.25). + #[error("class `{class}` has no parameter `{name}` that a specialization may assign")] + UnknownClassParameter { class: String, name: String }, } impl miette::Diagnostic for AnalyzerError {} diff --git a/crates/celox-sv-syntax/src/nodes.rs b/crates/celox-sv-syntax/src/nodes.rs index 110d4fa3a30..de6c52aceb9 100644 --- a/crates/celox-sv-syntax/src/nodes.rs +++ b/crates/celox-sv-syntax/src/nodes.rs @@ -968,6 +968,13 @@ pub struct ClassDeclaration { pub interfaces: Vec, /// Whether the class declares constraints, including prototypes. pub has_constraints: bool, + /// The parameter port list `#(...)`, after which the parameters the + /// body declares are local (8.25). + pub parameter_ports: Option, + /// The `parameter` and `localparam` declarations of the body. + pub parameters: Vec, + /// The `typedef` declarations of the body. + pub type_aliases: Vec, pub properties: Vec, pub methods: Vec, pub tokens: TokenRange, diff --git a/crates/celox-sv-syntax/src/parser/classes.rs b/crates/celox-sv-syntax/src/parser/classes.rs index 821fed8c460..bed49079811 100644 --- a/crates/celox-sv-syntax/src/parser/classes.rs +++ b/crates/celox-sv-syntax/src/parser/classes.rs @@ -132,6 +132,19 @@ impl Parser<'_> { } } + /// Record a parameter or type declaration that is an item of the + /// innermost open class. + pub(super) fn class_item(&mut self, kind: &BodyItemKind) { + let Some(class) = self.class_stack.last_mut() else { + return; + }; + match kind { + BodyItemKind::Parameter(id) => class.parameters.push(*id), + BodyItemKind::TypeAlias(id) => class.type_aliases.push(*id), + _ => {} + } + } + /// Complete the innermost open class at its `endclass`. pub(super) fn finish_class(&mut self) { if let Some(mut class) = self.class_stack.pop() { @@ -157,6 +170,7 @@ impl Parser<'_> { let name = self.name()?; let mut base = None; let mut interfaces = Vec::new(); + let mut parameter_ports = None; if self.eat("#") { let start = self.at; self.expect("(")?; @@ -166,6 +180,7 @@ impl Parser<'_> { parameters, tokens: self.range(start), }); + parameter_ports = Some(id); items.push(super::generate::Builder::node( self, start, @@ -208,6 +223,9 @@ impl Parser<'_> { base, interfaces, has_constraints: false, + parameter_ports, + parameters: Vec::new(), + type_aliases: Vec::new(), properties: Vec::new(), methods: Vec::new(), tokens: TokenRange { start, end: start }, diff --git a/crates/celox-sv-syntax/src/parser/declarations.rs b/crates/celox-sv-syntax/src/parser/declarations.rs index e04eddb87d0..5e7dedaa740 100644 --- a/crates/celox-sv-syntax/src/parser/declarations.rs +++ b/crates/celox-sv-syntax/src/parser/declarations.rs @@ -92,6 +92,9 @@ impl UnitFrame { checker.raw = None; checker.builder.complete(parser, start, kind)?; } else if let Some(class) = self.classes.last_mut() { + if self.scopes.last() == Some(&"endclass") { + parser.class_item(&kind); + } class .items .push(super::generate::Builder::node(parser, start, kind)?); @@ -270,6 +273,9 @@ impl Parser<'_> { None }; if let Some(kind) = kind { + if scopes.last() == Some(&"endclass") && delimiters.is_empty() { + self.class_item(&kind); + } if root { self.source_declaration(start, kind)?; pending = None; diff --git a/crates/celox-sv-syntax/src/parser/tests.rs b/crates/celox-sv-syntax/src/parser/tests.rs index f0cc4becf0d..cab7fc78510 100644 --- a/crates/celox-sv-syntax/src/parser/tests.rs +++ b/crates/celox-sv-syntax/src/parser/tests.rs @@ -2694,6 +2694,41 @@ fn class_header_defaults_keep_captured_native_ownership() { )); assert_eq!(syntax.units[0].parameters, None); assert_eq!(items.len(), 2); + // The class records its parameter port list and body parameters. + let class = &syntax.classes[0]; + let BodyItemKind::Parameter(body) = syntax.body_item(items[1]).kind else { + panic!("body parameter owner missing") + }; + assert!( + matches!(class.parameter_ports, Some(id) if syntax.parameter_declaration(id) == header) + ); + assert_eq!(class.parameters, [body]); + assert!(class.type_aliases.is_empty()); + } +} + +#[test] +fn class_body_typedefs_and_parameters_belong_to_their_class() { + for source in [ + "class C; typedef int count_t; parameter int N = 2; function int f(); localparam L = 1; return L; endfunction endclass module M; endmodule", + "module M; class C; typedef int count_t; parameter int N = 2; function int f(); localparam L = 1; return L; endfunction endclass endmodule", + ] { + let syntax = parse(source); + let class = &syntax.classes[0]; + assert_eq!(class.parameter_ports, None); + assert_eq!(class.type_aliases.len(), 1); + assert_eq!( + syntax.type_alias(class.type_aliases[0]).name.value(), + "count_t" + ); + // A parameter of a method is not one of the class. + assert_eq!(class.parameters.len(), 1); + assert_eq!( + syntax.parameter_declaration(class.parameters[0]).parameters[0] + .name + .value(), + "N" + ); } } diff --git a/crates/celox-test-suite/LIMITATIONS.md b/crates/celox-test-suite/LIMITATIONS.md index 93daa8b7347..86e2f1b4d45 100644 --- a/crates/celox-test-suite/LIMITATIONS.md +++ b/crates/celox-test-suite/LIMITATIONS.md @@ -544,10 +544,13 @@ four-state expectations; the assertions remain enabled on all Celox variants. | `sv_icarus_nested_class_members` | execute | icarus | 1 | Icarus 13.0 reads an empty string through a nested property path (kept.inner.text) after reporting "sorry: Nested member path not yet supported for class properties" for its assignment. IEEE 1800-2023 8.5 permits accessing a property of an object referred to by a property. Verilator passes the case. | | `sv_icarus_class_scope_resolution` | compile | icarus | 1 | Icarus 13.0 rejects class scope resolution with a syntax error: reading a static property (Counter::created), calling a static method (Counter::next()) and assigning a static property (Counter::last = "set"). IEEE 1800-2023 8.9, 8.10 and 8.23 define these accesses. Verilator passes the case. | | `sv_icarus_virtual_dispatch` | execute | icarus | 1 | Icarus 13.0 binds a virtual function called through a base-class handle to the handle's class instead of the object's: the shared case prints area=0 for every shape, and the adapter-free source prints 1 1 1 3 where IEEE 1800-2023 8.20 requires 2 3 4 4. Verilator and Celox print 2 3 4 4 and pass the case. | -| `sv_icarus_abstract_and_interface_classes` | compile | icarus | 6 | Icarus 13.0 rejects pure virtual method declarations and interface classes with syntax errors ("Invalid class item", "Invalid module item") and fails code generation without a diagnostic ("Code generation had 2 error(s)") for a method called on an element of an array of class handles. IEEE 1800-2023 8.21 and 8.26 define pure virtual methods and interface classes, and 7.4 and 8.4 permit arrays of class handles. Verilator passes the first three cases; see sv_verilator_interface_class_casts and sv_verilator_extended_interface_class_methods for the others. | +| `sv_icarus_abstract_and_interface_classes` | compile | icarus | 7 | Icarus 13.0 rejects pure virtual method declarations and interface classes with syntax errors ("Invalid class item", "Invalid module item") and fails code generation without a diagnostic ("Code generation had 2 error(s)") for a method called on an element of an array of class handles. IEEE 1800-2023 8.21 and 8.26 define pure virtual methods and interface classes, and 7.4 and 8.4 permit arrays of class handles. Verilator passes all but two cases; see sv_verilator_interface_class_casts and sv_verilator_extended_interface_class_methods. | | `sv_verilator_interface_class_casts` | execute | verilator | 1 | Verilator 5.052 returns 0 from $cast of a handle of one interface class to a variable of another interface class that the object's class also implements, so the case dereferences the unassigned null handle; the adapter-free source prints 0 1 where IEEE 1800-2023 8.16 and 8.26.5 require 1 1. Celox prints 1 1. Icarus rejects interface classes, see sv_icarus_abstract_and_interface_classes. | | `sv_verilator_extended_interface_class_methods` | compile | verilator | 1 | Verilator 5.052 does not find a method that an interface class inherits from an interface class it extends when the method is called through a handle of the extending class ("Class method 'sides' not found in class 'NamedShape'"). IEEE 1800-2023 8.26.3 makes the methods of the extended interface classes members of the extending one. Icarus rejects interface classes, see sv_icarus_abstract_and_interface_classes. | | `sv_icarus_cast` | execute | icarus | 1 | Icarus 13.0 does not implement $cast ("System task/function $cast() is not defined by any module"), which IEEE 1800-2023 6.24.2 and 8.16 define. Verilator passes the case. | +| `sv_verilator_class_specialization_identity` | execute | verilator | 1 | Verilator 5.052 makes a separate specialization of a parameterized class for each way a parameter value assignment is written, so Box#(2, int)::made and Box#(.N(2), .T(int))::made read 0 after an object of Box#(.T(int), .N(2)) was constructed; the adapter-free source prints 0 1 0 where IEEE 1800-2023 8.25 requires 1 1 1, as the three assignments give the same values. Celox prints 1 1 1. Icarus rejects parameterized classes, see sv_icarus_parameterized_classes. | +| `sv_verilator_untyped_class_parameters` | execute | verilator | 1 | Verilator 5.052 gives a class parameter declared without a type the 32-bit type of its default even when a specialization assigns it a sized value, so $bits(V) of Sized#(8'h1) is 32; the adapter-free source prints 32 32 where IEEE 1800-2023 6.20.2 requires 8 32, as the parameter takes the type of its final value after overrides. Celox prints 8 32. Icarus rejects parameterized classes, see sv_icarus_parameterized_classes. | +| `sv_icarus_parameterized_classes` | compile | icarus | 11 | Icarus 13.0 does not parse a parameter port list of a class (class Box #(int N = 4); is a syntax error), which IEEE 1800-2023 8.25 defines; each case declares a parameterized class. Verilator passes all but two cases, see sv_verilator_class_specialization_identity and sv_verilator_untyped_class_parameters. | | `sv_verilator_class_property_string_methods` | compile | verilator | 1 | Verilator 5.052 stops with an internal error ("AstNode is not of expected type, but instead has type 'MEMBERSEL'") on a string method called on a class property, n.name.itoa(42), which IEEE 1800-2023 6.16 and 8.5 permit. Icarus rejects the case too, see sv_icarus_classes. | | `sv_icarus_unpacked_array_patterns` | compile | icarus | 1 | Icarus 13.0 reports that an assignment pattern with unpacked array items assigned to a multidimensional unpacked array is not yet supported ("Procedural assignment of array or array slice"), so the run cannot count it as a language rejection. The design is invalid (IEEE 1800-2023 7.6, 10.8). | | `sv_icarus_display_field_width` | execute | icarus | 1 | Icarus 13.0 zero-pads a value wider than an explicit field width of %h or %o to the argument's full width (%3h of 32'h1234 prints 00001234); IEEE 1800-2023 21.2.1.2 expands the field to the value without leading zeros (1234). Verilator agrees with the expected value. | diff --git a/crates/celox-test-suite/src/sv/cases/class.vtest b/crates/celox-test-suite/src/sv/cases/class.vtest index 15ee5508f33..72f3d6beedb 100644 --- a/crates/celox-test-suite/src/sv/cases/class.vtest +++ b/crates/celox-test-suite/src/sv/cases/class.vtest @@ -712,6 +712,340 @@ endmodule (top Top) (run_until 0) (assert_eq done 1) (expect_output "1 8\n1 1\n0 8\n")) +(case specializations_of_parameterized_classes + (source "class.sv" #" +module Top #(parameter int W = 6)(output bit done); + class Box #(int N = 4, type T = bit [7:0]); + T value; + static int made; + localparam int Twice = N * 2; + function new(T v); + value = v; + made++; + endfunction + function T get(); + T copy = value; + return copy + T'(N); + endfunction + function int twice(); + return Twice; + endfunction + endclass + class Wide #(int M = 1) extends Box #(M + 1, int); + function new(); + super.new(100); + endfunction + function int kind(); + return M * 10 + N; + endfunction + endclass + Box b4; + Box #(W) bw; + Box #(.T(int), .N(2)) bi; + Box #(3, bit [3:0]) bn; + Wide #(5) w; + Box #(6, int) base; + initial begin + b4 = new(8'd10); + bw = new(8'd1); + bi = new(-5); + bn = new(4'd14); + w = new; + $display("%0d %0d %0d %0d", b4.get(), bw.get(), bi.get(), bn.get()); + $display("%0d %0d %0d %0d", b4.N, bw.twice(), Box#(.T(int), .N(2))::made, Box#()::made); + base = w; + $display("%0d %0d %0d %0d", base.get(), w.N, w.kind(), Box#(6, int)::made); + done = 1; + end +endmodule +"#) + (top Top) (run_until 0) (assert_eq done 1) + (expect_output "14 7 -3 1\n4 12 1 1\n106 6 56 1\n")) + +(case specializations_are_named_by_parameter_values + (source "class.sv" #" +module Top(output bit done); + class Box #(int N = 4, type T = bit [7:0]); + static int made; + function new(); + made++; + endfunction + endclass + Box #(.T(int), .N(2)) named; + initial begin + named = new; + $display("%0d %0d %0d", Box#(2, int)::made, Box#(.N(2), .T(int))::made, Box#(1 + 1, int)::made); + done = 1; + end +endmodule +"#) + (top Top) (run_until 0) (assert_eq done 1) + (expect_output "1 1 1\n")) + +(case specializations_with_their_own_handles + (source "class.sv" #" +module Top(output bit done); + class Box #(int N = 4); + virtual function int n(); + return N; + endfunction + endclass + class Sub #(int N = 4) extends Box #(N); + virtual function int n(); + return N * 10; + endfunction + endclass + Box #(2) two; + Box #(3) three; + Sub #(2) sub; + int ok; + initial begin + sub = new; + two = sub; + ok = $cast(three, two); + $display("%0d %0d %0d", two.n(), ok, three == null); + done = 1; + end +endmodule +"#) + (top Top) (run_until 0) (assert_eq done 1) + (expect_output "20 0 1\n")) + +(case class_scoped_parameters_and_types + (source "class.sv" #" +module Top(output bit done); + class C #(int p = 1, type T = int); + parameter int q = 5; + typedef bit [p:0] word_t; + extern static function T f(); + static function int g(); + int p = 100; + return p + C::p; + endfunction + static function word_t w(); + return '1; + endfunction + endclass + function C::T C::f(); + return p + C::p; + endfunction + C#(3)::word_t x; + C#(.T(bit [2:0]))::T y; + initial begin + x = C#(3)::w(); + y = 13; + $display("%0d %0d %0d", C#()::f(), C#(5)::f(), C#(3)::g()); + $display("%0d %0d %0d %0d", x, y, C#()::q, C#(7)::p); + done = 1; + end +endmodule +"#) + (top Top) (run_until 0) (assert_eq done 1) + (expect_output "2 10 103\n15 5 5 7\n")) + +(case specializations_of_interface_classes + (source "class.sv" #" +module Top(output bit done); + interface class Getter #(type T = int); + pure virtual function T get(); + endclass + class IntBox implements Getter#(int); + virtual function int get(); + return -7; + endfunction + endclass + class NibbleBox #(int V = 3) implements Getter#(bit [3:0]); + extern virtual function bit [3:0] get(); + endclass + function bit [3:0] NibbleBox::get(); + return V + 20; + endfunction + Getter #(int) gi; + Getter #(bit [3:0]) gn; + Getter gd; + IntBox ib; + NibbleBox #(5) nb; + initial begin + ib = new; + nb = new; + gi = ib; + gn = nb; + gd = ib; + $display("%0d %0d %0d", gi.get(), gn.get(), gd.get()); + done = 1; + end +endmodule +"#) + (top Top) (run_until 0) (assert_eq done 1) + (expect_output "-7 9 -7\n")) + +(case named_constructor_arguments + (source "class.sv" #" +module Top(output bit done); + class Base; + int s; + function new(int def = 3); + s = def; + endfunction + endclass + class Point #(int t = 12) extends Base; + int x; + int y; + function new(int x = 1, int y = 2); + super.new(.def(x + y)); + this.x = x; + this.y = y - t; + endfunction + endclass + Base base; + Point p; + initial begin + p = new(.y(30)); + $display("%0d %0d %0d", p.x, p.y, p.s); + base = Point#(.t(23))::new(.y(40), .x(4)); + $display("%0d", base.s); + done = 1; + end +endmodule +"#) + (top Top) (run_until 0) (assert_eq done 1) + (expect_output "1 18 31\n44\n")) + +(case typedefs_of_interface_classes + (source "class.sv" #" +module Top(output bit done); + interface class Hello; + typedef int count_t; + pure virtual function void hello(count_t value); + endclass + interface class Greeting extends Hello; + pure virtual function count_t greet(count_t value); + endclass + class Greeter implements Greeting; + virtual function void hello(Hello::count_t value); + $display("%0d", value); + endfunction + virtual function Greeting::count_t greet(Greeting::count_t value); + return value + 1; + endfunction + endclass + Greeter greeter; + initial begin + greeter = new; + greeter.hello(12); + $display("%0d", greeter.greet(12)); + done = 1; + end +endmodule +"#) + (top Top) (run_until 0) (assert_eq done 1) + (expect_output "12\n13\n")) + +(case specializations_in_generate_blocks + (source "class.sv" #" +module Top(output bit done); + class Box #(int N = 4); + static int made; + function new(); + made++; + endfunction + function int n(); + return N; + endfunction + endclass + for (genvar i = 1; i < 3; i++) begin : g + Box #(i * 10) kept; + initial begin + automatic Box #(i) local_box = new; + #(i); + kept = new; + $display("%0d %0d %0d", i, local_box.n(), kept.n() + Box#(i * 10)::made); + done = 1; + end + end +endmodule +"#) + (top Top) (run_until 2) (assert_eq done 1) + (expect_output "1 1 11\n2 2 21\n")) + +(case specializations_keep_their_parameter_scopes + (source "class.sv" #" +module Top(output bit done); + class Box #(int N = 4); + function int n(); + return N; + endfunction + endclass + class Base #(type T = int); + endclass + class Derived extends Base #(bit [3:0]); + typedef T nibble_t; + endclass + class Inner #(int N = 1); + function int v(); + return N * 100; + endfunction + endclass + class Outer #(int N = 1); + extern function int f(); + endclass + function int Outer::f(); + Inner #(N) inner; + inner = new; + return inner.v(); + endfunction + class Counted #(type T = logic [3:0]); + static int made; + function new(); + made++; + endfunction + endclass + Derived::nibble_t nibble; + Outer #(7) outer; + Counted #(logic [3:0]) logic_counted; + Counted #(reg [3:0]) reg_counted; + for (genvar N = 5; N < 6; N++) begin : g + Box #(N) box; + initial begin + box = new; + $display("%0d", box.n()); + end + end + initial begin + #1; + nibble = 20; + outer = new; + logic_counted = new; + reg_counted = new; + $display("%0d %0d %0d", nibble, outer.f(), Counted#(logic [3:0])::made); + done = 1; + end +endmodule +"#) + (top Top) (run_until 1) (assert_eq done 1) + (expect_output "5\n4 700 2\n")) + +(case untyped_class_parameters_take_the_type_of_their_value + (source "class.sv" #" +module Top(output bit done); + class Sized #(parameter V = 1); + function int bits(); + return $bits(V); + endfunction + endclass + Sized #(8'h1) narrow; + Sized #(32'h1) wide; + initial begin + narrow = new; + wide = new; + $display("%0d %0d", narrow.bits(), wide.bits()); + done = 1; + end +endmodule +"#) + (top Top) (run_until 0) (assert_eq done 1) + (expect_output "8 32\n")) + (case unconstrained_randomize (source "randomize.sv" #" module Top(output bit done, output int errors); @@ -1211,3 +1545,171 @@ module Top(output bit done, output int errors); endmodule "#) (top Top) (run_until 0) (assert_eq done 1) (assert_eq errors 0)) + +(case class_declarations_bind_in_their_scopes + (source "class.sv" #" +module Top(output bit done); + class Ordered; + typedef bit [7:0] byte_t; + parameter byte_t P = 8'hff; + typedef int table_t [2]; + endclass + class Init #(int N = 1); + static int value = N * 10; + endclass + class Named #(string S = "a"); + function string s(); + return S; + endfunction + endclass + class Self #(int N = 1); + typedef Self self_t; + function int n(); + return N; + endfunction + endclass + class Base #(type T = bit [3:0]); + endclass + class Derived #(type T = int) extends Base; + typedef T own_t; + endclass + class Wide #(logic [57:0] V = 0); + function bit [63:0] v(); + return V; + endfunction + endclass + class Plain; + typedef int T; + endclass + typedef Plain::T plain_t; + Ordered::table_t entries; + plain_t plain; + Self#(2)::self_t self_handle; + Named#("bc") named; + Wide#('1) wide; + Derived#()::own_t own; + initial begin + entries[1] = 5; + plain = -3; + self_handle = new; + named = new; + wide = new; + $display("%0d %0d %0d %0d", Ordered::P, entries[1], plain, $bits(own)); + $display("%0d %0d %0d %s %h", Init#(2)::value, Init#(3)::value, self_handle.n(), named.s(), wide.v()); + done = 1; + end +endmodule +"#) + (top Top) (run_until 0) (assert_eq done 1) + (expect_output "255 5 -3 32\n20 30 1 bc 03ffffffffffffff\n")) + +(case parameter_defaults_bind_where_the_class_is_declared + (source "class.sv" #" +module Top #(parameter int X = 1)(output bit done); + class Defaulted #(int N = X); + function int n(); + return N; + endfunction + endclass + if (1) begin : g + localparam int X = 2; + Defaulted#() inner; + initial begin + inner = new; + $display("%0d", inner.n()); + done = 1; + end + end +endmodule +"#) + (top Top) (run_until 0) (assert_eq done 1) + (expect_output "1\n")) + +(case specialization_keys_follow_the_bound_parameters + (source "class.sv" #" +module Top(output bit done); + localparam int N = 2; + typedef bit signed [3:0] S; + typedef S [1:0] Signed; + typedef bit [1:0][3:0] Unsigned; + typedef int Sized[2]; + typedef int Ranged[0:1]; + class Box #(type T = int); + static int made; + function new(); + made++; + endfunction + endclass + class Outer #(type T = int); + typedef T Inner; + Box#(Outer::Inner) box; + function new(); + box = new; + endfunction + endclass + class Base #(int N = 1); + endclass + class Derived #(int N = 2) extends Base; + typedef bit [N-1:0] T; + endclass + class Four #(logic [1:0] N = 0); + static int made; + function new(); + made++; + endfunction + endclass + class Real #(real V = 0.0); + static function real v(); + return V; + endfunction + endclass + class Announced #(int N = 1); + static int x = N; + endclass + localparam int K = 2; + interface class I #(int N = 0); + localparam int K = 1; + pure virtual function int n(); + endclass + interface class J extends I#(K); + endclass + class Impl implements J; + virtual function int n(); + return 7; + endfunction + endclass + Announced#(1) active; + if (0) begin : disabled + Announced#(2) unused; + end + initial begin + Box#(Sized) sized; + Box#(Ranged) ranged; + Box#(Signed) signed_elements; + Box#(Unsigned) unsigned_elements; + Outer#(byte) outer; + Four#(2'bxx) unknown; + Four#(1) one; + Derived#()::T t; + Impl impl; + I#(2) h; + sized = new; + ranged = new; + signed_elements = new; + unsigned_elements = new; + outer = new; + $display("%0d %0d %0d", Box#(Sized)::made, Box#(Signed)::made, Box#(byte)::made); + unknown = new; + one = new; + $display("%0d %0d", Four#(2'bxx)::made, Four#(1)::made); + $display("%0.1f %0.1f", Real#(1.0 + 2.0)::v(), Real#(3.0)::v()); + $display("%0d", $bits(t)); + impl = new; + h = impl; + $display("%0d", h.n()); + done = 1; + end +endmodule +"#) + (top Top) (run_until 0) (assert_eq done 1) + (expect_output "2 1 1\n1 1\n3.0 3.0\n2\n7\n")) diff --git a/crates/celox-test-suite/verification/repros/class_specialization_identity.sv b/crates/celox-test-suite/verification/repros/class_specialization_identity.sv new file mode 100644 index 00000000000..edb40a3a09e --- /dev/null +++ b/crates/celox-test-suite/verification/repros/class_specialization_identity.sv @@ -0,0 +1,16 @@ +// Two parameter value assignments that give a parameterized class the same +// values name one specialization, which has one copy of each static property +// (IEEE 1800-2023 8.25). Expected output: 1 1 1. +module Top; + class Box #(int N = 4, type T = bit [7:0]); + static int made; + function new(); + made++; + endfunction + endclass + Box #(.T(int), .N(2)) box; + initial begin + box = new; + $display("%0d %0d %0d", Box#(2, int)::made, Box#(.T(int), .N(2))::made, Box#(.N(2), .T(int))::made); + end +endmodule diff --git a/crates/celox-test-suite/verification/repros/class_specialization_identity_verilator.json b/crates/celox-test-suite/verification/repros/class_specialization_identity_verilator.json new file mode 100644 index 00000000000..3576b68a9f3 --- /dev/null +++ b/crates/celox-test-suite/verification/repros/class_specialization_identity_verilator.json @@ -0,0 +1,40 @@ +{ + "schema_version": 3, + "suite_version": "0.11.0", + "tool": "verilator", + "version": "Verilator 5.052 2026-09-05 rev v5.052", + "cases": [ + { + "category": "Types", + "detail": "class::specializations_are_named_by_parameter_values at 783:3: expect_output: expected [49, 32, 49, 32, 49, 10], got [48, 32, 48, 32, 48, 10]", + "expectation": "Simulation", + "name": "class::specializations_are_named_by_parameter_values", + "phase": "execute", + "status": "mismatch", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + } + ], + "counts": { + "passed": 0, + "mismatch": 1, + "compile_error": 0, + "emission_error": 0, + "ignored": 0, + "rejected": 0, + "runtime_error": 0, + "unexpected_accept": 0, + "unsupported": 0 + }, + "include_ignored": true, + "exclude_stronger_than_sv": false, + "standard": "IEEE 1800-2023 8.25: parameter value assignments that give a parameterized class the same values name the same specialization, which has one copy of each static property.", + "adapter_free": { + "source": "verification/repros/class_specialization_identity.sv", + "verilator_command": "verilator --binary --timing -Wno-fatal --top-module Top --Mdir class_specialization_identity.sv", + "verilator_version": "Verilator 5.052 2026-09-05 rev v5.052", + "verilator_output": "0 1 0", + "expected_output": "1 1 1" + } +} diff --git a/crates/celox-test-suite/verification/repros/untyped_class_parameters.sv b/crates/celox-test-suite/verification/repros/untyped_class_parameters.sv new file mode 100644 index 00000000000..c39e5721da1 --- /dev/null +++ b/crates/celox-test-suite/verification/repros/untyped_class_parameters.sv @@ -0,0 +1,17 @@ +// A class parameter without a type takes the type of the value that a +// specialization assigns it (IEEE 1800-2023 6.20.2, 8.25). Expected output: +// 8 32. +module Top; + class Sized #(parameter V = 1); + function int bits(); + return $bits(V); + endfunction + endclass + Sized #(8'h1) narrow; + Sized #(32'h1) wide; + initial begin + narrow = new; + wide = new; + $display("%0d %0d", narrow.bits(), wide.bits()); + end +endmodule diff --git a/crates/celox-test-suite/verification/repros/untyped_class_parameters_verilator.json b/crates/celox-test-suite/verification/repros/untyped_class_parameters_verilator.json new file mode 100644 index 00000000000..51972ce57ff --- /dev/null +++ b/crates/celox-test-suite/verification/repros/untyped_class_parameters_verilator.json @@ -0,0 +1,40 @@ +{ + "schema_version": 3, + "suite_version": "0.11.0", + "tool": "verilator", + "version": "Verilator 5.052 2026-09-05 rev v5.052", + "cases": [ + { + "category": "Types", + "detail": "class::untyped_class_parameters_take_the_type_of_their_value at 1045:3: expect_output: expected [56, 32, 51, 50, 10], got [51, 50, 32, 51, 50, 10]", + "expectation": "Simulation", + "name": "class::untyped_class_parameters_take_the_type_of_their_value", + "phase": "execute", + "status": "mismatch", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + } + ], + "counts": { + "passed": 0, + "mismatch": 1, + "compile_error": 0, + "emission_error": 0, + "ignored": 0, + "rejected": 0, + "runtime_error": 0, + "unexpected_accept": 0, + "unsupported": 0 + }, + "include_ignored": true, + "exclude_stronger_than_sv": false, + "standard": "IEEE 1800-2023 6.20.2 and 8.25: a parameter declared without a type or range takes the type and range of its final value after overrides, including the value a class specialization assigns.", + "adapter_free": { + "source": "verification/repros/untyped_class_parameters.sv", + "verilator_command": "verilator --binary --timing -Wno-fatal --top-module Top --Mdir untyped_class_parameters.sv", + "verilator_version": "Verilator 5.052 2026-09-05 rev v5.052", + "verilator_output": "32 32", + "expected_output": "8 32" + } +} diff --git a/crates/celox-test-suite/verification/sv/icarus/class.json b/crates/celox-test-suite/verification/sv/icarus/class.json index 1cde7a83605..12b0961973a 100644 --- a/crates/celox-test-suite/verification/sv/icarus/class.json +++ b/crates/celox-test-suite/verification/sv/icarus/class.json @@ -2,7 +2,7 @@ "cases": [ { "category": "Types", - "detail": "Icarus 13.0 rejects pure virtual method declarations and interface classes with syntax errors (\"Invalid class item\", \"Invalid module item\") and fails code generation without a diagnostic (\"Code generation had 2 error(s)\") for a method called on an element of an array of class handles. IEEE 1800-2023 8.21 and 8.26 define pure virtual methods and interface classes, and 7.4 and 8.4 permit arrays of class handles. Verilator passes the first three cases; see sv_verilator_interface_class_casts and sv_verilator_extended_interface_class_methods for the others.", + "detail": "Icarus 13.0 rejects pure virtual method declarations and interface classes with syntax errors (\"Invalid class item\", \"Invalid module item\") and fails code generation without a diagnostic (\"Code generation had 2 error(s)\") for a method called on an element of an array of class handles. IEEE 1800-2023 8.21 and 8.26 define pure virtual methods and interface classes, and 7.4 and 8.4 permit arrays of class handles. Verilator passes all but two cases; see sv_verilator_interface_class_casts and sv_verilator_extended_interface_class_methods.", "expectation": "Simulation", "known_issue": { "category": "simulator_compile_limitation", @@ -13,7 +13,7 @@ "id": "sv_icarus_abstract_and_interface_classes", "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", "phase": "compile", - "reason": "Icarus 13.0 rejects pure virtual method declarations and interface classes with syntax errors (\"Invalid class item\", \"Invalid module item\") and fails code generation without a diagnostic (\"Code generation had 2 error(s)\") for a method called on an element of an array of class handles. IEEE 1800-2023 8.21 and 8.26 define pure virtual methods and interface classes, and 7.4 and 8.4 permit arrays of class handles. Verilator passes the first three cases; see sv_verilator_interface_class_casts and sv_verilator_extended_interface_class_methods for the others.", + "reason": "Icarus 13.0 rejects pure virtual method declarations and interface classes with syntax errors (\"Invalid class item\", \"Invalid module item\") and fails code generation without a diagnostic (\"Code generation had 2 error(s)\") for a method called on an element of an array of class handles. IEEE 1800-2023 8.21 and 8.26 define pure virtual methods and interface classes, and 7.4 and 8.4 permit arrays of class handles. Verilator passes all but two cases; see sv_verilator_interface_class_casts and sv_verilator_extended_interface_class_methods.", "upstream": [] }, "name": "class::abstract_classes_and_pure_virtual_methods", @@ -25,7 +25,7 @@ }, { "category": "Types", - "detail": "Icarus 13.0 rejects pure virtual method declarations and interface classes with syntax errors (\"Invalid class item\", \"Invalid module item\") and fails code generation without a diagnostic (\"Code generation had 2 error(s)\") for a method called on an element of an array of class handles. IEEE 1800-2023 8.21 and 8.26 define pure virtual methods and interface classes, and 7.4 and 8.4 permit arrays of class handles. Verilator passes the first three cases; see sv_verilator_interface_class_casts and sv_verilator_extended_interface_class_methods for the others.", + "detail": "Icarus 13.0 rejects pure virtual method declarations and interface classes with syntax errors (\"Invalid class item\", \"Invalid module item\") and fails code generation without a diagnostic (\"Code generation had 2 error(s)\") for a method called on an element of an array of class handles. IEEE 1800-2023 8.21 and 8.26 define pure virtual methods and interface classes, and 7.4 and 8.4 permit arrays of class handles. Verilator passes all but two cases; see sv_verilator_interface_class_casts and sv_verilator_extended_interface_class_methods.", "expectation": "Simulation", "known_issue": { "category": "simulator_compile_limitation", @@ -36,7 +36,7 @@ "id": "sv_icarus_abstract_and_interface_classes", "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", "phase": "compile", - "reason": "Icarus 13.0 rejects pure virtual method declarations and interface classes with syntax errors (\"Invalid class item\", \"Invalid module item\") and fails code generation without a diagnostic (\"Code generation had 2 error(s)\") for a method called on an element of an array of class handles. IEEE 1800-2023 8.21 and 8.26 define pure virtual methods and interface classes, and 7.4 and 8.4 permit arrays of class handles. Verilator passes the first three cases; see sv_verilator_interface_class_casts and sv_verilator_extended_interface_class_methods for the others.", + "reason": "Icarus 13.0 rejects pure virtual method declarations and interface classes with syntax errors (\"Invalid class item\", \"Invalid module item\") and fails code generation without a diagnostic (\"Code generation had 2 error(s)\") for a method called on an element of an array of class handles. IEEE 1800-2023 8.21 and 8.26 define pure virtual methods and interface classes, and 7.4 and 8.4 permit arrays of class handles. Verilator passes all but two cases; see sv_verilator_interface_class_casts and sv_verilator_extended_interface_class_methods.", "upstream": [] }, "name": "class::casts_from_interface_class_handles", @@ -71,7 +71,53 @@ }, { "category": "Types", - "detail": "Icarus 13.0 rejects pure virtual method declarations and interface classes with syntax errors (\"Invalid class item\", \"Invalid module item\") and fails code generation without a diagnostic (\"Code generation had 2 error(s)\") for a method called on an element of an array of class handles. IEEE 1800-2023 8.21 and 8.26 define pure virtual methods and interface classes, and 7.4 and 8.4 permit arrays of class handles. Verilator passes the first three cases; see sv_verilator_interface_class_casts and sv_verilator_extended_interface_class_methods for the others.", + "detail": "Icarus 13.0 does not parse a parameter port list of a class (class Box #(int N = 4); is a syntax error), which IEEE 1800-2023 8.25 defines; each case declares a parameterized class. Verilator passes all but two cases, see sv_verilator_class_specialization_identity and sv_verilator_untyped_class_parameters.", + "expectation": "Simulation", + "known_issue": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/sv/limitations/icarus.json", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_icarus_parameterized_classes", + "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", + "phase": "compile", + "reason": "Icarus 13.0 does not parse a parameter port list of a class (class Box #(int N = 4); is a syntax error), which IEEE 1800-2023 8.25 defines; each case declares a parameterized class. Verilator passes all but two cases, see sv_verilator_class_specialization_identity and sv_verilator_untyped_class_parameters.", + "upstream": [] + }, + "name": "class::class_declarations_bind_in_their_scopes", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "Icarus 13.0 does not parse a parameter port list of a class (class Box #(int N = 4); is a syntax error), which IEEE 1800-2023 8.25 defines; each case declares a parameterized class. Verilator passes all but two cases, see sv_verilator_class_specialization_identity and sv_verilator_untyped_class_parameters.", + "expectation": "Simulation", + "known_issue": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/sv/limitations/icarus.json", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_icarus_parameterized_classes", + "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", + "phase": "compile", + "reason": "Icarus 13.0 does not parse a parameter port list of a class (class Box #(int N = 4); is a syntax error), which IEEE 1800-2023 8.25 defines; each case declares a parameterized class. Verilator passes all but two cases, see sv_verilator_class_specialization_identity and sv_verilator_untyped_class_parameters.", + "upstream": [] + }, + "name": "class::class_scoped_parameters_and_types", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "Icarus 13.0 rejects pure virtual method declarations and interface classes with syntax errors (\"Invalid class item\", \"Invalid module item\") and fails code generation without a diagnostic (\"Code generation had 2 error(s)\") for a method called on an element of an array of class handles. IEEE 1800-2023 8.21 and 8.26 define pure virtual methods and interface classes, and 7.4 and 8.4 permit arrays of class handles. Verilator passes all but two cases; see sv_verilator_interface_class_casts and sv_verilator_extended_interface_class_methods.", "expectation": "Simulation", "known_issue": { "category": "simulator_compile_limitation", @@ -82,7 +128,7 @@ "id": "sv_icarus_abstract_and_interface_classes", "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", "phase": "compile", - "reason": "Icarus 13.0 rejects pure virtual method declarations and interface classes with syntax errors (\"Invalid class item\", \"Invalid module item\") and fails code generation without a diagnostic (\"Code generation had 2 error(s)\") for a method called on an element of an array of class handles. IEEE 1800-2023 8.21 and 8.26 define pure virtual methods and interface classes, and 7.4 and 8.4 permit arrays of class handles. Verilator passes the first three cases; see sv_verilator_interface_class_casts and sv_verilator_extended_interface_class_methods for the others.", + "reason": "Icarus 13.0 rejects pure virtual method declarations and interface classes with syntax errors (\"Invalid class item\", \"Invalid module item\") and fails code generation without a diagnostic (\"Code generation had 2 error(s)\") for a method called on an element of an array of class handles. IEEE 1800-2023 8.21 and 8.26 define pure virtual methods and interface classes, and 7.4 and 8.4 permit arrays of class handles. Verilator passes all but two cases; see sv_verilator_interface_class_casts and sv_verilator_extended_interface_class_methods.", "upstream": [] }, "name": "class::classes_implementing_interface_classes", @@ -162,7 +208,7 @@ }, { "category": "Types", - "detail": "Icarus 13.0 rejects pure virtual method declarations and interface classes with syntax errors (\"Invalid class item\", \"Invalid module item\") and fails code generation without a diagnostic (\"Code generation had 2 error(s)\") for a method called on an element of an array of class handles. IEEE 1800-2023 8.21 and 8.26 define pure virtual methods and interface classes, and 7.4 and 8.4 permit arrays of class handles. Verilator passes the first three cases; see sv_verilator_interface_class_casts and sv_verilator_extended_interface_class_methods for the others.", + "detail": "Icarus 13.0 rejects pure virtual method declarations and interface classes with syntax errors (\"Invalid class item\", \"Invalid module item\") and fails code generation without a diagnostic (\"Code generation had 2 error(s)\") for a method called on an element of an array of class handles. IEEE 1800-2023 8.21 and 8.26 define pure virtual methods and interface classes, and 7.4 and 8.4 permit arrays of class handles. Verilator passes all but two cases; see sv_verilator_interface_class_casts and sv_verilator_extended_interface_class_methods.", "expectation": "Simulation", "known_issue": { "category": "simulator_compile_limitation", @@ -173,7 +219,7 @@ "id": "sv_icarus_abstract_and_interface_classes", "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", "phase": "compile", - "reason": "Icarus 13.0 rejects pure virtual method declarations and interface classes with syntax errors (\"Invalid class item\", \"Invalid module item\") and fails code generation without a diagnostic (\"Code generation had 2 error(s)\") for a method called on an element of an array of class handles. IEEE 1800-2023 8.21 and 8.26 define pure virtual methods and interface classes, and 7.4 and 8.4 permit arrays of class handles. Verilator passes the first three cases; see sv_verilator_interface_class_casts and sv_verilator_extended_interface_class_methods for the others.", + "reason": "Icarus 13.0 rejects pure virtual method declarations and interface classes with syntax errors (\"Invalid class item\", \"Invalid module item\") and fails code generation without a diagnostic (\"Code generation had 2 error(s)\") for a method called on an element of an array of class handles. IEEE 1800-2023 8.21 and 8.26 define pure virtual methods and interface classes, and 7.4 and 8.4 permit arrays of class handles. Verilator passes all but two cases; see sv_verilator_interface_class_casts and sv_verilator_extended_interface_class_methods.", "upstream": [] }, "name": "class::inherited_methods_of_extended_interface_classes", @@ -208,7 +254,7 @@ }, { "category": "Types", - "detail": "Icarus 13.0 rejects pure virtual method declarations and interface classes with syntax errors (\"Invalid class item\", \"Invalid module item\") and fails code generation without a diagnostic (\"Code generation had 2 error(s)\") for a method called on an element of an array of class handles. IEEE 1800-2023 8.21 and 8.26 define pure virtual methods and interface classes, and 7.4 and 8.4 permit arrays of class handles. Verilator passes the first three cases; see sv_verilator_interface_class_casts and sv_verilator_extended_interface_class_methods for the others.", + "detail": "Icarus 13.0 rejects pure virtual method declarations and interface classes with syntax errors (\"Invalid class item\", \"Invalid module item\") and fails code generation without a diagnostic (\"Code generation had 2 error(s)\") for a method called on an element of an array of class handles. IEEE 1800-2023 8.21 and 8.26 define pure virtual methods and interface classes, and 7.4 and 8.4 permit arrays of class handles. Verilator passes all but two cases; see sv_verilator_interface_class_casts and sv_verilator_extended_interface_class_methods.", "expectation": "Simulation", "known_issue": { "category": "simulator_compile_limitation", @@ -219,7 +265,7 @@ "id": "sv_icarus_abstract_and_interface_classes", "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", "phase": "compile", - "reason": "Icarus 13.0 rejects pure virtual method declarations and interface classes with syntax errors (\"Invalid class item\", \"Invalid module item\") and fails code generation without a diagnostic (\"Code generation had 2 error(s)\") for a method called on an element of an array of class handles. IEEE 1800-2023 8.21 and 8.26 define pure virtual methods and interface classes, and 7.4 and 8.4 permit arrays of class handles. Verilator passes the first three cases; see sv_verilator_interface_class_casts and sv_verilator_extended_interface_class_methods for the others.", + "reason": "Icarus 13.0 rejects pure virtual method declarations and interface classes with syntax errors (\"Invalid class item\", \"Invalid module item\") and fails code generation without a diagnostic (\"Code generation had 2 error(s)\") for a method called on an element of an array of class handles. IEEE 1800-2023 8.21 and 8.26 define pure virtual methods and interface classes, and 7.4 and 8.4 permit arrays of class handles. Verilator passes all but two cases; see sv_verilator_interface_class_casts and sv_verilator_extended_interface_class_methods.", "upstream": [] }, "name": "class::methods_called_through_interface_class_handles", @@ -231,7 +277,7 @@ }, { "category": "Types", - "detail": "Icarus 13.0 rejects pure virtual method declarations and interface classes with syntax errors (\"Invalid class item\", \"Invalid module item\") and fails code generation without a diagnostic (\"Code generation had 2 error(s)\") for a method called on an element of an array of class handles. IEEE 1800-2023 8.21 and 8.26 define pure virtual methods and interface classes, and 7.4 and 8.4 permit arrays of class handles. Verilator passes the first three cases; see sv_verilator_interface_class_casts and sv_verilator_extended_interface_class_methods for the others.", + "detail": "Icarus 13.0 rejects pure virtual method declarations and interface classes with syntax errors (\"Invalid class item\", \"Invalid module item\") and fails code generation without a diagnostic (\"Code generation had 2 error(s)\") for a method called on an element of an array of class handles. IEEE 1800-2023 8.21 and 8.26 define pure virtual methods and interface classes, and 7.4 and 8.4 permit arrays of class handles. Verilator passes all but two cases; see sv_verilator_interface_class_casts and sv_verilator_extended_interface_class_methods.", "expectation": "Simulation", "known_issue": { "category": "simulator_compile_limitation", @@ -242,7 +288,7 @@ "id": "sv_icarus_abstract_and_interface_classes", "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", "phase": "compile", - "reason": "Icarus 13.0 rejects pure virtual method declarations and interface classes with syntax errors (\"Invalid class item\", \"Invalid module item\") and fails code generation without a diagnostic (\"Code generation had 2 error(s)\") for a method called on an element of an array of class handles. IEEE 1800-2023 8.21 and 8.26 define pure virtual methods and interface classes, and 7.4 and 8.4 permit arrays of class handles. Verilator passes the first three cases; see sv_verilator_interface_class_casts and sv_verilator_extended_interface_class_methods for the others.", + "reason": "Icarus 13.0 rejects pure virtual method declarations and interface classes with syntax errors (\"Invalid class item\", \"Invalid module item\") and fails code generation without a diagnostic (\"Code generation had 2 error(s)\") for a method called on an element of an array of class handles. IEEE 1800-2023 8.21 and 8.26 define pure virtual methods and interface classes, and 7.4 and 8.4 permit arrays of class handles. Verilator passes all but two cases; see sv_verilator_interface_class_casts and sv_verilator_extended_interface_class_methods.", "upstream": [] }, "name": "class::methods_of_handle_array_elements", @@ -252,6 +298,29 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Types", + "detail": "Icarus 13.0 does not parse a parameter port list of a class (class Box #(int N = 4); is a syntax error), which IEEE 1800-2023 8.25 defines; each case declares a parameterized class. Verilator passes all but two cases, see sv_verilator_class_specialization_identity and sv_verilator_untyped_class_parameters.", + "expectation": "Simulation", + "known_issue": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/sv/limitations/icarus.json", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_icarus_parameterized_classes", + "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", + "phase": "compile", + "reason": "Icarus 13.0 does not parse a parameter port list of a class (class Box #(int N = 4); is a syntax error), which IEEE 1800-2023 8.25 defines; each case declares a parameterized class. Verilator passes all but two cases, see sv_verilator_class_specialization_identity and sv_verilator_untyped_class_parameters.", + "upstream": [] + }, + "name": "class::named_constructor_arguments", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Types", "detail": "", @@ -311,187 +380,279 @@ }, { "category": "Types", + "detail": "Icarus 13.0 does not parse a parameter port list of a class (class Box #(int N = 4); is a syntax error), which IEEE 1800-2023 8.25 defines; each case declares a parameterized class. Verilator passes all but two cases, see sv_verilator_class_specialization_identity and sv_verilator_untyped_class_parameters.", "expectation": "Simulation", - "name": "class::randomization_enum_alias", - "stronger_than_sv": false, - "tag_reasons": {}, - "tags": [], - "detail": "Icarus 13.0 rejects class randomize, srandom and rand_mode calls in these enum randomization cases. IEEE 1800-2023 18.3, 18.6 and 18.8 define these operations. The original compile diagnostics are retained.", "known_issue": { - "id": "sv_icarus_enum_randomization", "category": "simulator_compile_limitation", - "phase": "compile", - "observed_version": "Icarus Verilog version 13.0 (stable) (v13_0)", - "reason": "Icarus 13.0 rejects class randomize, srandom and rand_mode calls in these enum randomization cases. IEEE 1800-2023 18.3, 18.6 and 18.8 define these operations. The original compile diagnostics are retained.", - "upstream": [], "evidence": [ - "verification/repros/sv_enum_randomization_icarus.json", + "verification/sv/limitations/icarus.json", "LIMITATIONS.md#systemverilog-suite" - ] + ], + "id": "sv_icarus_parameterized_classes", + "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", + "phase": "compile", + "reason": "Icarus 13.0 does not parse a parameter port list of a class (class Box #(int N = 4); is a syntax error), which IEEE 1800-2023 8.25 defines; each case declares a parameterized class. Verilator passes all but two cases, see sv_verilator_class_specialization_identity and sv_verilator_untyped_class_parameters.", + "upstream": [] }, + "name": "class::parameter_defaults_bind_where_the_class_is_declared", "phase": "skip", - "status": "ignored" + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] }, { "category": "Types", + "detail": "Icarus 13.0 cannot elaborate class randomize, srandom and rand_mode calls in the randc cases. IEEE 1800-2023 18.4.2, 18.6 and 18.8 define these operations. The unchanged assertions cover full cycles, signed and enum domains, modes and inheritance.", "expectation": "Simulation", - "name": "class::randomization_enum_domain", + "known_issue": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/repros/sv_randc_icarus.json", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_icarus_randc", + "observed_version": "Icarus Verilog version 13.0 (stable) (v13_0)", + "phase": "compile", + "reason": "Icarus 13.0 cannot elaborate class randomize, srandom and rand_mode calls in the randc cases. IEEE 1800-2023 18.4.2, 18.6 and 18.8 define these operations. The unchanged assertions cover full cycles, signed and enum domains, modes and inheritance.", + "upstream": [] + }, + "name": "class::randomization_cyclic_controls", + "phase": "skip", + "status": "ignored", "stronger_than_sv": false, "tag_reasons": {}, - "tags": [], - "detail": "Icarus 13.0 rejects class randomize, srandom and rand_mode calls in these enum randomization cases. IEEE 1800-2023 18.3, 18.6 and 18.8 define these operations. The original compile diagnostics are retained.", + "tags": [] + }, + { + "category": "Types", + "detail": "Icarus 13.0 cannot elaborate class randomize, srandom and rand_mode calls in the randc cases. IEEE 1800-2023 18.4.2, 18.6 and 18.8 define these operations. The unchanged assertions cover full cycles, signed and enum domains, modes and inheritance.", + "expectation": "Simulation", "known_issue": { - "id": "sv_icarus_enum_randomization", "category": "simulator_compile_limitation", - "phase": "compile", - "observed_version": "Icarus Verilog version 13.0 (stable) (v13_0)", - "reason": "Icarus 13.0 rejects class randomize, srandom and rand_mode calls in these enum randomization cases. IEEE 1800-2023 18.3, 18.6 and 18.8 define these operations. The original compile diagnostics are retained.", - "upstream": [], "evidence": [ - "verification/repros/sv_enum_randomization_icarus.json", + "verification/repros/sv_randc_icarus.json", "LIMITATIONS.md#systemverilog-suite" - ] + ], + "id": "sv_icarus_randc", + "observed_version": "Icarus Verilog version 13.0 (stable) (v13_0)", + "phase": "compile", + "reason": "Icarus 13.0 cannot elaborate class randomize, srandom and rand_mode calls in the randc cases. IEEE 1800-2023 18.4.2, 18.6 and 18.8 define these operations. The unchanged assertions cover full cycles, signed and enum domains, modes and inheritance.", + "upstream": [] }, + "name": "class::randomization_cyclic_domains", "phase": "skip", - "status": "ignored" + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] }, { "category": "Types", + "detail": "Icarus 13.0 cannot elaborate class randomize, srandom and rand_mode calls in the randc cases. IEEE 1800-2023 18.4.2, 18.6 and 18.8 define these operations. The unchanged assertions cover full cycles, signed and enum domains, modes and inheritance.", "expectation": "Simulation", - "name": "class::randomization_enum_fill_literals", + "known_issue": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/repros/sv_randc_icarus.json", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_icarus_randc", + "observed_version": "Icarus Verilog version 13.0 (stable) (v13_0)", + "phase": "compile", + "reason": "Icarus 13.0 cannot elaborate class randomize, srandom and rand_mode calls in the randc cases. IEEE 1800-2023 18.4.2, 18.6 and 18.8 define these operations. The unchanged assertions cover full cycles, signed and enum domains, modes and inheritance.", + "upstream": [] + }, + "name": "class::randomization_cyclic_enum_alias", + "phase": "skip", + "status": "ignored", "stronger_than_sv": false, "tag_reasons": {}, - "tags": [], + "tags": [] + }, + { + "category": "Types", "detail": "Icarus 13.0 rejects class randomize, srandom and rand_mode calls in these enum randomization cases. IEEE 1800-2023 18.3, 18.6 and 18.8 define these operations. The original compile diagnostics are retained.", + "expectation": "Simulation", "known_issue": { - "id": "sv_icarus_enum_randomization", "category": "simulator_compile_limitation", - "phase": "compile", - "observed_version": "Icarus Verilog version 13.0 (stable) (v13_0)", - "reason": "Icarus 13.0 rejects class randomize, srandom and rand_mode calls in these enum randomization cases. IEEE 1800-2023 18.3, 18.6 and 18.8 define these operations. The original compile diagnostics are retained.", - "upstream": [], "evidence": [ "verification/repros/sv_enum_randomization_icarus.json", "LIMITATIONS.md#systemverilog-suite" - ] + ], + "id": "sv_icarus_enum_randomization", + "observed_version": "Icarus Verilog version 13.0 (stable) (v13_0)", + "phase": "compile", + "reason": "Icarus 13.0 rejects class randomize, srandom and rand_mode calls in these enum randomization cases. IEEE 1800-2023 18.3, 18.6 and 18.8 define these operations. The original compile diagnostics are retained.", + "upstream": [] }, + "name": "class::randomization_enum_alias", "phase": "skip", - "status": "ignored" + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] }, { "category": "Types", + "detail": "Icarus 13.0 rejects class randomize, srandom and rand_mode calls in these enum randomization cases. IEEE 1800-2023 18.3, 18.6 and 18.8 define these operations. The original compile diagnostics are retained.", "expectation": "Simulation", - "name": "class::randomization_enum_inheritance", + "known_issue": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/repros/sv_enum_randomization_icarus.json", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_icarus_enum_randomization", + "observed_version": "Icarus Verilog version 13.0 (stable) (v13_0)", + "phase": "compile", + "reason": "Icarus 13.0 rejects class randomize, srandom and rand_mode calls in these enum randomization cases. IEEE 1800-2023 18.3, 18.6 and 18.8 define these operations. The original compile diagnostics are retained.", + "upstream": [] + }, + "name": "class::randomization_enum_domain", + "phase": "skip", + "status": "ignored", "stronger_than_sv": false, "tag_reasons": {}, - "tags": [], + "tags": [] + }, + { + "category": "Types", "detail": "Icarus 13.0 rejects class randomize, srandom and rand_mode calls in these enum randomization cases. IEEE 1800-2023 18.3, 18.6 and 18.8 define these operations. The original compile diagnostics are retained.", + "expectation": "Simulation", "known_issue": { - "id": "sv_icarus_enum_randomization", "category": "simulator_compile_limitation", - "phase": "compile", - "observed_version": "Icarus Verilog version 13.0 (stable) (v13_0)", - "reason": "Icarus 13.0 rejects class randomize, srandom and rand_mode calls in these enum randomization cases. IEEE 1800-2023 18.3, 18.6 and 18.8 define these operations. The original compile diagnostics are retained.", - "upstream": [], "evidence": [ "verification/repros/sv_enum_randomization_icarus.json", "LIMITATIONS.md#systemverilog-suite" - ] + ], + "id": "sv_icarus_enum_randomization", + "observed_version": "Icarus Verilog version 13.0 (stable) (v13_0)", + "phase": "compile", + "reason": "Icarus 13.0 rejects class randomize, srandom and rand_mode calls in these enum randomization cases. IEEE 1800-2023 18.3, 18.6 and 18.8 define these operations. The original compile diagnostics are retained.", + "upstream": [] }, + "name": "class::randomization_enum_fill_literals", "phase": "skip", - "status": "ignored" + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] }, { "category": "Types", + "detail": "Icarus 13.0 rejects class randomize, srandom and rand_mode calls in these enum randomization cases. IEEE 1800-2023 18.3, 18.6 and 18.8 define these operations. The original compile diagnostics are retained.", "expectation": "Simulation", - "name": "class::randomization_inheritance", + "known_issue": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/repros/sv_enum_randomization_icarus.json", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_icarus_enum_randomization", + "observed_version": "Icarus Verilog version 13.0 (stable) (v13_0)", + "phase": "compile", + "reason": "Icarus 13.0 rejects class randomize, srandom and rand_mode calls in these enum randomization cases. IEEE 1800-2023 18.3, 18.6 and 18.8 define these operations. The original compile diagnostics are retained.", + "upstream": [] + }, + "name": "class::randomization_enum_inheritance", + "phase": "skip", + "status": "ignored", "stronger_than_sv": false, "tag_reasons": {}, - "tags": [], + "tags": [] + }, + { + "category": "Types", "detail": "Icarus 13.0 rejects randomize, srandom and rand_mode calls, including property rand_mode calls (\"Method name nesting is not supported yet\"). IEEE 1800-2023 18.6, 18.8 and 18.11 define these class methods and inline member selection.", + "expectation": "Simulation", "known_issue": { - "id": "sv_icarus_randomization_control", "category": "simulator_compile_limitation", - "phase": "compile", - "observed_version": "Icarus Verilog version 13.0 (stable) (v13_0)", - "reason": "Icarus 13.0 rejects randomize, srandom and rand_mode calls, including property rand_mode calls (\"Method name nesting is not supported yet\"). IEEE 1800-2023 18.6, 18.8 and 18.11 define these class methods and inline member selection.", - "upstream": [], "evidence": [ "verification/repros/sv_randomization_control_icarus.json", "LIMITATIONS.md#systemverilog-suite" - ] + ], + "id": "sv_icarus_randomization_control", + "observed_version": "Icarus Verilog version 13.0 (stable) (v13_0)", + "phase": "compile", + "reason": "Icarus 13.0 rejects randomize, srandom and rand_mode calls, including property rand_mode calls (\"Method name nesting is not supported yet\"). IEEE 1800-2023 18.6, 18.8 and 18.11 define these class methods and inline member selection.", + "upstream": [] }, + "name": "class::randomization_inheritance", "phase": "skip", - "status": "ignored" + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] }, { "category": "Types", - "expectation": "Simulation", - "name": "class::randomization_mode_bit_argument", - "stronger_than_sv": false, - "tag_reasons": {}, - "tags": [], "detail": "Icarus 13.0 rejects randomize, srandom and rand_mode calls, including property rand_mode calls (\"Method name nesting is not supported yet\"). IEEE 1800-2023 18.6, 18.8 and 18.11 define these class methods and inline member selection.", + "expectation": "Simulation", "known_issue": { - "id": "sv_icarus_randomization_control", "category": "simulator_compile_limitation", - "phase": "compile", - "observed_version": "Icarus Verilog version 13.0 (stable) (v13_0)", - "reason": "Icarus 13.0 rejects randomize, srandom and rand_mode calls, including property rand_mode calls (\"Method name nesting is not supported yet\"). IEEE 1800-2023 18.6, 18.8 and 18.11 define these class methods and inline member selection.", - "upstream": [], "evidence": [ "verification/repros/sv_randomization_control_icarus.json", "LIMITATIONS.md#systemverilog-suite" - ] + ], + "id": "sv_icarus_randomization_control", + "observed_version": "Icarus Verilog version 13.0 (stable) (v13_0)", + "phase": "compile", + "reason": "Icarus 13.0 rejects randomize, srandom and rand_mode calls, including property rand_mode calls (\"Method name nesting is not supported yet\"). IEEE 1800-2023 18.6, 18.8 and 18.11 define these class methods and inline member selection.", + "upstream": [] }, + "name": "class::randomization_mode_bit_argument", "phase": "skip", - "status": "ignored" + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] }, { "category": "Types", - "expectation": "Simulation", - "name": "class::randomization_modes_and_selection", - "stronger_than_sv": false, - "tag_reasons": {}, - "tags": [], "detail": "Icarus 13.0 rejects randomize, srandom and rand_mode calls, including property rand_mode calls (\"Method name nesting is not supported yet\"). IEEE 1800-2023 18.6, 18.8 and 18.11 define these class methods and inline member selection.", + "expectation": "Simulation", "known_issue": { - "id": "sv_icarus_randomization_control", "category": "simulator_compile_limitation", - "phase": "compile", - "observed_version": "Icarus Verilog version 13.0 (stable) (v13_0)", - "reason": "Icarus 13.0 rejects randomize, srandom and rand_mode calls, including property rand_mode calls (\"Method name nesting is not supported yet\"). IEEE 1800-2023 18.6, 18.8 and 18.11 define these class methods and inline member selection.", - "upstream": [], "evidence": [ "verification/repros/sv_randomization_control_icarus.json", "LIMITATIONS.md#systemverilog-suite" - ] + ], + "id": "sv_icarus_randomization_control", + "observed_version": "Icarus Verilog version 13.0 (stable) (v13_0)", + "phase": "compile", + "reason": "Icarus 13.0 rejects randomize, srandom and rand_mode calls, including property rand_mode calls (\"Method name nesting is not supported yet\"). IEEE 1800-2023 18.6, 18.8 and 18.11 define these class methods and inline member selection.", + "upstream": [] }, + "name": "class::randomization_modes_and_selection", "phase": "skip", - "status": "ignored" + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] }, { "category": "Types", - "expectation": "Simulation", - "name": "class::randomization_pre_hook_controls_modes", - "stronger_than_sv": false, - "tag_reasons": {}, - "tags": [], "detail": "Icarus 13.0 rejects randomize, srandom and rand_mode calls, including property rand_mode calls (\"Method name nesting is not supported yet\"). IEEE 1800-2023 18.6, 18.8 and 18.11 define these class methods and inline member selection.", + "expectation": "Simulation", "known_issue": { - "id": "sv_icarus_randomization_control", "category": "simulator_compile_limitation", - "phase": "compile", - "observed_version": "Icarus Verilog version 13.0 (stable) (v13_0)", - "reason": "Icarus 13.0 rejects randomize, srandom and rand_mode calls, including property rand_mode calls (\"Method name nesting is not supported yet\"). IEEE 1800-2023 18.6, 18.8 and 18.11 define these class methods and inline member selection.", - "upstream": [], "evidence": [ "verification/repros/sv_randomization_control_icarus.json", "LIMITATIONS.md#systemverilog-suite" - ] + ], + "id": "sv_icarus_randomization_control", + "observed_version": "Icarus Verilog version 13.0 (stable) (v13_0)", + "phase": "compile", + "reason": "Icarus 13.0 rejects randomize, srandom and rand_mode calls, including property rand_mode calls (\"Method name nesting is not supported yet\"). IEEE 1800-2023 18.6, 18.8 and 18.11 define these class methods and inline member selection.", + "upstream": [] }, + "name": "class::randomization_pre_hook_controls_modes", "phase": "skip", - "status": "ignored" + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] }, { "category": "Types", @@ -518,7 +679,7 @@ }, { "category": "Types", - "detail": "Icarus 13.0 rejects class scope resolution with a syntax error: reading a static property (Counter::created), calling a static method (Counter::next()) and assigning a static property (Counter::last = \"set\"). IEEE 1800-2023 8.9, 8.10 and 8.23 define these accesses. Verilator passes the case.", + "detail": "Icarus 13.0 does not parse a parameter port list of a class (class Box #(int N = 4); is a syntax error), which IEEE 1800-2023 8.25 defines; each case declares a parameterized class. Verilator passes all but two cases, see sv_verilator_class_specialization_identity and sv_verilator_untyped_class_parameters.", "expectation": "Simulation", "known_issue": { "category": "simulator_compile_limitation", @@ -526,13 +687,13 @@ "verification/sv/limitations/icarus.json", "LIMITATIONS.md#systemverilog-suite" ], - "id": "sv_icarus_class_scope_resolution", + "id": "sv_icarus_parameterized_classes", "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", "phase": "compile", - "reason": "Icarus 13.0 rejects class scope resolution with a syntax error: reading a static property (Counter::created), calling a static method (Counter::next()) and assigning a static property (Counter::last = \"set\"). IEEE 1800-2023 8.9, 8.10 and 8.23 define these accesses. Verilator passes the case.", + "reason": "Icarus 13.0 does not parse a parameter port list of a class (class Box #(int N = 4); is a syntax error), which IEEE 1800-2023 8.25 defines; each case declares a parameterized class. Verilator passes all but two cases, see sv_verilator_class_specialization_identity and sv_verilator_untyped_class_parameters.", "upstream": [] }, - "name": "class::static_properties_and_methods", + "name": "class::specialization_keys_follow_the_bound_parameters", "phase": "skip", "status": "ignored", "stronger_than_sv": false, @@ -541,7 +702,7 @@ }, { "category": "Types", - "detail": "Icarus 13.0 does not support extern methods (\"sorry: External methods are not yet supported\") or string methods called on a class property (\"Can't find task itoa in class Named\") or comparisons of class handles (\"SORRY: Compare class handles not implemented\"), aborts on a failed assertion in dup_expr.cc while compiling objects_referring_to_objects, and crashes with a segmentation fault while compiling implicit_constructors_and_this. IEEE 1800-2023 8.4, 8.7, 8.8 and 8.24 define these constructs. Verilator passes all but the string-method case, see sv_verilator_class_property_string_methods.", + "detail": "Icarus 13.0 does not parse a parameter port list of a class (class Box #(int N = 4); is a syntax error), which IEEE 1800-2023 8.25 defines; each case declares a parameterized class. Verilator passes all but two cases, see sv_verilator_class_specialization_identity and sv_verilator_untyped_class_parameters.", "expectation": "Simulation", "known_issue": { "category": "simulator_compile_limitation", @@ -549,13 +710,13 @@ "verification/sv/limitations/icarus.json", "LIMITATIONS.md#systemverilog-suite" ], - "id": "sv_icarus_classes", + "id": "sv_icarus_parameterized_classes", "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", "phase": "compile", - "reason": "Icarus 13.0 does not support extern methods (\"sorry: External methods are not yet supported\") or string methods called on a class property (\"Can't find task itoa in class Named\") or comparisons of class handles (\"SORRY: Compare class handles not implemented\"), aborts on a failed assertion in dup_expr.cc while compiling objects_referring_to_objects, and crashes with a segmentation fault while compiling implicit_constructors_and_this. IEEE 1800-2023 8.4, 8.7, 8.8 and 8.24 define these constructs. Verilator passes all but the string-method case, see sv_verilator_class_property_string_methods.", + "reason": "Icarus 13.0 does not parse a parameter port list of a class (class Box #(int N = 4); is a syntax error), which IEEE 1800-2023 8.25 defines; each case declares a parameterized class. Verilator passes all but two cases, see sv_verilator_class_specialization_identity and sv_verilator_untyped_class_parameters.", "upstream": [] }, - "name": "class::string_methods_on_properties", + "name": "class::specializations_are_named_by_parameter_values", "phase": "skip", "status": "ignored", "stronger_than_sv": false, @@ -564,21 +725,21 @@ }, { "category": "Types", - "detail": "Icarus 13.0 rejects the built-in class randomize and srandom methods during elaboration. IEEE 1800-2023 18.6 and 18.13.3 define these methods. Verilator executes both shared cases successfully, including hooks and independent object random streams.", + "detail": "Icarus 13.0 does not parse a parameter port list of a class (class Box #(int N = 4); is a syntax error), which IEEE 1800-2023 8.25 defines; each case declares a parameterized class. Verilator passes all but two cases, see sv_verilator_class_specialization_identity and sv_verilator_untyped_class_parameters.", "expectation": "Simulation", "known_issue": { - "category": "simulator_unsupported", + "category": "simulator_compile_limitation", "evidence": [ - "verification/repros/sv_class_randomize_icarus.json", + "verification/sv/limitations/icarus.json", "LIMITATIONS.md#systemverilog-suite" ], - "id": "sv_icarus_class_randomize", - "observed_version": "Icarus 13.0", + "id": "sv_icarus_parameterized_classes", + "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", "phase": "compile", - "reason": "Icarus 13.0 rejects the built-in class randomize and srandom methods during elaboration. IEEE 1800-2023 18.6 and 18.13.3 define these methods. Verilator executes both shared cases successfully, including hooks and independent object random streams.", + "reason": "Icarus 13.0 does not parse a parameter port list of a class (class Box #(int N = 4); is a syntax error), which IEEE 1800-2023 8.25 defines; each case declares a parameterized class. Verilator passes all but two cases, see sv_verilator_class_specialization_identity and sv_verilator_untyped_class_parameters.", "upstream": [] }, - "name": "class::unconstrained_randomize", + "name": "class::specializations_in_generate_blocks", "phase": "skip", "status": "ignored", "stronger_than_sv": false, @@ -587,22 +748,21 @@ }, { "category": "Types", - "detail": "Icarus 13.0 binds a virtual function called through a base-class handle to the handle's class instead of the object's: the shared case prints area=0 for every shape, and the adapter-free source prints 1 1 1 3 where IEEE 1800-2023 8.20 requires 2 3 4 4. Verilator and Celox print 2 3 4 4 and pass the case.", + "detail": "Icarus 13.0 does not parse a parameter port list of a class (class Box #(int N = 4); is a syntax error), which IEEE 1800-2023 8.25 defines; each case declares a parameterized class. Verilator passes all but two cases, see sv_verilator_class_specialization_identity and sv_verilator_untyped_class_parameters.", "expectation": "Simulation", "known_issue": { - "category": "simulator_disagreement", + "category": "simulator_compile_limitation", "evidence": [ - "verification/repros/virtual_dispatch_icarus.json", - "verification/repros/virtual_dispatch.sv", + "verification/sv/limitations/icarus.json", "LIMITATIONS.md#systemverilog-suite" ], - "id": "sv_icarus_virtual_dispatch", + "id": "sv_icarus_parameterized_classes", "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", - "phase": "execute", - "reason": "Icarus 13.0 binds a virtual function called through a base-class handle to the handle's class instead of the object's: the shared case prints area=0 for every shape, and the adapter-free source prints 1 1 1 3 where IEEE 1800-2023 8.20 requires 2 3 4 4. Verilator and Celox print 2 3 4 4 and pass the case.", + "phase": "compile", + "reason": "Icarus 13.0 does not parse a parameter port list of a class (class Box #(int N = 4); is a syntax error), which IEEE 1800-2023 8.25 defines; each case declares a parameterized class. Verilator passes all but two cases, see sv_verilator_class_specialization_identity and sv_verilator_untyped_class_parameters.", "upstream": [] }, - "name": "class::virtual_methods_dispatch_on_object_class", + "name": "class::specializations_keep_their_parameter_scopes", "phase": "skip", "status": "ignored", "stronger_than_sv": false, @@ -611,72 +771,211 @@ }, { "category": "Types", - "detail": "Icarus 13.0 cannot elaborate class randomize, srandom and rand_mode calls in the randc cases. IEEE 1800-2023 18.4.2, 18.6 and 18.8 define these operations. The unchanged assertions cover full cycles, signed and enum domains, modes and inheritance.", + "detail": "Icarus 13.0 does not parse a parameter port list of a class (class Box #(int N = 4); is a syntax error), which IEEE 1800-2023 8.25 defines; each case declares a parameterized class. Verilator passes all but two cases, see sv_verilator_class_specialization_identity and sv_verilator_untyped_class_parameters.", "expectation": "Simulation", - "name": "class::randomization_cyclic_controls", + "known_issue": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/sv/limitations/icarus.json", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_icarus_parameterized_classes", + "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", + "phase": "compile", + "reason": "Icarus 13.0 does not parse a parameter port list of a class (class Box #(int N = 4); is a syntax error), which IEEE 1800-2023 8.25 defines; each case declares a parameterized class. Verilator passes all but two cases, see sv_verilator_class_specialization_identity and sv_verilator_untyped_class_parameters.", + "upstream": [] + }, + "name": "class::specializations_of_interface_classes", "phase": "skip", "status": "ignored", "stronger_than_sv": false, "tag_reasons": {}, - "tags": [], + "tags": [] + }, + { + "category": "Types", + "detail": "Icarus 13.0 does not parse a parameter port list of a class (class Box #(int N = 4); is a syntax error), which IEEE 1800-2023 8.25 defines; each case declares a parameterized class. Verilator passes all but two cases, see sv_verilator_class_specialization_identity and sv_verilator_untyped_class_parameters.", + "expectation": "Simulation", "known_issue": { - "id": "sv_icarus_randc", "category": "simulator_compile_limitation", + "evidence": [ + "verification/sv/limitations/icarus.json", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_icarus_parameterized_classes", + "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", "phase": "compile", - "observed_version": "Icarus Verilog version 13.0 (stable) (v13_0)", - "reason": "Icarus 13.0 cannot elaborate class randomize, srandom and rand_mode calls in the randc cases. IEEE 1800-2023 18.4.2, 18.6 and 18.8 define these operations. The unchanged assertions cover full cycles, signed and enum domains, modes and inheritance.", - "upstream": [], + "reason": "Icarus 13.0 does not parse a parameter port list of a class (class Box #(int N = 4); is a syntax error), which IEEE 1800-2023 8.25 defines; each case declares a parameterized class. Verilator passes all but two cases, see sv_verilator_class_specialization_identity and sv_verilator_untyped_class_parameters.", + "upstream": [] + }, + "name": "class::specializations_of_parameterized_classes", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "Icarus 13.0 does not parse a parameter port list of a class (class Box #(int N = 4); is a syntax error), which IEEE 1800-2023 8.25 defines; each case declares a parameterized class. Verilator passes all but two cases, see sv_verilator_class_specialization_identity and sv_verilator_untyped_class_parameters.", + "expectation": "Simulation", + "known_issue": { + "category": "simulator_compile_limitation", "evidence": [ - "verification/repros/sv_randc_icarus.json", + "verification/sv/limitations/icarus.json", "LIMITATIONS.md#systemverilog-suite" - ] - } + ], + "id": "sv_icarus_parameterized_classes", + "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", + "phase": "compile", + "reason": "Icarus 13.0 does not parse a parameter port list of a class (class Box #(int N = 4); is a syntax error), which IEEE 1800-2023 8.25 defines; each case declares a parameterized class. Verilator passes all but two cases, see sv_verilator_class_specialization_identity and sv_verilator_untyped_class_parameters.", + "upstream": [] + }, + "name": "class::specializations_with_their_own_handles", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] }, { "category": "Types", - "detail": "Icarus 13.0 cannot elaborate class randomize, srandom and rand_mode calls in the randc cases. IEEE 1800-2023 18.4.2, 18.6 and 18.8 define these operations. The unchanged assertions cover full cycles, signed and enum domains, modes and inheritance.", + "detail": "Icarus 13.0 rejects class scope resolution with a syntax error: reading a static property (Counter::created), calling a static method (Counter::next()) and assigning a static property (Counter::last = \"set\"). IEEE 1800-2023 8.9, 8.10 and 8.23 define these accesses. Verilator passes the case.", "expectation": "Simulation", - "name": "class::randomization_cyclic_domains", + "known_issue": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/sv/limitations/icarus.json", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_icarus_class_scope_resolution", + "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", + "phase": "compile", + "reason": "Icarus 13.0 rejects class scope resolution with a syntax error: reading a static property (Counter::created), calling a static method (Counter::next()) and assigning a static property (Counter::last = \"set\"). IEEE 1800-2023 8.9, 8.10 and 8.23 define these accesses. Verilator passes the case.", + "upstream": [] + }, + "name": "class::static_properties_and_methods", "phase": "skip", "status": "ignored", "stronger_than_sv": false, "tag_reasons": {}, - "tags": [], + "tags": [] + }, + { + "category": "Types", + "detail": "Icarus 13.0 does not support extern methods (\"sorry: External methods are not yet supported\") or string methods called on a class property (\"Can't find task itoa in class Named\") or comparisons of class handles (\"SORRY: Compare class handles not implemented\"), aborts on a failed assertion in dup_expr.cc while compiling objects_referring_to_objects, and crashes with a segmentation fault while compiling implicit_constructors_and_this. IEEE 1800-2023 8.4, 8.7, 8.8 and 8.24 define these constructs. Verilator passes all but the string-method case, see sv_verilator_class_property_string_methods.", + "expectation": "Simulation", "known_issue": { - "id": "sv_icarus_randc", "category": "simulator_compile_limitation", + "evidence": [ + "verification/sv/limitations/icarus.json", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_icarus_classes", + "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", "phase": "compile", - "observed_version": "Icarus Verilog version 13.0 (stable) (v13_0)", - "reason": "Icarus 13.0 cannot elaborate class randomize, srandom and rand_mode calls in the randc cases. IEEE 1800-2023 18.4.2, 18.6 and 18.8 define these operations. The unchanged assertions cover full cycles, signed and enum domains, modes and inheritance.", - "upstream": [], + "reason": "Icarus 13.0 does not support extern methods (\"sorry: External methods are not yet supported\") or string methods called on a class property (\"Can't find task itoa in class Named\") or comparisons of class handles (\"SORRY: Compare class handles not implemented\"), aborts on a failed assertion in dup_expr.cc while compiling objects_referring_to_objects, and crashes with a segmentation fault while compiling implicit_constructors_and_this. IEEE 1800-2023 8.4, 8.7, 8.8 and 8.24 define these constructs. Verilator passes all but the string-method case, see sv_verilator_class_property_string_methods.", + "upstream": [] + }, + "name": "class::string_methods_on_properties", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "Icarus 13.0 rejects pure virtual method declarations and interface classes with syntax errors (\"Invalid class item\", \"Invalid module item\") and fails code generation without a diagnostic (\"Code generation had 2 error(s)\") for a method called on an element of an array of class handles. IEEE 1800-2023 8.21 and 8.26 define pure virtual methods and interface classes, and 7.4 and 8.4 permit arrays of class handles. Verilator passes all but two cases; see sv_verilator_interface_class_casts and sv_verilator_extended_interface_class_methods.", + "expectation": "Simulation", + "known_issue": { + "category": "simulator_compile_limitation", "evidence": [ - "verification/repros/sv_randc_icarus.json", + "verification/sv/limitations/icarus.json", "LIMITATIONS.md#systemverilog-suite" - ] - } + ], + "id": "sv_icarus_abstract_and_interface_classes", + "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", + "phase": "compile", + "reason": "Icarus 13.0 rejects pure virtual method declarations and interface classes with syntax errors (\"Invalid class item\", \"Invalid module item\") and fails code generation without a diagnostic (\"Code generation had 2 error(s)\") for a method called on an element of an array of class handles. IEEE 1800-2023 8.21 and 8.26 define pure virtual methods and interface classes, and 7.4 and 8.4 permit arrays of class handles. Verilator passes all but two cases; see sv_verilator_interface_class_casts and sv_verilator_extended_interface_class_methods.", + "upstream": [] + }, + "name": "class::typedefs_of_interface_classes", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] }, { "category": "Types", - "detail": "Icarus 13.0 cannot elaborate class randomize, srandom and rand_mode calls in the randc cases. IEEE 1800-2023 18.4.2, 18.6 and 18.8 define these operations. The unchanged assertions cover full cycles, signed and enum domains, modes and inheritance.", + "detail": "Icarus 13.0 rejects the built-in class randomize and srandom methods during elaboration. IEEE 1800-2023 18.6 and 18.13.3 define these methods. Verilator executes both shared cases successfully, including hooks and independent object random streams.", "expectation": "Simulation", - "name": "class::randomization_cyclic_enum_alias", + "known_issue": { + "category": "simulator_unsupported", + "evidence": [ + "verification/repros/sv_class_randomize_icarus.json", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_icarus_class_randomize", + "observed_version": "Icarus 13.0", + "phase": "compile", + "reason": "Icarus 13.0 rejects the built-in class randomize and srandom methods during elaboration. IEEE 1800-2023 18.6 and 18.13.3 define these methods. Verilator executes both shared cases successfully, including hooks and independent object random streams.", + "upstream": [] + }, + "name": "class::unconstrained_randomize", "phase": "skip", "status": "ignored", "stronger_than_sv": false, "tag_reasons": {}, - "tags": [], + "tags": [] + }, + { + "category": "Types", + "detail": "Icarus 13.0 does not parse a parameter port list of a class (class Box #(int N = 4); is a syntax error), which IEEE 1800-2023 8.25 defines; each case declares a parameterized class. Verilator passes all but two cases, see sv_verilator_class_specialization_identity and sv_verilator_untyped_class_parameters.", + "expectation": "Simulation", "known_issue": { - "id": "sv_icarus_randc", "category": "simulator_compile_limitation", + "evidence": [ + "verification/sv/limitations/icarus.json", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_icarus_parameterized_classes", + "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", "phase": "compile", - "observed_version": "Icarus Verilog version 13.0 (stable) (v13_0)", - "reason": "Icarus 13.0 cannot elaborate class randomize, srandom and rand_mode calls in the randc cases. IEEE 1800-2023 18.4.2, 18.6 and 18.8 define these operations. The unchanged assertions cover full cycles, signed and enum domains, modes and inheritance.", - "upstream": [], + "reason": "Icarus 13.0 does not parse a parameter port list of a class (class Box #(int N = 4); is a syntax error), which IEEE 1800-2023 8.25 defines; each case declares a parameterized class. Verilator passes all but two cases, see sv_verilator_class_specialization_identity and sv_verilator_untyped_class_parameters.", + "upstream": [] + }, + "name": "class::untyped_class_parameters_take_the_type_of_their_value", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "Icarus 13.0 binds a virtual function called through a base-class handle to the handle's class instead of the object's: the shared case prints area=0 for every shape, and the adapter-free source prints 1 1 1 3 where IEEE 1800-2023 8.20 requires 2 3 4 4. Verilator and Celox print 2 3 4 4 and pass the case.", + "expectation": "Simulation", + "known_issue": { + "category": "simulator_disagreement", "evidence": [ - "verification/repros/sv_randc_icarus.json", + "verification/repros/virtual_dispatch_icarus.json", + "verification/repros/virtual_dispatch.sv", "LIMITATIONS.md#systemverilog-suite" - ] - } + ], + "id": "sv_icarus_virtual_dispatch", + "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", + "phase": "execute", + "reason": "Icarus 13.0 binds a virtual function called through a base-class handle to the handle's class instead of the object's: the shared case prints area=0 for every shape, and the adapter-free source prints 1 1 1 3 where IEEE 1800-2023 8.20 requires 2 3 4 4. Verilator and Celox print 2 3 4 4 and pass the case.", + "upstream": [] + }, + "name": "class::virtual_methods_dispatch_on_object_class", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] } ] } diff --git a/crates/celox-test-suite/verification/sv/limitations.json b/crates/celox-test-suite/verification/sv/limitations.json index 9610bc6276a..a14cb6fdb09 100644 --- a/crates/celox-test-suite/verification/sv/limitations.json +++ b/crates/celox-test-suite/verification/sv/limitations.json @@ -1925,7 +1925,7 @@ "category": "simulator_compile_limitation", "phase": "compile", "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", - "reason": "Icarus 13.0 rejects pure virtual method declarations and interface classes with syntax errors (\"Invalid class item\", \"Invalid module item\") and fails code generation without a diagnostic (\"Code generation had 2 error(s)\") for a method called on an element of an array of class handles. IEEE 1800-2023 8.21 and 8.26 define pure virtual methods and interface classes, and 7.4 and 8.4 permit arrays of class handles. Verilator passes the first three cases; see sv_verilator_interface_class_casts and sv_verilator_extended_interface_class_methods for the others.", + "reason": "Icarus 13.0 rejects pure virtual method declarations and interface classes with syntax errors (\"Invalid class item\", \"Invalid module item\") and fails code generation without a diagnostic (\"Code generation had 2 error(s)\") for a method called on an element of an array of class handles. IEEE 1800-2023 8.21 and 8.26 define pure virtual methods and interface classes, and 7.4 and 8.4 permit arrays of class handles. Verilator passes all but two cases; see sv_verilator_interface_class_casts and sv_verilator_extended_interface_class_methods.", "upstream": [], "evidence": [ "verification/sv/limitations/icarus.json", @@ -1938,7 +1938,8 @@ "class::classes_implementing_interface_classes", "class::methods_called_through_interface_class_handles", "class::inherited_methods_of_extended_interface_classes", - "class::casts_from_interface_class_handles" + "class::casts_from_interface_class_handles", + "class::typedefs_of_interface_classes" ] } }, @@ -1994,6 +1995,70 @@ ] } }, + { + "id": "sv_verilator_class_specialization_identity", + "category": "simulator_disagreement", + "phase": "execute", + "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", + "reason": "Verilator 5.052 makes a separate specialization of a parameterized class for each way a parameter value assignment is written, so Box#(2, int)::made and Box#(.N(2), .T(int))::made read 0 after an object of Box#(.T(int), .N(2)) was constructed; the adapter-free source prints 0 1 0 where IEEE 1800-2023 8.25 requires 1 1 1, as the three assignments give the same values. Celox prints 1 1 1. Icarus rejects parameterized classes, see sv_icarus_parameterized_classes.", + "upstream": [], + "evidence": [ + "verification/repros/class_specialization_identity_verilator.json", + "verification/repros/class_specialization_identity.sv", + "LIMITATIONS.md#systemverilog-suite" + ], + "cases": { + "verilator": [ + "class::specializations_are_named_by_parameter_values" + ] + } + }, + { + "id": "sv_verilator_untyped_class_parameters", + "category": "simulator_disagreement", + "phase": "execute", + "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", + "reason": "Verilator 5.052 gives a class parameter declared without a type the 32-bit type of its default even when a specialization assigns it a sized value, so $bits(V) of Sized#(8'h1) is 32; the adapter-free source prints 32 32 where IEEE 1800-2023 6.20.2 requires 8 32, as the parameter takes the type of its final value after overrides. Celox prints 8 32. Icarus rejects parameterized classes, see sv_icarus_parameterized_classes.", + "upstream": [], + "evidence": [ + "verification/repros/untyped_class_parameters_verilator.json", + "verification/repros/untyped_class_parameters.sv", + "LIMITATIONS.md#systemverilog-suite" + ], + "cases": { + "verilator": [ + "class::untyped_class_parameters_take_the_type_of_their_value" + ] + } + }, + { + "id": "sv_icarus_parameterized_classes", + "category": "simulator_compile_limitation", + "phase": "compile", + "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", + "reason": "Icarus 13.0 does not parse a parameter port list of a class (class Box #(int N = 4); is a syntax error), which IEEE 1800-2023 8.25 defines; each case declares a parameterized class. Verilator passes all but two cases, see sv_verilator_class_specialization_identity and sv_verilator_untyped_class_parameters.", + "upstream": [], + "evidence": [ + "verification/sv/limitations/icarus.json", + "LIMITATIONS.md#systemverilog-suite" + ], + "cases": { + "icarus": [ + "class::specializations_of_parameterized_classes", + "class::specializations_are_named_by_parameter_values", + "class::specializations_with_their_own_handles", + "class::class_scoped_parameters_and_types", + "class::specializations_of_interface_classes", + "class::named_constructor_arguments", + "class::specializations_in_generate_blocks", + "class::specializations_keep_their_parameter_scopes", + "class::untyped_class_parameters_take_the_type_of_their_value", + "class::class_declarations_bind_in_their_scopes", + "class::parameter_defaults_bind_where_the_class_is_declared", + "class::specialization_keys_follow_the_bound_parameters" + ] + } + }, { "id": "sv_verilator_class_property_string_methods", "category": "simulator_compile_limitation", diff --git a/crates/celox-test-suite/verification/sv/limitations/icarus.json b/crates/celox-test-suite/verification/sv/limitations/icarus.json index fd6bb918a35..8d4523ff88d 100644 --- a/crates/celox-test-suite/verification/sv/limitations/icarus.json +++ b/crates/celox-test-suite/verification/sv/limitations/icarus.json @@ -9,7 +9,7 @@ "unexpected_accept": 1, "mismatch": 17, "emission_error": 0, - "compile_error": 120, + "compile_error": 133, "runtime_error": 8, "unsupported": 0, "ignored": 0 @@ -1359,6 +1359,110 @@ "name": "timing::always_star_timed_task_calls_wait_on_folded_branch_reads", "phase": "execute", "status": "mismatch" + }, + { + "category": "Types", + "detail": "Icarus build exit status: 26; see /build.log\n/source_0.sv:3: syntax error\n/source_0.sv:3: error: Invalid module item.\n/source_0.sv:6: syntax error\n/source_0.sv:6: error: Invalid module item.\n/source_0.sv:7: syntax error\n/source_0.sv:7: error: Invalid module item.\n/source_0.sv:9: syntax error\n/source_0.sv:9: error: Invalid module item.\n/source_0.sv:10: syntax error\n/source_0.sv:11: error: Invalid module item.\n/source_0.sv:12: syntax error\n/source_0.sv:12: error: Invalid module item.\n/source_0.sv:13: syntax error\n/source_0.sv:15: error: Invalid module item.\n/source_0.sv:16: syntax error\n/source_0.sv:16: error: Invalid module item.\n/source_0.sv:17: syntax error\n/source_0.sv:18: error: Invalid module item.\n/source_0.sv:19: syntax error\n/source_0.sv:19: error: Invalid module instantiation\n/source_0.sv:21: syntax error\n/source_0.sv:21: error: Malformed statement\n/source_0.sv:23: syntax error\n/source_0.sv:23: error: Malformed statement\n/source_0.sv:24: syntax error\n/source_0.sv:24: error: Malformed statement\n", + "expectation": "Simulation", + "name": "class::class_scoped_parameters_and_types", + "phase": "compile", + "status": "compile_error" + }, + { + "category": "Types", + "detail": "Icarus build exit status: 10; see /build.log\n/source_0.sv:9: syntax error\n/source_0.sv:9: error: Invalid module item.\n/source_0.sv:12: syntax error\n/source_0.sv:12: error: I give up on this function definition.\n/source_0.sv:17: syntax error\n/source_0.sv:18: error: Invalid module item.\n/source_0.sv:19: syntax error\n/source_0.sv:19: error: Invalid module instantiation\n/source_0.sv:23: syntax error\n/source_0.sv:23: error: Malformed statement\n", + "expectation": "Simulation", + "name": "class::named_constructor_arguments", + "phase": "compile", + "status": "compile_error" + }, + { + "category": "Types", + "detail": "Icarus build exit status: 8; see /build.log\n/source_0.sv:3: syntax error\n/source_0.sv:3: error: Invalid module item.\n/source_0.sv:5: syntax error\n/source_0.sv:5: error: I give up on this function definition.\n/source_0.sv:8: syntax error\n/source_0.sv:9: error: Invalid module item.\n/source_0.sv:12: syntax error\n/source_0.sv:12: error: Malformed statement\n", + "expectation": "Simulation", + "name": "class::specializations_are_named_by_parameter_values", + "phase": "compile", + "status": "compile_error" + }, + { + "category": "Types", + "detail": "Icarus build exit status: 28; see /build.log\n/source_0.sv:3: syntax error\n/source_0.sv:3: error: Invalid module item.\n/source_0.sv:4: syntax error\n/source_0.sv:4: error: Invalid module item.\n/source_0.sv:5: syntax error\n/source_0.sv:6: error: Invalid module item.\n/source_0.sv:7: syntax error\n/source_0.sv:7: error: Invalid module item.\n/source_0.sv:8: syntax error\n/source_0.sv:8: error: Invalid module item.\n/source_0.sv:9: syntax error\n/source_0.sv:11: error: Invalid module item.\n/source_0.sv:12: syntax error\n/source_0.sv:12: error: Invalid module item.\n/source_0.sv:13: syntax error\n/source_0.sv:14: error: Invalid module item.\n/source_0.sv:15: syntax error\n/source_0.sv:15: error: Invalid module item.\n/source_0.sv:16: syntax error\n/source_0.sv:17: error: Invalid module item.\n/source_0.sv:18: syntax error\n/source_0.sv:18: error: Invalid module instantiation\n/source_0.sv:19: syntax error\n/source_0.sv:19: error: Invalid module instantiation\n/source_0.sv:20: syntax error\n/source_0.sv:20: error: Invalid module instantiation\n/source_0.sv:21: syntax error\n/source_0.sv:21: error: Invalid module instantiation\n", + "expectation": "Simulation", + "name": "class::specializations_of_interface_classes", + "phase": "compile", + "status": "compile_error" + }, + { + "category": "Types", + "detail": "Icarus build exit status: 28; see /build.log\n/source_0.sv:3: syntax error\n/source_0.sv:3: error: Invalid module item.\n/source_0.sv:4: syntax error\n/source_0.sv:4: error: Invalid module instantiation\n/source_0.sv:7: syntax error\n/source_0.sv:7: error: I give up on this function definition.\n/source_0.sv:11: syntax error\n/source_0.sv:11: error: Syntax error defining function.\n/source_0.sv:18: syntax error\n/source_0.sv:19: error: Invalid module item.\n/source_0.sv:20: syntax error\n/source_0.sv:20: error: I give up on this function definition.\n/source_0.sv:26: syntax error\n/source_0.sv:27: error: Invalid module item.\n/source_0.sv:28: syntax error\n/source_0.sv:28: error: Invalid module instantiation\n/source_0.sv:29: syntax error\n/source_0.sv:29: error: Invalid module instantiation\n/source_0.sv:30: syntax error\n/source_0.sv:30: error: Invalid module instantiation\n/source_0.sv:31: syntax error\n/source_0.sv:31: error: Invalid module instantiation\n/source_0.sv:32: syntax error\n/source_0.sv:32: error: Invalid module instantiation\n/source_0.sv:40: syntax error\n/source_0.sv:40: error: Malformed statement\n/source_0.sv:42: syntax error\n/source_0.sv:42: error: Malformed statement\n", + "expectation": "Simulation", + "name": "class::specializations_of_parameterized_classes", + "phase": "compile", + "status": "compile_error" + }, + { + "category": "Types", + "detail": "Icarus build exit status: 18; see /build.log\n/source_0.sv:3: syntax error\n/source_0.sv:3: error: Invalid module item.\n/source_0.sv:4: syntax error\n/source_0.sv:4: error: Invalid module item.\n/source_0.sv:5: syntax error\n/source_0.sv:5: error: Invalid module item.\n/source_0.sv:6: syntax error\n/source_0.sv:8: error: Invalid module item.\n/source_0.sv:9: syntax error\n/source_0.sv:9: error: Invalid module item.\n/source_0.sv:10: syntax error\n/source_0.sv:10: error: Invalid module item.\n/source_0.sv:11: syntax error\n/source_0.sv:13: error: Invalid module item.\n/source_0.sv:14: syntax error\n/source_0.sv:14: error: Invalid module instantiation\n/source_0.sv:15: syntax error\n/source_0.sv:15: error: Invalid module instantiation\n", + "expectation": "Simulation", + "name": "class::specializations_with_their_own_handles", + "phase": "compile", + "status": "compile_error" + }, + { + "category": "Types", + "detail": "Icarus build exit status: 18; see /build.log\n/source_0.sv:3: syntax error\n/source_0.sv:3: error: Invalid module item.\n/source_0.sv:5: syntax error\n/source_0.sv:5: error: Invalid module item.\n/source_0.sv:6: syntax error\n/source_0.sv:7: error: Invalid module item.\n/source_0.sv:8: syntax error\n/source_0.sv:8: error: Invalid module item.\n/source_0.sv:9: syntax error\n/source_0.sv:10: error: Invalid module item.\n/source_0.sv:11: syntax error\n/source_0.sv:11: error: Invalid module item.\n/source_0.sv:13: syntax error\n/source_0.sv:14: error: Invalid module item.\n/source_0.sv:15: syntax error\n/source_0.sv:15: error: Invalid module item.\n/source_0.sv:16: syntax error\n/source_0.sv:18: error: Invalid module item.\n", + "expectation": "Simulation", + "name": "class::typedefs_of_interface_classes", + "phase": "compile", + "status": "compile_error" + }, + { + "category": "Types", + "detail": "Icarus build exit status: 134; see /build.log\n/source_0.sv:3: syntax error\n/source_0.sv:3: error: Invalid module item.\n/source_0.sv:5: syntax error\n/source_0.sv:5: error: I give up on this function definition.\n/source_0.sv:11: syntax error\n/source_0.sv:12: error: Invalid module item.\n/source_0.sv:12: syntax error\n/source_0.sv:12: error: Invalid module instantiation\n/source_0.sv:12: error: Invalid module instantiation\n/source_0.sv:15: sorry: Overriding the default variable lifetime is not yet supported.\n/source_0.sv:15: syntax error\n/source_0.sv:15: error: Malformed statement\n/source_0.sv:16: syntax error\n/source_0.sv:16: error: Invalid module instantiation\n/source_0.sv:17: syntax error\n/source_0.sv:17: error: Invalid module item.\n/source_0.sv:18: syntax error\n/source_0.sv:18: error: Invalid module instantiation\n/testbench.sv:3: error: Invalid module item.\n/testbench.sv:11: warning: Static variable initialization requires explicit lifetime in this context.\n/source_0.sv:2: assert: pform.cc:1478: failed assertion lexical_scope == cur_module\nAborted (core dumped)\n", + "expectation": "Simulation", + "name": "class::specializations_in_generate_blocks", + "phase": "compile", + "status": "compile_error" + }, + { + "category": "Types", + "detail": "Icarus build exit status: 36; see /build.log\n/source_0.sv:3: syntax error\n/source_0.sv:3: error: Invalid module item.\n/source_0.sv:7: syntax error\n/source_0.sv:8: error: Invalid module item.\n/source_0.sv:9: syntax error\n/source_0.sv:10: error: Invalid module item.\n/source_0.sv:11: syntax error\n/source_0.sv:11: error: Syntax error in typedef clause.\n/source_0.sv:12: syntax error\n/source_0.sv:13: error: Invalid module item.\n/source_0.sv:17: syntax error\n/source_0.sv:18: error: Invalid module item.\n/source_0.sv:19: syntax error\n/source_0.sv:19: error: Invalid module item.\n/source_0.sv:20: syntax error\n/source_0.sv:21: error: Invalid module item.\n/source_0.sv:22: syntax error\n/source_0.sv:22: error: Invalid module instantiation\n/source_0.sv:23: error: Invalid module instantiation\n/source_0.sv:24: error: Invalid module item.\n/source_0.sv:25: syntax error\n/source_0.sv:26: error: Invalid module item.\n/source_0.sv:28: syntax error\n/source_0.sv:28: error: I give up on this function definition.\n/source_0.sv:31: syntax error\n/source_0.sv:32: error: Invalid module item.\n/source_0.sv:33: syntax error\n/source_0.sv:33: error: Invalid module instantiation\n/source_0.sv:34: syntax error\n/source_0.sv:34: error: Invalid module instantiation\n/source_0.sv:35: syntax error\n/source_0.sv:35: error: Invalid module instantiation\n/source_0.sv:37: syntax error\n/source_0.sv:37: error: Invalid module instantiation\n/source_0.sv:48: syntax error\n/source_0.sv:48: error: Malformed statement\n", + "expectation": "Simulation", + "name": "class::specializations_keep_their_parameter_scopes", + "phase": "compile", + "status": "compile_error" + }, + { + "category": "Types", + "detail": "Icarus build exit status: 6; see /build.log\n/source_0.sv:3: syntax error\n/source_0.sv:3: error: Invalid module item.\n/source_0.sv:7: syntax error\n/source_0.sv:8: error: Invalid module item.\n/source_0.sv:9: syntax error\n/source_0.sv:9: error: Invalid module instantiation\n", + "expectation": "Simulation", + "name": "class::untyped_class_parameters_take_the_type_of_their_value", + "phase": "compile", + "status": "compile_error" + }, + { + "category": "Types", + "detail": "Icarus build exit status: 36; see /build.log\n/source_0.sv:8: syntax error\n/source_0.sv:8: error: Invalid module item.\n/source_0.sv:10: syntax error\n/source_0.sv:11: error: Invalid module item.\n/source_0.sv:15: syntax error\n/source_0.sv:16: error: Invalid module item.\n/source_0.sv:17: syntax error\n/source_0.sv:17: error: Syntax error in typedef clause.\n/source_0.sv:21: syntax error\n/source_0.sv:22: error: Invalid module item.\n/source_0.sv:23: syntax error\n/source_0.sv:24: error: Invalid module item.\n/source_0.sv:25: syntax error\n/source_0.sv:25: error: Syntax error in typedef clause.\n/source_0.sv:26: syntax error\n/source_0.sv:27: error: Invalid module item.\n/source_0.sv:31: syntax error\n/source_0.sv:32: error: Invalid module item.\n/source_0.sv:34: syntax error\n/source_0.sv:35: error: Invalid module item.\n/source_0.sv:36: syntax error\n/source_0.sv:1: error: Syntax error in variable list.\n/source_0.sv:37: syntax error\n/source_0.sv:37: error: Invalid module instantiation\n/source_0.sv:38: syntax error\n/source_0.sv:38: error: Invalid module instantiation\n/source_0.sv:39: syntax error\n/source_0.sv:39: error: Invalid module instantiation\n/source_0.sv:40: syntax error\n/source_0.sv:40: error: Invalid module instantiation\n/source_0.sv:41: syntax error\n/source_0.sv:41: error: Invalid module instantiation\n/source_0.sv:48: syntax error\n/source_0.sv:48: error: Malformed statement\n/source_0.sv:49: syntax error\n/source_0.sv:49: error: Malformed statement\n", + "expectation": "Simulation", + "name": "class::class_declarations_bind_in_their_scopes", + "phase": "compile", + "status": "compile_error" + }, + { + "category": "Types", + "detail": "Icarus build exit status: 10; see /build.log\n/source_0.sv:3: syntax error\n/source_0.sv:3: error: Invalid module item.\n/source_0.sv:7: syntax error\n/source_0.sv:9: error: Invalid module item.\n/source_0.sv:10: syntax error\n/source_0.sv:10: error: Invalid module instantiation\n/source_0.sv:16: syntax error\n/testbench.sv:3: error: Invalid module item.\n/testbench.sv:4: error: Repeat timeunit found and the initial timeunit for this scope is missing.\n/testbench.sv:5: error: Repeat timeprecision found and the initial timeprecision for this scope is missing.\n", + "expectation": "Simulation", + "name": "class::parameter_defaults_bind_where_the_class_is_declared", + "phase": "compile", + "status": "compile_error" + }, + { + "category": "Types", + "detail": "Icarus build exit status: 65; see /build.log\n/source_0.sv:9: syntax error\n/source_0.sv:9: error: Invalid module item.\n/source_0.sv:11: syntax error\n/source_0.sv:11: error: I give up on this function definition.\n/source_0.sv:14: syntax error\n/source_0.sv:15: error: Invalid module item.\n/source_0.sv:16: syntax error\n/source_0.sv:16: error: Syntax error in typedef clause.\n/source_0.sv:17: syntax error\n/source_0.sv:17: error: Syntax error in parameter value assignment list.\n/source_0.sv:17: error: Invalid module instantiation\n/source_0.sv:18: error: I give up on this function definition.\n/source_0.sv:21: syntax error\n/source_0.sv:22: error: Invalid module item.\n/source_0.sv:23: syntax error\n/source_0.sv:24: error: Invalid module item.\n/source_0.sv:26: syntax error\n/source_0.sv:27: error: Invalid module item.\n/source_0.sv:28: error: 'made' has already been declared in this scope.\n/source_0.sv:10: : It was declared here as a variable.\n/source_0.sv:29: syntax error\n/source_0.sv:29: error: I give up on this function definition.\n/source_0.sv:32: syntax error\n/source_0.sv:33: error: Invalid module item.\n/source_0.sv:35: syntax error\n/source_0.sv:36: error: Invalid module item.\n/source_0.sv:37: syntax error\n/source_0.sv:37: error: Invalid module item.\n/source_0.sv:39: syntax error\n/source_0.sv:39: error: Invalid module item.\n/source_0.sv:40: syntax error\n/source_0.sv:41: error: Invalid module item.\n/source_0.sv:42: syntax error\n/source_0.sv:43: error: Invalid module item.\n/source_0.sv:44: syntax error\n/source_0.sv:44: error: Invalid module item.\n/source_0.sv:45: syntax error\n/source_0.sv:45: error: Invalid module item.\n/source_0.sv:46: syntax error\n/source_0.sv:48: error: Invalid module item.\n/source_0.sv:50: syntax error\n/source_0.sv:50: error: Invalid module instantiation\n/source_0.sv:53: syntax error\n/source_0.sv:53: error: Malformed statement\n/source_0.sv:54: syntax error\n/source_0.sv:54: error: Malformed statement\n/source_0.sv:55: syntax error\n/source_0.sv:55: error: Malformed statement\n/source_0.sv:56: syntax error\n/source_0.sv:56: error: Malformed statement\n/source_0.sv:57: syntax error\n/source_0.sv:57: error: Malformed statement\n/source_0.sv:58: syntax error\n/source_0.sv:58: error: Malformed statement\n/source_0.sv:59: syntax error\n/source_0.sv:59: error: Malformed statement\n/source_0.sv:60: syntax error\n/source_0.sv:60: error: Malformed statement\n/source_0.sv:61: syntax error\n/source_0.sv:61: error: Malformed statement\n/source_0.sv:62: syntax error\n/source_0.sv:62: error: Malformed statement\n/source_0.sv:68: syntax error\n/source_0.sv:68: error: Malformed statement\n/source_0.sv:71: syntax error\n/source_0.sv:71: error: Malformed statement\n", + "expectation": "Simulation", + "name": "class::specialization_keys_follow_the_bound_parameters", + "phase": "compile", + "status": "compile_error" } ] } diff --git a/crates/celox-test-suite/verification/sv/limitations/verilator.json b/crates/celox-test-suite/verification/sv/limitations/verilator.json index baf0c215a6a..4ca00686a3e 100644 --- a/crates/celox-test-suite/verification/sv/limitations/verilator.json +++ b/crates/celox-test-suite/verification/sv/limitations/verilator.json @@ -7,7 +7,7 @@ "passed": 0, "rejected": 0, "unexpected_accept": 0, - "mismatch": 28, + "mismatch": 30, "emission_error": 0, "compile_error": 18, "runtime_error": 2, @@ -482,6 +482,22 @@ "name": "timing::always_star_timed_task_calls_wait_on_folded_branch_reads", "phase": "execute", "status": "mismatch" + }, + { + "category": "Types", + "detail": "class::specializations_are_named_by_parameter_values at 783:3: expect_output: expected [49, 32, 49, 32, 49, 10], got [48, 32, 48, 32, 48, 10]", + "expectation": "Simulation", + "name": "class::specializations_are_named_by_parameter_values", + "phase": "execute", + "status": "mismatch" + }, + { + "category": "Types", + "detail": "class::untyped_class_parameters_take_the_type_of_their_value at 1045:3: expect_output: expected [56, 32, 51, 50, 10], got [51, 50, 32, 51, 50, 10]", + "expectation": "Simulation", + "name": "class::untyped_class_parameters_take_the_type_of_their_value", + "phase": "execute", + "status": "mismatch" } ] } diff --git a/crates/celox-test-suite/verification/sv/verilator/class.json b/crates/celox-test-suite/verification/sv/verilator/class.json index 0afd033620e..b531bcbdd46 100644 --- a/crates/celox-test-suite/verification/sv/verilator/class.json +++ b/crates/celox-test-suite/verification/sv/verilator/class.json @@ -46,6 +46,28 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Types", + "detail": "", + "expectation": "Simulation", + "name": "class::class_declarations_bind_in_their_scopes", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "", + "expectation": "Simulation", + "name": "class::class_scoped_parameters_and_types", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Types", "detail": "", @@ -157,6 +179,17 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Types", + "detail": "", + "expectation": "Simulation", + "name": "class::named_constructor_arguments", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Types", "detail": "", @@ -192,72 +225,296 @@ }, { "category": "Types", + "detail": "", "expectation": "Simulation", - "name": "class::randomization_enum_alias", + "name": "class::parameter_defaults_bind_where_the_class_is_declared", + "phase": "execute", + "status": "passed", "stronger_than_sv": false, "tag_reasons": {}, - "tags": [], - "detail": "Verilator 5.052 randomizes an enum typedef alias as its underlying 8-bit integer, producing values outside the declared set {-7, 2, 91}. Generated __VBasicRand assigns a masked VL_RANDOM_RNG_I value instead of selecting from an enum table. IEEE 1800-2023 18.3 restricts enum randomization to declared values; the direct enum and inheritance cases pass unchanged.", + "tags": [] + }, + { + "category": "Types", + "detail": "Verilator 5.052 emits duplicate srandom declarations for the inherited randc control case using both base and derived handles. The shared assertions retain cyclic state and random-mode coverage under IEEE 1800-2023 18.4.2, 18.6.2 and 18.8.", + "expectation": "Simulation", + "known_issue": { + "category": "simulator_compile_limitation", + "evidence": [ + "verification/repros/sv_randc_verilator.json", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_verilator_randc_inheritance", + "observed_version": "Verilator 5.052 2026-09-05 rev v5.052", + "phase": "compile", + "reason": "Verilator 5.052 emits duplicate srandom declarations for the inherited randc control case using both base and derived handles. The shared assertions retain cyclic state and random-mode coverage under IEEE 1800-2023 18.4.2, 18.6.2 and 18.8.", + "upstream": [] + }, + "name": "class::randomization_cyclic_controls", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "", + "expectation": "Simulation", + "name": "class::randomization_cyclic_domains", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "Verilator 5.052 treats the randc enum typedef alias as its underlying integer. Generated __VBasicRand assigns the cyclic integer draw directly without an enum value table, producing undeclared values. IEEE 1800-2023 18.3 and 18.4.2 require a permutation of declared values. The direct enum and integer cycle case passes unchanged.", + "expectation": "Simulation", "known_issue": { - "id": "sv_verilator_enum_alias_randomization", "category": "simulator_disagreement", - "phase": "execute", + "evidence": [ + "verification/repros/sv_randc_verilator.json", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_verilator_randc_enum_alias", "observed_version": "Verilator 5.052 2026-09-05 rev v5.052", - "reason": "Verilator 5.052 randomizes an enum typedef alias as its underlying 8-bit integer, producing values outside the declared set {-7, 2, 91}. Generated __VBasicRand assigns a masked VL_RANDOM_RNG_I value instead of selecting from an enum table. IEEE 1800-2023 18.3 restricts enum randomization to declared values; the direct enum and inheritance cases pass unchanged.", - "upstream": [], + "phase": "execute", + "reason": "Verilator 5.052 treats the randc enum typedef alias as its underlying integer. Generated __VBasicRand assigns the cyclic integer draw directly without an enum value table, producing undeclared values. IEEE 1800-2023 18.3 and 18.4.2 require a permutation of declared values. The direct enum and integer cycle case passes unchanged.", + "upstream": [] + }, + "name": "class::randomization_cyclic_enum_alias", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "Verilator 5.052 randomizes an enum typedef alias as its underlying 8-bit integer, producing values outside the declared set {-7, 2, 91}. Generated __VBasicRand assigns a masked VL_RANDOM_RNG_I value instead of selecting from an enum table. IEEE 1800-2023 18.3 restricts enum randomization to declared values; the direct enum and inheritance cases pass unchanged.", + "expectation": "Simulation", + "known_issue": { + "category": "simulator_disagreement", "evidence": [ "verification/repros/sv_enum_randomization_verilator.json", "LIMITATIONS.md#systemverilog-suite" - ] + ], + "id": "sv_verilator_enum_alias_randomization", + "observed_version": "Verilator 5.052 2026-09-05 rev v5.052", + "phase": "execute", + "reason": "Verilator 5.052 randomizes an enum typedef alias as its underlying 8-bit integer, producing values outside the declared set {-7, 2, 91}. Generated __VBasicRand assigns a masked VL_RANDOM_RNG_I value instead of selecting from an enum table. IEEE 1800-2023 18.3 restricts enum randomization to declared values; the direct enum and inheritance cases pass unchanged.", + "upstream": [] }, + "name": "class::randomization_enum_alias", "phase": "skip", - "status": "ignored" + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] }, { "category": "Types", + "detail": "", "expectation": "Simulation", - "name": "class::randomization_inheritance", + "name": "class::randomization_enum_domain", + "phase": "execute", + "status": "passed", "stronger_than_sv": false, "tag_reasons": {}, - "tags": [], + "tags": [] + }, + { + "category": "Types", + "detail": "", + "expectation": "Simulation", + "name": "class::randomization_enum_fill_literals", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "", + "expectation": "Simulation", + "name": "class::randomization_enum_inheritance", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", "detail": "Verilator 5.052 reports duplicate declarations of the built-in srandom member/function when this inherited randomization case seeds the same object through both derived and base handles. IEEE 1800-2023 18.6.2 and 18.13.3 permit dynamic class randomization and object seeding. Celox preserves the assertions for inherited hidden members and hook dispatch.", + "expectation": "Simulation", "known_issue": { - "id": "sv_verilator_inherited_srandom", "category": "simulator_compile_limitation", - "phase": "compile", + "evidence": [ + "verification/repros/sv_randomization_control_verilator.json", + "LIMITATIONS.md#systemverilog-suite" + ], + "id": "sv_verilator_inherited_srandom", "observed_version": "Verilator 5.052 2026-09-05 rev v5.052", + "phase": "compile", "reason": "Verilator 5.052 reports duplicate declarations of the built-in srandom member/function when this inherited randomization case seeds the same object through both derived and base handles. IEEE 1800-2023 18.6.2 and 18.13.3 permit dynamic class randomization and object seeding. Celox preserves the assertions for inherited hidden members and hook dispatch.", - "upstream": [], + "upstream": [] + }, + "name": "class::randomization_inheritance", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "Verilator 5.052 treats rand_mode(2) as enabled for both member and object-wide setters. IEEE 1800-2023 18.8 declares a bit on_off formal, so integral 2 truncates to zero. The case records two assertion failures; generated C++ sets the mode to 1 for these calls. Celox retains the required bit conversion.", + "expectation": "Simulation", + "known_issue": { + "category": "simulator_disagreement", "evidence": [ "verification/repros/sv_randomization_control_verilator.json", "LIMITATIONS.md#systemverilog-suite" - ] + ], + "id": "sv_verilator_rand_mode_bit_argument", + "observed_version": "Verilator 5.052 2026-09-05 rev v5.052", + "phase": "execute", + "reason": "Verilator 5.052 treats rand_mode(2) as enabled for both member and object-wide setters. IEEE 1800-2023 18.8 declares a bit on_off formal, so integral 2 truncates to zero. The case records two assertion failures; generated C++ sets the mode to 1 for these calls. Celox retains the required bit conversion.", + "upstream": [] }, + "name": "class::randomization_mode_bit_argument", "phase": "skip", - "status": "ignored" + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] }, { "category": "Types", + "detail": "", "expectation": "Simulation", - "name": "class::randomization_mode_bit_argument", + "name": "class::randomization_modes_and_selection", + "phase": "execute", + "status": "passed", "stronger_than_sv": false, "tag_reasons": {}, - "tags": [], - "detail": "Verilator 5.052 treats rand_mode(2) as enabled for both member and object-wide setters. IEEE 1800-2023 18.8 declares a bit on_off formal, so integral 2 truncates to zero. The case records two assertion failures; generated C++ sets the mode to 1 for these calls. Celox retains the required bit conversion.", + "tags": [] + }, + { + "category": "Types", + "detail": "", + "expectation": "Simulation", + "name": "class::randomization_pre_hook_controls_modes", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "", + "expectation": "Simulation", + "name": "class::randomize_without_rand_members", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "", + "expectation": "Simulation", + "name": "class::specialization_keys_follow_the_bound_parameters", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "Verilator 5.052 makes a separate specialization of a parameterized class for each way a parameter value assignment is written, so Box#(2, int)::made and Box#(.N(2), .T(int))::made read 0 after an object of Box#(.T(int), .N(2)) was constructed; the adapter-free source prints 0 1 0 where IEEE 1800-2023 8.25 requires 1 1 1, as the three assignments give the same values. Celox prints 1 1 1. Icarus rejects parameterized classes, see sv_icarus_parameterized_classes.", + "expectation": "Simulation", "known_issue": { - "id": "sv_verilator_rand_mode_bit_argument", "category": "simulator_disagreement", - "phase": "execute", - "observed_version": "Verilator 5.052 2026-09-05 rev v5.052", - "reason": "Verilator 5.052 treats rand_mode(2) as enabled for both member and object-wide setters. IEEE 1800-2023 18.8 declares a bit on_off formal, so integral 2 truncates to zero. The case records two assertion failures; generated C++ sets the mode to 1 for these calls. Celox retains the required bit conversion.", - "upstream": [], "evidence": [ - "verification/repros/sv_randomization_control_verilator.json", + "verification/repros/class_specialization_identity_verilator.json", + "verification/repros/class_specialization_identity.sv", "LIMITATIONS.md#systemverilog-suite" - ] + ], + "id": "sv_verilator_class_specialization_identity", + "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", + "phase": "execute", + "reason": "Verilator 5.052 makes a separate specialization of a parameterized class for each way a parameter value assignment is written, so Box#(2, int)::made and Box#(.N(2), .T(int))::made read 0 after an object of Box#(.T(int), .N(2)) was constructed; the adapter-free source prints 0 1 0 where IEEE 1800-2023 8.25 requires 1 1 1, as the three assignments give the same values. Celox prints 1 1 1. Icarus rejects parameterized classes, see sv_icarus_parameterized_classes.", + "upstream": [] }, + "name": "class::specializations_are_named_by_parameter_values", "phase": "skip", - "status": "ignored" + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "", + "expectation": "Simulation", + "name": "class::specializations_in_generate_blocks", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "", + "expectation": "Simulation", + "name": "class::specializations_keep_their_parameter_scopes", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "", + "expectation": "Simulation", + "name": "class::specializations_of_interface_classes", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "", + "expectation": "Simulation", + "name": "class::specializations_of_parameterized_classes", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "", + "expectation": "Simulation", + "name": "class::specializations_with_their_own_handles", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] }, { "category": "Types", @@ -297,7 +554,7 @@ "category": "Types", "detail": "", "expectation": "Simulation", - "name": "class::virtual_methods_dispatch_on_object_class", + "name": "class::typedefs_of_interface_classes", "phase": "execute", "status": "passed", "stronger_than_sv": false, @@ -306,49 +563,49 @@ }, { "category": "Types", - "detail": "Verilator 5.052 emits duplicate srandom declarations for the inherited randc control case using both base and derived handles. The shared assertions retain cyclic state and random-mode coverage under IEEE 1800-2023 18.4.2, 18.6.2 and 18.8.", + "detail": "", "expectation": "Simulation", - "name": "class::randomization_cyclic_controls", - "phase": "skip", - "status": "ignored", + "name": "class::unconstrained_randomize", + "phase": "execute", + "status": "passed", "stronger_than_sv": false, "tag_reasons": {}, - "tags": [], + "tags": [] + }, + { + "category": "Types", + "detail": "Verilator 5.052 gives a class parameter declared without a type the 32-bit type of its default even when a specialization assigns it a sized value, so $bits(V) of Sized#(8'h1) is 32; the adapter-free source prints 32 32 where IEEE 1800-2023 6.20.2 requires 8 32, as the parameter takes the type of its final value after overrides. Celox prints 8 32. Icarus rejects parameterized classes, see sv_icarus_parameterized_classes.", + "expectation": "Simulation", "known_issue": { - "id": "sv_verilator_randc_inheritance", - "category": "simulator_compile_limitation", - "phase": "compile", - "observed_version": "Verilator 5.052 2026-09-05 rev v5.052", - "reason": "Verilator 5.052 emits duplicate srandom declarations for the inherited randc control case using both base and derived handles. The shared assertions retain cyclic state and random-mode coverage under IEEE 1800-2023 18.4.2, 18.6.2 and 18.8.", - "upstream": [], + "category": "simulator_disagreement", "evidence": [ - "verification/repros/sv_randc_verilator.json", + "verification/repros/untyped_class_parameters_verilator.json", + "verification/repros/untyped_class_parameters.sv", "LIMITATIONS.md#systemverilog-suite" - ] - } + ], + "id": "sv_verilator_untyped_class_parameters", + "observed_version": "Celox SV frontend; Verilator 5.052 / Icarus 13.0", + "phase": "execute", + "reason": "Verilator 5.052 gives a class parameter declared without a type the 32-bit type of its default even when a specialization assigns it a sized value, so $bits(V) of Sized#(8'h1) is 32; the adapter-free source prints 32 32 where IEEE 1800-2023 6.20.2 requires 8 32, as the parameter takes the type of its final value after overrides. Celox prints 8 32. Icarus rejects parameterized classes, see sv_icarus_parameterized_classes.", + "upstream": [] + }, + "name": "class::untyped_class_parameters_take_the_type_of_their_value", + "phase": "skip", + "status": "ignored", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] }, { "category": "Types", - "detail": "Verilator 5.052 treats the randc enum typedef alias as its underlying integer. Generated __VBasicRand assigns the cyclic integer draw directly without an enum value table, producing undeclared values. IEEE 1800-2023 18.3 and 18.4.2 require a permutation of declared values. The direct enum and integer cycle case passes unchanged.", + "detail": "", "expectation": "Simulation", - "name": "class::randomization_cyclic_enum_alias", - "phase": "skip", - "status": "ignored", + "name": "class::virtual_methods_dispatch_on_object_class", + "phase": "execute", + "status": "passed", "stronger_than_sv": false, "tag_reasons": {}, - "tags": [], - "known_issue": { - "id": "sv_verilator_randc_enum_alias", - "category": "simulator_disagreement", - "phase": "execute", - "observed_version": "Verilator 5.052 2026-09-05 rev v5.052", - "reason": "Verilator 5.052 treats the randc enum typedef alias as its underlying integer. Generated __VBasicRand assigns the cyclic integer draw directly without an enum value table, producing undeclared values. IEEE 1800-2023 18.3 and 18.4.2 require a permutation of declared values. The direct enum and integer cycle case passes unchanged.", - "upstream": [], - "evidence": [ - "verification/repros/sv_randc_verilator.json", - "LIMITATIONS.md#systemverilog-suite" - ] - } + "tags": [] } ] } diff --git a/crates/celox-test-suite/verification/sv/xezim/class.json b/crates/celox-test-suite/verification/sv/xezim/class.json index 275fed951b0..c74c87503c7 100644 --- a/crates/celox-test-suite/verification/sv/xezim/class.json +++ b/crates/celox-test-suite/verification/sv/xezim/class.json @@ -33,6 +33,28 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Types", + "detail": "class::class_declarations_bind_in_their_scopes at 1604:3: expect_output: expected [50, 53, 53, 32, 53, 32, 45, 51, 32, 51, 50, 10, 50, 48, 32, 51, 48, 32, 49, 32, 98, 99, 32, 48, 51, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 10], got [50, 53, 53, 32, 49, 32, 52, 50, 57, 52, 57, 54, 55, 50, 57, 51, 32, 51, 50, 10, 50, 48, 32, 51, 48, 32, 49, 32, 98, 99, 32, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 102, 10]", + "expectation": "Simulation", + "name": "class::class_declarations_bind_in_their_scopes", + "phase": "execute", + "status": "mismatch", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "class::class_scoped_parameters_and_types at 844:3: expect_output: expected [50, 32, 49, 48, 32, 49, 48, 51, 10, 49, 53, 32, 53, 32, 53, 32, 55, 10], got [48, 32, 48, 32, 49, 48, 51, 10, 52, 50, 57, 52, 57, 54, 55, 50, 57, 53, 32, 49, 51, 32, 53, 32, 55, 10]", + "expectation": "Simulation", + "name": "class::class_scoped_parameters_and_types", + "phase": "execute", + "status": "mismatch", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Types", "detail": "", @@ -132,6 +154,17 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Types", + "detail": "", + "expectation": "Simulation", + "name": "class::named_constructor_arguments", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Types", "detail": "", @@ -167,7 +200,51 @@ }, { "category": "Types", - "detail": "class::randomization_enum_alias at 1038:46: assert_eq errors: expected 0x0, got 0x81", + "detail": "class::parameter_defaults_bind_where_the_class_is_declared at 1626:3: expect_output: expected [49, 10], got [50, 10]", + "expectation": "Simulation", + "name": "class::parameter_defaults_bind_where_the_class_is_declared", + "phase": "execute", + "status": "mismatch", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "class::randomization_cyclic_controls at 1515:46: assert_eq errors: expected 0x0, got 0x1", + "expectation": "Simulation", + "name": "class::randomization_cyclic_controls", + "phase": "execute", + "status": "mismatch", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "class::randomization_cyclic_domains at 1462:46: assert_eq errors: expected 0x0, got 0x300", + "expectation": "Simulation", + "name": "class::randomization_cyclic_domains", + "phase": "execute", + "status": "mismatch", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "class::randomization_cyclic_enum_alias at 1547:46: assert_eq errors: expected 0x0, got 0x30", + "expectation": "Simulation", + "name": "class::randomization_cyclic_enum_alias", + "phase": "execute", + "status": "mismatch", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "class::randomization_enum_alias at 1372:46: assert_eq errors: expected 0x0, got 0x81", "expectation": "Simulation", "name": "class::randomization_enum_alias", "phase": "execute", @@ -178,7 +255,7 @@ }, { "category": "Types", - "detail": "class::randomization_enum_domain at 979:46: assert_eq errors: expected 0x0, got 0x1e5", + "detail": "class::randomization_enum_domain at 1313:46: assert_eq errors: expected 0x0, got 0x1e5", "expectation": "Simulation", "name": "class::randomization_enum_domain", "phase": "execute", @@ -189,7 +266,7 @@ }, { "category": "Types", - "detail": "class::randomization_enum_fill_literals at 1069:46: assert_eq errors: expected 0x0, got 0x18", + "detail": "class::randomization_enum_fill_literals at 1403:46: assert_eq errors: expected 0x0, got 0x18", "expectation": "Simulation", "name": "class::randomization_enum_fill_literals", "phase": "execute", @@ -200,7 +277,7 @@ }, { "category": "Types", - "detail": "class::randomization_enum_inheritance at 1010:46: assert_eq errors: expected 0x0, got 0xff", + "detail": "class::randomization_enum_inheritance at 1344:46: assert_eq errors: expected 0x0, got 0xff", "expectation": "Simulation", "name": "class::randomization_enum_inheritance", "phase": "execute", @@ -211,7 +288,7 @@ }, { "category": "Types", - "detail": "class::randomization_inheritance at 835:46: assert_eq errors: expected 0x0, got 0x1", + "detail": "class::randomization_inheritance at 1169:46: assert_eq errors: expected 0x0, got 0x1", "expectation": "Simulation", "name": "class::randomization_inheritance", "phase": "execute", @@ -222,7 +299,7 @@ }, { "category": "Types", - "detail": "class::randomization_mode_bit_argument at 931:46: assert_eq errors: expected 0x0, got 0x3", + "detail": "class::randomization_mode_bit_argument at 1265:46: assert_eq errors: expected 0x0, got 0x3", "expectation": "Simulation", "name": "class::randomization_mode_bit_argument", "phase": "execute", @@ -233,7 +310,7 @@ }, { "category": "Types", - "detail": "class::randomization_modes_and_selection at 882:46: assert_eq errors: expected 0x0, got 0x1414", + "detail": "class::randomization_modes_and_selection at 1216:46: assert_eq errors: expected 0x0, got 0x1414", "expectation": "Simulation", "name": "class::randomization_modes_and_selection", "phase": "execute", @@ -244,7 +321,7 @@ }, { "category": "Types", - "detail": "class::randomization_pre_hook_controls_modes at 908:46: assert_eq errors: expected 0x0, got 0x2", + "detail": "class::randomization_pre_hook_controls_modes at 1242:46: assert_eq errors: expected 0x0, got 0x2", "expectation": "Simulation", "name": "class::randomization_pre_hook_controls_modes", "phase": "execute", @@ -264,6 +341,83 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Types", + "detail": "class::specialization_keys_follow_the_bound_parameters at 1715:3: expect_output: expected [50, 32, 49, 32, 49, 10, 49, 32, 49, 10, 51, 46, 48, 32, 51, 46, 48, 10, 50, 10, 55, 10], got [50, 32, 49, 32, 48, 10, 48, 32, 49, 10, 48, 46, 48, 32, 48, 46, 48, 10, 50, 10, 55, 10]", + "expectation": "Simulation", + "name": "class::specialization_keys_follow_the_bound_parameters", + "phase": "execute", + "status": "mismatch", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "", + "expectation": "Simulation", + "name": "class::specializations_are_named_by_parameter_values", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "class::specializations_in_generate_blocks at 969:3: expect_output: expected [49, 32, 49, 32, 49, 49, 10, 50, 32, 50, 32, 50, 49, 10], got [49, 32, 48, 32, 49, 48, 10, 50, 32, 48, 32, 50, 48, 10]", + "expectation": "Simulation", + "name": "class::specializations_in_generate_blocks", + "phase": "execute", + "status": "mismatch", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "class::specializations_keep_their_parameter_scopes at 1026:3: expect_output: expected [53, 10, 52, 32, 55, 48, 48, 32, 50, 10], got [53, 10, 50, 48, 32, 48, 32, 49, 10]", + "expectation": "Simulation", + "name": "class::specializations_keep_their_parameter_scopes", + "phase": "execute", + "status": "mismatch", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "class::specializations_of_interface_classes at 880:3: expect_output: expected [45, 55, 32, 57, 32, 45, 55, 10], got [45, 55, 32, 48, 32, 45, 55, 10]", + "expectation": "Simulation", + "name": "class::specializations_of_interface_classes", + "phase": "execute", + "status": "mismatch", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "class::specializations_of_parameterized_classes at 763:3: expect_output: expected [49, 52, 32, 55, 32, 45, 51, 32, 49, 10, 52, 32, 49, 50, 32, 49, 32, 49, 10, 49, 48, 54, 32, 54, 32, 53, 54, 32, 49, 10], got [49, 52, 32, 55, 32, 45, 51, 32, 49, 10, 52, 32, 49, 50, 32, 49, 32, 49, 10, 49, 48, 52, 32, 52, 32, 53, 52, 32, 48, 10]", + "expectation": "Simulation", + "name": "class::specializations_of_parameterized_classes", + "phase": "execute", + "status": "mismatch", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, + { + "category": "Types", + "detail": "", + "expectation": "Simulation", + "name": "class::specializations_with_their_own_handles", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Types", "detail": "", @@ -286,6 +440,17 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Types", + "detail": "", + "expectation": "Simulation", + "name": "class::typedefs_of_interface_classes", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Types", "detail": "", @@ -297,6 +462,17 @@ "tag_reasons": {}, "tags": [] }, + { + "category": "Types", + "detail": "", + "expectation": "Simulation", + "name": "class::untyped_class_parameters_take_the_type_of_their_value", + "phase": "execute", + "status": "passed", + "stronger_than_sv": false, + "tag_reasons": {}, + "tags": [] + }, { "category": "Types", "detail": "", diff --git a/crates/celox-test-suite/verification/xezim-review.json b/crates/celox-test-suite/verification/xezim-review.json index 864b9cb918d..fc12387205b 100644 --- a/crates/celox-test-suite/verification/xezim-review.json +++ b/crates/celox-test-suite/verification/xezim-review.json @@ -614,6 +614,34 @@ "sv_new-X11": { "title": "The time-0 value of a continuous assignment through a function that fills a local unpacked array in a loop is all ones", "standard": "IEEE 1800-2023 10.3.2, 13.4" + }, + "sv_class-X3": { + "title": "A class value parameter with an explicit type (`logic [57:0] V`) keeps the actual's width: `C#('1)` gives 64 ones, a 64-bit actual is not truncated, and `$bits(V)` is 32", + "standard": "IEEE 1800-2023 6.20.2, 8.25, 23.10, 5.7.1" + }, + "sv_class-X2": { + "title": "A type reached through the class scope operator that is a class type parameter or a typedef of one (`C#(.T(bit [2:0]))::T`, `D::t` with `typedef T t` of an inherited parameter, `PT::t` through a typedef of a specialization) gets 32 bits instead of the specialization's type", + "standard": "IEEE 1800-2023 8.25.1, 8.23, 8.13" + }, + "sv_class-X5": { + "title": "A class parameter default (`class D #(int N = X)`) is evaluated at the specialization site instead of the class declaration: a generate block with its own X changes `D#()`", + "standard": "IEEE 1800-2023 8.25, 23.9" + }, + "sv_class-X6": { + "title": "Matching specializations are treated as distinct (separate static members): a typedef of a type parameter (`Box#(Outer::Inner)` with Inner = byte) vs `Box#(byte)`, `logic [3:0]` vs `reg [3:0]`, and two occurrences of an x-valued argument `Four#(2'bxx)`", + "standard": "IEEE 1800-2023 8.25, 6.22.1, 6.11.1" + }, + "sv_class-X8": { + "title": "In a generate loop, a procedural handle `Box#(i)` with a genvar argument gets N = 0, and `Box#(i * 10)::made` in the generate block names a different specialization than the block's `Box#(i * 10)` handle", + "standard": "IEEE 1800-2023 27.4, 8.25, 8.25.1" + }, + "sv_class-X9": { + "title": "A specialization written inside a method of a parameterized class (`Inner#(N)` in `Outer#(7)`) binds the class's default N instead of the current specialization's", + "standard": "IEEE 1800-2023 8.25, 8.24, 23.9" + }, + "sv_class-X10": { + "title": "In `extends Base #(expr, T)` an ordered value argument that is an operator expression (`M + 1`, `(2 + 4)`) is dropped when another argument follows; the base class gets its default", + "standard": "IEEE 1800-2023 8.25, 23.10.2.1" } }, "cases": [ @@ -3840,6 +3868,93 @@ "classification": "xezim_bug", "bug": "sv_new-X11", "note": "For index = 0 (the zero start value, so no update event) `assign y = identity(index)` keeps xezim's time-0 value 0x3ffffffffffffff instead of 0x1; identity clears words[i] and sets words[i][i] for i = 0..57 and returns words[selected]. After index changes, xezim computes the right one-hot value. Related to I0, also a wrong time-0 value of a function-valued continuous assignment. Repro: work/triage/new3/x11_time0_function_scratch_array.sv." + }, + { + "suite": "sv", + "name": "class::class_declarations_bind_in_their_scopes", + "status": "mismatch", + "classification": "xezim_bug", + "bug": "sv_class-X3", + "note": "Wide#('1) with `class Wide #(logic [57:0] V = 0)` must give V = 58 ones (the override is converted to the declared type, '1 filling 58 bits), so v() returns 64'h03ffffffffffffff; xezim prints ffffffffffffffff even as top (it keeps the actual's width; $bits(V) is 32). As non-top dut, line 1 is also wrong: entries (Ordered::table_t = int [2]) and plain (Plain::T = int) are declared as unsigned 32-bit vectors (entries[1] is a bit-select = 1, plain = 4294967293), a further defect (in a non-top module, a variable declared with a class-scoped typedef (`Plain::T`, `Ordered::table_t`, `C#(3)::word_t`) gets an unsigned 32-bit vector type: signedness, width and unpacked dimensions of the typedef are lost). Repros: work/review5/xezim/r/c1_wide.sv, work/review5/xezim/r/c1_typedef.sv (+ .wrap.sv)." + }, + { + "suite": "sv", + "name": "class::class_scoped_parameters_and_types", + "status": "mismatch", + "classification": "xezim_bug", + "bug": "sv_class-X2", + "note": "The case is the 8.25.1 example (C#()::f(), C#(5)::f() print \"2 10\") plus C#(.T(bit [2:0]))::T y, which is 3 bits, so y = 13 reads 5. As top, xezim declares y with 32 bits (prints 13), sv_class-X2. As non-top dut, the out-of-block C::f body also reads p and C::p as 0 (\"0 0\", sv_rest-X4) and x (C#(3)::word_t = bit [3:0]) becomes 32 bits, so '1 prints 4294967295 (a further defect (in a non-top module, a variable declared with a class-scoped typedef (`Plain::T`, `Ordered::table_t`, `C#(3)::word_t`) gets an unsigned 32-bit vector type: signedness, width and unpacked dimensions of the typedef are lost)). Repros: work/review5/xezim/r/c2_typeparam.sv, work/review5/xezim/r/c2_extern.sv (+ .wrap.sv)." + }, + { + "suite": "sv", + "name": "class::parameter_defaults_bind_where_the_class_is_declared", + "status": "mismatch", + "classification": "xezim_bug", + "bug": "sv_class-X5", + "note": "Defaulted #(int N = X) is declared in Top (X = 1); the default expression is part of the class declaration, so its X resolves upward from the class (23.9) to Top's X, not to the generate block g where Defaulted#() is used and which declares its own X = 2. Expected 1; xezim prints 2 as top and as non-top." + }, + { + "suite": "sv", + "name": "class::randomization_cyclic_controls", + "status": "mismatch", + "classification": "lrm_ambiguous", + "note": "Only the last check fails: a.calls is 40 instead of 48 because xezim runs no pre/post_randomize for each of the 8 a.randomize(null) calls (it does run them for a.randomize() with every variable rand_mode(0)). Reading 1 (the suite's, Verilator 5.052): 18.6.2 says randomize() calls the hooks, 18.6.3 exempts only a failed call, and 18.11.1 makes randomize(null) a checker like a class without random variables, so the hooks run. Reading 2 (xezim): randomize(null) only checks the constraints and randomizes nothing, so the hooks need not run; 18.11.1 does not mention them. As for randomization_modes_and_selection, whether the hooks run for the null checker form is not explicit. Repro: work/review5/xezim/r/c6_hooks.sv." + }, + { + "suite": "sv", + "name": "class::randomization_cyclic_domains", + "status": "mismatch", + "classification": "xezim_bug", + "bug": "sv_new-X3", + "note": "errors = 768 = 3 x 256: every randomize of `randc Single single_value` (enum bit [63:0] {ONLY='1}) gives 1 instead of the only constant 64'hffffffffffffffff (18.3 restricts enum random variables to the named constants, randc included); the byte, signed and E cycles all pass. Same defect as the rand fill-literal case; a constant written 64'hffffffffffffffff works. Repro: work/review5/xezim/r/c7_fill.sv." + }, + { + "suite": "sv", + "name": "class::randomization_cyclic_enum_alias", + "status": "mismatch", + "classification": "xezim_bug", + "bug": "sv_new-X4", + "note": "`randc Alias value` with `typedef E Alias` takes arbitrary 64-bit values (each randomize hits the default branch), while `randc E` cycles through NEG/MID/HIGH. 18.3 and 6.18 (an alias names the same enum type) require the enum domain. Repro: work/review5/xezim/r/c8_alias.sv." + }, + { + "suite": "sv", + "name": "class::specialization_keys_follow_the_bound_parameters", + "status": "mismatch", + "classification": "xezim_bug", + "bug": "sv_class-X6", + "note": "Line 1: Outer#(byte) constructs Box#(Outer::Inner) with Inner = T = byte, which matches byte (6.22.1 b), so Box#(byte)::made is 1; xezim 0. Line 2: Four#(2'bxx)::made is 1 because the declaration and the reference use the same value 2'bxx (8.25 b); xezim 0. Line 3: Real#(1.0 + 2.0)::v() and Real#(3.0)::v() must return 3.0; xezim returns 0.0 for a real parameter in a static method called through the class scope (a further defect (a real class parameter reads 0.0 in a static method called through the class scope (`Real#(3.0)::v()`); instance methods see the value)). Verilator 5.052 agrees with the expected output. Repros: work/review5/xezim/r/c10_keys.sv, work/review5/xezim/r/c10b.sv." + }, + { + "suite": "sv", + "name": "class::specializations_in_generate_blocks", + "status": "mismatch", + "classification": "xezim_bug", + "bug": "sv_class-X8", + "note": "In g[i], `automatic Box #(i) local_box` must have N = i (the genvar is a localparam of each block, 27.4), and kept (Box#(i*10)) is the same specialization as Box#(i*10)::made, so the lines are \"1 1 11\" / \"2 2 21\". xezim gives local_box.n() = 0 and made = 0 (kept.n() is right) as top and non-top; Box#(J) with `localparam J = i + 4` works for handles. Repros: work/review5/xezim/r/c11_gen.sv, work/review5/xezim/r/c11b.sv." + }, + { + "suite": "sv", + "name": "class::specializations_keep_their_parameter_scopes", + "status": "mismatch", + "classification": "xezim_bug", + "bug": "sv_class-X9", + "note": "outer.f() builds Inner #(N) in Outer#(7)'s method, so N = 7 and v() = 700; xezim uses Outer's default N = 1 (100) as top, and 0 as non-top (out-of-block body, sv_rest-X4). Also Derived::nibble_t (typedef T, T = bit [3:0] from `extends Base #(bit [3:0])`) is declared with 32 bits so 20 is not truncated to 4 (sv_class-X2), and Counted#(logic [3:0]) and Counted#(reg [3:0]) are one specialization (6.11.1: logic and reg denote the same type) so made = 2; xezim 1 (sv_class-X6). Verilator 5.052 prints 4 700 2. Repro: work/review5/xezim/r/c12.sv (+ .wrap.sv)." + }, + { + "suite": "sv", + "name": "class::specializations_of_interface_classes", + "status": "mismatch", + "classification": "xezim_bug", + "bug": "sv_rest-X4", + "note": "The out-of-block NibbleBox::get returns V + 20 = 25 truncated to 4 bits = 9. As non-top dut xezim's out-of-block body reads the class parameter V as 0 (prints 0; as top it prints 9), the same loss of class members in extern bodies as sv_rest-X4 (b), here for a parameter instead of a property. Repro: work/review5/xezim/r/c2_extern.sv (+ .wrap.sv)." + }, + { + "suite": "sv", + "name": "class::specializations_of_parameterized_classes", + "status": "mismatch", + "classification": "xezim_bug", + "bug": "sv_class-X10", + "note": "Wide #(5) extends Box #(M + 1, int), so its base is Box#(6, int): w.N = 6, base.get() = 100 + 6, kind() = 56, and super.new increments Box#(6, int)::made (1). xezim gives the base the default N = 4 (104 4 54 0) as top and non-top. The ordered argument `M + 1` (even `(2 + 4)`) is lost only in an extends clause and only when a second argument follows; `extends Box #(M + 1)`, `extends Box #(M, int)` and a variable `Box #(2 + 4, int)` work. Repros: work/review5/xezim/r/c14c.sv, work/review5/xezim/r/c14d.sv." } ] } diff --git a/crates/celox/tests/frontends/systemverilog/class.rs b/crates/celox/tests/frontends/systemverilog/class.rs index de50527500c..796adcea29e 100644 --- a/crates/celox/tests/frontends/systemverilog/class.rs +++ b/crates/celox/tests/frontends/systemverilog/class.rs @@ -24,9 +24,54 @@ sv_backends! { fn class_inherited_methods_of_extended_interface_classes(sim) { @case "class::inherited_methods_of_extended_interface_classes"; } fn class_casts_of_class_handles(sim) { @case "class::casts_of_class_handles"; } fn class_casts_from_interface_class_handles(sim) { @case "class::casts_from_interface_class_handles"; } + fn class_specializations_of_parameterized_classes(sim) { @case "class::specializations_of_parameterized_classes"; } + fn class_specializations_are_named_by_parameter_values(sim) { @case "class::specializations_are_named_by_parameter_values"; } + fn class_specializations_with_their_own_handles(sim) { @case "class::specializations_with_their_own_handles"; } + fn class_class_scoped_parameters_and_types(sim) { @case "class::class_scoped_parameters_and_types"; } + fn class_specializations_of_interface_classes(sim) { @case "class::specializations_of_interface_classes"; } + fn class_named_constructor_arguments(sim) { @case "class::named_constructor_arguments"; } + fn class_typedefs_of_interface_classes(sim) { @case "class::typedefs_of_interface_classes"; } + fn class_specializations_in_generate_blocks(sim) { @case "class::specializations_in_generate_blocks"; } + fn class_specializations_keep_their_parameter_scopes(sim) { @case "class::specializations_keep_their_parameter_scopes"; } + fn class_untyped_class_parameters_take_the_type_of_their_value(sim) { @case "class::untyped_class_parameters_take_the_type_of_their_value"; } + fn class_class_declarations_bind_in_their_scopes(sim) { @case "class::class_declarations_bind_in_their_scopes"; } + fn class_parameter_defaults_bind_where_the_class_is_declared(sim) { @case "class::parameter_defaults_bind_where_the_class_is_declared"; } + fn class_specialization_keys_follow_the_bound_parameters(sim) { @case "class::specialization_keys_follow_the_bound_parameters"; } } sv_backends! { + // Actuals are evaluated in the order they are written, as for other + // calls with named arguments. + fn named_constructor_arguments_are_evaluated_in_written_order(sim) { + @setup { + let source = r#"module Top(output int x, output int y); + class Point; + int x; + int y; + function new(int x = 0, int y = 0); + this.x = x; + this.y = y; + endfunction + endclass + int count; + function int next(); + count++; + return count; + endfunction + Point point; + initial begin + point = new(.y(next()), .x(next())); + x = point.x; + y = point.y; + end + endmodule"#; + } + @build celox::Simulation::from_sv_sources(vec![(source, Path::new("order.sv"))], "Top"); + sim.run_until(0).unwrap(); + assert_eq!(sim.get(sim.signal("x")), 2u32.into()); + assert_eq!(sim.get(sim.signal("y")), 1u32.into()); + } + fn null_dereferences_are_runtime_errors(sim) { @setup { let source = r#"module Top(output int value, output bit done); @@ -194,6 +239,86 @@ fn incompatible_class_handle_assignments_are_rejected() { } } +#[test] +fn misused_parameterized_classes_are_rejected() { + for (items, want) in [ + ( + "Box #(2) two; Box #(3) three; initial begin three = new; two = three; end", + ["handle of class `Box#(N=3)`", "class `Box#(N=2)`"], + ), + ( + "initial $display(Box::N);", + ["`Box::` outside class `Box`", "`Box#()::`"], + ), + ( + "Box #(.M(1)) other;", + ["class `Box` has no parameter `M`", ""], + ), + ( + "interface class Get #(type T = int); pure virtual function T get(); endclass + interface class Both extends Get#(int), Get#(bit); endclass", + ["interface class `Both`", "inherits `T` from both"], + ), + ( + "class Self #(int N = 0) extends Self#(N + 1); endclass Self self;", + ["nested more than 64 deep", "class `Self`"], + ), + ( + "class Sized #(parameter V = 1); endclass Sized #(8'h1) a; Sized #(32'h1) b; + initial begin b = new; a = b; end", + ["class `Sized#(V=32'd1)`", "class `Sized#(V=8'd1)`"], + ), + ( + "Box #(.N(3), 4) mixed;", + ["positional parameter value after a named one", ""], + ), + ( + "class Point; function new(int x = 0); endfunction endclass Point p; + initial p = new(.x(), .x(1));", + ["constructor argument passed twice", ""], + ), + ( + "Box #(.N(), .N(2)) twice;", + ["duplicate parameter assignment `N`", ""], + ), + ( + "class Plain; typedef int T; endclass Plain#(123)::T value;", + ["class `Plain`, which has no parameters", ""], + ), + ( + "typedef enum {A, B} e_t; class Typed #(type T = int); endclass Typed#(e_t) typed;", + ["enumeration type as a class type parameter value", ""], + ), + ( + "typedef struct packed { int x; } s_t; class Typed #(type T = int); endclass Typed#(s_t) typed;", + ["struct or union type as a class type parameter value", ""], + ), + ( + // The class parameter hides the module's `N`, whose value must + // not name `Four#(1)` (#1964 tracks four-state actuals). + "localparam int N = 1; class Four #(logic [1:0] N = 0); endclass + class Shadow #(logic [1:0] N = 2'bxx); function void make(); Four#(N) four; endfunction endclass + Shadow#() shadow;", + ["class parameter value that is not constant", ""], + ), + ] { + let source = format!( + "module Top; + class Box #(int N = 4); endclass + {items} + endmodule" + ); + let Err(error) = + Simulator::from_sv_sources(vec![(source.as_str(), Path::new("class.sv"))], "Top") + .build_cranelift() + else { + panic!("`{items}` is rejected"); + }; + let error = error.to_string(); + assert!(want.iter().all(|want| error.contains(want)), "{error}"); + } +} + sv_backends! { fn class_unconstrained_randomize(sim) { @case "class::unconstrained_randomize"; } fn class_randomize_without_rand_members(sim) { @case "class::randomize_without_rand_members"; } @@ -379,6 +504,95 @@ sv_backends! { } } +#[test] +fn a_class_of_another_module_does_not_hide_a_package() { + let source = "package P; typedef bit [2:0] T; endpackage + module Other; class P; typedef int T; endclass endmodule + module Top(output int bits); P::T value; assign bits = $bits(value); endmodule"; + let mut sim = Simulator::from_sv_sources(vec![(source, Path::new("class.sv"))], "Top") + .build_cranelift() + .unwrap(); + assert_eq!(sim.get(sim.signal("bits")), 3u32.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); + class Defs; typedef bit [7:0] T; endclass + class Box #(type T = int); + T value; + function int bits(); return $bits(value); endfunction + endclass + Box#(Defs::T) box; + for (genvar i = 2; i < 4; i++) begin : g + Box#(bit [i:0]) sized; + initial begin + sized = new; + if (i == 2) narrow = sized.bits(); else wide = sized.bits(); + end + end + initial begin box = new; defs = box.bits(); end + endmodule"; + let mut sim = celox::Simulation::from_sv_sources(vec![(source, Path::new("class.sv"))], "Top") + .build() + .unwrap(); + sim.run_until(0).unwrap(); + assert_eq!(sim.get(sim.signal("defs")), 8u32.into()); + assert_eq!(sim.get(sim.signal("narrow")), 3u32.into()); + assert_eq!(sim.get(sim.signal("wide")), 4u32.into()); + // Arrays of strings of two sizes are two types (IEEE 1800-2023 6.22). + let source = "module Top; + class Box #(type T = int); endclass + typedef string A [2]; + typedef string B [3]; + Box#(A) a; + Box#(B) b; + initial begin b = new; a = b; end + endmodule"; + let Err(error) = + Simulator::from_sv_sources(vec![(source, Path::new("class.sv"))], "Top").build_cranelift() + else { + panic!("handles of two specializations are not assignment compatible"); + }; + assert!(error.to_string().contains("a handle of class"), "{error}"); +} + +#[test] +fn specializations_tell_types_apart_and_keep_their_bases() { + let source = r#"module Top(output int packed_made, output int unpacked_made, output int width, output int base_n); + localparam int K = 2; + class Box #(type T = int); static int made; function new(); made++; endfunction endclass + typedef bit [1:0] A; + typedef bit B [1:0]; + class Inner #(int N = 1); typedef bit [N:0] T; endclass + class Outer #(int N = 1); + function int w(); Inner#(N)::T v; return $bits(v); endfunction + endclass + class Base #(int N = 0); localparam int K = 1; function int n(); return N; endfunction endclass + class Derived extends Base#(K); endclass + Box#(A) a; Box#(B) b; + Outer#(2) o; + Derived d; + initial begin + a = new; b = new; o = new; d = new; + packed_made = Box#(A)::made; + unpacked_made = Box#(B)::made; + width = o.w(); + base_n = d.n(); + end +endmodule"#; + let mut sim = celox::Simulation::from_sv_sources(vec![(source, Path::new("class.sv"))], "Top") + .build() + .unwrap(); + sim.run_until(0).unwrap(); + // `bit [1:0]` and `bit [1:0]` unpacked are two types (IEEE 1800-2023 6.22). + assert_eq!(sim.get(sim.signal("packed_made")), 1u32.into()); + assert_eq!(sim.get(sim.signal("unpacked_made")), 1u32.into()); + assert_eq!(sim.get(sim.signal("width")), 3u32.into()); + // `extends Base#(K)` names the module's `K`, not the one `Base` declares. + assert_eq!(sim.get(sim.signal("base_n")), 2u32.into()); +} + sv_backends! { fn class_randomization_enum_inheritance(sim) { @case "class::randomization_enum_inheritance"; } fn class_randomization_enum_alias(sim) { @case "class::randomization_enum_alias"; } diff --git a/docs/guide/systemverilog-reference.md b/docs/guide/systemverilog-reference.md index e76ef25edc3..72105e17cca 100644 --- a/docs/guide/systemverilog-reference.md +++ b/docs/guide/systemverilog-reference.md @@ -32,7 +32,7 @@ synthesis and is tested at the design level. | Selects | constant and run-time bit selects and indexed part-selects (`[i]`, `[i +: W]`, `[i -: W]`), in reads and writes, in either declaration direction | | Patterns | assignment patterns for packed structs, packed arrays and unpacked arrays (`'{a, b}`, `'{x: a, default: 0}`, `'{n{a}}`, `T'{...}`) | | Strings | `string` variables, function arguments and results: assignment of strings, string literals and casts (`string'(x)`), `==`, `!=` and ordering comparisons, concatenation and replication (with a run-time count), character reads and writes (`s[i]`), and the methods `len`, `getc`, `putc`, `toupper`, `tolower`, `compare`, `icompare`, `substr`, `atoi` / `atohex` / `atooct` / `atobin` and `itoa` / `hextoa` / `octtoa` / `bintoa`; `%s` and format-less display of string values. See [strings](#strings) | -| Classes | classes declared in a module: properties of 2-state integral types up to 64 bits, `string` and class handle types, with initializers; `new` with and without arguments, implicit and explicit constructors; methods (`function` and `task`, also `extern` with an out-of-block body) called through a handle or unqualified inside the class; `this`, `null`, handle assignment and comparison; inheritance of properties and methods, with base constructors called by `super.new(...)` or `extends Base(...)`; `super.` members; virtual methods, abstract (`virtual`) classes and pure virtual methods; classes that implement interface classes and method calls through interface class handles; `$cast` of class handles, as a function and as a task; static properties and methods; `C::` scope resolution of static members and `C::new`; arrays of handles. See [classes](#classes) | +| Classes | classes declared in a module: properties of 2-state integral types up to 64 bits, `string` and class handle types, with initializers; `new` with and without arguments, implicit and explicit constructors; methods (`function` and `task`, also `extern` with an out-of-block body) called through a handle or unqualified inside the class; `this`, `null`, handle assignment and comparison; inheritance of properties and methods, with base constructors called by `super.new(...)` or `extends Base(...)`; `super.` members; virtual methods, abstract (`virtual`) classes and pure virtual methods; classes that implement interface classes and method calls through interface class handles; `$cast` of class handles, as a function and as a task; static properties and methods; `C::` scope resolution of static members and `C::new`; arrays of handles; parameterized classes with value and type parameters, parameters read through a handle or `C#(...)::`, typedefs of classes and interface classes and `C::T`; named constructor arguments. See [classes](#classes) | | Parameters | integral parameters and overrides preserving widths beyond 128 bits and X/Z values, and parameters of unpacked array or packed struct type given by an assignment pattern (constant tables), including unpacked-array pattern overrides | ### Processes and control flow @@ -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, typedefs and parameters of interface classes, classes declared in packages, parameterized classes, named constructor arguments, shallow copies (`new h`), 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, classes declared in packages, shallow copies (`new h`), 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`. @@ -324,6 +324,21 @@ initializers of the properties its class declares, then its body (IEEE 1800-2023 8.17). A static property is a variable of the module that declares the class, so each instance of the module has its own. +Each set of parameter values and types of a parameterized class is a +specialization, a class of its own with its own static properties (IEEE +1800-2023 8.25): `C#(2, int)` and `C#(.T(int), .N(2))` are one specialization, +and a handle of `C#(2)` cannot be assigned to a variable of `C#(3)`. A +parameter value assignment is evaluated where it is written, so the values may +depend on parameters of the module. As a type, the class name alone denotes +the default specialization `C#()`, inside the class too; as the prefix of +`::` inside the class and its out-of-block methods it refers to the +specialization being declared, and elsewhere `C#()::` is required (8.25.1). An interface class inherits the parameters and typedefs of the +interface classes it extends, and one that inherits the same name from two +different interface classes or specializations must declare its own +(8.26.6.2, 8.26.6.3). Celox makes the specializations that the types and +scopes of a module name before it runs, binding an assignment inside a generate +block once for each of its instances. + Checkpoints keep objects. State files record strings but not objects, so saving a state file fails while any variable holds an object. diff --git a/docs/ja/guide/systemverilog-reference.md b/docs/ja/guide/systemverilog-reference.md index aa70dec1646..282d29ac1bc 100644 --- a/docs/ja/guide/systemverilog-reference.md +++ b/docs/ja/guide/systemverilog-reference.md @@ -29,7 +29,7 @@ outline: [2, 3] | 式 | `**` を含む算術、論理、シフト、比較、リダクション、連結・複製、`?:`、`inside`、`==?` / `!=?`、キャスト(`N'(x)`、`signed'(x)`、`T'(x)`)、`$signed` / `$unsigned` | | 選択 | 定数・実行時のビット選択と indexed part-select(`[i]`、`[i +: W]`、`[i -: W]`)。読み書きの両方、宣言の向きによらず | | パターン | packed 構造体・packed 配列・unpacked 配列の assignment pattern(`'{a, b}`、`'{x: a, default: 0}`、`'{n{a}}`、`T'{...}`) | -| クラス | モジュール内で宣言したクラス。64 ビット以下の 2 値整数型・`string`・クラスハンドル型のプロパティ(初期値つきも可)、引数あり・なしの `new`、暗黙と明示のコンストラクタ、ハンドル経由またはクラス内から修飾なしで呼ぶメソッド(`function` と `task`、本体をクラス外に書く `extern` も可)、`this`、`null`、ハンドルの代入と比較、プロパティとメソッドの継承(基底クラスのコンストラクタは `super.new(...)` か `extends Base(...)` で呼ぶ)、`super.` によるメンバ参照、virtual メソッド、抽象クラス(`virtual class`)と pure virtual メソッド、interface クラスを実装するクラスと interface クラスのハンドルを通したメソッド呼び出し、関数とタスクとしてのクラスハンドルの `$cast`、static プロパティとメソッド、static メンバと `C::new` の `C::` によるスコープ解決、ハンドルの配列。[クラス](#classes)を参照 | +| クラス | モジュール内で宣言したクラス。64 ビット以下の 2 値整数型・`string`・クラスハンドル型のプロパティ(初期値つきも可)、引数あり・なしの `new`、暗黙と明示のコンストラクタ、ハンドル経由またはクラス内から修飾なしで呼ぶメソッド(`function` と `task`、本体をクラス外に書く `extern` も可)、`this`、`null`、ハンドルの代入と比較、プロパティとメソッドの継承(基底クラスのコンストラクタは `super.new(...)` か `extends Base(...)` で呼ぶ)、`super.` によるメンバ参照、virtual メソッド、抽象クラス(`virtual class`)と pure virtual メソッド、interface クラスを実装するクラスと interface クラスのハンドルを通したメソッド呼び出し、関数とタスクとしてのクラスハンドルの `$cast`、static プロパティとメソッド、static メンバと `C::new` の `C::` によるスコープ解決、ハンドルの配列、値パラメータと型パラメータを持つパラメータ付きクラス、ハンドルや `C#(...)::` を通したパラメータの参照、クラスと interface クラスの typedef と `C::T`、名前付きのコンストラクタ引数。[クラス](#classes)を参照 | | 文字列 | `string` 型の変数、関数の引数と戻り値。文字列・文字列リテラル・キャスト(`string'(x)`)の代入、`==` / `!=` と大小比較、連結と複製(実行時の回数も可)、文字の読み書き(`s[i]`)、メソッド `len`、`getc`、`putc`、`toupper`、`tolower`、`compare`、`icompare`、`substr`、`atoi` / `atohex` / `atooct` / `atobin`、`itoa` / `hextoa` / `octtoa` / `bintoa`。`%s` と書式なしの表示。[文字列](#strings)を参照 | | パラメータ | 整数のパラメータ、128ビットを超える幅と X/Z を保持するパラメータ上書き、assignment pattern で与える unpacked 配列型・packed 構造体型のパラメータ(定数テーブル)と unpacked 配列のパターンによる上書き | @@ -163,7 +163,7 @@ SystemVerilog に対しても、共有の Veryl 適合性スイートを実行 その構文を追跡する issue の番号が含まれます。専用の issue がない構文は、フロントエンドの ロードマップ [#88](https://github.com/celox-sim/celox/issues/88) を指します。 -- [対応範囲](#classes)外のクラスの機能:クラスハンドル以外の変数への `$cast`、interface クラスの typedef とパラメータ、package 内で宣言したクラス、パラメータ付きクラス、名前付きのコンストラクタ引数、浅いコピー(`new h`)、4 値・`real`・配列・64 ビットを超えるプロパティ。時間待ちを含む task の static ローカル宣言、再帰呼び出し、`ref` 引数。 +- [対応範囲](#classes)外のクラスの機能:クラスハンドル以外の変数への `$cast`、クラス内で宣言した列挙定数、クラスパラメータの値としての列挙型・構造体型・共用体型と名前付きの 4 値・文字列定数、package 内で宣言したクラス、浅いコピー(`new h`)、4 値・`real`・配列・64 ビットを超えるプロパティ。時間待ちを含む task の static ローカル宣言、再帰呼び出し、`ref` 引数。 - interface のポート、`inout` / `ref` / 式を使う modport、virtual interface など。 interface 自体と入れ子の interface は対応しています。型パラメータはインスタンスごとに解決し、modport ポート経由でも伝搬します。 再帰する特殊化と64段を超える入れ子は拒否します。細かな制約は[英語版の一覧](/guide/systemverilog-reference#interface-restrictions)を参照してください。 @@ -214,6 +214,8 @@ SystemVerilog に対しても、共有の Veryl 適合性スイートを実行 コンストラクタは、まず `super.new(...)` または `extends` 節の引数で基底クラスのコンストラクタを呼び、次に自クラスが宣言するプロパティの初期値を設定し、最後に本体を実行します(IEEE 1800-2023 8.17)。static プロパティはクラスを宣言したモジュールの変数なので、モジュールのインスタンスごとに 1 つずつあります。 +パラメータ付きクラスでは、パラメータの値と型の組ごとに 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 ブロック内の割り当てはそのインスタンスごとに評価します。 + チェックポイントはオブジェクトを保持します。状態ファイルは文字列を記録しますがオブジェクトは記録しないため、オブジェクトを持つ変数があると状態ファイルの保存は失敗します。 ### インスタンス配列の要素