hollow out ConstrainableImports

This commit is contained in:
Folkert 2022-03-11 21:29:50 +01:00
parent 364bc81dc4
commit 20ae9ff1e3
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
2 changed files with 43 additions and 64 deletions

View file

@ -164,8 +164,7 @@ pub fn constrain_imports(
} }
pub struct ConstrainableImports { pub struct ConstrainableImports {
pub imported_symbols: Vec<Import>, pub imported_builtins: Vec<Import>,
pub imported_aliases: MutMap<Symbol, Alias>,
pub unused_imports: MutMap<ModuleId, Region>, pub unused_imports: MutMap<ModuleId, Region>,
} }
@ -182,7 +181,6 @@ pub fn pre_constrain_imports(
stdlib: &StdLib, stdlib: &StdLib,
) -> ConstrainableImports { ) -> ConstrainableImports {
let mut imported_symbols = Vec::with_capacity(references.len()); let mut imported_symbols = Vec::with_capacity(references.len());
let mut imported_aliases = MutMap::default();
let mut unused_imports = imported_modules; // We'll remove these as we encounter them. let mut unused_imports = imported_modules; // We'll remove these as we encounter them.
// Translate referenced symbols into constraints. We do this on the main // Translate referenced symbols into constraints. We do this on the main
@ -260,8 +258,7 @@ pub fn pre_constrain_imports(
} }
ConstrainableImports { ConstrainableImports {
imported_symbols, imported_builtins: imported_symbols,
imported_aliases,
unused_imports, unused_imports,
} }
} }

View file

@ -729,7 +729,7 @@ enum BuildTask<'a> {
Solve { Solve {
module: Module, module: Module,
ident_ids: IdentIds, ident_ids: IdentIds,
imported_symbols: Vec<Import>, imported_builtins: Vec<Import>,
exposed_for_module: ExposedForModule, exposed_for_module: ExposedForModule,
module_timing: ModuleTiming, module_timing: ModuleTiming,
constraints: Constraints, constraints: Constraints,
@ -3054,8 +3054,7 @@ impl<'a> BuildTask<'a> {
// to avoid having to lock the map of exposed types, or to clone it // to avoid having to lock the map of exposed types, or to clone it
// (which would be more expensive for the main thread). // (which would be more expensive for the main thread).
let ConstrainableImports { let ConstrainableImports {
imported_symbols, imported_builtins,
imported_aliases: _, // TODO well then... do we even need those?
unused_imports, unused_imports,
} = pre_constrain_imports( } = pre_constrain_imports(
home, home,
@ -3069,7 +3068,7 @@ impl<'a> BuildTask<'a> {
Self::Solve { Self::Solve {
module, module,
ident_ids, ident_ids,
imported_symbols, imported_builtins,
exposed_for_module, exposed_for_module,
constraints, constraints,
constraint, constraint,
@ -3087,7 +3086,7 @@ fn run_solve<'a>(
module: Module, module: Module,
ident_ids: IdentIds, ident_ids: IdentIds,
mut module_timing: ModuleTiming, mut module_timing: ModuleTiming,
imported_symbols: Vec<Import>, imported_builtins: Vec<Import>,
mut exposed_for_module: ExposedForModule, mut exposed_for_module: ExposedForModule,
mut constraints: Constraints, mut constraints: Constraints,
constraint: ConstraintSoa, constraint: ConstraintSoa,
@ -3099,21 +3098,7 @@ fn run_solve<'a>(
// We have more constraining work to do now, so we'll add it to our timings. // We have more constraining work to do now, so we'll add it to our timings.
let constrain_start = SystemTime::now(); let constrain_start = SystemTime::now();
// only retain symbols that are not provided with a storage subs let (mut rigid_vars, mut def_types) = constrain_imports(imported_builtins, &mut var_store);
let mut imported_symbols = imported_symbols;
const NEW_TYPES: bool = true;
if NEW_TYPES {
imported_symbols.retain(|k| {
!exposed_for_module
.imported_symbols
.iter()
.any(|i| k.loc_symbol.value == *i)
});
}
let (mut rigid_vars, mut def_types) = constrain_imports(imported_symbols, &mut var_store);
let constrain_end = SystemTime::now(); let constrain_end = SystemTime::now();
@ -3130,47 +3115,44 @@ fn run_solve<'a>(
let mut import_variables = Vec::new(); let mut import_variables = Vec::new();
if NEW_TYPES { for symbol in exposed_for_module.imported_symbols {
for symbol in exposed_for_module.imported_symbols { match exposed_for_module
match exposed_for_module .exposed_by_module
.exposed_by_module .get_mut(&symbol.module_id())
.get_mut(&symbol.module_id()) {
{ Some(t) => match t {
Some(t) => match t { ExposedModuleTypes::Invalid => {
ExposedModuleTypes::Invalid => { // idk, just skip?
// idk, just skip? continue;
continue; }
} ExposedModuleTypes::Valid {
ExposedModuleTypes::Valid { stored_vars_by_symbol,
stored_vars_by_symbol, storage_subs,
storage_subs, } => {
} => { let variable = match stored_vars_by_symbol.iter().find(|(s, _)| *s == symbol) {
let variable = None => {
match stored_vars_by_symbol.iter().find(|(s, _)| *s == symbol) { // TODO happens for imported types
None => { continue;
// TODO happens for imported types }
continue; Some((_, x)) => *x,
} };
Some((_, x)) => *x,
};
let copied_import = storage_subs.export_variable_to(&mut subs, variable); let copied_import = storage_subs.export_variable_to(&mut subs, variable);
// not a typo; rigids are turned into flex during type inference, but when imported we must // not a typo; rigids are turned into flex during type inference, but when imported we must
// consider them rigid variables // consider them rigid variables
rigid_vars.extend(copied_import.rigid); rigid_vars.extend(copied_import.rigid);
rigid_vars.extend(copied_import.flex); rigid_vars.extend(copied_import.flex);
import_variables.extend(copied_import.registered); import_variables.extend(copied_import.registered);
def_types.push(( def_types.push((
symbol, symbol,
Loc::at_zero(roc_types::types::Type::Variable(copied_import.variable)), Loc::at_zero(roc_types::types::Type::Variable(copied_import.variable)),
)); ));
} }
}, },
None => todo!(), None => todo!(),
}
} }
} }
@ -3826,7 +3808,7 @@ fn run_task<'a>(
Solve { Solve {
module, module,
module_timing, module_timing,
imported_symbols, imported_builtins,
exposed_for_module, exposed_for_module,
constraints, constraints,
constraint, constraint,
@ -3839,7 +3821,7 @@ fn run_task<'a>(
module, module,
ident_ids, ident_ids,
module_timing, module_timing,
imported_symbols, imported_builtins,
exposed_for_module, exposed_for_module,
constraints, constraints,
constraint, constraint,