remove another result wrapper

This commit is contained in:
Folkert 2022-05-08 17:09:33 +02:00
parent d5b010cb13
commit 2e9477e011
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
2 changed files with 296 additions and 313 deletions

View file

@ -170,7 +170,7 @@ pub fn canonicalize_module_defs<'a>(
exposed_symbols: &VecSet<Symbol>, exposed_symbols: &VecSet<Symbol>,
symbols_from_requires: &[(Loc<Symbol>, Loc<TypeAnnotation<'a>>)], symbols_from_requires: &[(Loc<Symbol>, Loc<TypeAnnotation<'a>>)],
var_store: &mut VarStore, var_store: &mut VarStore,
) -> Result<ModuleOutput, RuntimeError> { ) -> ModuleOutput {
let mut can_exposed_imports = MutMap::default(); let mut can_exposed_imports = MutMap::default();
let mut scope = Scope::new(home, exposed_ident_ids); let mut scope = Scope::new(home, exposed_ident_ids);
let mut env = Env::new(home, dep_idents, module_ids); let mut env = Env::new(home, dep_idents, module_ids);
@ -351,9 +351,7 @@ pub fn canonicalize_module_defs<'a>(
..Default::default() ..Default::default()
}; };
match sort_can_defs(&mut env, defs, new_output) { let (mut declarations, mut output) = sort_can_defs(&mut env, defs, new_output);
(mut declarations, mut output) => {
use crate::def::Declaration::*;
let symbols_from_requires = symbols_from_requires let symbols_from_requires = symbols_from_requires
.iter() .iter()
@ -401,6 +399,7 @@ pub fn canonicalize_module_defs<'a>(
); );
} }
use crate::def::Declaration::*;
for decl in declarations.iter_mut() { for decl in declarations.iter_mut() {
match decl { match decl {
Declare(def) => { Declare(def) => {
@ -560,14 +559,12 @@ pub fn canonicalize_module_defs<'a>(
for declaration in declarations.iter_mut() { for declaration in declarations.iter_mut() {
match declaration { match declaration {
Declare(def) => fix_values_captured_in_closure_def(def, &mut VecSet::default()), Declare(def) => fix_values_captured_in_closure_def(def, &mut VecSet::default()),
DeclareRec(defs) => { DeclareRec(defs) => fix_values_captured_in_closure_defs(defs, &mut VecSet::default()),
fix_values_captured_in_closure_defs(defs, &mut VecSet::default())
}
InvalidCycle(_) | Builtin(_) => {} InvalidCycle(_) | Builtin(_) => {}
} }
} }
let output = ModuleOutput { ModuleOutput {
scope, scope,
aliases, aliases,
rigid_variables, rigid_variables,
@ -578,10 +575,6 @@ pub fn canonicalize_module_defs<'a>(
problems: env.problems, problems: env.problems,
symbols_from_requires, symbols_from_requires,
lookups, lookups,
};
Ok(output)
}
} }
} }

View file

@ -3873,7 +3873,7 @@ fn canonicalize_and_constrain<'a>(
let before = roc_types::types::get_type_clone_count(); let before = roc_types::types::get_type_clone_count();
let mut var_store = VarStore::default(); let mut var_store = VarStore::default();
let canonicalized = canonicalize_module_defs( let module_output = canonicalize_module_defs(
arena, arena,
parsed_defs, parsed_defs,
&header_for, &header_for,
@ -3902,8 +3902,6 @@ fn canonicalize_and_constrain<'a>(
module_timing.canonicalize = canonicalize_end.duration_since(canonicalize_start).unwrap(); module_timing.canonicalize = canonicalize_end.duration_since(canonicalize_start).unwrap();
match canonicalized {
Ok(module_output) => {
// Generate documentation information // Generate documentation information
// TODO: store timing information? // TODO: store timing information?
let module_docs = match module_name { let module_docs = match module_name {
@ -3994,14 +3992,6 @@ fn canonicalize_and_constrain<'a>(
canonicalization_problems: module_output.problems, canonicalization_problems: module_output.problems,
module_docs, module_docs,
}) })
}
Err(runtime_error) => {
panic!(
"TODO gracefully handle module canonicalization error {:?}",
runtime_error
);
}
}
} }
fn parse<'a>(arena: &'a Bump, header: ModuleHeader<'a>) -> Result<Msg<'a>, LoadingProblem<'a>> { fn parse<'a>(arena: &'a Bump, header: ModuleHeader<'a>) -> Result<Msg<'a>, LoadingProblem<'a>> {