mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +00:00
use bumpmap in partialproc
This commit is contained in:
parent
3290528d70
commit
efc004b19a
2 changed files with 29 additions and 20 deletions
|
@ -842,7 +842,7 @@ struct State<'a> {
|
||||||
/// pending specializations in the same thread.
|
/// pending specializations in the same thread.
|
||||||
pub needs_specialization: MutSet<ModuleId>,
|
pub needs_specialization: MutSet<ModuleId>,
|
||||||
|
|
||||||
pub all_pending_specializations: MutMap<Symbol, MutMap<Layout<'a>, PendingSpecialization>>,
|
pub all_pending_specializations: MutMap<Symbol, MutMap<Layout<'a>, PendingSpecialization<'a>>>,
|
||||||
|
|
||||||
pub specializations_in_flight: u32,
|
pub specializations_in_flight: u32,
|
||||||
|
|
||||||
|
@ -3969,6 +3969,7 @@ fn add_def_to_module<'a>(
|
||||||
procs.insert_exposed(
|
procs.insert_exposed(
|
||||||
symbol,
|
symbol,
|
||||||
layout,
|
layout,
|
||||||
|
mono_env.arena,
|
||||||
mono_env.subs,
|
mono_env.subs,
|
||||||
def.annotation,
|
def.annotation,
|
||||||
annotation,
|
annotation,
|
||||||
|
@ -4021,6 +4022,7 @@ fn add_def_to_module<'a>(
|
||||||
procs.insert_exposed(
|
procs.insert_exposed(
|
||||||
symbol,
|
symbol,
|
||||||
layout,
|
layout,
|
||||||
|
mono_env.arena,
|
||||||
mono_env.subs,
|
mono_env.subs,
|
||||||
def.annotation,
|
def.annotation,
|
||||||
annotation,
|
annotation,
|
||||||
|
|
|
@ -77,31 +77,35 @@ impl<'a> CapturedSymbols<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub struct PendingSpecialization {
|
pub struct PendingSpecialization<'a> {
|
||||||
solved_type: SolvedType,
|
solved_type: SolvedType,
|
||||||
host_exposed_aliases: MutMap<Symbol, SolvedType>,
|
host_exposed_aliases: BumpMap<'a, Symbol, SolvedType>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PendingSpecialization {
|
impl<'a> PendingSpecialization<'a> {
|
||||||
pub fn from_var(subs: &Subs, var: Variable) -> Self {
|
pub fn from_var(arena: &'a Bump, subs: &Subs, var: Variable) -> Self {
|
||||||
let solved_type = SolvedType::from_var(subs, var);
|
let solved_type = SolvedType::from_var(subs, var);
|
||||||
PendingSpecialization {
|
PendingSpecialization {
|
||||||
solved_type,
|
solved_type,
|
||||||
host_exposed_aliases: MutMap::default(),
|
host_exposed_aliases: BumpMap::new_in(arena),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_var_host_exposed(
|
pub fn from_var_host_exposed(
|
||||||
|
arena: &'a Bump,
|
||||||
subs: &Subs,
|
subs: &Subs,
|
||||||
var: Variable,
|
var: Variable,
|
||||||
host_exposed_aliases: &MutMap<Symbol, Variable>,
|
exposed: &MutMap<Symbol, Variable>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let solved_type = SolvedType::from_var(subs, var);
|
let solved_type = SolvedType::from_var(subs, var);
|
||||||
|
|
||||||
let host_exposed_aliases = host_exposed_aliases
|
let mut host_exposed_aliases = BumpMap::with_capacity_in(exposed.len(), arena);
|
||||||
|
|
||||||
|
host_exposed_aliases.extend(
|
||||||
|
exposed
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(symbol, variable)| (*symbol, SolvedType::from_var(subs, *variable)))
|
.map(|(symbol, variable)| (*symbol, SolvedType::from_var(subs, *variable))),
|
||||||
.collect();
|
);
|
||||||
|
|
||||||
PendingSpecialization {
|
PendingSpecialization {
|
||||||
solved_type,
|
solved_type,
|
||||||
|
@ -275,7 +279,8 @@ pub struct Procs<'a> {
|
||||||
pub partial_procs: MutMap<Symbol, PartialProc<'a>>,
|
pub partial_procs: MutMap<Symbol, PartialProc<'a>>,
|
||||||
pub imported_module_thunks: MutSet<Symbol>,
|
pub imported_module_thunks: MutSet<Symbol>,
|
||||||
pub module_thunks: MutSet<Symbol>,
|
pub module_thunks: MutSet<Symbol>,
|
||||||
pub pending_specializations: Option<MutMap<Symbol, MutMap<Layout<'a>, PendingSpecialization>>>,
|
pub pending_specializations:
|
||||||
|
Option<MutMap<Symbol, MutMap<Layout<'a>, PendingSpecialization<'a>>>>,
|
||||||
pub specialized: MutMap<(Symbol, Layout<'a>), InProgressProc<'a>>,
|
pub specialized: MutMap<(Symbol, Layout<'a>), InProgressProc<'a>>,
|
||||||
pub call_by_pointer_wrappers: MutMap<Symbol, Symbol>,
|
pub call_by_pointer_wrappers: MutMap<Symbol, Symbol>,
|
||||||
pub runtime_errors: MutMap<Symbol, &'a str>,
|
pub runtime_errors: MutMap<Symbol, &'a str>,
|
||||||
|
@ -502,7 +507,7 @@ impl<'a> Procs<'a> {
|
||||||
// Changing it to use .entry() would necessarily make it incorrect.
|
// Changing it to use .entry() would necessarily make it incorrect.
|
||||||
#[allow(clippy::map_entry)]
|
#[allow(clippy::map_entry)]
|
||||||
if !already_specialized {
|
if !already_specialized {
|
||||||
let pending = PendingSpecialization::from_var(env.subs, annotation);
|
let pending = PendingSpecialization::from_var(env.arena, env.subs, annotation);
|
||||||
|
|
||||||
let partial_proc;
|
let partial_proc;
|
||||||
if let Some(existing) = self.partial_procs.get(&symbol) {
|
if let Some(existing) = self.partial_procs.get(&symbol) {
|
||||||
|
@ -576,6 +581,7 @@ impl<'a> Procs<'a> {
|
||||||
&mut self,
|
&mut self,
|
||||||
name: Symbol,
|
name: Symbol,
|
||||||
layout: Layout<'a>,
|
layout: Layout<'a>,
|
||||||
|
arena: &'a Bump,
|
||||||
subs: &Subs,
|
subs: &Subs,
|
||||||
opt_annotation: Option<roc_can::def::Annotation>,
|
opt_annotation: Option<roc_can::def::Annotation>,
|
||||||
fn_var: Variable,
|
fn_var: Variable,
|
||||||
|
@ -590,8 +596,9 @@ impl<'a> Procs<'a> {
|
||||||
// We're done with that tuple, so move layout back out to avoid cloning it.
|
// We're done with that tuple, so move layout back out to avoid cloning it.
|
||||||
let (name, layout) = tuple;
|
let (name, layout) = tuple;
|
||||||
let pending = match opt_annotation {
|
let pending = match opt_annotation {
|
||||||
None => PendingSpecialization::from_var(subs, fn_var),
|
None => PendingSpecialization::from_var(arena, subs, fn_var),
|
||||||
Some(annotation) => PendingSpecialization::from_var_host_exposed(
|
Some(annotation) => PendingSpecialization::from_var_host_exposed(
|
||||||
|
arena,
|
||||||
subs,
|
subs,
|
||||||
fn_var,
|
fn_var,
|
||||||
&annotation.introduced_variables.host_exposed_aliases,
|
&annotation.introduced_variables.host_exposed_aliases,
|
||||||
|
@ -634,7 +641,7 @@ impl<'a> Procs<'a> {
|
||||||
// We're done with that tuple, so move layout back out to avoid cloning it.
|
// We're done with that tuple, so move layout back out to avoid cloning it.
|
||||||
let (name, layout) = tuple;
|
let (name, layout) = tuple;
|
||||||
|
|
||||||
let pending = PendingSpecialization::from_var(env.subs, fn_var);
|
let pending = PendingSpecialization::from_var(env.arena, env.subs, fn_var);
|
||||||
|
|
||||||
// This should only be called when pending_specializations is Some.
|
// This should only be called when pending_specializations is Some.
|
||||||
// Otherwise, it's being called in the wrong pass!
|
// Otherwise, it's being called in the wrong pass!
|
||||||
|
@ -674,10 +681,10 @@ impl<'a> Procs<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_pending<'a>(
|
fn add_pending<'a>(
|
||||||
pending_specializations: &mut MutMap<Symbol, MutMap<Layout<'a>, PendingSpecialization>>,
|
pending_specializations: &mut MutMap<Symbol, MutMap<Layout<'a>, PendingSpecialization<'a>>>,
|
||||||
symbol: Symbol,
|
symbol: Symbol,
|
||||||
layout: Layout<'a>,
|
layout: Layout<'a>,
|
||||||
pending: PendingSpecialization,
|
pending: PendingSpecialization<'a>,
|
||||||
) {
|
) {
|
||||||
let all_pending = pending_specializations
|
let all_pending = pending_specializations
|
||||||
.entry(symbol)
|
.entry(symbol)
|
||||||
|
@ -1662,7 +1669,7 @@ pub fn specialize_all<'a>(
|
||||||
name,
|
name,
|
||||||
layout_cache,
|
layout_cache,
|
||||||
solved_type,
|
solved_type,
|
||||||
MutMap::default(),
|
BumpMap::new_in(env.arena),
|
||||||
partial_proc,
|
partial_proc,
|
||||||
) {
|
) {
|
||||||
Ok((proc, layout)) => {
|
Ok((proc, layout)) => {
|
||||||
|
@ -2335,7 +2342,7 @@ fn specialize_solved_type<'a>(
|
||||||
proc_name: Symbol,
|
proc_name: Symbol,
|
||||||
layout_cache: &mut LayoutCache<'a>,
|
layout_cache: &mut LayoutCache<'a>,
|
||||||
solved_type: SolvedType,
|
solved_type: SolvedType,
|
||||||
host_exposed_aliases: MutMap<Symbol, SolvedType>,
|
host_exposed_aliases: BumpMap<Symbol, SolvedType>,
|
||||||
partial_proc: PartialProc<'a>,
|
partial_proc: PartialProc<'a>,
|
||||||
) -> Result<(Proc<'a>, Layout<'a>), SpecializeFailure<'a>> {
|
) -> Result<(Proc<'a>, Layout<'a>), SpecializeFailure<'a>> {
|
||||||
// add the specializations that other modules require of us
|
// add the specializations that other modules require of us
|
||||||
|
@ -6089,7 +6096,7 @@ fn call_by_name<'a>(
|
||||||
let iter = loc_args.into_iter().rev().zip(field_symbols.iter().rev());
|
let iter = loc_args.into_iter().rev().zip(field_symbols.iter().rev());
|
||||||
assign_to_symbols(env, procs, layout_cache, iter, result)
|
assign_to_symbols(env, procs, layout_cache, iter, result)
|
||||||
} else {
|
} else {
|
||||||
let pending = PendingSpecialization::from_var(env.subs, fn_var);
|
let pending = PendingSpecialization::from_var(env.arena, env.subs, fn_var);
|
||||||
|
|
||||||
// When requested (that is, when procs.pending_specializations is `Some`),
|
// When requested (that is, when procs.pending_specializations is `Some`),
|
||||||
// store a pending specialization rather than specializing immediately.
|
// store a pending specialization rather than specializing immediately.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue