From c66bca582953c8d7550188a4585f2e8052b8ed23 Mon Sep 17 00:00:00 2001 From: KtorZ Date: Sat, 15 Mar 2025 17:00:05 +0100 Subject: [PATCH] remove unused value constructors from modules type info This is a mildly scaring change, as it may horribly break things down the line if we have ever relied on that information... However, the value constructors inside each module are meant to reflect the own module public API, and shouldn't be populated with Prelude stuff. Not only does that mean this information is duplicated for all modules (possibly significantly slowing things down), but it may also cause weird scoping issues (e.g. one accessing a Prelude's constructor through some random module). Hence why I am isolating this change in this single commit, so it's easier to troubleshoot if that ends up causing weird issues. Signed-off-by: KtorZ --- crates/aiken-lang/src/tipo/infer.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/aiken-lang/src/tipo/infer.rs b/crates/aiken-lang/src/tipo/infer.rs index a8945811..a148a6a9 100644 --- a/crates/aiken-lang/src/tipo/infer.rs +++ b/crates/aiken-lang/src/tipo/infer.rs @@ -17,7 +17,12 @@ use crate::{ tipo::{expr::infer_function, Span, Type, TypeVar}, IdGenerator, }; -use std::{borrow::Borrow, collections::HashMap, ops::Deref, rc::Rc}; +use std::{ + borrow::Borrow, + collections::{BTreeSet, HashMap}, + ops::Deref, + rc::Rc, +}; impl UntypedModule { #[allow(clippy::too_many_arguments)] @@ -116,8 +121,14 @@ impl UntypedModule { .module_types .retain(|_, info| info.public && info.module == module_name); + let own_types = environment.module_types.keys().collect::>(); + environment.module_values.retain(|_, info| info.public); + environment + .module_types_constructors + .retain(|k, _| own_types.contains(k)); + environment .accessors .retain(|_, accessors| accessors.public);