bring storage subs into solve again

This commit is contained in:
Folkert 2022-03-11 10:28:10 +01:00
parent 78f5526db3
commit 973e3ac7ed
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
2 changed files with 34 additions and 3 deletions

View file

@ -5,7 +5,7 @@ use roc_collections::all::{MutMap, MutSet, SendMap};
use roc_module::symbol::{ModuleId, Symbol};
use roc_region::all::{Loc, Region};
use roc_types::solved_types::{FreeVars, SolvedType};
use roc_types::subs::{VarStore, Variable};
use roc_types::subs::{StorageSubs, VarStore, Variable};
use roc_types::types::{Alias, Problem};
pub type SubsByModule = MutMap<ModuleId, ExposedModuleTypes>;
@ -111,10 +111,18 @@ pub fn constrain_imports(
pub struct ConstrainableImports {
pub imported_symbols: Vec<Import>,
pub hacky_symbols: Vec<HackyImport>,
pub imported_aliases: MutMap<Symbol, Alias>,
pub unused_imports: MutMap<ModuleId, Region>,
}
#[derive(Debug)]
pub struct HackyImport {
storage_subs: StorageSubs,
loc_symbol: Loc<Symbol>,
variable: Variable,
}
/// Run this before constraining imports.
///
/// Constraining imports is split into two different functions, because this
@ -128,6 +136,7 @@ pub fn pre_constrain_imports(
stdlib: &StdLib,
) -> ConstrainableImports {
let mut imported_symbols = Vec::with_capacity(references.len());
let mut hacky_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.
@ -198,6 +207,19 @@ pub fn pre_constrain_imports(
loc_symbol,
solved_type: solved_type.clone(),
});
let variable = stored_vars_by_symbol
.iter()
.find(|(s, _)| *s == loc_symbol.value)
.unwrap()
.1;
hacky_symbols.push(HackyImport {
loc_symbol,
variable,
// TODO very bad, so much cloning!
storage_subs: storage_subs.clone(),
});
}
}
Some(ExposedModuleTypes::Invalid) => {
@ -207,6 +229,8 @@ pub fn pre_constrain_imports(
loc_symbol,
solved_type: SolvedType::Erroneous(Problem::InvalidModule),
});
// TODO what about storage subs here?
}
None => {
panic!(
@ -220,6 +244,7 @@ pub fn pre_constrain_imports(
ConstrainableImports {
imported_symbols,
hacky_symbols,
imported_aliases,
unused_imports,
}

View file

@ -11,7 +11,7 @@ use roc_can::module::{canonicalize_module_defs, Module};
use roc_collections::all::{default_hasher, BumpMap, MutMap, MutSet};
use roc_constrain::module::{
constrain_imports, constrain_module, pre_constrain_imports, ConstrainableImports,
ExposedModuleTypes, Import, SubsByModule,
ExposedModuleTypes, HackyImport, Import, SubsByModule,
};
use roc_module::ident::{Ident, ModuleName, QualifiedModuleName};
use roc_module::symbol::{
@ -730,6 +730,7 @@ enum BuildTask<'a> {
module: Module,
ident_ids: IdentIds,
imported_symbols: Vec<Import>,
imported_storage_subs: Vec<HackyImport>,
module_timing: ModuleTiming,
constraints: Constraints,
constraint: ConstraintSoa,
@ -3052,8 +3053,9 @@ impl<'a> BuildTask<'a> {
// (which would be more expensive for the main thread).
let ConstrainableImports {
imported_symbols,
imported_aliases: _,
imported_aliases: _, // TODO well then... do we even need those?
unused_imports,
hacky_symbols,
} = pre_constrain_imports(
home,
&module.references,
@ -3067,6 +3069,7 @@ impl<'a> BuildTask<'a> {
module,
ident_ids,
imported_symbols,
imported_storage_subs: hacky_symbols,
constraints,
constraint,
var_store,
@ -3084,6 +3087,7 @@ fn run_solve<'a>(
ident_ids: IdentIds,
mut module_timing: ModuleTiming,
imported_symbols: Vec<Import>,
imported_storage_subs: Vec<HackyImport>,
mut constraints: Constraints,
constraint: ConstraintSoa,
mut var_store: VarStore,
@ -3770,6 +3774,7 @@ fn run_task<'a>(
module,
module_timing,
imported_symbols,
imported_storage_subs,
constraints,
constraint,
var_store,
@ -3782,6 +3787,7 @@ fn run_task<'a>(
ident_ids,
module_timing,
imported_symbols,
imported_storage_subs,
constraints,
constraint,
var_store,