mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 00:24:34 +00:00
bump set
This commit is contained in:
parent
503d011c43
commit
a2f144f4db
3 changed files with 42 additions and 21 deletions
|
@ -29,6 +29,7 @@ pub type SendMap<K, V> = im::hashmap::HashMap<K, V, BuildHasher>;
|
||||||
pub type SendSet<K> = im::hashset::HashSet<K, BuildHasher>;
|
pub type SendSet<K> = im::hashset::HashSet<K, BuildHasher>;
|
||||||
|
|
||||||
pub type BumpMap<'a, K, V> = hashbrown::HashMap<K, V, BuildHasher, hashbrown::BumpWrapper<'a>>;
|
pub type BumpMap<'a, K, V> = hashbrown::HashMap<K, V, BuildHasher, hashbrown::BumpWrapper<'a>>;
|
||||||
|
pub type BumpSet<'a, K> = hashbrown::HashSet<K, BuildHasher, hashbrown::BumpWrapper<'a>>;
|
||||||
|
|
||||||
pub trait BumpMapDefault<'a> {
|
pub trait BumpMapDefault<'a> {
|
||||||
fn new_in(arena: &'a bumpalo::Bump) -> Self;
|
fn new_in(arena: &'a bumpalo::Bump) -> Self;
|
||||||
|
@ -50,6 +51,20 @@ impl<'a, K, V> BumpMapDefault<'a> for BumpMap<'a, K, V> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a, K> BumpMapDefault<'a> for BumpSet<'a, K> {
|
||||||
|
fn new_in(arena: &'a bumpalo::Bump) -> Self {
|
||||||
|
hashbrown::HashSet::with_hasher_in(default_hasher(), hashbrown::BumpWrapper(arena))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn with_capacity_in(capacity: usize, arena: &'a bumpalo::Bump) -> Self {
|
||||||
|
hashbrown::HashSet::with_capacity_and_hasher_in(
|
||||||
|
capacity,
|
||||||
|
default_hasher(),
|
||||||
|
hashbrown::BumpWrapper(arena),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn arena_join<'a, I>(arena: &'a Bump, strings: &mut I, join_str: &str) -> String<'a>
|
pub fn arena_join<'a, I>(arena: &'a Bump, strings: &mut I, join_str: &str) -> String<'a>
|
||||||
where
|
where
|
||||||
I: Iterator<Item = &'a str>,
|
I: Iterator<Item = &'a str>,
|
||||||
|
|
|
@ -8,7 +8,7 @@ use roc_builtins::std::StdLib;
|
||||||
use roc_can::constraint::Constraint;
|
use roc_can::constraint::Constraint;
|
||||||
use roc_can::def::{Declaration, Def};
|
use roc_can::def::{Declaration, Def};
|
||||||
use roc_can::module::{canonicalize_module_defs, Module};
|
use roc_can::module::{canonicalize_module_defs, Module};
|
||||||
use roc_collections::all::{default_hasher, BumpMap, MutMap, MutSet};
|
use roc_collections::all::{default_hasher, BumpMap, BumpMapDefault, BumpSet, MutMap, MutSet};
|
||||||
use roc_constrain::module::{
|
use roc_constrain::module::{
|
||||||
constrain_imports, pre_constrain_imports, ConstrainableImports, Import,
|
constrain_imports, pre_constrain_imports, ConstrainableImports, Import,
|
||||||
};
|
};
|
||||||
|
@ -369,7 +369,12 @@ struct ModuleCache<'a> {
|
||||||
header_sources: MutMap<ModuleId, (PathBuf, &'a str)>,
|
header_sources: MutMap<ModuleId, (PathBuf, &'a str)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_phase<'a>(module_id: ModuleId, phase: Phase, state: &mut State<'a>) -> Vec<BuildTask<'a>> {
|
fn start_phase<'a>(
|
||||||
|
module_id: ModuleId,
|
||||||
|
phase: Phase,
|
||||||
|
arena: &'a Bump,
|
||||||
|
state: &mut State<'a>,
|
||||||
|
) -> Vec<BuildTask<'a>> {
|
||||||
// we blindly assume all dependencies are met
|
// we blindly assume all dependencies are met
|
||||||
|
|
||||||
match state
|
match state
|
||||||
|
@ -391,7 +396,7 @@ fn start_phase<'a>(module_id: ModuleId, phase: Phase, state: &mut State<'a>) ->
|
||||||
.dependencies
|
.dependencies
|
||||||
.notify(module_id, phase)
|
.notify(module_id, phase)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(module_id, phase)| start_phase(module_id, phase, state))
|
.map(|(module_id, phase)| start_phase(module_id, phase, arena, state))
|
||||||
.flatten()
|
.flatten()
|
||||||
.collect();
|
.collect();
|
||||||
}
|
}
|
||||||
|
@ -545,7 +550,7 @@ fn start_phase<'a>(module_id: ModuleId, phase: Phase, state: &mut State<'a>) ->
|
||||||
ident_ids,
|
ident_ids,
|
||||||
} = typechecked;
|
} = typechecked;
|
||||||
|
|
||||||
let mut imported_module_thunks = MutSet::default();
|
let mut imported_module_thunks = BumpSet::new_in(arena);
|
||||||
|
|
||||||
if let Some(imports) = state.module_cache.imports.get(&module_id) {
|
if let Some(imports) = state.module_cache.imports.get(&module_id) {
|
||||||
for imported in imports.iter() {
|
for imported in imports.iter() {
|
||||||
|
@ -971,7 +976,7 @@ enum BuildTask<'a> {
|
||||||
module_timing: ModuleTiming,
|
module_timing: ModuleTiming,
|
||||||
layout_cache: LayoutCache<'a>,
|
layout_cache: LayoutCache<'a>,
|
||||||
solved_subs: Solved<Subs>,
|
solved_subs: Solved<Subs>,
|
||||||
imported_module_thunks: MutSet<Symbol>,
|
imported_module_thunks: BumpSet<'a, Symbol>,
|
||||||
module_id: ModuleId,
|
module_id: ModuleId,
|
||||||
ident_ids: IdentIds,
|
ident_ids: IdentIds,
|
||||||
decls: Vec<Declaration>,
|
decls: Vec<Declaration>,
|
||||||
|
@ -1603,13 +1608,14 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_tasks<'a>(
|
fn start_tasks<'a>(
|
||||||
work: MutSet<(ModuleId, Phase)>,
|
arena: &'a Bump,
|
||||||
state: &mut State<'a>,
|
state: &mut State<'a>,
|
||||||
|
work: MutSet<(ModuleId, Phase)>,
|
||||||
injector: &Injector<BuildTask<'a>>,
|
injector: &Injector<BuildTask<'a>>,
|
||||||
worker_listeners: &'a [Sender<WorkerMsg>],
|
worker_listeners: &'a [Sender<WorkerMsg>],
|
||||||
) -> Result<(), LoadingProblem<'a>> {
|
) -> Result<(), LoadingProblem<'a>> {
|
||||||
for (module_id, phase) in work {
|
for (module_id, phase) in work {
|
||||||
for task in start_phase(module_id, phase, state) {
|
for task in start_phase(module_id, phase, arena, state) {
|
||||||
enqueue_task(&injector, worker_listeners, task)?
|
enqueue_task(&injector, worker_listeners, task)?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1731,11 +1737,11 @@ fn update<'a>(
|
||||||
|
|
||||||
state.module_cache.headers.insert(header.module_id, header);
|
state.module_cache.headers.insert(header.module_id, header);
|
||||||
|
|
||||||
start_tasks(work, &mut state, &injector, worker_listeners)?;
|
start_tasks(arena, &mut state, work, &injector, worker_listeners)?;
|
||||||
|
|
||||||
let work = state.dependencies.notify(home, Phase::LoadHeader);
|
let work = state.dependencies.notify(home, Phase::LoadHeader);
|
||||||
|
|
||||||
start_tasks(work, &mut state, &injector, worker_listeners)?;
|
start_tasks(arena, &mut state, work, &injector, worker_listeners)?;
|
||||||
|
|
||||||
Ok(state)
|
Ok(state)
|
||||||
}
|
}
|
||||||
|
@ -1768,7 +1774,7 @@ fn update<'a>(
|
||||||
|
|
||||||
let work = state.dependencies.notify(module_id, Phase::Parse);
|
let work = state.dependencies.notify(module_id, Phase::Parse);
|
||||||
|
|
||||||
start_tasks(work, &mut state, &injector, worker_listeners)?;
|
start_tasks(arena, &mut state, work, &injector, worker_listeners)?;
|
||||||
|
|
||||||
Ok(state)
|
Ok(state)
|
||||||
}
|
}
|
||||||
|
@ -1803,7 +1809,7 @@ fn update<'a>(
|
||||||
.dependencies
|
.dependencies
|
||||||
.notify(module_id, Phase::CanonicalizeAndConstrain);
|
.notify(module_id, Phase::CanonicalizeAndConstrain);
|
||||||
|
|
||||||
start_tasks(work, &mut state, &injector, worker_listeners)?;
|
start_tasks(arena, &mut state, work, &injector, worker_listeners)?;
|
||||||
|
|
||||||
Ok(state)
|
Ok(state)
|
||||||
}
|
}
|
||||||
|
@ -1854,7 +1860,7 @@ fn update<'a>(
|
||||||
.notify(module_id, Phase::CanonicalizeAndConstrain),
|
.notify(module_id, Phase::CanonicalizeAndConstrain),
|
||||||
);
|
);
|
||||||
|
|
||||||
start_tasks(work, &mut state, &injector, worker_listeners)?;
|
start_tasks(arena, &mut state, work, &injector, worker_listeners)?;
|
||||||
|
|
||||||
Ok(state)
|
Ok(state)
|
||||||
}
|
}
|
||||||
|
@ -1956,7 +1962,7 @@ fn update<'a>(
|
||||||
state.constrained_ident_ids.insert(module_id, ident_ids);
|
state.constrained_ident_ids.insert(module_id, ident_ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
start_tasks(work, &mut state, &injector, worker_listeners)?;
|
start_tasks(arena, &mut state, work, &injector, worker_listeners)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(state)
|
Ok(state)
|
||||||
|
@ -2011,7 +2017,7 @@ fn update<'a>(
|
||||||
.dependencies
|
.dependencies
|
||||||
.notify(module_id, Phase::FindSpecializations);
|
.notify(module_id, Phase::FindSpecializations);
|
||||||
|
|
||||||
start_tasks(work, &mut state, &injector, worker_listeners)?;
|
start_tasks(arena, &mut state, work, &injector, worker_listeners)?;
|
||||||
|
|
||||||
Ok(state)
|
Ok(state)
|
||||||
}
|
}
|
||||||
|
@ -2104,7 +2110,7 @@ fn update<'a>(
|
||||||
existing.extend(requested);
|
existing.extend(requested);
|
||||||
}
|
}
|
||||||
|
|
||||||
start_tasks(work, &mut state, &injector, worker_listeners)?;
|
start_tasks(arena, &mut state, work, &injector, worker_listeners)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(state)
|
Ok(state)
|
||||||
|
@ -3825,7 +3831,7 @@ fn make_specializations<'a>(
|
||||||
fn build_pending_specializations<'a>(
|
fn build_pending_specializations<'a>(
|
||||||
arena: &'a Bump,
|
arena: &'a Bump,
|
||||||
solved_subs: Solved<Subs>,
|
solved_subs: Solved<Subs>,
|
||||||
imported_module_thunks: MutSet<Symbol>,
|
imported_module_thunks: BumpSet<'a, Symbol>,
|
||||||
home: ModuleId,
|
home: ModuleId,
|
||||||
mut ident_ids: IdentIds,
|
mut ident_ids: IdentIds,
|
||||||
decls: Vec<Declaration>,
|
decls: Vec<Declaration>,
|
||||||
|
|
|
@ -6,7 +6,7 @@ use crate::layout::{
|
||||||
};
|
};
|
||||||
use bumpalo::collections::Vec;
|
use bumpalo::collections::Vec;
|
||||||
use bumpalo::Bump;
|
use bumpalo::Bump;
|
||||||
use roc_collections::all::{default_hasher, BumpMap, BumpMapDefault, MutMap, MutSet};
|
use roc_collections::all::{default_hasher, BumpMap, BumpMapDefault, BumpSet, MutMap, MutSet};
|
||||||
use roc_module::ident::{ForeignSymbol, Lowercase, TagName};
|
use roc_module::ident::{ForeignSymbol, Lowercase, TagName};
|
||||||
use roc_module::low_level::LowLevel;
|
use roc_module::low_level::LowLevel;
|
||||||
use roc_module::symbol::{IdentIds, ModuleId, Symbol};
|
use roc_module::symbol::{IdentIds, ModuleId, Symbol};
|
||||||
|
@ -277,8 +277,8 @@ impl ExternalSpecializations {
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Procs<'a> {
|
pub struct Procs<'a> {
|
||||||
pub partial_procs: BumpMap<'a, Symbol, PartialProc<'a>>,
|
pub partial_procs: BumpMap<'a, Symbol, PartialProc<'a>>,
|
||||||
pub imported_module_thunks: MutSet<Symbol>,
|
pub imported_module_thunks: BumpSet<'a, Symbol>,
|
||||||
pub module_thunks: MutSet<Symbol>,
|
pub module_thunks: BumpSet<'a, Symbol>,
|
||||||
pub pending_specializations:
|
pub pending_specializations:
|
||||||
Option<MutMap<Symbol, MutMap<Layout<'a>, PendingSpecialization<'a>>>>,
|
Option<MutMap<Symbol, MutMap<Layout<'a>, PendingSpecialization<'a>>>>,
|
||||||
pub specialized: BumpMap<'a, (Symbol, Layout<'a>), InProgressProc<'a>>,
|
pub specialized: BumpMap<'a, (Symbol, Layout<'a>), InProgressProc<'a>>,
|
||||||
|
@ -292,8 +292,8 @@ impl<'a> Procs<'a> {
|
||||||
pub fn new_in(arena: &'a Bump) -> Self {
|
pub fn new_in(arena: &'a Bump) -> Self {
|
||||||
Self {
|
Self {
|
||||||
partial_procs: BumpMap::new_in(arena),
|
partial_procs: BumpMap::new_in(arena),
|
||||||
imported_module_thunks: MutSet::default(),
|
imported_module_thunks: BumpSet::new_in(arena),
|
||||||
module_thunks: MutSet::default(),
|
module_thunks: BumpSet::new_in(arena),
|
||||||
pending_specializations: Some(MutMap::default()),
|
pending_specializations: Some(MutMap::default()),
|
||||||
specialized: BumpMap::new_in(arena),
|
specialized: BumpMap::new_in(arena),
|
||||||
runtime_errors: BumpMap::new_in(arena),
|
runtime_errors: BumpMap::new_in(arena),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue