mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-16 16:55:00 +00:00
Add a LayoutBuffer to store layouts aside and thread it through
This commit is contained in:
parent
a0af21becc
commit
3d73e33b49
4 changed files with 64 additions and 0 deletions
|
@ -5,6 +5,7 @@ use crate::layout::{
|
|||
LambdaName, LambdaSet, Layout, LayoutCache, LayoutInterner, LayoutProblem, RawFunctionLayout,
|
||||
STLayoutInterner, TagIdIntType, UnionLayout, WrappedVariant,
|
||||
};
|
||||
use crate::LayoutBuffer;
|
||||
use bumpalo::collections::{CollectIn, Vec};
|
||||
use bumpalo::Bump;
|
||||
use roc_builtins::bitcode::{FloatWidth, IntWidth};
|
||||
|
@ -1474,6 +1475,7 @@ pub struct Env<'a, 'i> {
|
|||
pub abilities: AbilitiesView<'i>,
|
||||
pub exposed_by_module: &'i ExposedByModule,
|
||||
pub derived_module: &'i SharedDerivedModule,
|
||||
pub layout_buffer: &'i mut LayoutBuffer<'a>,
|
||||
}
|
||||
|
||||
impl<'a, 'i> Env<'a, 'i> {
|
||||
|
|
24
crates/compiler/mono/src/layout_buffer.rs
Normal file
24
crates/compiler/mono/src/layout_buffer.rs
Normal file
|
@ -0,0 +1,24 @@
|
|||
use roc_collections::soa::Slice;
|
||||
|
||||
use crate::layout::Layout;
|
||||
|
||||
/// A look-aside buffer to keep layouts in.
|
||||
#[derive(Default, Debug)]
|
||||
pub struct LayoutBuffer<'a>(Vec<Layout<'a>>);
|
||||
|
||||
impl<'a> LayoutBuffer<'a> {
|
||||
pub fn reserve(&mut self, size: usize) -> Slice<Layout<'a>> {
|
||||
Slice::extend_new(&mut self.0, std::iter::repeat(Layout::VOID).take(size))
|
||||
}
|
||||
|
||||
pub fn set_reserved(
|
||||
&mut self,
|
||||
slice: Slice<Layout<'a>>,
|
||||
layouts: impl ExactSizeIterator<Item = Layout<'a>>,
|
||||
) {
|
||||
debug_assert_eq!(layouts.len(), slice.len());
|
||||
for (index, layout) in slice.indices().zip(layouts) {
|
||||
self.0[index] = layout;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -12,6 +12,7 @@ pub mod code_gen_help;
|
|||
pub mod inc_dec;
|
||||
pub mod ir;
|
||||
pub mod layout;
|
||||
mod layout_buffer;
|
||||
pub mod layout_soa;
|
||||
pub mod low_level;
|
||||
pub mod reset_reuse;
|
||||
|
@ -23,3 +24,5 @@ pub mod tail_recursion;
|
|||
pub mod decision_tree;
|
||||
|
||||
pub mod debug;
|
||||
|
||||
pub use layout_buffer::LayoutBuffer;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue