mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 06:14:46 +00:00
Get started with semantic layouts for tag unions
This commit is contained in:
parent
24e65cbf8d
commit
8ca71c7eda
6 changed files with 95 additions and 29 deletions
|
@ -1,5 +1,7 @@
|
|||
//! Semantic representations of memory layouts for the purposes of specialization.
|
||||
|
||||
use roc_module::symbol::Symbol;
|
||||
|
||||
/// A semantic representation of a memory layout.
|
||||
/// 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
|
||||
|
@ -18,6 +20,8 @@ enum Inner<'a> {
|
|||
None,
|
||||
Record(SemaRecord<'a>),
|
||||
Tuple(SemaTuple),
|
||||
TagUnion(SemaTagUnion<'a>),
|
||||
Lambdas(SemaLambdas<'a>),
|
||||
}
|
||||
|
||||
impl<'a> SemanticRepr<'a> {
|
||||
|
@ -31,6 +35,14 @@ impl<'a> SemanticRepr<'a> {
|
|||
pub(super) fn tuple(size: usize) -> Self {
|
||||
Self(Inner::Tuple(SemaTuple { size }))
|
||||
}
|
||||
|
||||
pub(super) fn tag_union(tags: &'a [&'a str]) -> Self {
|
||||
Self(Inner::TagUnion(SemaTagUnion { tags }))
|
||||
}
|
||||
|
||||
pub(super) fn lambdas(lambdas: &'a [Symbol]) -> Self {
|
||||
Self(Inner::Lambdas(SemaLambdas { lambdas }))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
|
@ -42,3 +54,13 @@ struct SemaRecord<'a> {
|
|||
struct SemaTuple {
|
||||
size: usize,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
struct SemaTagUnion<'a> {
|
||||
tags: &'a [&'a str],
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
struct SemaLambdas<'a> {
|
||||
lambdas: &'a [Symbol],
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue