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
10 changes: 5 additions & 5 deletions crates/celox-sv-analyzer/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1434,7 +1434,7 @@ impl Module {
.collect(),
enum_constants: enum_constants.clone(),
functions: functions.clone(),
function_return_types: packed_dimensions.function_return_types.clone(),
function_return_types: (*packed_dimensions.function_return_types).clone(),
constant_functions: const_functions::installed(&syntax_tree.state.const_functions),
subroutine_params: subroutine_params.clone(),
subroutine_shapes: subroutine_shapes.clone(),
Expand Down Expand Up @@ -3036,8 +3036,8 @@ struct FunctionReturnMetadata {
struct PackedDimensions {
variables: ScopedMap<VariableDimensions>,
const_env: SharedMap<i128>,
type_aliases: HashMap<String, Type>,
function_return_types: HashMap<String, FunctionReturnMetadata>,
type_aliases: SharedMap<Type>,
function_return_types: SharedMap<FunctionReturnMetadata>,
functions: Arc<HashMap<String, Function>>,
parameter_values: SharedMap<Expr>,
/// Constant array initializers for binding child parameter values.
Expand Down Expand Up @@ -3067,8 +3067,8 @@ impl PackedDimensions {
Self {
variables: variables.into(),
const_env: const_env.clone().into(),
type_aliases: type_aliases.clone(),
function_return_types: HashMap::default(),
type_aliases: type_aliases.clone().into(),
function_return_types: SharedMap::default(),
functions: Arc::default(),
parameter_values: SharedMap::default(),
array_parameter_values: SharedMap::default(),
Expand Down
42 changes: 33 additions & 9 deletions crates/celox-sv-analyzer/src/ast/classes/specializations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,32 @@ pub(in crate::ast) fn scope(
env: &HashMap<String, i128>,
aliases: &HashMap<String, Type>,
) -> (HashMap<String, i128>, HashMap<String, Type>) {
let (env, aliases) = shared_scope(tree, name, &env.clone().into(), &aliases.clone().into());
(env.into_iter().collect(), aliases.into_iter().collect())
}

/// [`scope`] of shared tables, which are copied only when the class adds
/// parameters or inherited types to them.
pub(in crate::ast) fn shared_scope(
tree: &AnalysisContext<'_>,
name: &str,
env: &SharedMap<i128>,
aliases: &SharedMap<Type>,
) -> (SharedMap<i128>, SharedMap<Type>) {
let mut env = env.clone();
let mut aliases = aliases.clone();
let own = generic(tree, name);
for specialization in lineage(tree, name) {
env.extend(specialization.env.clone());
for key in &specialization.hidden {
env.remove(key);
if !specialization.env.is_empty() || !specialization.hidden.is_empty() {
env.extend(specialization.env.clone());
for key in &specialization.hidden {
env.remove(key);
}
}
let mut inherited = inherited(&own, &specialization).peekable();
if inherited.peek().is_some() {
aliases.extend(inherited);
}
aliases.extend(inherited(&own, &specialization));
}
(env, aliases)
}
Expand Down Expand Up @@ -471,8 +488,12 @@ fn prepare(
}
// The declarations of the class are bound in the scope that declares it,
// the actuals in the scope that names the specialization.
let (mut env, mut aliases) = declaration_scope(tree, generic)
.unwrap_or_else(|| ((*context.const_env).clone(), context.type_aliases.clone()));
let (mut env, mut aliases) = declaration_scope(tree, generic).unwrap_or_else(|| {
(
(*context.const_env).clone(),
(*context.type_aliases).clone(),
)
});
let mut parameters = Parameters {
values,
types,
Expand Down Expand Up @@ -1182,7 +1203,10 @@ pub(in crate::ast) fn collect(tree: &AnalysisContext<'_>, context: &PackedDimens
(*item.env).clone(),
item.type_aliases(&context.type_aliases).into_owned(),
),
None => ((*context.const_env).clone(), context.type_aliases.clone()),
None => (
(*context.const_env).clone(),
(*context.type_aliases).clone(),
),
};
let name = super::declared_name(tree, class);
if item.is_some_and(|item| items.iter().filter(|other| other.id == item.id).count() > 1) {
Expand Down Expand Up @@ -1223,7 +1247,7 @@ pub(in crate::ast) fn collect(tree: &AnalysisContext<'_>, context: &PackedDimens
.map(|item| {
let mut scope = context.clone();
scope.const_env = (*item.env).clone().into();
scope.type_aliases = item.type_aliases(&context.type_aliases).into_owned();
scope.type_aliases = item.type_aliases(&context.type_aliases).into_owned().into();
scope
})
.collect::<Vec<_>>();
Expand Down Expand Up @@ -1259,7 +1283,7 @@ pub(in crate::ast) fn collect(tree: &AnalysisContext<'_>, context: &PackedDimens
let (env, aliases) =
self::scope(tree, &scope, &context.const_env, &context.type_aliases);
context.const_env = env.into();
context.type_aliases = aliases;
context.type_aliases = aliases.into();
let _ = specialize(tree, name, arguments, &context);
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/celox-sv-analyzer/src/ast/constant_binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub(super) fn value_expression(
) -> Converted<Option<ConstExpr>> {
let mut context = dimensions.clone();
context.const_env = HashMap::default().into();
context.type_aliases = HashMap::default();
context.type_aliases = SharedMap::default();
bind_in_context(root, native, tree, &context, dimensions)
}
pub(super) fn bind(
Expand Down
1 change: 1 addition & 0 deletions crates/celox-sv-analyzer/src/ast/dimensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ pub(super) fn parameter_type_from_lookup(
thread_local! {
static SYNTAX_TYPE_DISCOVERIES: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
pub(super) static PARAMETER_TYPE_SCAN_ENTRIES: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
pub(super) static CLASS_SIGNATURE_BINDINGS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
}

#[cfg(test)]
Expand Down
Loading
Loading