Store target info on layout interners

This commit is contained in:
Ayaz Hafiz 2023-01-03 18:05:34 -06:00
parent d8b2ff07f8
commit e14a0abb99
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
5 changed files with 18 additions and 11 deletions

View file

@ -1072,7 +1072,7 @@ impl<'a> State<'a> {
exec_mode,
make_specializations_pass: MakeSpecializationsPass::Pass(1),
world_abilities: Default::default(),
layout_interner: GlobalLayoutInterner::with_capacity(128),
layout_interner: GlobalLayoutInterner::with_capacity(128, target_info),
}
}
}
@ -3072,7 +3072,7 @@ fn update<'a>(
}
let layout_interner = {
let mut taken = GlobalLayoutInterner::with_capacity(0);
let mut taken = GlobalLayoutInterner::with_capacity(0, state.target_info);
std::mem::swap(&mut state.layout_interner, &mut taken);
taken
};

View file

@ -4394,7 +4394,7 @@ mod test {
#[test]
fn width_and_alignment_union_empty_struct() {
let mut interner = STLayoutInterner::with_capacity(4);
let mut interner = STLayoutInterner::with_capacity(4, TargetInfo::default_x86_64());
let lambda_set = LambdaSet {
set: &(&[(Symbol::LIST_MAP, &[] as &[InLayout])] as &[(Symbol, &[InLayout])]),
@ -4415,7 +4415,7 @@ mod test {
#[test]
fn memcpy_size_result_u32_unit() {
let interner = STLayoutInterner::with_capacity(4);
let interner = STLayoutInterner::with_capacity(4, TargetInfo::default_x86_64());
let ok_tag = &[Layout::Builtin(Builtin::Int(IntWidth::U32))];
let err_tag = &[Layout::UNIT];
@ -4432,7 +4432,7 @@ mod test {
#[test]
fn void_stack_size() {
let interner = STLayoutInterner::with_capacity(4);
let interner = STLayoutInterner::with_capacity(4, TargetInfo::default_x86_64());
let target_info = TargetInfo::default_x86_64();
assert_eq!(Layout::VOID.stack_size(&interner, target_info), 0);
}

View file

@ -170,6 +170,7 @@ struct GlobalLayoutInternerInner<'a> {
map: Mutex<BumpMap<Layout<'a>, InLayout<'a>>>,
normalized_lambda_set_map: Mutex<BumpMap<LambdaSet<'a>, LambdaSet<'a>>>,
vec: RwLock<Vec<Layout<'a>>>,
target_info: TargetInfo,
}
/// A derivative of a [GlobalLayoutInterner] interner that provides caching desirable for
@ -199,6 +200,7 @@ pub struct STLayoutInterner<'a> {
map: BumpMap<Layout<'a>, InLayout<'a>>,
normalized_lambda_set_map: BumpMap<LambdaSet<'a>, LambdaSet<'a>>,
vec: Vec<Layout<'a>>,
target_info: TargetInfo,
}
/// Generic hasher for a value, to be used by all interners.
@ -224,8 +226,8 @@ fn make_normalized_lamdba_set<'a>(
impl<'a> GlobalLayoutInterner<'a> {
/// Creates a new global interner with the given capacity.
pub fn with_capacity(cap: usize) -> Self {
STLayoutInterner::with_capacity(cap).into_global()
pub fn with_capacity(cap: usize, target_info: TargetInfo) -> Self {
STLayoutInterner::with_capacity(cap, target_info).into_global()
}
/// Creates a derivative [TLLayoutInterner] pointing back to this global interner.
@ -246,6 +248,7 @@ impl<'a> GlobalLayoutInterner<'a> {
map,
normalized_lambda_set_map,
vec,
target_info,
} = match Arc::try_unwrap(self.0) {
Ok(inner) => inner,
Err(li) => return Err(Self(li)),
@ -257,6 +260,7 @@ impl<'a> GlobalLayoutInterner<'a> {
map,
normalized_lambda_set_map,
vec,
target_info,
})
}
@ -404,11 +408,12 @@ impl<'a> LayoutInterner<'a> for TLLayoutInterner<'a> {
impl<'a> STLayoutInterner<'a> {
/// Creates a new single threaded interner with the given capacity.
pub fn with_capacity(cap: usize) -> Self {
pub fn with_capacity(cap: usize, target_info: TargetInfo) -> Self {
let mut interner = Self {
map: BumpMap::with_capacity_and_hasher(cap, default_hasher()),
normalized_lambda_set_map: BumpMap::with_capacity_and_hasher(cap, default_hasher()),
vec: Vec::with_capacity(cap),
target_info,
};
fill_reserved_layouts(&mut interner);
interner
@ -423,11 +428,13 @@ impl<'a> STLayoutInterner<'a> {
map,
normalized_lambda_set_map,
vec,
target_info,
} = self;
GlobalLayoutInterner(Arc::new(GlobalLayoutInternerInner {
map: Mutex::new(map),
normalized_lambda_set_map: Mutex::new(normalized_lambda_set_map),
vec: RwLock::new(vec),
target_info,
}))
}

View file

@ -19,14 +19,14 @@ fn width_and_alignment_u8_u8() {
use roc_mono::layout::Layout;
use roc_mono::layout::UnionLayout;
let interner = STLayoutInterner::with_capacity(4);
let target_info = roc_target::TargetInfo::default_x86_64();
let interner = STLayoutInterner::with_capacity(4, target_info);
let t = &[Layout::u8()] as &[_];
let tt = [t, t];
let layout = Layout::Union(UnionLayout::NonRecursive(&tt));
let target_info = roc_target::TargetInfo::default_x86_64();
assert_eq!(layout.alignment_bytes(&interner, target_info), 1);
assert_eq!(layout.stack_size(&interner, target_info), 2);
}

View file

@ -150,7 +150,7 @@ pub fn load_types(
}
});
let layout_interner = GlobalLayoutInterner::with_capacity(128);
let layout_interner = GlobalLayoutInterner::with_capacity(128, target_info);
let architectures = Architecture::iter();
let mut types_and_targets = Vec::with_capacity(architectures.len());