Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions conformance/sv-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,19 @@ cases in 2state and 526 in 4state. No passing case regresses: classes that are
declared but never constructed, interface classes and pure virtual methods are
not lowered. `8.7--constructor` keeps failing because it initializes an
implicitly static procedural variable without the `static` keyword, which IEEE
1800-2023 6.21 requires. Inheritance with constructors, `super`, static members,
virtual dispatch and parameterized classes stay unsupported.
1800-2023 6.21 requires; `8.7--constructor_param` fails for the same reason.

Base constructors, `super`, static members and `C::` scope resolution update
eighteen more rows: both state modes for `8.7--constructor_super`,
`8.8--typed_constructor`, `8.9--static_properties`, `8.10--static_methods`,
`8.13--inheritance`, `8.14--override_member`, `8.15--super`,
`8.17--constructor_const_arg` and `8.23--scope_resolution` change from fail to
pass. Each was simulated and its displayed values checked, including the base
method that a base-class handle calls in `8.14--override_member`. Full official
runs at the pinned revision report 534 passing cases in 2state and 536 in
4state, with no passing case regressing. Virtual dispatch, abstract and
interface classes, classes in packages, parameterized classes and shallow copies
stay unsupported.

The report contains each case’s state mode, verdict, selected execution mode,
tags, tool return code and path to the official log. The output directory retains
Expand Down
36 changes: 18 additions & 18 deletions conformance/sv-tests/expected.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -1461,26 +1461,26 @@ chapter-7/unions/tagged/packed.sv 2state fail
chapter-7/unions/tagged/packed.sv 4state fail
chapter-7/unions/unpacked/basic.sv 2state fail
chapter-7/unions/unpacked/basic.sv 4state fail
chapter-8/8.10--static_methods.sv 2state fail
chapter-8/8.10--static_methods.sv 4state fail
chapter-8/8.10--static_methods.sv 2state pass
chapter-8/8.10--static_methods.sv 4state pass
chapter-8/8.11--this.sv 2state pass
chapter-8/8.11--this.sv 4state pass
chapter-8/8.12--assignment.sv 2state pass
chapter-8/8.12--assignment.sv 4state pass
chapter-8/8.12--shallow_copy.sv 2state fail
chapter-8/8.12--shallow_copy.sv 4state fail
chapter-8/8.13--inheritance.sv 2state fail
chapter-8/8.13--inheritance.sv 4state fail
chapter-8/8.14--override_member.sv 2state fail
chapter-8/8.14--override_member.sv 4state fail
chapter-8/8.13--inheritance.sv 2state pass
chapter-8/8.13--inheritance.sv 4state pass
chapter-8/8.14--override_member.sv 2state pass
chapter-8/8.14--override_member.sv 4state pass
chapter-8/8.15--super-default-new.sv 2state fail
chapter-8/8.15--super-default-new.sv 4state fail
chapter-8/8.15--super.sv 2state fail
chapter-8/8.15--super.sv 4state fail
chapter-8/8.15--super.sv 2state pass
chapter-8/8.15--super.sv 4state pass
chapter-8/8.16--cast_func.sv 2state fail
chapter-8/8.16--cast_func.sv 4state fail
chapter-8/8.17--constructor_const_arg.sv 2state fail
chapter-8/8.17--constructor_const_arg.sv 4state fail
chapter-8/8.17--constructor_const_arg.sv 2state pass
chapter-8/8.17--constructor_const_arg.sv 4state pass
chapter-8/8.18--var_local.sv 2state pass
chapter-8/8.18--var_local.sv 4state pass
chapter-8/8.18--var_protected.sv 2state pass
Expand All @@ -1497,8 +1497,8 @@ chapter-8/8.21--abstract_class_inst.sv 2state pass
chapter-8/8.21--abstract_class_inst.sv 4state pass
chapter-8/8.22--dynamic_method_lookup.sv 2state fail
chapter-8/8.22--dynamic_method_lookup.sv 4state fail
chapter-8/8.23--scope_resolution.sv 2state fail
chapter-8/8.23--scope_resolution.sv 4state fail
chapter-8/8.23--scope_resolution.sv 2state pass
chapter-8/8.23--scope_resolution.sv 4state pass
chapter-8/8.24--out_of_block_methods.sv 2state pass
chapter-8/8.24--out_of_block_methods.sv 4state pass
chapter-8/8.25--parametrized_class_extend.sv 2state fail
Expand Down Expand Up @@ -1559,14 +1559,14 @@ chapter-8/8.7--constructor.sv 2state fail
chapter-8/8.7--constructor.sv 4state fail
chapter-8/8.7--constructor_param.sv 2state fail
chapter-8/8.7--constructor_param.sv 4state fail
chapter-8/8.7--constructor_super.sv 2state fail
chapter-8/8.7--constructor_super.sv 4state fail
chapter-8/8.8--typed_constructor.sv 2state fail
chapter-8/8.8--typed_constructor.sv 4state fail
chapter-8/8.7--constructor_super.sv 2state pass
chapter-8/8.7--constructor_super.sv 4state pass
chapter-8/8.8--typed_constructor.sv 2state pass
chapter-8/8.8--typed_constructor.sv 4state pass
chapter-8/8.8--typed_constructor_param.sv 2state fail
chapter-8/8.8--typed_constructor_param.sv 4state fail
chapter-8/8.9--static_properties.sv 2state fail
chapter-8/8.9--static_properties.sv 4state fail
chapter-8/8.9--static_properties.sv 2state pass
chapter-8/8.9--static_properties.sv 4state pass
chapter-9/9.2.1--initial.sv 2state pass
chapter-9/9.2.1--initial.sv 4state pass
chapter-9/9.2.2.1--always.sv 2state pass
Expand Down
3 changes: 3 additions & 0 deletions crates/celox-sv-analyzer/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2734,6 +2734,8 @@ struct PackedDimensions {
/// assignment patterns passed as arguments.
subroutine_param_shapes: Arc<HashMap<String, Vec<VariableDimensions>>>,
subroutine_param_names: Arc<HashMap<String, Vec<String>>>,
/// The class whose method is being bound.
class_scope: Option<String>,
}

impl PackedDimensions {
Expand All @@ -2756,6 +2758,7 @@ impl PackedDimensions {
type_query: false,
subroutine_param_shapes: Arc::default(),
subroutine_param_names: Arc::default(),
class_scope: None,
}
}
}
Expand Down
144 changes: 131 additions & 13 deletions crates/celox-sv-analyzer/src/ast/classes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ pub(super) struct Property {
pub initializer: Option<celox_sv_syntax::ExprId>,
}

/// A static property of a class: one variable of the module that declares
/// the class, shared by all of its objects (IEEE 1800-2023 8.9).
#[derive(Debug, Clone, PartialEq, Eq)]
pub(super) struct StaticProperty {
pub name: String,
/// The class that declares the property.
pub owner: String,
pub r#type: Type,
/// The name of the variable that holds the property.
pub variable: String,
pub initializer: Option<celox_sv_syntax::ExprId>,
}

/// A method of a class.
#[derive(Debug, Clone, PartialEq, Eq)]
pub(super) struct Method {
Expand All @@ -47,6 +60,10 @@ pub(super) struct Class {
pub base: Option<String>,
/// Properties of the class and its bases, bases first.
pub properties: Vec<Property>,
/// How many of `properties` the bases declare.
pub base_properties: usize,
/// Static properties of the class and its bases.
pub statics: Vec<StaticProperty>,
/// Methods visible in the class, overrides replacing inherited ones.
pub methods: Vec<Method>,
/// Bytes of an object.
Expand All @@ -63,14 +80,58 @@ impl Class {
.find(|property| property.name == name)
}

pub fn static_property(&self, name: &str) -> Option<&StaticProperty> {
self.statics.iter().find(|property| property.name == name)
}

pub fn method(&self, name: &str) -> Option<&Method> {
self.methods.iter().find(|method| method.name == name)
}

/// The subroutine name of `method` of `owner`.
/// The properties the class itself declares.
pub fn own_properties(&self) -> &[Property] {
&self.properties[self.base_properties..]
}

/// The number of formals of the constructor, which takes the handle of
/// the object it initializes before them.
pub fn constructor_formals(&self, native: &celox_sv_syntax::Declarations) -> usize {
self.method("new").map_or(0, |method| {
native
.subroutine(method.native)
.ports
.as_ref()
.map_or(0, Vec::len)
})
}

/// The subroutine name of `method` of `owner`, and the variable name of
/// its static property `method`.
pub fn subroutine_name(owner: &str, method: &str) -> String {
format!("{owner}::{method}")
}

/// An allocation of an uninitialized object of the class.
pub fn allocation(&self) -> Expr {
let handles = self
.properties
.iter()
.filter_map(|property| {
property
.field
.handle
.map(|handle| (property.field.offset, handle))
})
.collect();
object_call(
ObjectOp::New {
class: self.id,
size: self.size,
handles,
},
Vec::new(),
)
}
}

/// The declaration of class `name`, if one exists.
Expand Down Expand Up @@ -110,11 +171,12 @@ pub(super) fn item_classes(

/// The methods that class `name` implements, with their definitions: the
/// method itself or, for an `extern` method, its out-of-block definition.
/// A pure virtual method has none (IEEE 1800-2023 8.21).
/// A pure virtual method has none (IEEE 1800-2023 8.21). Each comes with
/// whether it is static.
pub(super) fn declared_methods(
tree: &AnalysisContext<'_>,
name: &str,
) -> Converted<Vec<celox_sv_syntax::SubroutineId>> {
) -> Converted<Vec<(celox_sv_syntax::SubroutineId, bool)>> {
let Some(declaration) = declaration(tree, name) else {
return Ok(Vec::new());
};
Expand All @@ -126,18 +188,55 @@ pub(super) fn declared_methods(
.map(|method| {
let subroutine = native.subroutine(method.subroutine);
if !subroutine.prototype {
return Ok(method.subroutine);
return Ok((method.subroutine, method.qualifiers.is_static));
}
let method_name = instances::normalize_identifier(&subroutine.name.spelling);
out_of_block_definition(tree, name, &method_name).ok_or_else(|| {
unsupported(format!(
"extern method `{name}::{method_name}` without a body"
))
})
out_of_block_definition(tree, name, &method_name)
.map(|id| (id, method.qualifiers.is_static))
.ok_or_else(|| {
unsupported(format!(
"extern method `{name}::{method_name}` without a body"
))
})
})
.collect()
}

/// The static properties that the classes of body item `item` declare,
/// which are variables of the module (IEEE 1800-2023 8.9). A class that
/// cannot be laid out declares none here; its uses report why.
pub(super) fn item_statics(
item: celox_sv_syntax::BodyItemId,
tree: &AnalysisContext<'_>,
env: &HashMap<String, i128>,
aliases: &HashMap<String, Type>,
) -> Vec<StaticProperty> {
item_classes(item, tree)
.into_iter()
.filter_map(|name| {
let class = class(tree, &name, env, aliases).ok()?;
Some(
class
.statics
.iter()
.filter(|property| property.owner == name)
.cloned()
.collect::<Vec<_>>(),
)
})
.flatten()
.collect()
}

/// The arguments that the `extends` clause of class `name` passes to the
/// constructor of its base (IEEE 1800-2023 8.17).
pub(super) fn base_arguments<'a>(
tree: &'a AnalysisContext<'_>,
name: &str,
) -> Option<&'a [celox_sv_syntax::Argument]> {
declaration(tree, name)?.base.as_ref()?.arguments.as_deref()
}

/// The handle type of class `name`, if it is a class.
pub(super) fn handle_type(tree: &AnalysisContext<'_>, name: &str) -> Option<Type> {
declaration(tree, name)?;
Expand Down Expand Up @@ -179,11 +278,13 @@ pub(super) fn class(
.as_ref()
.map(|base| base.properties.clone())
.unwrap_or_default();
let base_properties = properties.len();
let mut statics = base
.as_ref()
.map(|base| base.statics.clone())
.unwrap_or_default();
let mut size = base.as_ref().map_or(0, |base| base.size);
for property in &declaration.properties {
if property.qualifiers.is_static {
return Err(unsupported("static class property"));
}
let ty = type_binding::procedural_type(
property.declaration.data_type,
native,
Expand All @@ -196,7 +297,19 @@ pub(super) fn class(
if !variable.dimensions.is_empty() {
return Err(unsupported("class property with unpacked dimensions"));
}
let name = instances::normalize_identifier(&variable.name.spelling);
let property_name = instances::normalize_identifier(&variable.name.spelling);
if property.qualifiers.is_static {
statics.retain(|known| known.name != property_name);
statics.push(StaticProperty {
variable: Class::subroutine_name(name, &property_name),
name: property_name,
owner: name.to_owned(),
r#type: ty.clone(),
initializer: variable.value,
});
continue;
}
let name = property_name;
let field = field(&tree.state, &ty, env, size)?;
size = field.offset + field.bytes();
properties.push(Property {
Expand All @@ -207,10 +320,13 @@ pub(super) fn class(
});
}
}
// A constructor is not inherited: a class without one has an implicit
// constructor (IEEE 1800-2023 8.7).
let mut methods = base
.as_ref()
.map(|base| base.methods.clone())
.unwrap_or_default();
methods.retain(|method| method.name != "new");
for method in &declaration.methods {
let subroutine = native.subroutine(method.subroutine);
let method_name = instances::normalize_identifier(&subroutine.name.spelling);
Expand Down Expand Up @@ -241,6 +357,8 @@ pub(super) fn class(
id: class_id(name),
base: base.map(|base| base.name.clone()),
properties,
base_properties,
statics,
methods,
size: size.max(1),
});
Expand Down
5 changes: 5 additions & 0 deletions crates/celox-sv-analyzer/src/ast/declarations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,11 @@ pub(super) fn signals_from_body_item(
}
values
}
BodyItemKind::Unconverted { .. } => classes::item_statics(id, tree, env, aliases)
.into_iter()
.filter(|property| selected_name.is_none_or(|selected| selected == property.variable))
.map(|property| Signal::new(property.variable, property.r#type))
.collect(),
_ => Vec::new(),
};
substitute_signal_local_constants(&mut declared, env);
Expand Down
Loading
Loading