Merge pull request #4849 from roc-lang/intern-layouts-5-lambda-set-layout-cache

Reduce layout intern allocations
This commit is contained in:
Richard Feldman 2023-01-10 20:35:09 -05:00 committed by GitHub
commit 94ccb0fd8d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 337 additions and 188 deletions

View file

@ -3593,7 +3593,7 @@ fn specialize_proc_help<'a>(
let ordered_field_layouts = Vec::from_iter_in(
combined
.iter()
.map(|(_, layout)| *layout_cache.get_in(**layout)),
.map(|(_, layout)| layout_cache.get_in(**layout)),
env.arena,
);
let ordered_field_layouts = ordered_field_layouts.into_bump_slice();
@ -3619,7 +3619,7 @@ fn specialize_proc_help<'a>(
specialized_body = Stmt::Let(
symbol,
expr,
*layout_cache.get_in(**layout),
layout_cache.get_in(**layout),
env.arena.alloc(specialized_body),
);
}
@ -4635,7 +4635,7 @@ pub fn with_hole<'a>(
Ok(elem_layout) => {
let expr = Expr::EmptyArray;
// TODO don't alloc once elem_layout is interned
let elem_layout = layout_cache.put_in(env.arena.alloc(elem_layout));
let elem_layout = layout_cache.put_in(elem_layout);
Stmt::Let(
assigned,
expr,
@ -4646,7 +4646,7 @@ pub fn with_hole<'a>(
Err(LayoutProblem::UnresolvedTypeVar(_)) => {
let expr = Expr::EmptyArray;
// TODO don't alloc once elem_layout is interned
let elem_layout = layout_cache.put_in(env.arena.alloc(Layout::VOID));
let elem_layout = layout_cache.put_in(Layout::VOID);
Stmt::Let(
assigned,
expr,
@ -4695,7 +4695,7 @@ pub fn with_hole<'a>(
elems: elements.into_bump_slice(),
};
let elem_layout = layout_cache.put_in(env.arena.alloc(elem_layout));
let elem_layout = layout_cache.put_in(elem_layout);
let stmt = Stmt::Let(
assigned,
@ -5792,7 +5792,7 @@ where
let symbols =
Vec::from_iter_in(combined.iter().map(|(a, _)| *a), env.arena).into_bump_slice();
let field_layouts = Vec::from_iter_in(
combined.iter().map(|(_, b)| *layout_cache.get_in(**b)),
combined.iter().map(|(_, b)| layout_cache.get_in(**b)),
env.arena,
)
.into_bump_slice();