diff --git a/compiler/load/src/file.rs b/compiler/load/src/file.rs index 14a0b78a39..fe11c89a38 100644 --- a/compiler/load/src/file.rs +++ b/compiler/load/src/file.rs @@ -2332,6 +2332,10 @@ fn load_pkg_config<'a>( ))) } Ok((ast::Module::Platform { header }, parser_state)) => { + let delta = bytes.len() - parser_state.bytes.len(); + let chomped = &bytes[..delta]; + let header_src = unsafe { std::str::from_utf8_unchecked(chomped) }; + // make a Pkg-Config module that ultimately exposes `main` to the host let pkg_config_module_msg = fabricate_pkg_config_module( arena, @@ -2342,6 +2346,7 @@ fn load_pkg_config<'a>( module_ids.clone(), ident_ids_by_module.clone(), &header, + header_src, pkg_module_timing, ) .1; @@ -2939,18 +2944,24 @@ fn send_header<'a>( ) } -// TODO refactor so more logic is shared with `send_header` -#[allow(clippy::too_many_arguments)] -fn send_header_two<'a>( - arena: &'a Bump, +#[derive(Debug)] +struct PlatformHeaderInfo<'a> { filename: PathBuf, is_root_module: bool, shorthand: &'a str, + header_src: &'a str, app_module_id: ModuleId, packages: &'a [Located>], provides: &'a [Located>], requires: &'a [Located>], imports: &'a [Located>], +} + +// TODO refactor so more logic is shared with `send_header` +#[allow(clippy::too_many_arguments)] +fn send_header_two<'a>( + arena: &'a Bump, + info: PlatformHeaderInfo<'a>, parse_state: parser::State<'a>, module_ids: Arc>>, ident_ids_by_module: Arc>>, @@ -2958,6 +2969,18 @@ fn send_header_two<'a>( ) -> (ModuleId, Msg<'a>) { use inlinable_string::InlinableString; + let PlatformHeaderInfo { + filename, + shorthand, + is_root_module, + header_src, + app_module_id, + packages, + provides, + requires, + imports, + } = info; + let declared_name: InlinableString = "".into(); let mut imported: Vec<(QualifiedModuleName, Vec, Region)> = @@ -3149,7 +3172,7 @@ fn send_header_two<'a>( package_qualified_imported_modules, deps_by_name, exposes: exposed, - header_src: "#builtin effect header", + header_src, parse_state, exposed_imports: scope, module_timing, @@ -3278,21 +3301,27 @@ fn fabricate_pkg_config_module<'a>( module_ids: Arc>>, ident_ids_by_module: Arc>>, header: &PlatformHeader<'a>, + header_src: &'a str, module_timing: ModuleTiming, ) -> (ModuleId, Msg<'a>) { let provides: &'a [Located>] = header.provides.clone().into_bump_slice(); + let info = PlatformHeaderInfo { + filename, + is_root_module: false, + shorthand, + header_src, + app_module_id, + packages: &[], + provides, + requires: header.requires.clone().into_bump_slice(), + imports: header.imports.clone().into_bump_slice(), + }; + send_header_two( arena, - filename, - false, - shorthand, - app_module_id, - &[], - provides, - header.requires.clone().into_bump_slice(), - header.imports.clone().into_bump_slice(), + info, parse_state, module_ids, ident_ids_by_module, diff --git a/compiler/mono/src/ir.rs b/compiler/mono/src/ir.rs index 4b536732fc..de2c6944c6 100644 --- a/compiler/mono/src/ir.rs +++ b/compiler/mono/src/ir.rs @@ -456,7 +456,7 @@ impl<'a> Procs<'a> { name, PartialProc { annotation, - pattern_symbols: pattern_symbols.into_bump_slice() , + pattern_symbols: pattern_symbols.into_bump_slice(), captured_symbols: CapturedSymbols::None, body: roc_can::expr::Expr::RuntimeError(error.value), is_self_recursive: false, @@ -1795,10 +1795,11 @@ fn specialize_external<'a>( let snapshot = env.subs.snapshot(); let cache_snapshot = layout_cache.snapshot(); - let unified = roc_unify::unify::unify(env.subs, annotation, fn_var); + let _unified = roc_unify::unify::unify(env.subs, annotation, fn_var); - let is_valid = matches!(unified, roc_unify::unify::Unified::Success(_)); - debug_assert!(is_valid, "unificaton failure for {:?}", proc_name); + // This will not hold for programs with type errors + // let is_valid = matches!(unified, roc_unify::unify::Unified::Success(_)); + // debug_assert!(is_valid, "unificaton failure for {:?}", proc_name); // if this is a closure, add the closure record argument let pattern_symbols = if let CapturedSymbols::Captured(_) = captured_symbols { @@ -2138,9 +2139,7 @@ fn build_specialized_proc_adapter<'a>( arg_layouts.push(layout); } - let ret_layout = layout_cache - .from_var(&env.arena, ret_var, env.subs) - .unwrap_or_else(|err| panic!("TODO handle invalid function {:?}", err)); + let ret_layout = layout_cache.from_var(&env.arena, ret_var, env.subs)?; build_specialized_proc( env.arena,