mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +00:00
fix a bug with taking a scratchpad arena
This commit is contained in:
parent
cfccb92bf9
commit
8c321c1aa4
1 changed files with 17 additions and 17 deletions
|
@ -370,7 +370,8 @@ fn solve(
|
||||||
// then we copy from that module's Subs into our own. If the value
|
// then we copy from that module's Subs into our own. If the value
|
||||||
// is being looked up in this module, then we use our Subs as both
|
// is being looked up in this module, then we use our Subs as both
|
||||||
// the source and destination.
|
// the source and destination.
|
||||||
let actual = deep_copy_var(subs, rank, pools, var);
|
let actual = deep_copy_var_in(subs, rank, pools, var, arena);
|
||||||
|
|
||||||
let expected = type_to_var(
|
let expected = type_to_var(
|
||||||
subs,
|
subs,
|
||||||
rank,
|
rank,
|
||||||
|
@ -779,21 +780,16 @@ impl<T> LocalDefVarsVec<T> {
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
std::thread_local! {
|
std::thread_local! {
|
||||||
/// Scratchpad arena so we don't need to allocate a new one all the time
|
/// Scratchpad arena so we don't need to allocate a new one all the time
|
||||||
static SCRATCHPAD: RefCell<bumpalo::Bump> = RefCell::new(bumpalo::Bump::with_capacity(4 * 1024));
|
static SCRATCHPAD: RefCell<Option<bumpalo::Bump>> = RefCell::new(Some(bumpalo::Bump::with_capacity(4 * 1024)));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn take_scratchpad() -> bumpalo::Bump {
|
fn take_scratchpad() -> bumpalo::Bump {
|
||||||
let mut result = bumpalo::Bump::new();
|
SCRATCHPAD.with(|f| f.take().unwrap())
|
||||||
SCRATCHPAD.with(|f| {
|
|
||||||
result = f.replace(bumpalo::Bump::new());
|
|
||||||
});
|
|
||||||
|
|
||||||
result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn put_scratchpad(scratchpad: bumpalo::Bump) {
|
fn put_scratchpad(scratchpad: bumpalo::Bump) {
|
||||||
SCRATCHPAD.with(|f| {
|
SCRATCHPAD.with(|f| {
|
||||||
f.replace(scratchpad);
|
f.replace(Some(scratchpad));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -976,7 +972,7 @@ fn type_to_variable<'a>(
|
||||||
return reserved;
|
return reserved;
|
||||||
} else {
|
} else {
|
||||||
// for any other rank, we need to copy; it takes care of adjusting the rank
|
// for any other rank, we need to copy; it takes care of adjusting the rank
|
||||||
return deep_copy_var(subs, rank, pools, reserved);
|
return deep_copy_var_in(subs, rank, pools, reserved, arena);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1044,6 +1040,7 @@ fn type_to_variable<'a>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
fn alias_to_var<'a>(
|
fn alias_to_var<'a>(
|
||||||
subs: &mut Subs,
|
subs: &mut Subs,
|
||||||
rank: Rank,
|
rank: Rank,
|
||||||
|
@ -1073,6 +1070,7 @@ fn alias_to_var<'a>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
fn roc_result_to_var<'a>(
|
fn roc_result_to_var<'a>(
|
||||||
subs: &mut Subs,
|
subs: &mut Subs,
|
||||||
rank: Rank,
|
rank: Rank,
|
||||||
|
@ -1821,10 +1819,14 @@ fn instantiate_rigids_help(subs: &mut Subs, max_rank: Rank, initial: Variable) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deep_copy_var(subs: &mut Subs, rank: Rank, pools: &mut Pools, var: Variable) -> Variable {
|
fn deep_copy_var_in(
|
||||||
let mut arena = take_scratchpad();
|
subs: &mut Subs,
|
||||||
|
rank: Rank,
|
||||||
let mut visited = bumpalo::collections::Vec::with_capacity_in(4 * 1024, &arena);
|
pools: &mut Pools,
|
||||||
|
var: Variable,
|
||||||
|
arena: &Bump,
|
||||||
|
) -> Variable {
|
||||||
|
let mut visited = bumpalo::collections::Vec::with_capacity_in(256, arena);
|
||||||
|
|
||||||
let copy = deep_copy_var_help(subs, rank, pools, &mut visited, var);
|
let copy = deep_copy_var_help(subs, rank, pools, &mut visited, var);
|
||||||
|
|
||||||
|
@ -1840,9 +1842,6 @@ fn deep_copy_var(subs: &mut Subs, rank: Rank, pools: &mut Pools, var: Variable)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
arena.reset();
|
|
||||||
put_scratchpad(arena);
|
|
||||||
|
|
||||||
copy
|
copy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2081,6 +2080,7 @@ fn deep_copy_var_help(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
fn register(subs: &mut Subs, rank: Rank, pools: &mut Pools, content: Content) -> Variable {
|
fn register(subs: &mut Subs, rank: Rank, pools: &mut Pools, content: Content) -> Variable {
|
||||||
let descriptor = Descriptor {
|
let descriptor = Descriptor {
|
||||||
content,
|
content,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue