Get started with semantic layouts for tag unions

This commit is contained in:
Ayaz Hafiz 2023-05-10 18:47:10 -05:00
parent 24e65cbf8d
commit 8ca71c7eda
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
6 changed files with 95 additions and 29 deletions

View file

@ -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],
}