Skip to content

feat(sv): support classes declared in packages and the compilation unit - #1850

Merged
mergify[bot] merged 1 commit into
masterfrom
stack/tignear/feat/string-class-heap/support-classes-declared-pkgs-compilation-unit--12b64cde
Oct 26, 2026
Merged

mergify[bot] merged 1 commit into
masterfrom
stack/tignear/feat/string-class-heap/support-classes-declared-pkgs-compilation-unit--12b64cde

Conversation

@tignear

@tignear tignear commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

A class declared in a package or in the compilation unit is named by its
scope, p::C or $unit::C, and is laid out and lowered once, in that scope
(IEEE 1800-2023 3.12.1, 26.3). The scope exports the class layouts with its
symbols, and the class as a type, so a module uses the class through an
import, p::C, p::C::member or, for the compilation unit, its name, also
from another source: it never lays out a class of another scope again, and
calls its methods through their exported formals. Static properties of the
classes are package variables. A class of another scope is a dispatch and
$cast target of the scopes that see it; when a class of a module overrides a
virtual method of such a class, the module lowers the method's dispatcher
again over every class it sees, so calls through package code reach the
override too.

A specialization of a parameterized class is made from its declaration, so
outside its scope only the specializations the scope names are usable; a
new one reports that. Static properties follow the existing rule for package
variables, which processes of one instance may write (#1146).

The sv_tests driver elaborates sources of packages and compilation-unit items
alone, reporting the errors of their compilation units.

sv-tests: 31 chapter 18 cases that declare only classes pass (1112/1123
passing); seven were simulated with a module using the class, the others
pass by elaboration and keep their constraints unchecked, while randomize()
of a class with constraints stays rejected. Icarus 13.0 rejects the new
shared cases on constructs it does not support, recorded with the existing
groups; Verilator passes them.

Depends-On: #1810

@tignear

tignear commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor Author

This pull request is part of a Mergify stack:

# Pull Request Link
1 feat(sv)!: support parameterized classes #1796
2 fix(sv): bind derived classes in their own declaration scopes #2093
3 feat(sv)!: support shallow copies of class objects #1810
4 feat(sv): support classes declared in packages and the compilation unit #1850 👈
5 feat(sv): let processes of several instances write a package variable #1872

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-26T00:25:21.344018Z
We couldn’t complete this review. Comment @codex review to try again.
af8df00 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 85455f4c50

ℹ️ 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".

Comment on lines +1878 to +1880
for class in &imported.classes {
for method in class.dispatched_methods() {
let name = classes::Class::dispatcher_name(&class.name, &method.name);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Rebuild imported cast helpers for locally declared subclasses

When a module declares D extends p::B, $cast(b, d) with destination type p::B calls the imported p::B cast helper. That helper's accepted class IDs were fixed by lower_cast while analyzing the package, before D was visible. This new loop rebuilds virtual dispatchers but leaves cast helpers unchanged, so the valid cast returns 0 and leaves the destination unchanged. Regenerate imported cast helpers against the consuming scope's visible classes as well.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 8ce6209: the importing scope rebuilds an imported $cast helper over the classes it sees when one of its own classes is a target, as it does for virtual dispatchers; $cast(b, d) with D extends p::B returns 1. Covered by classes_of_packages_in_other_sources_keep_their_behaviour.

Comment on lines 550 to +551
pub(super) fn handle_type(tree: &AnalysisContext<'_>, name: &str) -> Option<Type> {
declaration(tree, name)?;
Some(handle(name))
(declaration(tree, name).is_some() || imported(tree, name).is_some()).then(|| handle(name))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Recognize imported layouts when validating interface classes

When an interface class is declared in a separate package source, a module class using implements p::I still fails in interface_name: that function requires declaration(tree, &name) to find a native interface declaration in the consumer's source. Although this change makes the imported handle type and layout available, that check never consults the imported layout's is_interface flag and rejects the valid implementation as “not an interface class.” Validate imported interfaces through their exported layouts too; the added same-source package test does not exercise this path.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 8ce6209: an imported interface class is validated by its exported layout. Covered by classes_of_packages_in_other_sources_keep_their_behaviour (implements p::I with the package in another source).

Comment on lines +606 to +612
let Some(declaration) = declaration else {
let class = imported(tree, name).ok_or_else(|| unsupported(format!("class `{name}`")))?;
tree.state
.classes
.borrow_mut()
.insert(name.to_owned(), class.clone());
return Ok(class);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Remove consumer-source lookups when checking imported hooks

For a package class declared in another source that defines pre_randomize or post_randomize, calling object.randomize() invokes Class::check_randomize(tree), which still indexes the consumer's declarations with method.native. The imported layout retains the declaring source's SubroutineId, so a consumer with no subroutines panics in Declarations::subroutine; with enough unrelated subroutines it validates the wrong declaration instead. Export the hook metadata needed by this check, or perform the validation in the declaring scope, rather than dereferencing the foreign ID.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 8ce6209: methods export whether they are functions and their formals, and check_randomize uses those instead of a syntax id. Covered by classes_of_packages_in_other_sources_keep_their_behaviour (pre_randomize of a class from another source).

Comment on lines 406 to 410
for expression in &native.expressions {
if let ExprKind::Name(name) = &expression.kind
&& !pattern_keys.contains(&expression.tokens.start)
&& !qualified.iter().any(|base| {
native.expression(*base).tokens == expression.tokens
&& matches!(&native.expression(*base).kind, ExprKind::Name(_))
})
{
add(&name.spelling, expression.tokens.start);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Exclude actual package qualifiers from wildcard binding

When two wildcard-imported packages both declare an item named p, referencing an unrelated package through p::x now incorrectly triggers an ambiguous wildcard-import error for p. This loop adds every expression name, including actual package qualifiers, to unqualified_names; resolve_imports subsequently passes those names to candidates, which reports the conflict even though no unqualified package item was referenced. Previously package qualifiers were excluded. Distinguish actual package qualifiers from imported class qualifiers before treating them as wildcard references.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 8ce6209: a :: scope that names a package no longer counts as a wildcard-import reference. Covered by classes_of_packages_in_other_sources_keep_their_behaviour (two wildcard packages declaring p next to p::B).

Comment on lines +61 to +64
/// The classes the scope declares, laid out, by their qualified names
/// (IEEE 1800-2023 26.3): a scope that uses them may be analyzed from
/// another source, without their declarations.
pub classes: Vec<classes::Class>,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Export class-scoped typedefs alongside imported layouts

For a package containing class C; typedef bit [7:0] word_t; endclass, a consuming module with import p::C; C::word_t value; cannot resolve the typedef. class_scope resolves the imported class correctly, but specializations::member_type searches only tree.state.class_specializations; module analysis creates a fresh AnalysisState, and the exported Class layout contains none of the specialization aliases. This also affects non-parameterized classes, whose typedefs are stored in their sole specialization. Export the resolved class-scoped types and make member lookup use them rather than relying on the declaring analysis's private state.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracked in #1892: class-scoped types of an imported class are not exported yet; such a use reports the type unknown.

@mergify

mergify Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Queued — the merge queue status continues in this comment ↓.

@tignear
tignear force-pushed the stack/tignear/feat/string-class-heap/support-shallow-copies-class-objects--ace3f3bb branch from 75eeaba to 2a56321 Compare October 24, 2026 07:17
@tignear
tignear force-pushed the stack/tignear/feat/string-class-heap/support-classes-declared-pkgs-compilation-unit--12b64cde branch from 85455f4 to 6de9ff1 Compare October 24, 2026 07:17
@tignear

tignear commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Revision history

# Type Changes Reason Date
1 initial 85455f4 2026-10-24 07:16 UTC
2 content 85455f4 → 6de9ff1 Rebased onto the revised #1796/#1810 and master; class resolution keeps the visibility rule of #1796. 2026-10-24 07:16 UTC
3 content 6de9ff1 → 8ce6209 Review: imported $cast helpers rebuilt for module subclasses, imported interface classes validated by layout, randomization hooks checked without foreign syntax ids, package qualifiers kept out of wi… 2026-10-24 11:45 UTC
4 content 8ce6209 → 5e90e35 Review: compilation-unit class caches cleared per unit and their ids salted with the source path, signatures published only for the scope's own classes, imported dispatchers and cast helpers rebuilt … 2026-10-24 18:09 UTC
5 content 5e90e35 → af3f0a8 Rebased onto master with class enum randomization (#1859 and earlier); class test files merged and the Verilator/Icarus class reports regenerated. 2026-10-24 21:08 UTC
6 content 3493193 → 4eb7c7e 2026-10-24 23:39 UTC
7 content 4eb7c7e → 8b00336 Rebased onto master: wildcard-import name collection ported to the per-scope Facts of #1957. sv-tests totals 588/590. 2026-10-25 07:34 UTC
8 content 8b00336 → f03b45c (raw) 2026-10-25 10:59 UTC
9 content f03b45c → af8df00 Review: p::C inside package p resolves as a type and as a constructor scope. Rebased onto master: README paragraph moved to the current corpus (1112/1123); Icarus limitation and xezim review of the n… 2026-10-26 00:24 UTC

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6de9ff1cce

ℹ️ 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".

Comment on lines +1878 to +1880
for class in &imported.classes {
for method in class.dispatched_methods() {
let name = classes::Class::dispatcher_name(&class.name, &method.name);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Rebuild imported randomization dispatch for local subclasses

When a module declares D extends p::B and calls randomize() through a p::B handle holding a D, the call still uses the package's previously lowered p::B::randomize. Its dynamic-class cases were generated before D was visible, and this loop rebuilds only user-declared virtual dispatchers. The call consequently falls through to ObjectOp::Check(B.id), which rejects the derived object with RandomizationClassMismatch instead of randomizing it. Object-wide rand_mode has the same problem. Rebuild these imported built-in dispatchers against the consumer's visible subclasses as well.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracked in #1892: the imported randomization dispatch is not rebuilt for module subclasses yet; the call fails with a runtime error rather than randomizing the wrong object.

Comment on lines +130 to +132
let Some(name) = classes::resolve(tree, &name) else {
return Ok(None);
}
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Resolve the qualified specialization key inside package classes

Inside a parameterized package class, an unqualified self-scope such as C::N no longer finds the active specialization: specializations::specialize now stores its scope alias as p::C::, but the preceding lookup still searches for C::. Resolving C to p::C here happens after that lookup, so named_class reports UnspecializedClassScope despite being inside the specialization. For example, a package containing class C #(int N = 1); static function int f(); return C::N; endfunction endclass and typedef C#(2) C2; cannot lower f. Look up the active specialization using the resolved class name; the analogous lookup in type_binding::class_scope needs the same treatment for self-qualified types.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 8ce6209: the scope-of-specialization lookup also tries the resolved (qualified) class name, so C::N inside a parameterized package class works. Covered by classes_of_packages_in_other_sources_keep_their_behaviour (p::P2::f()).

&instances::normalize_identifier(&package.spelling),
&instances::normalize_identifier(&name.spelling),
);
return Ok(classes::handle_type(tree, &class).map(|_| class));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Resolve package-qualified class typedefs before member lookup

When a package exports a typedef of a class, such as class C; endclass typedef C Alias;, a consumer can bind the handle type p::Alias, but p::Alias::new cannot resolve its constructor. This new branch checks only handle_type(tree, "p::Alias"), which requires a class declaration or exported layout with that exact name; the layout is actually named p::C. Unlike the unqualified-name path below, it never checks dimensions.type_aliases for the underlying class. This also prevents qualified static calls through exported typedefs of parameterized specializations, even though those typedefs are the supported way to use such specializations outside their declaring scope. Resolve the qualified type alias to its class before checking the layout.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 8ce6209: p::Alias:: resolves the package typedef to its class first. Covered by classes_of_packages_in_other_sources_keep_their_behaviour (p::Alias::new).

Comment on lines +337 to +340
Some(unit) if unit.kind == celox_sv_syntax::UnitKind::Package => format!(
"{}::{name}",
instances::normalize_identifier(&unit.name.spelling)
),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restrict extern method lookup to the declaring package

When two packages in the same source each declare a class C with an extern method f, their layouts now receive distinct qualified names, but both declared_methods and class still call out_of_block_definition with the unqualified declaration spelling C. That helper scans every subroutine in the source and returns the first matching C::f, without checking its enclosing package. Consequently, if p defines C::f to return 1 and q defines it to return 2, q::C::f() is lowered using the body from p and returns 1. Match the definition's enclosing package as well as its class and method names.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 8ce6209: an out-of-block definition must be in the same package (or module, or compilation unit) as its class, so q::C::f and r::C::f keep their own bodies. Covered by classes_of_packages_in_other_sources_keep_their_behaviour.

@tignear
tignear force-pushed the stack/tignear/feat/string-class-heap/support-shallow-copies-class-objects--ace3f3bb branch from 2a56321 to e11b661 Compare October 24, 2026 11:46
@tignear
tignear force-pushed the stack/tignear/feat/string-class-heap/support-classes-declared-pkgs-compilation-unit--12b64cde branch from 6de9ff1 to 8ce6209 Compare October 24, 2026 11:46

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8ce62098c8

ℹ️ 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".

instances::normalize_identifier(&unit.name.spelling)
),
Some(_) => name,
None => format!("{}::{name}", packages::UNIT),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include compilation-unit identity in class names

When two source files each declare a compilation-unit class named C, both receive the internal name $unit::C, although these are separate declarations. Packages::analyze_with_roots_impl analyzes all compilation units using one shared AnalysisState, so classes::class and specialization lookup reuse the first file's cached layout for the second file. For example, classes with an 8-bit and a 16-bit property named x can both acquire the first layout, truncating values in the second file. Include the declaring compilation unit in the internal class identity while preserving $unit::C as its source-level spelling.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 5e90e35: each compilation unit is analyzed with its class caches cleared, and the run-time identifier of a compilation-unit class includes its source path, so two sources' $unit::C keep their own layouts and identifiers. Covered by classes_keep_the_identity_and_signatures_of_their_scopes.

Comment on lines +563 to 564
for class_name in classes::specializations_of(tree, class) {
let _ = class_signatures(class, &class_name, tree, context);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve imported signatures instead of rebinding foreign classes

When a package and its consuming module are in the same source, this loop still visits the package's class declarations and republishes their signatures using the module's PackedDimensions. Module analysis has a fresh specialization state, so class_signatures cannot recover the package's declaration environment and overwrites the correctly imported metadata. For example, a package with N = 8 and a static method returning bit [N-1:0] is rebound as a 16-bit return in a consuming module declaring N = 16, making return-width queries and expression sizing incorrect. Restrict signature discovery to classes declared in the current scope and retain exported signatures for imported classes.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 5e90e35: signature discovery publishes only the classes the current scope declares; imported classes keep the signatures their scope exported, so a package method returning bit [N-1:0] keeps the package's N. Covered by classes_keep_the_identity_and_signatures_of_their_scopes.

Comment on lines +905 to +909
if packages.get(package_name).is_none()
&& (imports
.explicit
.iter()
.any(|(_, item)| item == package_name)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Recognize class imports declared inside generate blocks

When a generate block imports a package class and uses a class-qualified member, such as if (1) begin : g import p::C; initial value = C::f(); end, this check does not recognize C as an imported class. ScopeImports::from_scope deliberately excludes generate-block imports from imports.explicit and imports.wildcard, keeping them in the generate scopes instead. Consequently, resolution falls through to package(package_name)? and reports an unknown package C before the later generate-scope lookup can bind it. Consult the enclosing generate imports when distinguishing class qualifiers from package qualifiers.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracked in #1892 (item 3): a class imported inside a generate block and used as C::f() is rejected as an unknown package, not lowered wrongly.

Comment on lines +1895 to +1899
if targets
.iter()
.all(|(_, ids)| ids.iter().all(|id| imported_ids.contains(id)))
{
continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Rebuild dispatchers for subclasses imported from other packages

When package q declares D extends p::B and overrides a virtual method, a module using q::D through a p::B handle still receives the original dispatcher from p. Although analyzing q rebuilds that dispatcher to include D, Packages::closure imports dependencies first and ScopeSymbols::extend keeps the first subroutine with each name, discarding q's rebuilt version. This condition then skips rebuilding in the module because both B and D have imported IDs, leaving no dispatch case for D and failing to call its override. Determine whether the retained dispatcher covers the targets rather than assuming every imported class is already covered.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 5e90e35: an imported dispatcher (or $cast helper) is rebuilt whenever its case labels miss a target the importing scope sees, so q::D extends p::B reaches its override through a p::B handle. Covered by classes_keep_the_identity_and_signatures_of_their_scopes.

@tignear
tignear force-pushed the stack/tignear/feat/string-class-heap/support-shallow-copies-class-objects--ace3f3bb branch from e11b661 to d441141 Compare October 24, 2026 18:17
@tignear
tignear force-pushed the stack/tignear/feat/string-class-heap/support-classes-declared-pkgs-compilation-unit--12b64cde branch 2 times, most recently from 5e90e35 to af3f0a8 Compare October 24, 2026 21:08
@tignear
tignear force-pushed the stack/tignear/feat/string-class-heap/support-shallow-copies-class-objects--ace3f3bb branch from d441141 to 458faa0 Compare October 24, 2026 21:08

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: af3f0a8998

ℹ️ 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".

Comment on lines +58 to 60
/// The definition, or the prototype of a pure virtual method, in the
/// source of the scope that declares the class.
pub native: celox_sv_syntax::SubroutineId,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include method ownership when comparing imported syntax IDs

When a base class comes from another source, its inherited methods retain source-local SubroutineId values that can equal those of unrelated methods in the derived class. procedural::lower_subroutine still determines staticness with class.methods.iter().any(|method| method.native == native_id && method.qualifiers.is_static), without checking ownership. For example, if the package source's first method is a static B::g and the module source's first method is an instance D::f, both IDs coincide and D::f is incorrectly lowered without this; accessing an instance property then rejects an otherwise valid design. Restrict that comparison to the declaring class, or use the current method's qualified identity.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 4eb7c7e: lower_subroutine treats a method as static only when the class itself declares it (method.owner == class.name), so an inherited method of a class from another source with the same source-local identifier no longer makes the derived method static. Covered by inherited_members_of_package_classes_keep_their_declarations (fails without the fix: "non-static property y in a static method").

Comment on lines +615 to +620
let Some(declaration) = declaration else {
let class = imported(tree, name).ok_or_else(|| unsupported(format!("class `{name}`")))?;
tree.state
.classes
.borrow_mut()
.insert(name.to_owned(), class.clone());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Resolve exported static-property types in their declaring scope

When an imported base has a static property whose width uses a package parameter, the exported layout still contains the unqualified parameter expression. For example, with p::N = 8, B::x declared as static bit [N-1:0] x, and a consuming module declaring N = 16 and D extends p::B, BodyBuilder::enter_class_scope installs the inherited property's unresolved type into the derived method's dimensions. Consequently, $bits(x) inside a method of D evaluates to 16 although the package allocated an 8-bit variable. Resolve the property types against their declaration environment before exporting or importing the layout, rather than cloning those unresolved types into the consumer.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 4eb7c7e: the exported layouts fix the types of properties and static properties in the declaring scope (type_parameters::resolve with the package's constants and the specialization's parameters) before another scope imports them. Covered by inherited_members_of_package_classes_keep_their_declarations: $bits(x) in a module subclass of p::B is 8 with module N = 16 (16 without the fix).

Comment on lines +905 to +909
if packages.get(package_name).is_none()
&& (imports
.explicit
.iter()
.any(|(_, item)| item == package_name)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Recognize class imports inherited from the compilation unit

When import p::C; or import p::*; appears at compilation-unit scope before a module, a class-qualified call such as C::f() inside that module is rejected as an unknown package C. The module's ScopeImports does not contain its enclosing compilation unit's imports, so this condition falls through to package(package_name)? before the later unit.visibility.imports lookup can resolve C. Include the compilation-unit imports visible before the module when distinguishing imported class qualifiers from package qualifiers.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a rejection (unknown package C) rather than a wrong result; added to #1892 (item 4) together with the generate-block import case, since both need the class-qualifier classification to consult imports outside the module's own ScopeImports.

@tignear
tignear force-pushed the stack/tignear/feat/string-class-heap/support-shallow-copies-class-objects--ace3f3bb branch from 458faa0 to 322bd44 Compare October 24, 2026 21:18
@tignear
tignear force-pushed the stack/tignear/feat/string-class-heap/support-classes-declared-pkgs-compilation-unit--12b64cde branch from af3f0a8 to 3493193 Compare October 24, 2026 21:18
@tignear
tignear force-pushed the stack/tignear/feat/string-class-heap/support-shallow-copies-class-objects--ace3f3bb branch from 322bd44 to 9120d4d Compare October 24, 2026 23:40
@tignear
tignear force-pushed the stack/tignear/feat/string-class-heap/support-classes-declared-pkgs-compilation-unit--12b64cde branch from 3493193 to 4eb7c7e Compare October 24, 2026 23:40
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

1 similar comment
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@tignear
tignear force-pushed the stack/tignear/feat/string-class-heap/support-classes-declared-pkgs-compilation-unit--12b64cde branch from 4eb7c7e to 8b00336 Compare October 25, 2026 07:39
@tignear
tignear force-pushed the stack/tignear/feat/string-class-heap/support-shallow-copies-class-objects--ace3f3bb branch from 9120d4d to 06d0395 Compare October 25, 2026 07:40
@tignear

tignear commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

Local review (Codex CLI) of this commit:

Rebased onto master: the wildcard-import name collection now uses the per-scope Facts of #1957. sv-tests totals 588/590.

@tignear
tignear force-pushed the stack/tignear/feat/string-class-heap/support-classes-declared-pkgs-compilation-unit--12b64cde branch from 8b00336 to f03b45c Compare October 25, 2026 11:00
@tignear
tignear force-pushed the stack/tignear/feat/string-class-heap/support-shallow-copies-class-objects--ace3f3bb branch from 06d0395 to ce9510e Compare October 25, 2026 11:00

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f03b45cdf1

ℹ️ 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".

Comment on lines +98 to +102
let class = scope::qualified_name(
&tree.state,
&instances::normalize_identifier(&package.spelling),
&instances::normalize_identifier(&name.spelling),
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve class qualification inside its declaring package

When a package refers to its own class as p::C, scope::qualified_name returns the unqualified name C while enter_package("p") is active. However, class declarations and layouts are now keyed by p::C, so the subsequent handle_type lookup fails. For example, package p; class C; endclass function C make(); return p::C::new; endfunction endpackage cannot resolve its constructor even though C::new works. Preserve the fully qualified class identity here, or resolve the resulting local name before looking up the layout; package-local type binding needs the same treatment.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in af8df00: inside package p, a qualified p::C whose local name does not name a layout is resolved to the package's class (p::C) both in named_class (so p::C::new constructs) and in type binding (so p::C h; is a handle of p::C). Covered by class::package_classes_by_their_qualified_names.

A class declared in a package or in the compilation unit is named by its
scope, `p::C` or `$unit::C`, and is laid out and lowered once, in that scope
(IEEE 1800-2023 3.12.1, 26.3). The scope exports the class layouts with its
symbols, and the class as a type, so a module uses the class through an
import, `p::C`, `p::C::member` or, for the compilation unit, its name, also
from another source: it never lays out a class of another scope again, and
calls its methods through their exported formals. Static properties of the
classes are package variables. A class of another scope is a dispatch and
`$cast` target of the scopes that see it; when a class of a module overrides a
virtual method of such a class, the module lowers the method's dispatcher
again over every class it sees, so calls through package code reach the
override too.

A specialization of a parameterized class is made from its declaration, so
outside its scope only the specializations the scope names are usable; a
new one reports that. Static properties follow the existing rule for package
variables, which processes of one instance may write (#1146).

The sv_tests driver elaborates sources of packages and compilation-unit items
alone, reporting the errors of their compilation units.

sv-tests: 31 chapter 18 cases that declare only classes pass (1112/1123
passing); seven were simulated with a module using the class, the others
pass by elaboration and keep their constraints unchecked, while `randomize()`
of a class with constraints stays rejected. Icarus 13.0 rejects the new
shared cases on constructs it does not support, recorded with the existing
groups; Verilator passes them.

Change-Id: I12b64cde387059361235e2b6ccbf6591c4087907
@tignear
tignear force-pushed the stack/tignear/feat/string-class-heap/support-classes-declared-pkgs-compilation-unit--12b64cde branch from f03b45c to af8df00 Compare October 26, 2026 00:25
@tignear
tignear force-pushed the stack/tignear/feat/string-class-heap/support-shallow-copies-class-objects--ace3f3bb branch from ce9510e to 0cc4b2e Compare October 26, 2026 00:25
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

1 similar comment
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

Base automatically changed from stack/tignear/feat/string-class-heap/support-shallow-copies-class-objects--ace3f3bb to master October 26, 2026 02:37
@tignear tignear added the merge-ready Request merging through Mergify after required checks label Oct 26, 2026
@mergify mergify Bot added the queued Mergify queue entry label Oct 26, 2026
@mergify

mergify Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-26 02:39 UTC · Rule: changes · triggered by rule Queue explicitly requested merges
  • ✅ Checks passed · on draft merge queue: checking #1850 on master (a4b02fb) #2097
  • ✅ Merged — 2026-10-26 03:13 UTC · at 1588e7062000b0107538e84f2f60334013c4a791 · merge

This pull request spent 33 minutes 49 seconds in the queue, including 32 minutes 10 seconds running CI.

Required conditions to merge
  • check-success = Conventional Commit title
  • check-success = Queue validation
  • depends-on = celox-sim/celox#1810 [⛓️ feat(sv)!: support shallow copies of class objects #1810]
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Lint & Format
    • check-neutral = @github-actions/Lint & Format
    • check-skipped = @github-actions/Lint & Format
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/NAPI Build (Linux ARM64 GNU)
    • check-neutral = @github-actions/NAPI Build (Linux ARM64 GNU)
    • check-skipped = @github-actions/NAPI Build (Linux ARM64 GNU)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/NAPI Build (Windows)
    • check-neutral = @github-actions/NAPI Build (Windows)
    • check-skipped = @github-actions/NAPI Build (Windows)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Rust Test & NAPI Build
    • check-neutral = @github-actions/Rust Test & NAPI Build
    • check-skipped = @github-actions/Rust Test & NAPI Build
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/JS Test (Ubuntu)
    • check-neutral = @github-actions/JS Test (Ubuntu)
    • check-skipped = @github-actions/JS Test (Ubuntu)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/JS Test (Windows)
    • check-neutral = @github-actions/JS Test (Windows)
    • check-skipped = @github-actions/JS Test (Windows)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Conventional Commit title
    • check-neutral = @github-actions/Conventional Commit title
    • check-skipped = @github-actions/Conventional Commit title

@mergify mergify Bot mentioned this pull request Oct 26, 2026
43 of 73 tasks
@mergify
mergify Bot merged commit 1588e70 into master Oct 26, 2026
27 of 45 checks passed
@mergify
mergify Bot deleted the stack/tignear/feat/string-class-heap/support-classes-declared-pkgs-compilation-unit--12b64cde branch October 26, 2026 03:13
@mergify mergify Bot removed the queued Mergify queue entry label Oct 26, 2026
@mergify mergify Bot mentioned this pull request Oct 26, 2026
43 of 73 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-ready Request merging through Mergify after required checks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant