show platform header in error messages

This commit is contained in:
Folkert 2021-03-23 23:00:18 +01:00
parent c9f396b985
commit dd8bdcb806
2 changed files with 48 additions and 20 deletions

View file

@ -2332,6 +2332,10 @@ fn load_pkg_config<'a>(
))) )))
} }
Ok((ast::Module::Platform { header }, parser_state)) => { 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 // make a Pkg-Config module that ultimately exposes `main` to the host
let pkg_config_module_msg = fabricate_pkg_config_module( let pkg_config_module_msg = fabricate_pkg_config_module(
arena, arena,
@ -2342,6 +2346,7 @@ fn load_pkg_config<'a>(
module_ids.clone(), module_ids.clone(),
ident_ids_by_module.clone(), ident_ids_by_module.clone(),
&header, &header,
header_src,
pkg_module_timing, pkg_module_timing,
) )
.1; .1;
@ -2939,18 +2944,24 @@ fn send_header<'a>(
) )
} }
// TODO refactor so more logic is shared with `send_header` #[derive(Debug)]
#[allow(clippy::too_many_arguments)] struct PlatformHeaderInfo<'a> {
fn send_header_two<'a>(
arena: &'a Bump,
filename: PathBuf, filename: PathBuf,
is_root_module: bool, is_root_module: bool,
shorthand: &'a str, shorthand: &'a str,
header_src: &'a str,
app_module_id: ModuleId, app_module_id: ModuleId,
packages: &'a [Located<PackageEntry<'a>>], packages: &'a [Located<PackageEntry<'a>>],
provides: &'a [Located<ExposesEntry<'a, &'a str>>], provides: &'a [Located<ExposesEntry<'a, &'a str>>],
requires: &'a [Located<TypedIdent<'a>>], requires: &'a [Located<TypedIdent<'a>>],
imports: &'a [Located<ImportsEntry<'a>>], imports: &'a [Located<ImportsEntry<'a>>],
}
// 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>, parse_state: parser::State<'a>,
module_ids: Arc<Mutex<PackageModuleIds<'a>>>, module_ids: Arc<Mutex<PackageModuleIds<'a>>>,
ident_ids_by_module: Arc<Mutex<MutMap<ModuleId, IdentIds>>>, ident_ids_by_module: Arc<Mutex<MutMap<ModuleId, IdentIds>>>,
@ -2958,6 +2969,18 @@ fn send_header_two<'a>(
) -> (ModuleId, Msg<'a>) { ) -> (ModuleId, Msg<'a>) {
use inlinable_string::InlinableString; 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 declared_name: InlinableString = "".into();
let mut imported: Vec<(QualifiedModuleName, Vec<Ident>, Region)> = let mut imported: Vec<(QualifiedModuleName, Vec<Ident>, Region)> =
@ -3149,7 +3172,7 @@ fn send_header_two<'a>(
package_qualified_imported_modules, package_qualified_imported_modules,
deps_by_name, deps_by_name,
exposes: exposed, exposes: exposed,
header_src: "#builtin effect header", header_src,
parse_state, parse_state,
exposed_imports: scope, exposed_imports: scope,
module_timing, module_timing,
@ -3278,21 +3301,27 @@ fn fabricate_pkg_config_module<'a>(
module_ids: Arc<Mutex<PackageModuleIds<'a>>>, module_ids: Arc<Mutex<PackageModuleIds<'a>>>,
ident_ids_by_module: Arc<Mutex<MutMap<ModuleId, IdentIds>>>, ident_ids_by_module: Arc<Mutex<MutMap<ModuleId, IdentIds>>>,
header: &PlatformHeader<'a>, header: &PlatformHeader<'a>,
header_src: &'a str,
module_timing: ModuleTiming, module_timing: ModuleTiming,
) -> (ModuleId, Msg<'a>) { ) -> (ModuleId, Msg<'a>) {
let provides: &'a [Located<ExposesEntry<'a, &'a str>>] = let provides: &'a [Located<ExposesEntry<'a, &'a str>>] =
header.provides.clone().into_bump_slice(); 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( send_header_two(
arena, arena,
filename, info,
false,
shorthand,
app_module_id,
&[],
provides,
header.requires.clone().into_bump_slice(),
header.imports.clone().into_bump_slice(),
parse_state, parse_state,
module_ids, module_ids,
ident_ids_by_module, ident_ids_by_module,

View file

@ -1795,10 +1795,11 @@ fn specialize_external<'a>(
let snapshot = env.subs.snapshot(); let snapshot = env.subs.snapshot();
let cache_snapshot = layout_cache.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(_)); // This will not hold for programs with type errors
debug_assert!(is_valid, "unificaton failure for {:?}", proc_name); // 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 // if this is a closure, add the closure record argument
let pattern_symbols = if let CapturedSymbols::Captured(_) = captured_symbols { let pattern_symbols = if let CapturedSymbols::Captured(_) = captured_symbols {
@ -2138,9 +2139,7 @@ fn build_specialized_proc_adapter<'a>(
arg_layouts.push(layout); arg_layouts.push(layout);
} }
let ret_layout = layout_cache let ret_layout = layout_cache.from_var(&env.arena, ret_var, env.subs)?;
.from_var(&env.arena, ret_var, env.subs)
.unwrap_or_else(|err| panic!("TODO handle invalid function {:?}", err));
build_specialized_proc( build_specialized_proc(
env.arena, env.arena,