Repository navigation
feat(sv)!: support parameterized classes - #1796
mergify[bot] merged 1 commit into
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Queued — the merge queue status continues in this comment ↓. |
2203a0e to
1fd053a
Compare
Revision history
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1fd053a548
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let value = constant_binding::bind(id, tree, context)? | ||
| .and_then(|expr| eval_ast_const_expr(&tree.state, &expr, &context.const_env)) | ||
| .ok_or_else(|| unsupported("class parameter value that is not constant"))?; | ||
| Ok(ConstExpr::Literal(if value >= 0 { | ||
| value.to_string() | ||
| } else { | ||
| format_typed_parameter_literal(value, 128, true) | ||
| })) |
There was a problem hiding this comment.
Preserve source types of class value arguments
When an untyped class parameter is overridden with a sized or differently signed expression, such as C#(8'h1), this conversion retains only its i128 value and recreates it as the unsized decimal literal 1 (or as a 128-bit signed literal for negatives). The final value determines an untyped parameter's type and width, so constructs such as $bits(P) and ranges derived from P become incorrect, and specializations such as C#(8'h1) and C#(32'h1) are incorrectly collapsed despite having different parameter types.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in b582538: an override keeps the width and signing of its expression, and a parameter without a type takes the type of its final value (6.20.2), so Sized#(8'h1) and Sized#(32'h1) are distinct specializations with $bits(V) 8 and 32. Covered by untyped_class_parameters_take_the_type_of_their_value (Verilator 5.052 prints 32 32; recorded with a repro).
| // Inside the class, its name refers to the specialization (8.25). | ||
| aliases.insert(generic.to_owned(), super::handle(&name)); | ||
| env.retain(|key, value| base_env.get(key) != Some(value)); |
There was a problem hiding this comment.
Keep class-owned values in specialization environments
If the specialization site already has a constant with the same name and value as a class parameter—for example, a generate scope with genvar N = 5 naming Box#(5) whose formal is also N—this filter removes the class's own N binding. Methods are subsequently lowered in the class declaration scope, where that generate binding is absent, so uses of N fail to bind; in a scope that has a different N, they can instead bind to the wrong value. The retained environment needs to distinguish class-declared parameter names from inherited caller bindings rather than comparing values.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in b582538: the values the class declares, with their markers, are kept by name rather than by comparing values. A genvar N naming Box#(N) is covered by specializations_keep_their_parameter_scopes.
| for &id in &declaration.type_aliases { | ||
| let alias = native.type_alias(id); | ||
| let celox_sv_syntax::TypeAliasTarget::DataType(target) = alias.target else { | ||
| continue; | ||
| }; | ||
| if !alias.dimensions.is_empty() { | ||
| 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. | ||
| if let Some(ty) = type_binding::procedural_type(target, native, tree, &env, &aliases) |
There was a problem hiding this comment.
Bind inherited types before class typedefs
For a derived class whose body declares a typedef in terms of an inherited type parameter or typedef, such as class D extends B; typedef T U; endclass, this loop attempts to bind U before the base specialization is resolved and its aliases are added. Binding therefore fails and is silently ignored, leaving later uses of D::U unknown even though T is visible in the derived class. Resolve and merge the base specialization's scope before processing body typedefs.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in b582538: the bases are resolved first and body typedefs are bound in a scope that includes their parameters and typedefs. typedef T nibble_t; in a derived class is covered by specializations_keep_their_parameter_scopes.
| let enclosing = |tokens: celox_sv_syntax::TokenRange| { | ||
| classes | ||
| .iter() | ||
| .filter(|class| within(class.tokens, tokens)) | ||
| .min_by_key(|class| class.tokens.end - class.tokens.start) | ||
| .map(|class| instances::normalize_identifier(&class.name.spelling)) |
There was a problem hiding this comment.
Associate extern method bodies with their class specialization
The enclosing-class lookup only considers declaration token ranges, so references inside an out-of-block method definition are classified as module-scope references. For example, an extern method of A#(N) containing a local B#(N) is analyzed without A's specialization environment; N cannot be evaluated, so B#(...) is not created during collection and its signatures and static properties are missing when the method is lowered. Out-of-block definitions need to map their token range back to the qualified class.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in b582538: out-of-block method definitions are treated as class scopes in the specialization pass, so Inner#(N) inside Outer#(N)::f is made per specialization of Outer. Covered by specializations_keep_their_parameter_scopes.
| for actual in class.constructor_arguments(native, arguments)? { | ||
| args.push( | ||
| argument | ||
| .value | ||
| actual | ||
| .map(|value| bind_value(value, native, tree, dimensions, None)) | ||
| .transpose()?, |
There was a problem hiding this comment.
Preserve source order for named constructor actuals
When named constructor arguments are written out of formal order and have side effects, such as new(.y(next()), .x(next())), constructor_arguments has already rearranged them into formal order before this loop binds them, and the resulting call records no arg_order. Consequently x is evaluated before y, contrary to the authored argument order used for ordinary named calls, which can change both assigned values and external side effects.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in b582538: constructor calls and super.new now carry an arg_order with the actuals in written order, as other named calls do. Covered by named_constructor_arguments_are_evaluated_in_written_order.
| if actual.is_some() { | ||
| return Err(unsupported("constructor argument passed twice")); | ||
| } | ||
| *actual = argument.value; |
There was a problem hiding this comment.
Track omitted constructor arguments as already bound
An explicit named omission such as .x() stores None, which is indistinguishable here from a formal that has not appeared at all. A subsequent .x(1) therefore passes the actual.is_some() duplicate check and silently replaces the omission, so new(.x(), .x(1)) is accepted even though the same formal is assigned twice. Use a separate bound set, as the ordinary named-call binder does.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in b582538: formals are tracked in a separate bound list, so new(.x(), .x(1)) is rejected as an argument passed twice. Covered by misused_parameterized_classes_are_rejected.
| TypeKind::Bit => "bit", | ||
| TypeKind::Logic | TypeKind::Implicit => "logic", | ||
| TypeKind::Reg => "reg", |
There was a problem hiding this comment.
Canonicalize reg and logic type arguments identically
SystemVerilog defines reg as synonymous with logic, but this specialization spelling gives them different identities. Thus C#(logic [3:0]) and C#(reg [3:0]) get separate static properties and incompatible handle types even though their type parameter values are the same type. Map TypeKind::Reg to the same canonical spelling as TypeKind::Logic.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in b582538: reg is spelled as logic in specialization names, so C#(reg [3:0]) and C#(logic [3:0]) are one specialization. Covered by specializations_keep_their_parameter_scopes.
| 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); |
There was a problem hiding this comment.
Detect recursive specializations before resolving bases
For a recursively specialized inheritance chain such as class C #(int N = 0) extends C#(N + 1);, resolving the base recursively calls specialize before the current specialization is inserted or counted. Every recursive call therefore sees neither an existing entry nor progress toward MAX_SPECIALIZATIONS, and the compiler recurses until stack overflow instead of issuing the intended bounded-specialization or inheritance diagnostic. Record an in-progress specialization or detect the cycle before binding its bases.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in b582538: making a specialization is now bounded at 64 nested levels, so class C #(int N = 0) extends C#(N + 1); reports "class specializations nested more than 64 deep" instead of recursing. Covered by misused_parameterized_classes_are_rejected.
| for (index, argument) in arguments.iter().enumerate() { | ||
| let parameter = match &argument.name { | ||
| Some(name) => { | ||
| 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, | ||
| })? | ||
| } | ||
| None => ports.get(index).ok_or_else(|| { | ||
| unsupported(format!("more parameter values than class `{generic}` has")) | ||
| })?, |
There was a problem hiding this comment.
Reject positional class arguments after named arguments
Class parameter assignments cannot switch back to ordered form after a named assignment, but this loop never records that named binding has begun. For example, C#(.A(3), 4) is accepted and the second argument is assigned to ports[1], even though this mixture is invalid SystemVerilog and should be diagnosed like positional constructor or subroutine arguments after named ones.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in b582538: a positional value after a named one is rejected ("positional parameter value after a named one"). Covered by misused_parameterized_classes_are_rejected.
1fd053a to
c1e74be
Compare
|
This pull request is part of a Mergify stack:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c1e74bea28
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // An empty named assignment keeps the default. | ||
| let Some(value) = argument.value else { | ||
| continue; |
There was a problem hiding this comment.
Reject repeated empty class parameter assignments
When an empty named assignment is followed by another assignment to the same formal, such as C#(.N(), .N(2)), this continue occurs before recording that N was assigned. The second assignment is therefore accepted instead of producing the duplicate-parameter diagnostic; track assigned formal names separately from whether an override value exists.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 76f7612: assigned formals are tracked separately from their values, so C#(.N(), .N(2)) reports a duplicate parameter assignment. Covered by misused_parameterized_classes_are_rejected.
| let declarations = declaration | ||
| .parameter_ports | ||
| .iter() | ||
| .map(|&id| (id, true)) | ||
| .chain(declaration.parameters.iter().map(|&id| (id, false))); |
There was a problem hiding this comment.
Bind class declarations in source dependency order
Concatenating all parameter declarations ahead of all typedef declarations loses their relative source order. For example, in class C; typedef bit [7:0] T; parameter T P = 0; endclass, P is lowered before T is added to aliases, so specialization fails even though the typedef is already visible at the parameter declaration. Process class parameters and typedefs in declaration order, or otherwise make the class typedefs available while binding parameter types.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 76f7612: the body parameters and typedefs are bound in source order, so typedef bit [7:0] byte_t; parameter byte_t P = 8'hff; works. Covered by class_declarations_bind_in_their_scopes.
| if !alias.dimensions.is_empty() { | ||
| continue; | ||
| } |
There was a problem hiding this comment.
Retain dimensions on class-scoped typedefs
Any class typedef with dimensions after its name, such as typedef int table_t[2];, is silently omitted from the specialization here. Consequently a valid use such as C::table_t value; cannot be resolved by member_type, despite class-scoped typedef support; bind the target and apply alias.dimensions instead of skipping the alias.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 76f7612: a class typedef keeps its unpacked dimensions; typedef int table_t [2]; is usable as C::table_t. Covered by class_declarations_bind_in_their_scopes.
| 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)) |
There was a problem hiding this comment.
Bind each static initializer in its specialization scope
Expanding a class item to all specialization names makes item_statics return each specialized static property, but initial_processes_from_scope subsequently binds every stored initializer using only the enclosing generate item's dimensions and literals. Thus class C #(int N); static int value = N; endclass either cannot bind N or captures an unrelated outer N, instead of initializing each specialization from its own parameter value; retain the owning specialization and apply body_scope while lowering each initializer.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 76f7612: each static initializer is bound in the scope of the specialization that owns it, so static int value = N * 10; gives 20 and 30 for Init#(2) and Init#(3). Covered by class_declarations_bind_in_their_scopes.
| 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); |
There was a problem hiding this comment.
Collect specializations with procedural-local constants
When a specialization argument inside an ordinary function or method depends on a procedural localparam or local typedef, such as B#(M) after localparam M = 2, module_scopes contains only module/generate bindings. This branch marks the reference done and discards the failed specialization attempt, so it is not available when class signatures and methods are enumerated; creating it later while lowering the procedure can leave its method definitions or metadata missing. Collection needs the enclosing procedural declaration scope, or must retry rather than permanently consuming failed references.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Addressed in 76f7612: the specializations of a scope are frozen once its class signatures are published, so one that only a procedure could name is reported ("specialization ... that only a procedure names") instead of lowering without methods. The localparam M = 2; C#(M) c = new; example itself is collected and runs.
| // `C::T` names a type of class `C` (IEEE 1800-2023 8.23). | ||
| && !native.classes.iter().any(|class| { | ||
| class.name.spelling == package.name.spelling | ||
| }) |
There was a problem hiding this comment.
Restrict class-scope detection to visible classes
This test scans every class in the parsed declarations rather than classes visible at the qualified type site. If another module declares a class named P, then P::T in the current module is excluded from package dependency discovery even when P is a package containing T; the later type binder can also misinterpret it as that unrelated class. Resolve the first segment in the active lexical scope instead of suppressing packages based on a global name match.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 76f7612: C:: and C::T count only classes declared in the current scope or the compilation unit, so a class P of another module no longer hides package P. Covered by a_class_of_another_module_does_not_hide_a_package.
| if !super::super::classes::is_parameterized(tree, &name) { | ||
| return Ok(Some(name)); |
There was a problem hiding this comment.
Reject arguments on nonparameterized class scopes
For a nonparameterized class, this returns the class without checking whether the scope segment supplied arguments. As a result, an invalid type such as C#(123)::T is accepted and treated as C::T, even though the same nonempty assignment is rejected when C#(123) is used directly as a type or expression scope. Diagnose any nonempty argument list before returning the nonparameterized class.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 76f7612: a parameter value assignment on a class without parameters is rejected ("parameter value assignment of class Plain, which has no parameters"), as a type scope and as an expression scope. Covered by misused_parameterized_classes_are_rejected.
c1e74be to
b582538
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b582538487
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let base_env: &HashMap<String, i128> = &context.const_env; | ||
| let mut env = base_env.clone(); | ||
| let mut aliases = context.type_aliases.clone(); |
There was a problem hiding this comment.
Evaluate parameter defaults in the declaration scope
When a specialization is referenced from a nested scope, cloning the caller's environment here also uses that scope to resolve formal defaults. For example, if module-scope X is 1, class C #(int N = X) is declared outside a generate block, and that block shadows X with 2 before using C#(), this creates the N=2 specialization even though the default was declared where X is 1. This can change method results, static-property identity, and inherited types; explicit actuals should use the caller context, but defaults need the class declaration's lexical context.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 76f7612: the scope that declares each class is recorded before the module is elaborated (refined for classes in generate blocks), and defaults and the class body are bound there while actuals use the caller's scope. A generate block shadowing X now gets N = 1 from class Defaulted #(int N = X). Covered by parameter_defaults_bind_where_the_class_is_declared.
| let value = env.get(&name).copied().ok_or_else(|| { | ||
| unsupported(format!("class parameter `{name}` without a constant value")) | ||
| })?; |
There was a problem hiding this comment.
Accept literal-only class parameter values
This unconditional lookup requires every value parameter to have an i128 representation, even though bind_generate_parameter deliberately stores constants that cannot be represented numerically in literals. Consequently valid specializations such as class C #(string S = "a"); or class C #(logic [1:0] V = 2'bx1); fail with “without a constant value” despite the string or four-state literal being available. Specialization identity and class-body substitution need to use the retained literal when no numeric environment entry exists.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 76f7612: a value with only a literal (a string or a four-state value) is accepted, spelled by its literal in the specialization name and substituted from it. Named#("bc") is covered by class_declarations_bind_in_their_scopes.
| // A typedef may name the parameters and types of the bases. | ||
| let (mut visible_env, mut visible) = (env.clone(), aliases.clone()); |
There was a problem hiding this comment.
Make the current specialization visible to its typedefs
The typedef-binding scope is created before the class-name alias is added at line 405, so an unadorned self-reference in a parameterized class does not denote the current specialization. For example, class C #(int N=1); typedef C self_t; endclass binds self_t while specializing C#(2) by recursively requesting the default C#() specialization, eventually making the alias refer to C#(1) or omitting it after the nesting limit, rather than referring to C#(2). Add the current specialization's handle to visible before processing class typedefs.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changed as suggested: IEEE 1800-2023 8.25 says "Other than as the prefix of the scope resolution operator, use of the unadorned name of a parameterized class shall denote the default specialization of the class", so typedef C self_t; inside C#(2) denotes C#() (Verilator 5.052 agrees). 76f7612 makes that so: the bare name as a type is the default specialization everywhere, C:: inside the class still refers to the specialization being declared, and a specialization may name itself while it is made, which removes the recursion. Covered by class_declarations_bind_in_their_scopes (Self#(2)::self_t objects report N = 1).
b582538 to
f3f644e
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f3f644eae5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let (mut visible_env, mut visible) = (env.clone(), aliases.clone()); | ||
| for base in &bases { | ||
| (visible_env, visible) = scope(tree, base, &visible_env, &visible); |
There was a problem hiding this comment.
Preserve derived parameters when merging the base scope
When a derived class declares a parameter with the same name as an inherited parameter, this merge overwrites the derived binding before its typedefs are resolved. For example, class B #(type T = bit [3:0]); endclass followed by class D #(type T = int) extends B; typedef T U; endclass binds D#()::U as four bits instead of 32. scope extends its input with the base's bindings, so the class's own parameters must be reapplied after merging inherited declarations to preserve lexical shadowing.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 76f7612: the class's own parameters and types are reapplied after the bases' scopes are merged, so D#()::U is 32 bits. Covered by class_declarations_bind_in_their_scopes.
| if ty.is_enum || !ty.members.is_empty() || !ty.unpacked_ranges().is_empty() { | ||
| // An aggregate or enumeration is told apart by its whole structure. | ||
| use std::hash::{Hash, Hasher}; | ||
| let mut hasher = fxhash::FxHasher::default(); | ||
| ty.hash(&mut hasher); |
There was a problem hiding this comment.
Include enumeration declaration identity in specialization keys
When two distinct enum typedefs have the same underlying type, hashing the lowered Type gives both arguments the same specialization name: Type retains only is_enum and the base layout, not the enum declaration or its enumerators. Thus C#(E1) and C#(E2) collapse into one class even for separately declared enums, incorrectly sharing static properties and accepting assignments between their handles. Preserve enum declaration identity in the bound type and include it in the specialization key rather than relying on this structural hash.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Addressed in 76f7612: the bound type does not carry enum declaration identity, so an enumeration type as a class type parameter value is now rejected as unsupported rather than collapsing specializations. Covered by misused_parameterized_classes_are_rejected.
| Ok(ConstExpr::Literal(format_typed_parameter_literal( | ||
| value, ty.width, ty.signed, | ||
| ))) |
There was a problem hiding this comment.
Preserve unbased fill literals until the formal width is known
When a typed class parameter is wider than 32 bits, passing '1 does not fill the declared width. For example, class C #(logic [57:0] N = 0); endclass C#('1) c; converts the actual into the fixed-width literal 32'd4294967295 here. The subsequent normalize_unbased_unsized_parameter_value call can no longer recognize the original fill literal, so N has only its low 32 bits set instead of all 58, also producing the wrong specialization identity. Keep unbased-unsized literals intact until the formal parameter's width and signing are applied.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 76f7612: an unbased unsized literal is passed on unchanged until the formal's width applies, so Wide#('1) fills all 58 bits. Covered by class_declarations_bind_in_their_scopes.
| if !super::super::classes::is_parameterized(tree, &name) { | ||
| return Ok(Some(name)); |
There was a problem hiding this comment.
Materialize nonparameterized classes before resolving member types
When a module typedef references a nonparameterized class's typedef, this return supplies the class name without creating the specialization that stores its members. For example, class C; typedef int T; endclass typedef C::T U; U x; fails with an unknown class-member type: Module::from_selected_scope calls type_aliases_from_scope before specialization collection, and the subsequent member_type lookup therefore sees no entry for C. Ensure the nonparameterized class's specialization exists before resolving its member types, as the parameterized branch already does.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 76f7612: the specialization of a class without parameters is made before its member types are looked up, so typedef Plain::T plain_t; works. Covered by class_declarations_bind_in_their_scopes.
f3f644e to
76f7612
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 76f7612855
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if let Some(class) = ty.class() { | ||
| return class.to_owned(); | ||
| } | ||
| let mut spelled = match ty.kind() { | ||
| TypeKind::Real => return "real".to_owned(), |
There was a problem hiding this comment.
Include unpacked dimensions in non-integral type keys
When a type argument is an unpacked array of strings, reals, shortreals, or class handles, these early returns bypass the dimensional hashing below. For example, typedef string A[2]; typedef string B[3]; makes C#(A) and C#(B) receive the same specialization name. They consequently share static properties and accept assignments between their handles despite having different type parameters. Preserve the array dimensions in the specialization key for these element types too.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in a534644: unpacked dimensions are part of the specialization name for every element type, so C#(A) and C#(B) with string arrays of 2 and 3 elements are different classes. Covered by type_arguments_keep_their_dimensions_scopes_and_class_scoped_types.
| _ => None, | ||
| }; | ||
| let ty = ty.ok_or_else(|| unsupported("class type parameter value"))?; |
There was a problem hiding this comment.
Resolve class-scoped typedefs used as type arguments
For a valid argument such as Box#(Defs::T), where Defs declares typedef bit [7:0] T, the expression parser produces an ExprKind::Member, which falls through here and reports “class type parameter value”. Thus a class-scoped typedef works in an ordinary declaration but cannot be supplied directly to a class type parameter; introducing an intermediate module typedef changes whether the same type is accepted. Resolve qualified type arguments through the class-member type lookup rather than rejecting this expression form.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in a534644: a :: type argument resolves through the class-member lookup (or the package's types), so Box#(Defs::T) works. Covered by type_arguments_keep_their_dimensions_scopes_and_class_scoped_types.
| let (env, aliases) = specializations::scope(tree, name, env, aliases); | ||
| let (env, aliases) = (&env, &aliases); |
There was a problem hiding this comment.
Bind interface return types in their owning specialization
When a class implements an interface whose method returns a type parameter, the interface conformance check later in class() binds both return types using this implementing-class scope. Implemented interfaces deliberately do not contribute their type aliases to that scope, so interface class I #(type T = int); pure virtual function T get(); endclass followed by a class implementing I#(int) with function int get() is incorrectly rejected: the prototype's T resolves to no type rather than int. Retain each required method's owning specialization and use its scope when binding the prototype return type, independently of the implementation's scope.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in the stack by #1850 (8ce6209): each method keeps its return type resolved in the scope of the class that declares it, and conformance compares those, so a class implementing I#(int) with function int get() is accepted. Covered by classes_of_packages_in_other_sources_keep_their_behaviour (Getter#(int)).
| // 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}`")))?; |
There was a problem hiding this comment.
Freeze explicit type-argument bounds in the caller's scope
When an explicit type argument contains a caller-local constant, type_argument leaves its bounds as symbolic expressions, but this resolution uses the class declaration's environment instead of the caller's. For example, a module-level C #(type T = int) used as C#(bit [i:0]) inside a genvar loop cannot resolve i; if a generate-local constant shadows a module constant, the argument instead silently takes the module constant's value and produces the wrong width and specialization identity. Resolve explicit actual types against context.const_env before storing them in types, while continuing to resolve defaults in the declaration scope.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in a534644: explicit type arguments are fixed in the caller's constants before they are stored, defaults still in the declaration scope; Box#(bit [i:0]) in a genvar loop gives 3 and 4 bits. Covered by type_arguments_keep_their_dimensions_scopes_and_class_scoped_types.
76f7612 to
a534644
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a534644ac7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // Unpacked dimensions of any element type are part of the type. | ||
| for range in ty.unpacked_ranges() { | ||
| spelled.push_str(&format!("[{}:{}]", bound(&range.left), bound(&range.right))); |
There was a problem hiding this comment.
Distinguish packed and unpacked dimensions in specialization keys
For explicitly ranged arrays, packed and unpacked dimensions are appended with identical syntax. For example, typedef bit [1:0] A; typedef bit B [1:0]; gives both types the key bit[1:0], so Box#(A) and Box#(B) collapse into one specialization. These are different types with different operations and layouts; sharing their specialization also shares static properties and incorrectly permits assignments between their handles. Encode the dimension category in the key rather than concatenating both range lists identically.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in c6c132b: unpacked dimensions are spelled apart from packed ones in the specialization key, so Box#(bit [1:0]) and Box# of bit B [1:0] are different classes. Covered by specializations_tell_types_apart_and_keep_their_bases.
| if let celox_sv_syntax::DataTypeKind::Named(path) = &ty.kind | ||
| && let [segment] = path.as_slice() |
There was a problem hiding this comment.
Collect specializations named by qualified member types
A qualified type such as Inner#(N)::T has two path segments and is skipped here; its scope is also not an ExprKind::Parameterized, so the expression scan does not recover it. Consequently, an Outer#(2) method declaring an Inner#(N)::T local fails when lowered: Inner#(2) was never collected, and specialization creation has already been frozen by all_class_signatures. This occurs even when N is an ordinary class parameter, without any unsupported procedural-local constants. Collect the class scope segment of qualified types in the enclosing specialization's environment too.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in c6c132b: the specialization pass also collects the class scope of a qualified type, C#(...)::T, in the enclosing specialization, so Inner#(N)::T inside Outer#(2) works. Covered by specializations_tell_types_apart_and_keep_their_bases.
| let (env, aliases) = specializations::scope(tree, name, env, aliases); | ||
| let (env, aliases) = (&env, &aliases); |
There was a problem hiding this comment.
Reuse the base specialization resolved before inheritance
When an inherited declaration shadows a name used in the extends arguments, adding the complete specialization scope here changes the base selected by the subsequent procedural_type(base.data_type, ...) call. For example, with module-level localparam int K = 2, class Base #(int N = 0); localparam int K = 1; endclass, and class Derived extends Base#(K); endclass, specialization collection correctly records Base#(N=2), but layout re-evaluates K using the inherited value 1 and instead makes Derived extend Base#(N=1). This changes inherited values and handle compatibility. Reuse the recorded base specialization, or resolve the header in its pre-inheritance environment rather than the class-body scope.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in c6c132b: the layout reuses the base that the specialization recorded from the class header, before inherited declarations could hide its names; extends Base#(K) with a module K = 2 extends Base#(2). Covered by specializations_tell_types_apart_and_keep_their_bases.
a534644 to
c6c132b
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c6c132bf03
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if super::is_visible(tree, &scope) { | ||
| Some(specialize(tree, &scope, &[], context)?) |
There was a problem hiding this comment.
Resolve unadorned class scopes in the current specialization
Inside a parameterized class, a qualified type argument such as Box#(C::T) must resolve C:: to the specialization being declared. This branch instead calls specialize with no arguments, selecting the default specialization and ignoring the existing scope_key("C") alias. For example, inside C#(bit [7:0]), where C declares type T = int, Box#(C::T) incorrectly becomes Box#(int) rather than Box#(bit [7:0]); if C has no parameter defaults, the valid reference fails altogether. Consult the specialization-scope alias before requesting a default specialization, as the ordinary qualified-type binder already does.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in e07fd68: a class-scoped type argument such as Box#(C::T) first looks up the specialization alias C:: of the enclosing class scope, as the ordinary qualified-type binder does, and only otherwise uses the default specialization. Covered by class::specialization_keys_follow_the_bound_parameters (Box#(Outer::Inner) inside Outer#(byte) is Box#(byte)).
| if let Some(size) = &range.size { | ||
| spelled.push_str(&format!("#{}", bound(size))); | ||
| } |
There was a problem hiding this comment.
Canonicalize equivalent unpacked dimension spellings
For typedef int A[2]; typedef int B[0:1];, both typedefs describe the same unpacked array type, but only the first retains range.size. Appending that field gives Box#(A) and Box#(B) different specialization keys despite their identical resolved bounds and element types. Consequently, these specializations incorrectly have separate static properties and reject assignments between their handles. Build the identity from the normalized range rather than additionally encoding whether the source used a size shorthand.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in e07fd68: the specialization key spells an unpacked dimension by its normalized bounds only, so int A[2] and int B[0:1] name one specialization (7.4.2). Covered by class::specialization_keys_follow_the_bound_parameters.
c6c132b to
d9b70cf
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d9b70cfe20
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for (key, value) in env.iter() { | ||
| if before.get(key) != Some(value) { | ||
| self.own_env.insert(key.clone(), *value); | ||
| } |
There was a problem hiding this comment.
Retain own parameter bindings even when their values are unchanged
When a derived value parameter equals an enclosing constant of the same name, this comparison omits it from own_env, so merging the base scope overwrites it without the subsequent reapplication restoring it. For example, with module-level localparam int N = 2, class B #(int N = 1); endclass and class D #(int N = 2) extends B; typedef bit [N-1:0] T; endclass, D#()::T is incorrectly bound as one bit instead of two. The fresh evidence beyond the earlier shadowing fix is this conditional population of own_env: unlike own_aliases, it records only changed values, not every binding the class declares. Record all of each parameter's binding keys regardless of whether their values match the enclosing environment.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in e07fd68: a value parameter first removes every binding key of the name (parameters::binding_keys) and then records all of them as the class's own, with the ones it leaves unset recorded as removed, so a base's or an enclosing binding of the same name never survives regardless of whether the values match. Covered by class::specialization_keys_follow_the_bound_parameters (Derived#()::T is two bits wide with module N = 2 and base N = 1).
| if integral { | ||
| for range in ty.packed_ranges() { | ||
| spelled.push_str(&format!("[{}:{}]", bound(&range.left), bound(&range.right))); | ||
| } | ||
| } |
There was a problem hiding this comment.
Include packed element signing in specialization keys
For typedef bit signed [3:0] S; typedef S [1:0] A; typedef bit [1:0][3:0] B;, both arguments are spelled bit[1:0][3:0], although A[0] is signed and B[0] is unsigned. types::enclose_aliased_packed_type preserves this distinction in signed_element_depth, but this key ignores it and only hashes types with enum or aggregate members. Consequently C#(A) and C#(B) reuse whichever specialization was created first, sharing static properties and potentially giving methods the wrong signed arithmetic when they select an element of T. Include the retained element-signing information in the key.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in e07fd68: the key of an integral type includes its signed_element_depth, so S [1:0] with a signed S and bit [1:0][3:0] are different specializations. Covered by class::specialization_keys_follow_the_bound_parameters.
| if scopes.is_empty() { | ||
| scopes.push(context.clone()); |
There was a problem hiding this comment.
Exclude inactive generate references from specialization collection
When a reference belongs to an unselected generate branch, generate::items supplies no containing active item, but this fallback treats the reference as module-scoped and creates its specialization anyway. For example, a module-level class C #(int N = 1); static int x = announce(); endclass with an active C#(1) handle and if (0) begin : disabled C#(2) unused; end also creates C#(2). Because item_statics enumerates every collected specialization of the module-level class, initial_processes_from_scope runs the extra specialization's initializer, producing an additional announce() call despite the branch being disabled. Distinguish actual module-scope references from references excluded by generate elaboration before applying this fallback.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in e07fd68: a module-scope reference inside a block of a generate construct (conditional, case or loop) that elaboration does not select is in no scope and makes no specialization; only references outside generate constructs fall back to the module scope. class::specialization_keys_follow_the_bound_parameters keeps a disabled if (0) branch naming another specialization. (A static initializer that calls a function, as in the example, is rejected by the frontend independently of this change, so the case uses a constant initializer.)
d9b70cf to
ba224ec
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ba224ec228
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let (env, aliases) = specializations::scope(tree, name, env, aliases); | ||
| let (env, aliases) = (&env, &aliases); |
There was a problem hiding this comment.
Reuse recorded specializations for interface inheritance
When an inherited declaration shadows a name used in an interface-class header, applying the complete specialization scope here changes the interfaces subsequently selected by interface_name. For example, with module-level K = 2, interface class I #(int N = 0); localparam int K = 1; endclass, and interface class D extends I#(K); endclass, specialization collection records I#(2) as D's base, but layout re-evaluates the header with inherited K = 1 and makes D extend I#(1) instead. This gives D the wrong interface ancestry and handle compatibility. The recorded-base fix below covers ordinary class inheritance only; interface-class inheritance needs to reuse its recorded bases too.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in e07fd68: an interface class reuses the interface classes its specialization recorded where its header is (checked to be interface classes), as a class reuses its recorded base, so inherited declarations cannot change its ancestry. Covered by class::specialization_keys_follow_the_bound_parameters (interface class J extends I#(K) with module K = 2 and I declaring K = 1: a J implementation is assignable to I#(2)).
| let spelling = match (env.get(&name), self.literals.get(&name)) { | ||
| (Some(value), _) if typed => value.to_string(), | ||
| (_, Some(Expr::Literal(literal))) => literal.clone(), |
There was a problem hiding this comment.
Clear shadowed numeric bindings for four-state parameters
When a four-state class parameter shadows an enclosing numeric constant, bind_generate_parameter retains the enclosing numeric entry if the new value cannot be represented as an i128. This match then prefers that stale entry over the correctly retained literal. For example, with module-level localparam int N = 1 and class C #(logic [1:0] N = 0); static int count; endclass, C#(2'bxx) and C#(1) both receive the specialization key C#(N=1), incorrectly sharing static properties and handle identity. Remove the shadowed numeric binding when the class parameter resolves only to a literal before constructing the specialization key.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in e07fd68 together with the own_env comment: binding a value parameter removes the shadowed numeric entry first, so a four-state or string value keeps only its literal and C#(2'bxx) and C#(1) are different specializations. Covered by class::specialization_keys_follow_the_bound_parameters.
| type_parameters::resolve( | ||
| &tree.state, | ||
| types::type_with_unpacked_ranges(ty, ranges), | ||
| &env, | ||
| ) |
There was a problem hiding this comment.
Defer class typedef materialization until constants are available
When a module typedef accesses a class typedef whose bounds depend on a module constant, the initial alias-discovery pass materializes the class with an empty constant environment. For example, localparam int W = 8; class C #(int N = 1); typedef bit [W-1:0] T; endclass typedef C#()::T U; fails: Module::from_selected_scope calls type_aliases_from_scope before binding module parameters, this resolution drops T because W is unavailable, and the member lookup immediately reports an unknown type. The specialization is also cached without T, preventing later passes from repairing it. Unlike the earlier missing-specialization issue, the specialization now exists but was permanently materialized with incomplete bindings; defer this work or allow incomplete aliases to be retried after the declaration environment is populated.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
This is a rejection (the class typedef is reported unknown), not a wrong simulation, and fixing it means deferring specializations made during the early alias-discovery pass or rebuilding incomplete ones, so it is tracked in #1939 rather than in this PR.
ba224ec to
e07fd68
Compare
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
e07fd68 to
1f3bd97
Compare
|
Local review (Codex CLI,
Also resolved the conflict with master (program blocks, hierarchical references, randc); sv-tests totals are now 556/558. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1f3bd979a7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if let celox_sv_syntax::DataTypeKind::Named(path) = &ty.kind | ||
| && let [segment] | [segment, _] = path.as_slice() |
There was a problem hiding this comment.
Preserve current-specialization semantics when collecting class scopes
When a parameterized class contains a qualified type such as C::T, this treats it like the unqualified type C and records an empty argument list. The collection loop subsequently calls specialize(C, []), creating the default specialization instead of reusing the enclosing specialization's C:: alias. For example, if only C#(2) is instantiated and one of its methods declares a C::T local, collection also creates C#(1) when the default is 1. item_statics and initial_processes_from_scope then initialize both specializations' static properties, so an initializer with side effects runs an extra time. Retain whether the reference is a qualified scope and consult its specialization alias before requesting defaults.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 880e92e: specialization collection no longer records an unadorned qualified type (C::T without a parameter value assignment). Inside C it names the specialization being declared, and elsewhere an unadorned scope of a parameterized class needs C#():: (8.25.1), while a class without parameters is collected anyway, so no default specialization is made for it.
| for specialization in lineage(tree, name) { | ||
| env.extend(specialization.env.clone()); | ||
| aliases.extend(inherited(&own, &specialization)); |
There was a problem hiding this comment.
Propagate removed bindings when applying specialization scopes
When a string or four-state class parameter shadows a numeric constant, its specialization correctly omits the numeric binding, but extending the caller's environment here leaves the caller's old value intact; body_scope has the same problem. For example, with module-level N = 1 and class C #(logic [1:0] N = 2'bxx), a Box#(N) declaration inside a C method is collected and bound as Box#(1), because value_argument evaluates the revived numeric entry. The fresh evidence beyond the earlier shadow-clearing fix is that this scope merge reintroduces the binding after specialization construction removed it. Preserve removal markers in Specialization and apply them in both scope helpers so later binding cannot recover a shadowed outer or inherited value.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 880e92e: a Specialization records the constants its value parameters hide without a numeric value of their own (hidden), and scope and body_scope remove them after merging each specialization's environment, so a later binding cannot revive the outer or inherited number. With module N = 1 and class Shadow #(logic [1:0] N = 2'bxx), Four#(N) in a method of Shadow is no longer bound as Four#(1). It is now rejected as not constant: named four-state actuals need the scope's literals and are tracked in #1964. Covered in misused_parameterized_classes_are_rejected.
| let Some(value) = eval_ast_const_expr(&tree.state, &expr, &context.const_env) else { | ||
| // A string or four-state value is its literal. | ||
| return match expr { | ||
| ConstExpr::Literal(_) => Ok(expr), | ||
| _ => Err(unsupported("class parameter value that is not constant")), |
There was a problem hiding this comment.
Evaluate constant real expressions passed as class arguments
For an actual such as C#(1.0 + 2.0) with class C #(real R = 0.0), constant_binding::bind produces a constant binary expression, but eval_ast_const_expr deliberately returns None for real-valued results. This fallback then rejects it as nonconstant solely because it is not already a literal. Consequently, C#(3.0) works while the equivalent constant expression fails, even though ordinary parameter binding already supports real arithmetic through parameters::real_literal. Evaluate real-valued actuals in the caller's scope and retain their real literal representation before applying the formal parameter's type.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 880e92e: an actual that is not an integer constant is evaluated as a real constant expression (parameters::real_literal) before it is rejected, so C#(1.0 + 2.0) and C#(3.0) name one specialization. Covered by class::specialization_keys_follow_the_bound_parameters.
1f3bd97 to
880e92e
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 880e92e44f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for base in &bases { | ||
| (env, aliases) = scope(tree, base, &env, &aliases); |
There was a problem hiding this comment.
Inherit only bindings declared by the base class
When a derived class is declared in a generate scope that shadows a module constant, this merge can replace that constant with the base class's enclosing-module binding, even though the base never declares it. For example, with module-level K = 2, a module-level class Base #(int N = 0); endclass, and a generate block containing K = 3 and class Derived #(int M = 0) extends Base; typedef bit [K-1:0] T; endclass, Derived#()::T is bound as two bits instead of three. Specialization.env and aliases retain the entire declaration environment, so applying the base's complete scope leaks its lexical surroundings into the derived class; reapplying only the derived parameters does not restore generate-local bindings. Keep the declaration environment separate from the declarations actually inherited from the base.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed (a derived class declared in a generate block that hides a module constant binds its typedef with the base's surroundings). The fix lands in a follow-up commit of this stack so #1796 can merge: a class now inherits only what its base and the base's bases declare (parameters, body parameters and typedefs), recorded per specialization as declared_env/declared_aliases, not the scope around the base's declaration. Covered by class::derived_classes_keep_their_declaration_scopes.
| .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 | ||
| }); |
There was a problem hiding this comment.
Preserve each generate instance's class declaration scope
When a parameterized class is declared inside a loop-generate, every elaborated iteration has the same source token range, so this selection retains only one iteration's environment. That environment is then stored under the unqualified class name and reused for references in every iteration. For example, with module-level K = 0, a generate loop whose iterations declare localparam int K = i + 1; class C #(int N = K); endclass makes C#()::N use the same selected iteration's K throughout the loop instead of each declaration's own value. Class declaration scopes and specialization identities need to distinguish elaborated generate instances rather than collapsing them by source range and class name.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed. Classes declared in a block that loop generation repeats need a class identity per elaborated iteration, tracked in #2064. Until then the follow-up commit of this stack rejects them ("class C declared in a loop generate block") instead of merging the iterations, covered in misused_parameterized_classes_are_rejected.
Merge Queue Status
This pull request spent 28 minutes 41 seconds in the queue, with no time running CI. ReasonThe pull request conflicts with the base branch The pull request was held in the queue, conflicting with at least one of 3 pull requests ahead of it. The conflict became a base branch one after #2061, #2067 merged. HintYou should update or rebase your pull request. If you want to requeue this pull request, you can post a Requeued — the merge queue status continues in this comment ↓. |
Classes accept value and type parameters (IEEE 1800-2023 8.25). Each set of parameter values and types is a specialization: a class of its own, with its own static properties and run-time identifier, named by its values, so C#(2, int) and C#(.T(int), .N(2)) are one class and a handle of C#(2) is not assignment compatible with C#(3). Parameter value assignments are evaluated where they are written, including module and generate parameters; the specializations a module names are made before its classes are lowered, iterating over references inside classes until no new one appears. Inside a parameterized class and its out-of-block methods the class name alone refers to the specialization; elsewhere it is the default specialization as a type, and C#()::, not C::, is required as a scope (8.25.1). Class parameters are read through a handle or C#(...)::, derived classes see the parameters and typedefs of their bases, class typedefs are usable inside the class and as C::T, and interface classes inherit the parameters and typedefs of the interface classes they extend. An interface class inheriting one name from two different interface classes or specializations must declare its own (8.26.6.2, 8.26.6.3). Constructor calls and super.new accept named arguments. The parser records the parameter port list, body parameters and typedefs of each class. sv-tests: 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 pass, and the negative 8.26.6.2--parameter_type_conflict_unresolved and 8.26.6.3--diamond_relationship_parametrized probes are now rejected for the conflict they test (1080/1091 passing). Verilator 5.052 treats differently written assignments of the same values as different specializations, and Icarus 13.0 does not parse class parameter port lists; both are recorded with evidence. BREAKING CHANGE: AnalyzerError gains ConflictingInterfaceClassDeclaration, UnspecializedClassScope and UnknownClassParameter, and celox_sv_syntax::ClassDeclaration gains parameter_ports, parameters and type_aliases fields. Change-Id: I45d026291acf9b8870619829b3234ab84bfc65ad
880e92e to
c3bded9
Compare
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
The generate-scope fixes from the last review round (derived classes inheriting only what their bases declare, and rejecting classes declared in loop generate blocks, #2064) are in the follow-up #2093 so that this PR stays as reviewed. This push only rebases onto master (new sv-tests corpus, class member visibility) and adds the xezim review of the class cases. |
|
@Mergifyio queue |
Merge Queue Status
This pull request spent 33 minutes 21 seconds in the queue, including 31 minutes 1 second running CI. Required conditions to merge
|
Classes accept value and type parameters (IEEE 1800-2023 8.25). Each set of
parameter values and types is a specialization: a class of its own, with its
own static properties and run-time identifier, named by its values, so
C#(2, int) and C#(.T(int), .N(2)) are one class and a handle of C#(2) is not
assignment compatible with C#(3). Parameter value assignments are evaluated
where they are written, including module and generate parameters; the
specializations a module names are made before its classes are lowered,
iterating over references inside classes until no new one appears.
Inside a parameterized class and its out-of-block methods the class name
alone refers to the specialization; elsewhere it is the default
specialization as a type, and C#()::, not C::, is required as a scope
(8.25.1). Class parameters are read through a handle or C#(...)::, derived
classes see the parameters and typedefs of their bases, class typedefs are
usable inside the class and as C::T, and interface classes inherit the
parameters and typedefs of the interface classes they extend. An interface
class inheriting one name from two different interface classes or
specializations must declare its own (8.26.6.2, 8.26.6.3). Constructor
calls and super.new accept named arguments.
The parser records the parameter port list, body parameters and typedefs of
each class. sv-tests: 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 pass, and the negative
8.26.6.2--parameter_type_conflict_unresolved and
8.26.6.3--diamond_relationship_parametrized probes are now rejected for the
conflict they test (1080/1091 passing). Verilator 5.052 treats differently
written assignments of the same values as different specializations, and
Icarus 13.0 does not parse class parameter port lists; both are recorded
with evidence.
BREAKING CHANGE: AnalyzerError gains ConflictingInterfaceClassDeclaration,
UnspecializedClassScope and UnknownClassParameter, and
celox_sv_syntax::ClassDeclaration gains parameter_ports, parameters and
type_aliases fields.