mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
Hide away SemanticRepr definition
This commit is contained in:
parent
a37a0f1770
commit
31c9cc8227
5 changed files with 39 additions and 30 deletions
|
@ -9821,7 +9821,7 @@ where
|
||||||
let interned_unboxed_struct_layout = layout_interner.insert(*unboxed_struct_layout);
|
let interned_unboxed_struct_layout = layout_interner.insert(*unboxed_struct_layout);
|
||||||
let boxed_struct_layout = Layout {
|
let boxed_struct_layout = Layout {
|
||||||
repr: LayoutRepr::Boxed(interned_unboxed_struct_layout),
|
repr: LayoutRepr::Boxed(interned_unboxed_struct_layout),
|
||||||
semantic: SemanticRepr::None,
|
semantic: SemanticRepr::NONE,
|
||||||
};
|
};
|
||||||
let boxed_struct_layout = layout_interner.insert(boxed_struct_layout);
|
let boxed_struct_layout = layout_interner.insert(boxed_struct_layout);
|
||||||
let mut answer = bumpalo::collections::Vec::with_capacity_in(field_layouts.len(), arena);
|
let mut answer = bumpalo::collections::Vec::with_capacity_in(field_layouts.len(), arena);
|
||||||
|
@ -9935,7 +9935,7 @@ where
|
||||||
let interned = layout_interner.insert(*unboxed_struct_layout);
|
let interned = layout_interner.insert(*unboxed_struct_layout);
|
||||||
let boxed_struct_layout = Layout {
|
let boxed_struct_layout = Layout {
|
||||||
repr: LayoutRepr::Boxed(interned),
|
repr: LayoutRepr::Boxed(interned),
|
||||||
semantic: SemanticRepr::None,
|
semantic: SemanticRepr::NONE,
|
||||||
};
|
};
|
||||||
let boxed_struct_layout = layout_interner.insert(boxed_struct_layout);
|
let boxed_struct_layout = layout_interner.insert(boxed_struct_layout);
|
||||||
let mut answer = bumpalo::collections::Vec::with_capacity_in(field_layouts.len(), arena);
|
let mut answer = bumpalo::collections::Vec::with_capacity_in(field_layouts.len(), arena);
|
||||||
|
|
|
@ -3127,7 +3127,7 @@ fn layout_from_flat_type<'a>(
|
||||||
cached!(Layout::from_var(env, inner_var), criteria, env.subs);
|
cached!(Layout::from_var(env, inner_var), criteria, env.subs);
|
||||||
let boxed_layout = env.cache.put_in(Layout {
|
let boxed_layout = env.cache.put_in(Layout {
|
||||||
repr: LayoutRepr::Boxed(inner_layout),
|
repr: LayoutRepr::Boxed(inner_layout),
|
||||||
semantic: SemanticRepr::None,
|
semantic: SemanticRepr::NONE,
|
||||||
});
|
});
|
||||||
|
|
||||||
Cacheable(Ok(boxed_layout), criteria)
|
Cacheable(Ok(boxed_layout), criteria)
|
||||||
|
@ -4112,7 +4112,7 @@ where
|
||||||
repr: LayoutRepr::Union(UnionLayout::NonRecursive(
|
repr: LayoutRepr::Union(UnionLayout::NonRecursive(
|
||||||
tag_layouts.into_bump_slice(),
|
tag_layouts.into_bump_slice(),
|
||||||
)),
|
)),
|
||||||
semantic: SemanticRepr::None,
|
semantic: SemanticRepr::NONE,
|
||||||
};
|
};
|
||||||
env.cache.put_in(layout)
|
env.cache.put_in(layout)
|
||||||
}
|
}
|
||||||
|
@ -4228,14 +4228,14 @@ where
|
||||||
env.arena,
|
env.arena,
|
||||||
Layout {
|
Layout {
|
||||||
repr: LayoutRepr::Union(union_layout),
|
repr: LayoutRepr::Union(union_layout),
|
||||||
semantic: SemanticRepr::None,
|
semantic: SemanticRepr::NONE,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
// There are no naked recursion pointers, so we can insert the layout as-is.
|
// There are no naked recursion pointers, so we can insert the layout as-is.
|
||||||
env.cache.interner.insert(Layout {
|
env.cache.interner.insert(Layout {
|
||||||
repr: LayoutRepr::Union(union_layout),
|
repr: LayoutRepr::Union(union_layout),
|
||||||
semantic: SemanticRepr::None,
|
semantic: SemanticRepr::NONE,
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -4371,7 +4371,7 @@ pub(crate) fn list_layout_from_elem<'a>(
|
||||||
|
|
||||||
let list_layout = env.cache.put_in(Layout {
|
let list_layout = env.cache.put_in(Layout {
|
||||||
repr: LayoutRepr::Builtin(Builtin::List(element_layout)),
|
repr: LayoutRepr::Builtin(Builtin::List(element_layout)),
|
||||||
semantic: SemanticRepr::None,
|
semantic: SemanticRepr::NONE,
|
||||||
});
|
});
|
||||||
|
|
||||||
Cacheable(Ok(list_layout), criteria)
|
Cacheable(Ok(list_layout), criteria)
|
||||||
|
@ -4549,13 +4549,13 @@ mod test {
|
||||||
let a = &[Layout::UNIT] as &[_];
|
let a = &[Layout::UNIT] as &[_];
|
||||||
let b = &[interner.insert(Layout {
|
let b = &[interner.insert(Layout {
|
||||||
repr: LayoutRepr::LambdaSet(lambda_set),
|
repr: LayoutRepr::LambdaSet(lambda_set),
|
||||||
semantic: SemanticRepr::None,
|
semantic: SemanticRepr::NONE,
|
||||||
})] as &[_];
|
})] as &[_];
|
||||||
let tt = [a, b];
|
let tt = [a, b];
|
||||||
|
|
||||||
let layout = Layout {
|
let layout = Layout {
|
||||||
repr: LayoutRepr::Union(UnionLayout::NonRecursive(&tt)),
|
repr: LayoutRepr::Union(UnionLayout::NonRecursive(&tt)),
|
||||||
semantic: SemanticRepr::None,
|
semantic: SemanticRepr::NONE,
|
||||||
};
|
};
|
||||||
|
|
||||||
let target_info = TargetInfo::default_x86_64();
|
let target_info = TargetInfo::default_x86_64();
|
||||||
|
@ -4569,14 +4569,14 @@ mod test {
|
||||||
|
|
||||||
let ok_tag = &[interner.insert(Layout {
|
let ok_tag = &[interner.insert(Layout {
|
||||||
repr: LayoutRepr::Builtin(Builtin::Int(IntWidth::U32)),
|
repr: LayoutRepr::Builtin(Builtin::Int(IntWidth::U32)),
|
||||||
semantic: SemanticRepr::None,
|
semantic: SemanticRepr::NONE,
|
||||||
})];
|
})];
|
||||||
let err_tag = &[Layout::UNIT];
|
let err_tag = &[Layout::UNIT];
|
||||||
let tags = [ok_tag as &[_], err_tag as &[_]];
|
let tags = [ok_tag as &[_], err_tag as &[_]];
|
||||||
let union_layout = UnionLayout::NonRecursive(&tags as &[_]);
|
let union_layout = UnionLayout::NonRecursive(&tags as &[_]);
|
||||||
let layout = Layout {
|
let layout = Layout {
|
||||||
repr: LayoutRepr::Union(union_layout),
|
repr: LayoutRepr::Union(union_layout),
|
||||||
semantic: SemanticRepr::None,
|
semantic: SemanticRepr::NONE,
|
||||||
};
|
};
|
||||||
|
|
||||||
let target_info = TargetInfo::default_x86_64();
|
let target_info = TargetInfo::default_x86_64();
|
||||||
|
|
|
@ -51,7 +51,7 @@ macro_rules! nosema {
|
||||||
($r:expr) => {
|
($r:expr) => {
|
||||||
Layout {
|
Layout {
|
||||||
repr: $r,
|
repr: $r,
|
||||||
semantic: SemanticRepr::None,
|
semantic: SemanticRepr::NONE,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ impl_to_from_int_width! {
|
||||||
impl<'a> Layout<'a> {
|
impl<'a> Layout<'a> {
|
||||||
pub(super) const VOID_NAKED: Self = Layout {
|
pub(super) const VOID_NAKED: Self = Layout {
|
||||||
repr: LayoutRepr::Union(UnionLayout::NonRecursive(&[])),
|
repr: LayoutRepr::Union(UnionLayout::NonRecursive(&[])),
|
||||||
semantic: SemanticRepr::None,
|
semantic: SemanticRepr::NONE,
|
||||||
};
|
};
|
||||||
pub(super) const UNIT_NAKED: Self = Layout {
|
pub(super) const UNIT_NAKED: Self = Layout {
|
||||||
repr: LayoutRepr::Struct { field_layouts: &[] },
|
repr: LayoutRepr::Struct { field_layouts: &[] },
|
||||||
|
@ -157,7 +157,7 @@ pub trait LayoutInterner<'a>: Sized {
|
||||||
fn insert_no_semantic(&mut self, repr: LayoutRepr<'a>) -> InLayout<'a> {
|
fn insert_no_semantic(&mut self, repr: LayoutRepr<'a>) -> InLayout<'a> {
|
||||||
self.insert(Layout {
|
self.insert(Layout {
|
||||||
repr,
|
repr,
|
||||||
semantic: SemanticRepr::None,
|
semantic: SemanticRepr::NONE,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -665,7 +665,7 @@ impl<'a> GlobalLayoutInterner<'a> {
|
||||||
};
|
};
|
||||||
let lambda_set_layout = Layout {
|
let lambda_set_layout = Layout {
|
||||||
repr: LayoutRepr::LambdaSet(full_lambda_set),
|
repr: LayoutRepr::LambdaSet(full_lambda_set),
|
||||||
semantic: SemanticRepr::None,
|
semantic: SemanticRepr::NONE,
|
||||||
};
|
};
|
||||||
|
|
||||||
vec[slot.0] = lambda_set_layout;
|
vec[slot.0] = lambda_set_layout;
|
||||||
|
@ -974,7 +974,7 @@ macro_rules! st_impl {
|
||||||
};
|
};
|
||||||
let lay = Layout {
|
let lay = Layout {
|
||||||
repr: LayoutRepr::LambdaSet(lambda_set),
|
repr: LayoutRepr::LambdaSet(lambda_set),
|
||||||
semantic: SemanticRepr::None
|
semantic: SemanticRepr::NONE
|
||||||
};
|
};
|
||||||
self.vec[slot.0] = lay;
|
self.vec[slot.0] = lay;
|
||||||
|
|
||||||
|
@ -1065,7 +1065,7 @@ mod reify {
|
||||||
};
|
};
|
||||||
Layout {
|
Layout {
|
||||||
repr,
|
repr,
|
||||||
semantic: SemanticRepr::None,
|
semantic: SemanticRepr::NONE,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1544,7 +1544,7 @@ mod insert_lambda_set {
|
||||||
interner.insert_lambda_set(arena, TEST_ARGS, TEST_RET, TEST_SET, FIXUP, Layout::UNIT);
|
interner.insert_lambda_set(arena, TEST_ARGS, TEST_RET, TEST_SET, FIXUP, Layout::UNIT);
|
||||||
let lambda_set_layout_in = interner.insert(Layout {
|
let lambda_set_layout_in = interner.insert(Layout {
|
||||||
repr: LayoutRepr::LambdaSet(lambda_set),
|
repr: LayoutRepr::LambdaSet(lambda_set),
|
||||||
semantic: SemanticRepr::None,
|
semantic: SemanticRepr::NONE,
|
||||||
});
|
});
|
||||||
assert_eq!(lambda_set.full_layout, lambda_set_layout_in);
|
assert_eq!(lambda_set.full_layout, lambda_set_layout_in);
|
||||||
}
|
}
|
||||||
|
@ -1603,7 +1603,7 @@ mod insert_recursive_layout {
|
||||||
fn make_layout<'a>(arena: &'a Bump, interner: &mut impl LayoutInterner<'a>) -> Layout<'a> {
|
fn make_layout<'a>(arena: &'a Bump, interner: &mut impl LayoutInterner<'a>) -> Layout<'a> {
|
||||||
let list_rec = Layout {
|
let list_rec = Layout {
|
||||||
repr: LayoutRepr::Builtin(Builtin::List(Layout::NAKED_RECURSIVE_PTR)),
|
repr: LayoutRepr::Builtin(Builtin::List(Layout::NAKED_RECURSIVE_PTR)),
|
||||||
semantic: SemanticRepr::None,
|
semantic: SemanticRepr::NONE,
|
||||||
};
|
};
|
||||||
let repr = LayoutRepr::Union(UnionLayout::Recursive(&*arena.alloc([
|
let repr = LayoutRepr::Union(UnionLayout::Recursive(&*arena.alloc([
|
||||||
&*arena.alloc([interner.insert(list_rec)]),
|
&*arena.alloc([interner.insert(list_rec)]),
|
||||||
|
@ -1613,7 +1613,7 @@ mod insert_recursive_layout {
|
||||||
])));
|
])));
|
||||||
Layout {
|
Layout {
|
||||||
repr,
|
repr,
|
||||||
semantic: SemanticRepr::None,
|
semantic: SemanticRepr::NONE,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,31 +4,40 @@
|
||||||
/// Semantic representations describe the shape of a type a [Layout][super::Layout] is generated
|
/// Semantic representations describe the shape of a type a [Layout][super::Layout] is generated
|
||||||
/// for. Semantic representations disambiguate types that have the same runtime memory layout, but
|
/// for. Semantic representations disambiguate types that have the same runtime memory layout, but
|
||||||
/// different shapes.
|
/// different shapes.
|
||||||
|
#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||||
|
pub struct SemanticRepr<'a>(Inner<'a>);
|
||||||
|
|
||||||
|
impl<'a> std::fmt::Debug for SemanticRepr<'a> {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
self.0.fmt(f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||||
pub enum SemanticRepr<'a> {
|
enum Inner<'a> {
|
||||||
None,
|
None,
|
||||||
Record(SemaRecord<'a>),
|
Record(SemaRecord<'a>),
|
||||||
Tuple(SemaTuple),
|
Tuple(SemaTuple),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> SemanticRepr<'a> {
|
impl<'a> SemanticRepr<'a> {
|
||||||
pub(super) const EMPTY_RECORD: Self = Self::Record(SemaRecord { fields: &[] });
|
pub const NONE: Self = Self(Inner::None);
|
||||||
|
|
||||||
pub(super) fn record(fields: &'a [&'a str]) -> Self {
|
pub(super) const fn record(fields: &'a [&'a str]) -> Self {
|
||||||
Self::Record(SemaRecord { fields })
|
Self(Inner::Record(SemaRecord { fields }))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn tuple(size: usize) -> Self {
|
pub(super) fn tuple(size: usize) -> Self {
|
||||||
Self::Tuple(SemaTuple { size })
|
Self(Inner::Tuple(SemaTuple { size }))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||||
pub struct SemaRecord<'a> {
|
struct SemaRecord<'a> {
|
||||||
pub fields: &'a [&'a str],
|
fields: &'a [&'a str],
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||||
pub struct SemaTuple {
|
struct SemaTuple {
|
||||||
pub size: usize,
|
size: usize,
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ fn width_and_alignment_u8_u8() {
|
||||||
|
|
||||||
let layout = Layout {
|
let layout = Layout {
|
||||||
repr: LayoutRepr::Union(UnionLayout::NonRecursive(&tt)),
|
repr: LayoutRepr::Union(UnionLayout::NonRecursive(&tt)),
|
||||||
semantic: SemanticRepr::None,
|
semantic: SemanticRepr::NONE,
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(layout.alignment_bytes(&interner, target_info), 1);
|
assert_eq!(layout.alignment_bytes(&interner, target_info), 1);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue