Merge remote-tracking branch 'origin/main' into packages

This commit is contained in:
Richard Feldman 2022-12-17 03:32:52 -05:00
commit 3e448fd2b4
No known key found for this signature in database
GPG key ID: F1F21AA5B1D9E43B
61 changed files with 1506 additions and 538 deletions

View file

@ -140,7 +140,6 @@ struct ModuleCache<'a> {
found_specializations: MutMap<ModuleId, FoundSpecializationsModule<'a>>,
late_specializations: MutMap<ModuleId, LateSpecializationsModule<'a>>,
external_specializations_requested: MutMap<ModuleId, Vec<ExternalSpecializations<'a>>>,
expectations: VecMap<ModuleId, Expectations>,
/// Various information
imports: MutMap<ModuleId, MutSet<ModuleId>>,
@ -217,7 +216,6 @@ impl Default for ModuleCache<'_> {
can_problems: Default::default(),
type_problems: Default::default(),
sources: Default::default(),
expectations: Default::default(),
}
}
}
@ -437,6 +435,7 @@ fn start_phase<'a>(
decls,
ident_ids,
abilities_store,
expectations,
} = typechecked;
let mut imported_module_thunks = bumpalo::collections::Vec::new_in(arena);
@ -453,8 +452,8 @@ fn start_phase<'a>(
let derived_module = SharedDerivedModule::clone(&state.derived_module);
let build_expects = matches!(state.exec_mode, ExecutionMode::Test)
&& state.module_cache.expectations.contains_key(&module_id);
let build_expects =
matches!(state.exec_mode, ExecutionMode::Test) && expectations.is_some();
BuildTask::BuildPendingSpecializations {
layout_cache,
@ -469,6 +468,7 @@ fn start_phase<'a>(
// TODO: awful, how can we get rid of the clone?
exposed_by_module: state.exposed_types.clone(),
derived_module,
expectations,
build_expects,
}
}
@ -490,67 +490,90 @@ fn start_phase<'a>(
specializations_we_must_make.extend(derived_synth_specializations)
}
let (mut ident_ids, mut subs, mut procs_base, layout_cache, mut module_timing) =
if state.make_specializations_pass.current_pass() == 1
&& module_id == ModuleId::DERIVED_GEN
{
// This is the first time the derived module is introduced into the load
// graph. It has no abilities of its own or anything, just generate fresh
// information for it.
(
IdentIds::default(),
Subs::default(),
ProcsBase::default(),
LayoutCache::new(state.layout_interner.fork(), state.target_info),
ModuleTiming::new(Instant::now()),
)
} else if state.make_specializations_pass.current_pass() == 1 {
let found_specializations = state
.module_cache
.found_specializations
.remove(&module_id)
.unwrap();
let (
mut ident_ids,
mut subs,
expectations,
mut procs_base,
layout_cache,
mut module_timing,
) = if state.make_specializations_pass.current_pass() == 1
&& module_id == ModuleId::DERIVED_GEN
{
// This is the first time the derived module is introduced into the load
// graph. It has no abilities of its own or anything, just generate fresh
// information for it.
(
IdentIds::default(),
Subs::default(),
None, // no expectations for derived module
ProcsBase::default(),
LayoutCache::new(state.layout_interner.fork(), state.target_info),
ModuleTiming::new(Instant::now()),
)
} else if state.make_specializations_pass.current_pass() == 1 {
let found_specializations = state
.module_cache
.found_specializations
.remove(&module_id)
.unwrap();
let FoundSpecializationsModule {
ident_ids,
subs,
procs_base,
layout_cache,
module_timing,
abilities_store,
} = found_specializations;
let FoundSpecializationsModule {
ident_ids,
subs,
procs_base,
layout_cache,
module_timing,
abilities_store,
expectations,
} = found_specializations;
let our_exposed_types = state
.exposed_types
.get(&module_id)
.unwrap_or_else(|| {
internal_error!("Exposed types for {:?} missing", module_id)
})
.clone();
let our_exposed_types = state
.exposed_types
.get(&module_id)
.unwrap_or_else(|| {
internal_error!("Exposed types for {:?} missing", module_id)
})
.clone();
// Add our abilities to the world.
state.world_abilities.insert(
module_id,
abilities_store,
our_exposed_types.exposed_types_storage_subs,
);
// Add our abilities to the world.
state.world_abilities.insert(
module_id,
abilities_store,
our_exposed_types.exposed_types_storage_subs,
);
(ident_ids, subs, procs_base, layout_cache, module_timing)
} else {
let LateSpecializationsModule {
ident_ids,
subs,
module_timing,
layout_cache,
procs_base,
} = state
.module_cache
.late_specializations
.remove(&module_id)
.unwrap();
(
ident_ids,
subs,
expectations,
procs_base,
layout_cache,
module_timing,
)
} else {
let LateSpecializationsModule {
ident_ids,
subs,
expectations,
module_timing,
layout_cache,
procs_base,
} = state
.module_cache
.late_specializations
.remove(&module_id)
.unwrap();
(ident_ids, subs, procs_base, layout_cache, module_timing)
};
(
ident_ids,
subs,
expectations,
procs_base,
layout_cache,
module_timing,
)
};
if module_id == ModuleId::DERIVED_GEN {
load_derived_partial_procs(
@ -581,6 +604,7 @@ fn start_phase<'a>(
// TODO: awful, how can we get rid of the clone?
exposed_by_module: state.exposed_types.clone(),
derived_module,
expectations,
}
}
}
@ -681,6 +705,7 @@ pub struct TypeCheckedModule<'a> {
pub decls: Declarations,
pub ident_ids: IdentIds,
pub abilities_store: AbilitiesStore,
pub expectations: Option<Expectations>,
}
#[derive(Debug)]
@ -691,6 +716,7 @@ struct FoundSpecializationsModule<'a> {
subs: Subs,
module_timing: ModuleTiming,
abilities_store: AbilitiesStore,
expectations: Option<Expectations>,
}
#[derive(Debug)]
@ -700,6 +726,7 @@ struct LateSpecializationsModule<'a> {
module_timing: ModuleTiming,
layout_cache: LayoutCache<'a>,
procs_base: ProcsBase<'a>,
expectations: Option<Expectations>,
}
#[derive(Debug, Default)]
@ -833,6 +860,7 @@ enum Msg<'a> {
module_timing: ModuleTiming,
abilities_store: AbilitiesStore,
toplevel_expects: ToplevelExpects,
expectations: Option<Expectations>,
},
MadeSpecializations {
module_id: ModuleId,
@ -844,6 +872,7 @@ enum Msg<'a> {
update_mode_ids: UpdateModeIds,
module_timing: ModuleTiming,
subs: Subs,
expectations: Option<Expectations>,
},
/// The task is to only typecheck AND monomorphize modules
@ -854,6 +883,7 @@ enum Msg<'a> {
/// DO NOT use the one on state; that is left in an empty state after specialization is complete!
layout_interner: STLayoutInterner<'a>,
exposed_to_host: ExposedToHost,
module_expectations: VecMap<ModuleId, Expectations>,
},
FailedToParse(FileError<'a, SyntaxError<'a>>),
@ -1150,6 +1180,7 @@ enum BuildTask<'a> {
exposed_by_module: ExposedByModule,
abilities_store: AbilitiesStore,
derived_module: SharedDerivedModule,
expectations: Option<Expectations>,
build_expects: bool,
},
MakeSpecializations {
@ -1163,6 +1194,7 @@ enum BuildTask<'a> {
exposed_by_module: ExposedByModule,
world_abilities: WorldAbilities,
derived_module: SharedDerivedModule,
expectations: Option<Expectations>,
},
}
@ -1671,6 +1703,7 @@ fn state_thread_step<'a>(
subs,
layout_interner,
exposed_to_host,
module_expectations,
} => {
// We're done! There should be no more messages pending.
debug_assert!(msg_rx.is_empty());
@ -1681,6 +1714,7 @@ fn state_thread_step<'a>(
subs,
layout_interner,
exposed_to_host,
module_expectations,
)?;
Ok(ControlFlow::Break(LoadResult::Monomorphized(monomorphized)))
@ -2636,22 +2670,19 @@ fn update<'a>(
.expect("root or this module is not yet known - that's a bug!")
};
if should_include_expects {
let opt_expectations = if should_include_expects {
let (path, _) = state.module_cache.sources.get(&module_id).unwrap();
let expectations = Expectations {
Some(Expectations {
expectations: loc_expects,
dbgs: loc_dbgs,
subs: solved_subs.clone().into_inner(),
path: path.to_owned(),
ident_ids: ident_ids.clone(),
};
state
.module_cache
.expectations
.insert(module_id, expectations);
}
})
} else {
None
};
let work = state.dependencies.notify(module_id, Phase::SolveTypes);
@ -2764,6 +2795,7 @@ fn update<'a>(
decls,
ident_ids,
abilities_store,
expectations: opt_expectations,
};
state
@ -2803,6 +2835,7 @@ fn update<'a>(
module_timing,
abilities_store,
toplevel_expects,
expectations,
} => {
log!("found specializations for {:?}", module_id);
@ -2825,6 +2858,7 @@ fn update<'a>(
subs,
module_timing,
abilities_store,
expectations,
};
state
@ -2850,6 +2884,7 @@ fn update<'a>(
external_specializations_requested,
module_timing,
layout_cache,
expectations,
..
} => {
debug_assert!(
@ -2871,6 +2906,7 @@ fn update<'a>(
subs,
layout_cache,
procs_base,
expectations,
},
);
@ -2928,6 +2964,9 @@ fn update<'a>(
);
}
let mut module_expectations =
VecMap::with_capacity(state.module_cache.module_names.len());
// Flush late-specialization module information to the top-level of the state
// where it will be visible to others, since we don't need late specialization
// anymore.
@ -2939,6 +2978,7 @@ fn update<'a>(
module_timing,
layout_cache: _layout_cache,
procs_base: _,
expectations,
},
) in state.module_cache.late_specializations.drain()
{
@ -2947,6 +2987,9 @@ fn update<'a>(
state.root_subs = Some(subs);
}
state.timings.insert(module_id, module_timing);
if let Some(expectations) = expectations {
module_expectations.insert(module_id, expectations);
}
#[cfg(debug_assertions)]
{
@ -3009,6 +3052,7 @@ fn update<'a>(
subs,
layout_interner,
exposed_to_host: state.exposed_to_host.clone(),
module_expectations,
})
.map_err(|_| LoadingProblem::MsgChannelDied)?;
@ -3146,6 +3190,7 @@ fn finish_specialization<'a>(
subs: Subs,
layout_interner: STLayoutInterner<'a>,
exposed_to_host: ExposedToHost,
module_expectations: VecMap<ModuleId, Expectations>,
) -> Result<MonomorphizedModule<'a>, LoadingProblem<'a>> {
if false {
println!(
@ -3186,7 +3231,6 @@ fn finish_specialization<'a>(
} = state;
let ModuleCache {
expectations,
type_problems,
can_problems,
sources,
@ -3277,7 +3321,7 @@ fn finish_specialization<'a>(
can_problems,
type_problems,
output_path,
expectations,
expectations: module_expectations,
exposed_to_host,
module_id: state.root_id,
subs,
@ -5395,6 +5439,7 @@ fn make_specializations<'a>(
world_abilities: WorldAbilities,
exposed_by_module: &ExposedByModule,
derived_module: SharedDerivedModule,
mut expectations: Option<Expectations>,
) -> Msg<'a> {
let make_specializations_start = Instant::now();
let mut update_mode_ids = UpdateModeIds::new();
@ -5402,6 +5447,7 @@ fn make_specializations<'a>(
let mut mono_env = roc_mono::ir::Env {
arena,
subs: &mut subs,
expectation_subs: expectations.as_mut().map(|e| &mut e.subs),
home,
ident_ids: &mut ident_ids,
target_info,
@ -5453,6 +5499,7 @@ fn make_specializations<'a>(
procedures,
update_mode_ids,
subs,
expectations,
external_specializations_requested,
module_timing,
}
@ -5472,6 +5519,7 @@ fn build_pending_specializations<'a>(
exposed_by_module: &ExposedByModule,
abilities_store: AbilitiesStore,
derived_module: SharedDerivedModule,
mut expectations: Option<Expectations>,
build_expects: bool,
) -> Msg<'a> {
let find_specializations_start = Instant::now();
@ -5492,6 +5540,7 @@ fn build_pending_specializations<'a>(
let mut mono_env = roc_mono::ir::Env {
arena,
subs: &mut subs,
expectation_subs: expectations.as_mut().map(|e| &mut e.subs),
home,
ident_ids: &mut ident_ids,
target_info,
@ -5881,6 +5930,7 @@ fn build_pending_specializations<'a>(
module_timing,
abilities_store,
toplevel_expects,
expectations,
}
}
@ -5922,6 +5972,8 @@ fn load_derived_partial_procs<'a>(
let mut mono_env = roc_mono::ir::Env {
arena,
subs,
// There are no derived expectations.
expectation_subs: None,
home,
ident_ids,
target_info,
@ -6081,6 +6133,7 @@ fn run_task<'a>(
abilities_store,
exposed_by_module,
derived_module,
expectations,
build_expects,
} => Ok(build_pending_specializations(
arena,
@ -6096,6 +6149,7 @@ fn run_task<'a>(
&exposed_by_module,
abilities_store,
derived_module,
expectations,
build_expects,
)),
MakeSpecializations {
@ -6109,6 +6163,7 @@ fn run_task<'a>(
world_abilities,
exposed_by_module,
derived_module,
expectations,
} => Ok(make_specializations(
arena,
module_id,
@ -6122,6 +6177,7 @@ fn run_task<'a>(
world_abilities,
&exposed_by_module,
derived_module,
expectations,
)),
}?;