specializations requested in file.rs are specializations for the host

This commit is contained in:
Folkert 2021-10-29 21:27:26 +02:00
parent eda904e63e
commit 05b5cd3429

View file

@ -2067,7 +2067,7 @@ fn update<'a>(
log!("found specializations for {:?}", module_id); log!("found specializations for {:?}", module_id);
let subs = solved_subs.into_inner(); let subs = solved_subs.into_inner();
for (symbol, specs) in &procs_base.pending_specializations { for (symbol, specs) in &procs_base.specializations_for_host {
let existing = match state.all_pending_specializations.entry(*symbol) { let existing = match state.all_pending_specializations.entry(*symbol) {
Vacant(entry) => entry.insert(MutMap::default()), Vacant(entry) => entry.insert(MutMap::default()),
Occupied(entry) => entry.into_mut(), Occupied(entry) => entry.into_mut(),
@ -3970,13 +3970,16 @@ fn make_specializations<'a>(
&mut mono_env, &mut mono_env,
procs, procs,
specializations_we_must_make, specializations_we_must_make,
procs_base.pending_specializations, procs_base.specializations_for_host,
&mut layout_cache, &mut layout_cache,
); );
let external_specializations_requested = procs.externals_we_need.clone(); let external_specializations_requested = procs.externals_we_need.clone();
let procedures = procs.get_specialized_procs_without_rc(&mut mono_env); let procedures = procs.get_specialized_procs_without_rc(&mut mono_env);
// Turn `Bytes.Decode.IdentId(238)` into `Bytes.Decode.238`, we rely on this in mono tests
mono_env.home.register_debug_idents(mono_env.ident_ids);
let make_specializations_end = SystemTime::now(); let make_specializations_end = SystemTime::now();
module_timing.make_specializations = make_specializations_end module_timing.make_specializations = make_specializations_end
.duration_since(make_specializations_start) .duration_since(make_specializations_start)
@ -3998,20 +4001,21 @@ fn make_specializations<'a>(
struct ProcsBase<'a> { struct ProcsBase<'a> {
partial_procs: BumpMap<Symbol, PartialProc<'a>>, partial_procs: BumpMap<Symbol, PartialProc<'a>>,
module_thunks: &'a [Symbol], module_thunks: &'a [Symbol],
pending_specializations: BumpMap<Symbol, MutMap<ProcLayout<'a>, PendingSpecialization<'a>>>, /// A host-exposed function must be specialized; it's a seed for subsequent specializations
specializations_for_host: BumpMap<Symbol, MutMap<ProcLayout<'a>, PendingSpecialization<'a>>>,
runtime_errors: BumpMap<Symbol, &'a str>, runtime_errors: BumpMap<Symbol, &'a str>,
imported_module_thunks: &'a [Symbol], imported_module_thunks: &'a [Symbol],
} }
impl<'a> ProcsBase<'a> { impl<'a> ProcsBase<'a> {
fn add_pending( fn add_specialization_for_host(
&mut self, &mut self,
symbol: Symbol, symbol: Symbol,
layout: ProcLayout<'a>, layout: ProcLayout<'a>,
pending: PendingSpecialization<'a>, pending: PendingSpecialization<'a>,
) { ) {
let all_pending = self let all_pending = self
.pending_specializations .specializations_for_host
.entry(symbol) .entry(symbol)
.or_insert_with(|| HashMap::with_capacity_and_hasher(1, default_hasher())); .or_insert_with(|| HashMap::with_capacity_and_hasher(1, default_hasher()));
@ -4040,7 +4044,7 @@ fn build_pending_specializations<'a>(
let mut procs_base = ProcsBase { let mut procs_base = ProcsBase {
partial_procs: BumpMap::default(), partial_procs: BumpMap::default(),
module_thunks: &[], module_thunks: &[],
pending_specializations: BumpMap::default(), specializations_for_host: BumpMap::default(),
runtime_errors: BumpMap::default(), runtime_errors: BumpMap::default(),
imported_module_thunks, imported_module_thunks,
}; };
@ -4146,15 +4150,6 @@ fn add_def_to_module<'a>(
// never gets called by Roc code, it will never // never gets called by Roc code, it will never
// get specialized! // get specialized!
if is_exposed { if is_exposed {
let mut pattern_vars = bumpalo::collections::Vec::with_capacity_in(
loc_args.len(),
mono_env.arena,
);
for (var, _) in loc_args.iter() {
pattern_vars.push(*var);
}
let layout = match layout_cache.raw_from_var( let layout = match layout_cache.raw_from_var(
mono_env.arena, mono_env.arena,
annotation, annotation,
@ -4185,7 +4180,7 @@ fn add_def_to_module<'a>(
annotation, annotation,
); );
procs.add_pending( procs.add_specialization_for_host(
symbol, symbol,
ProcLayout::from_raw(mono_env.arena, layout), ProcLayout::from_raw(mono_env.arena, layout),
pending, pending,
@ -4249,7 +4244,7 @@ fn add_def_to_module<'a>(
annotation, annotation,
); );
procs.add_pending(symbol, top_level, pending); procs.add_specialization_for_host(symbol, top_level, pending);
} }
let proc = PartialProc { let proc = PartialProc {