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 {
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);
} else {
continue;
@ -86,12 +86,9 @@ impl ExposedForModule {
/// The types of all exposed values/functions of a module
#[derive(Clone, Debug)]
pub enum ExposedModuleTypes {
Invalid,
Valid {
stored_vars_by_symbol: Vec<(Symbol, Variable)>,
storage_subs: roc_types::subs::StorageSubs,
},
pub struct ExposedModuleTypes {
pub stored_vars_by_symbol: Vec<(Symbol, Variable)>,
pub storage_subs: roc_types::subs::StorageSubs,
}
pub fn constrain_module(

View File

@ -2121,7 +2121,7 @@ fn update<'a>(
} else {
state.exposed_types.insert(
module_id,
ExposedModuleTypes::Valid {
ExposedModuleTypes {
stored_vars_by_symbol: solved_module.stored_vars_by_symbol,
storage_subs: solved_module.storage_subs,
},
@ -3589,51 +3589,39 @@ fn add_imports(
for symbol in exposed_for_module.imported_values {
let module_id = symbol.module_id();
match exposed_for_module.exposed_by_module.get_mut(&module_id) {
Some(t) => match t {
ExposedModuleTypes::Invalid => {
// make the type a flex var, so it unifies with anything
// this way the error is only reported in the module it originates in
let variable = subs.fresh_unnamed_flex_var();
Some(ExposedModuleTypes {
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,
};
def_types.push((
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);
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
// consider them rigid variables
rigid_vars.extend(copied_import.rigid);
rigid_vars.extend(copied_import.flex);
// Rigid vars bound to abilities are also treated like rigids.
rigid_vars.extend(copied_import.rigid_able);
rigid_vars.extend(copied_import.flex_able);
// Rigid vars bound to abilities are also treated like rigids.
rigid_vars.extend(copied_import.rigid_able);
rigid_vars.extend(copied_import.flex_able);
import_variables.extend(copied_import.registered);
import_variables.extend(copied_import.registered);
def_types.push((
symbol,
Loc::at_zero(roc_types::types::Type::Variable(copied_import.variable)),
));
}
},
def_types.push((
symbol,
Loc::at_zero(roc_types::types::Type::Variable(copied_import.variable)),
));
}
None => {
internal_error!("Imported module {:?} is not available", module_id)
}