Simplify ExposedModuleTypes

The `Invalid` variant was never constructed, so we can eliminate it.
This commit is contained in:
Ayaz Hafiz 2022-05-18 09:59:37 -04:00
parent 2c09907116
commit a8265426df
No known key found for this signature in database
GPG Key ID: 0E2A37416A25EF58
2 changed files with 33 additions and 48 deletions

View File

@ -70,7 +70,7 @@ impl ExposedForModule {
for symbol in it { for symbol in it {
let module = exposed_by_module.exposed.get(&symbol.module_id()); let module = exposed_by_module.exposed.get(&symbol.module_id());
if let Some(ExposedModuleTypes::Valid { .. }) = module { if let Some(ExposedModuleTypes { .. }) = module {
imported_values.push(*symbol); imported_values.push(*symbol);
} else { } else {
continue; continue;
@ -86,12 +86,9 @@ impl ExposedForModule {
/// The types of all exposed values/functions of a module /// The types of all exposed values/functions of a module
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum ExposedModuleTypes { pub struct ExposedModuleTypes {
Invalid, pub stored_vars_by_symbol: Vec<(Symbol, Variable)>,
Valid { pub storage_subs: roc_types::subs::StorageSubs,
stored_vars_by_symbol: Vec<(Symbol, Variable)>,
storage_subs: roc_types::subs::StorageSubs,
},
} }
pub fn constrain_module( pub fn constrain_module(

View File

@ -2121,7 +2121,7 @@ fn update<'a>(
} else { } else {
state.exposed_types.insert( state.exposed_types.insert(
module_id, module_id,
ExposedModuleTypes::Valid { ExposedModuleTypes {
stored_vars_by_symbol: solved_module.stored_vars_by_symbol, stored_vars_by_symbol: solved_module.stored_vars_by_symbol,
storage_subs: solved_module.storage_subs, storage_subs: solved_module.storage_subs,
}, },
@ -3589,51 +3589,39 @@ fn add_imports(
for symbol in exposed_for_module.imported_values { for symbol in exposed_for_module.imported_values {
let module_id = symbol.module_id(); let module_id = symbol.module_id();
match exposed_for_module.exposed_by_module.get_mut(&module_id) { match exposed_for_module.exposed_by_module.get_mut(&module_id) {
Some(t) => match t { Some(ExposedModuleTypes {
ExposedModuleTypes::Invalid => { stored_vars_by_symbol,
// make the type a flex var, so it unifies with anything storage_subs,
// this way the error is only reported in the module it originates in }) => {
let variable = subs.fresh_unnamed_flex_var(); let variable = match stored_vars_by_symbol.iter().find(|(s, _)| *s == symbol) {
None => {
// Today we define builtins in each module that uses them
// so even though they have a different module name from
// the surrounding module, they are not technically imported
debug_assert!(symbol.is_builtin());
continue;
}
Some((_, x)) => *x,
};
def_types.push(( let copied_import = storage_subs.export_variable_to(subs, variable);
symbol,
Loc::at_zero(roc_types::types::Type::Variable(variable)),
));
}
ExposedModuleTypes::Valid {
stored_vars_by_symbol,
storage_subs,
} => {
let variable = match stored_vars_by_symbol.iter().find(|(s, _)| *s == symbol) {
None => {
// Today we define builtins in each module that uses them
// so even though they have a different module name from
// the surrounding module, they are not technically imported
debug_assert!(symbol.is_builtin());
continue;
}
Some((_, x)) => *x,
};
let copied_import = storage_subs.export_variable_to(subs, variable); // not a typo; rigids are turned into flex during type inference, but when imported we must
// consider them rigid variables
rigid_vars.extend(copied_import.rigid);
rigid_vars.extend(copied_import.flex);
// not a typo; rigids are turned into flex during type inference, but when imported we must // Rigid vars bound to abilities are also treated like rigids.
// consider them rigid variables rigid_vars.extend(copied_import.rigid_able);
rigid_vars.extend(copied_import.rigid); rigid_vars.extend(copied_import.flex_able);
rigid_vars.extend(copied_import.flex);
// Rigid vars bound to abilities are also treated like rigids. import_variables.extend(copied_import.registered);
rigid_vars.extend(copied_import.rigid_able);
rigid_vars.extend(copied_import.flex_able);
import_variables.extend(copied_import.registered); def_types.push((
symbol,
def_types.push(( Loc::at_zero(roc_types::types::Type::Variable(copied_import.variable)),
symbol, ));
Loc::at_zero(roc_types::types::Type::Variable(copied_import.variable)), }
));
}
},
None => { None => {
internal_error!("Imported module {:?} is not available", module_id) internal_error!("Imported module {:?} is not available", module_id)
} }