mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 06:44:46 +00:00
refactor
This commit is contained in:
parent
640b4e2d0b
commit
dddfddc835
1 changed files with 68 additions and 89 deletions
|
@ -2006,7 +2006,9 @@ pub fn specialize_all<'a>(
|
||||||
specializations_for_host: HostSpecializations,
|
specializations_for_host: HostSpecializations,
|
||||||
layout_cache: &mut LayoutCache<'a>,
|
layout_cache: &mut LayoutCache<'a>,
|
||||||
) -> Procs<'a> {
|
) -> Procs<'a> {
|
||||||
specialize_externals_others_need(env, &mut procs, externals_others_need, layout_cache);
|
for externals in externals_others_need {
|
||||||
|
specialize_external_specializations(env, &mut procs, layout_cache, externals);
|
||||||
|
}
|
||||||
|
|
||||||
// When calling from_can, pending_specializations should be unavailable.
|
// When calling from_can, pending_specializations should be unavailable.
|
||||||
// This must be a single pass, and we must not add any more entries to it!
|
// This must be a single pass, and we must not add any more entries to it!
|
||||||
|
@ -2042,114 +2044,91 @@ fn specialize_host_specializations<'a>(
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.zip(host_exposed_aliases.into_iter());
|
.zip(host_exposed_aliases.into_iter());
|
||||||
for (store_variable, host_exposed_aliases) in it {
|
for (store_variable, host_exposed_aliases) in it {
|
||||||
let variable = offset_variable(store_variable);
|
barfoo(
|
||||||
|
env,
|
||||||
|
procs,
|
||||||
|
layout_cache,
|
||||||
|
symbol,
|
||||||
|
offset_variable(store_variable),
|
||||||
|
host_exposed_aliases,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn specialize_external_specializations<'a>(
|
||||||
|
env: &mut Env<'a, '_>,
|
||||||
|
procs: &mut Procs<'a>,
|
||||||
|
layout_cache: &mut LayoutCache<'a>,
|
||||||
|
externals_others_need: ExternalSpecializations<'a>,
|
||||||
|
) {
|
||||||
|
let (store, it) = externals_others_need.decompose();
|
||||||
|
|
||||||
|
let offset_variable = StorageSubs::merge_into(store, env.subs);
|
||||||
|
|
||||||
|
for (symbol, solved_types) in it {
|
||||||
|
for store_variable in solved_types {
|
||||||
// historical note: we used to deduplicate with a hash here,
|
// historical note: we used to deduplicate with a hash here,
|
||||||
// but the cost of that hash is very high. So for now we make
|
// but the cost of that hash is very high. So for now we make
|
||||||
// duplicate specializations, and the insertion into a hash map
|
// duplicate specializations, and the insertion into a hash map
|
||||||
// below will deduplicate them.
|
// below will deduplicate them.
|
||||||
|
|
||||||
let name = symbol;
|
barfoo(
|
||||||
|
|
||||||
let partial_proc_id = match procs.partial_procs.symbol_to_id(name) {
|
|
||||||
Some(v) => v,
|
|
||||||
None => {
|
|
||||||
panic!("Cannot find a partial proc for {:?}", name);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO I believe this is also duplicated
|
|
||||||
match specialize_variable(
|
|
||||||
env,
|
env,
|
||||||
procs,
|
procs,
|
||||||
name,
|
|
||||||
layout_cache,
|
layout_cache,
|
||||||
variable,
|
symbol,
|
||||||
host_exposed_aliases,
|
offset_variable(store_variable),
|
||||||
partial_proc_id,
|
MutMap::default(),
|
||||||
) {
|
)
|
||||||
Ok((proc, layout)) => {
|
|
||||||
let top_level = ProcLayout::from_raw(env.arena, layout);
|
|
||||||
|
|
||||||
if procs.is_module_thunk(name) {
|
|
||||||
debug_assert!(top_level.arguments.is_empty());
|
|
||||||
}
|
|
||||||
|
|
||||||
procs.specialized.insert_specialized(name, top_level, proc);
|
|
||||||
}
|
|
||||||
Err(SpecializeFailure {
|
|
||||||
problem: _,
|
|
||||||
attempted_layout,
|
|
||||||
}) => {
|
|
||||||
let proc = generate_runtime_error_function(env, name, attempted_layout);
|
|
||||||
|
|
||||||
let top_level = ProcLayout::from_raw(env.arena, attempted_layout);
|
|
||||||
|
|
||||||
procs.specialized.insert_specialized(name, top_level, proc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn specialize_externals_others_need<'a>(
|
fn barfoo<'a>(
|
||||||
env: &mut Env<'a, '_>,
|
env: &mut Env<'a, '_>,
|
||||||
procs: &mut Procs<'a>,
|
procs: &mut Procs<'a>,
|
||||||
all_externals_others_need: std::vec::Vec<ExternalSpecializations<'a>>,
|
|
||||||
layout_cache: &mut LayoutCache<'a>,
|
layout_cache: &mut LayoutCache<'a>,
|
||||||
|
name: Symbol,
|
||||||
|
variable: Variable,
|
||||||
|
host_exposed_aliases: MutMap<Symbol, SolvedType>,
|
||||||
) {
|
) {
|
||||||
for externals_others_need in all_externals_others_need {
|
let partial_proc_id = match procs.partial_procs.symbol_to_id(name) {
|
||||||
let (store, it) = externals_others_need.decompose();
|
Some(v) => v,
|
||||||
|
None => {
|
||||||
|
panic!("Cannot find a partial proc for {:?}", name);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let offset_variable = StorageSubs::merge_into(store, env.subs);
|
let specialization_result = specialize_variable(
|
||||||
|
env,
|
||||||
|
procs,
|
||||||
|
name,
|
||||||
|
layout_cache,
|
||||||
|
variable,
|
||||||
|
host_exposed_aliases,
|
||||||
|
partial_proc_id,
|
||||||
|
);
|
||||||
|
|
||||||
for (symbol, solved_types) in it {
|
match specialization_result {
|
||||||
for store_variable in solved_types {
|
Ok((proc, layout)) => {
|
||||||
let variable = offset_variable(store_variable);
|
let top_level = ProcLayout::from_raw(env.arena, layout);
|
||||||
// historical note: we used to deduplicate with a hash here,
|
|
||||||
// but the cost of that hash is very high. So for now we make
|
|
||||||
// duplicate specializations, and the insertion into a hash map
|
|
||||||
// below will deduplicate them.
|
|
||||||
|
|
||||||
let name = symbol;
|
if procs.is_module_thunk(name) {
|
||||||
|
debug_assert!(top_level.arguments.is_empty());
|
||||||
let partial_proc_id = match procs.partial_procs.symbol_to_id(name) {
|
|
||||||
Some(v) => v,
|
|
||||||
None => {
|
|
||||||
panic!("Cannot find a partial proc for {:?}", name);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO I believe this is also duplicated
|
|
||||||
match specialize_variable(
|
|
||||||
env,
|
|
||||||
procs,
|
|
||||||
name,
|
|
||||||
layout_cache,
|
|
||||||
variable,
|
|
||||||
MutMap::default(),
|
|
||||||
partial_proc_id,
|
|
||||||
) {
|
|
||||||
Ok((proc, layout)) => {
|
|
||||||
let top_level = ProcLayout::from_raw(env.arena, layout);
|
|
||||||
|
|
||||||
if procs.is_module_thunk(name) {
|
|
||||||
debug_assert!(top_level.arguments.is_empty());
|
|
||||||
}
|
|
||||||
|
|
||||||
procs.specialized.insert_specialized(name, top_level, proc);
|
|
||||||
}
|
|
||||||
Err(SpecializeFailure {
|
|
||||||
problem: _,
|
|
||||||
attempted_layout,
|
|
||||||
}) => {
|
|
||||||
let proc = generate_runtime_error_function(env, name, attempted_layout);
|
|
||||||
|
|
||||||
let top_level = ProcLayout::from_raw(env.arena, attempted_layout);
|
|
||||||
|
|
||||||
procs.specialized.insert_specialized(name, top_level, proc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
procs.specialized.insert_specialized(name, top_level, proc);
|
||||||
|
}
|
||||||
|
Err(SpecializeFailure {
|
||||||
|
problem: _,
|
||||||
|
attempted_layout,
|
||||||
|
}) => {
|
||||||
|
let proc = generate_runtime_error_function(env, name, attempted_layout);
|
||||||
|
|
||||||
|
let top_level = ProcLayout::from_raw(env.arena, attempted_layout);
|
||||||
|
|
||||||
|
procs.specialized.insert_specialized(name, top_level, proc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue