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 boxed_struct_layout = 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 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 boxed_struct_layout = Layout {
|
||||
repr: LayoutRepr::Boxed(interned),
|
||||
semantic: SemanticRepr::None,
|
||||
semantic: SemanticRepr::NONE,
|
||||
};
|
||||
let boxed_struct_layout = layout_interner.insert(boxed_struct_layout);
|
||||
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);
|
||||
let boxed_layout = env.cache.put_in(Layout {
|
||||
repr: LayoutRepr::Boxed(inner_layout),
|
||||
semantic: SemanticRepr::None,
|
||||
semantic: SemanticRepr::NONE,
|
||||
});
|
||||
|
||||
Cacheable(Ok(boxed_layout), criteria)
|
||||
|
@ -4112,7 +4112,7 @@ where
|
|||
repr: LayoutRepr::Union(UnionLayout::NonRecursive(
|
||||
tag_layouts.into_bump_slice(),
|
||||
)),
|
||||
semantic: SemanticRepr::None,
|
||||
semantic: SemanticRepr::NONE,
|
||||
};
|
||||
env.cache.put_in(layout)
|
||||
}
|
||||
|
@ -4228,14 +4228,14 @@ where
|
|||
env.arena,
|
||||
Layout {
|
||||
repr: LayoutRepr::Union(union_layout),
|
||||
semantic: SemanticRepr::None,
|
||||
semantic: SemanticRepr::NONE,
|
||||
},
|
||||
)
|
||||
} else {
|
||||
// There are no naked recursion pointers, so we can insert the layout as-is.
|
||||
env.cache.interner.insert(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 {
|
||||
repr: LayoutRepr::Builtin(Builtin::List(element_layout)),
|
||||
semantic: SemanticRepr::None,
|
||||
semantic: SemanticRepr::NONE,
|
||||
});
|
||||
|
||||
Cacheable(Ok(list_layout), criteria)
|
||||
|
@ -4549,13 +4549,13 @@ mod test {
|
|||
let a = &[Layout::UNIT] as &[_];
|
||||
let b = &[interner.insert(Layout {
|
||||
repr: LayoutRepr::LambdaSet(lambda_set),
|
||||
semantic: SemanticRepr::None,
|
||||
semantic: SemanticRepr::NONE,
|
||||
})] as &[_];
|
||||
let tt = [a, b];
|
||||
|
||||
let layout = Layout {
|
||||
repr: LayoutRepr::Union(UnionLayout::NonRecursive(&tt)),
|
||||
semantic: SemanticRepr::None,
|
||||
semantic: SemanticRepr::NONE,
|
||||
};
|
||||
|
||||
let target_info = TargetInfo::default_x86_64();
|
||||
|
@ -4569,14 +4569,14 @@ mod test {
|
|||
|
||||
let ok_tag = &[interner.insert(Layout {
|
||||
repr: LayoutRepr::Builtin(Builtin::Int(IntWidth::U32)),
|
||||
semantic: SemanticRepr::None,
|
||||
semantic: SemanticRepr::NONE,
|
||||
})];
|
||||
let err_tag = &[Layout::UNIT];
|
||||
let tags = [ok_tag as &[_], err_tag as &[_]];
|
||||
let union_layout = UnionLayout::NonRecursive(&tags as &[_]);
|
||||
let layout = Layout {
|
||||
repr: LayoutRepr::Union(union_layout),
|
||||
semantic: SemanticRepr::None,
|
||||
semantic: SemanticRepr::NONE,
|
||||
};
|
||||
|
||||
let target_info = TargetInfo::default_x86_64();
|
||||
|
|
|
@ -51,7 +51,7 @@ macro_rules! nosema {
|
|||
($r:expr) => {
|
||||
Layout {
|
||||
repr: $r,
|
||||
semantic: SemanticRepr::None,
|
||||
semantic: SemanticRepr::NONE,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ impl_to_from_int_width! {
|
|||
impl<'a> Layout<'a> {
|
||||
pub(super) const VOID_NAKED: Self = Layout {
|
||||
repr: LayoutRepr::Union(UnionLayout::NonRecursive(&[])),
|
||||
semantic: SemanticRepr::None,
|
||||
semantic: SemanticRepr::NONE,
|
||||
};
|
||||
pub(super) const UNIT_NAKED: Self = Layout {
|
||||
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> {
|
||||
self.insert(Layout {
|
||||
repr,
|
||||
semantic: SemanticRepr::None,
|
||||
semantic: SemanticRepr::NONE,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -665,7 +665,7 @@ impl<'a> GlobalLayoutInterner<'a> {
|
|||
};
|
||||
let lambda_set_layout = Layout {
|
||||
repr: LayoutRepr::LambdaSet(full_lambda_set),
|
||||
semantic: SemanticRepr::None,
|
||||
semantic: SemanticRepr::NONE,
|
||||
};
|
||||
|
||||
vec[slot.0] = lambda_set_layout;
|
||||
|
@ -974,7 +974,7 @@ macro_rules! st_impl {
|
|||
};
|
||||
let lay = Layout {
|
||||
repr: LayoutRepr::LambdaSet(lambda_set),
|
||||
semantic: SemanticRepr::None
|
||||
semantic: SemanticRepr::NONE
|
||||
};
|
||||
self.vec[slot.0] = lay;
|
||||
|
||||
|
@ -1065,7 +1065,7 @@ mod reify {
|
|||
};
|
||||
Layout {
|
||||
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);
|
||||
let lambda_set_layout_in = interner.insert(Layout {
|
||||
repr: LayoutRepr::LambdaSet(lambda_set),
|
||||
semantic: SemanticRepr::None,
|
||||
semantic: SemanticRepr::NONE,
|
||||
});
|
||||
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> {
|
||||
let list_rec = Layout {
|
||||
repr: LayoutRepr::Builtin(Builtin::List(Layout::NAKED_RECURSIVE_PTR)),
|
||||
semantic: SemanticRepr::None,
|
||||
semantic: SemanticRepr::NONE,
|
||||
};
|
||||
let repr = LayoutRepr::Union(UnionLayout::Recursive(&*arena.alloc([
|
||||
&*arena.alloc([interner.insert(list_rec)]),
|
||||
|
@ -1613,7 +1613,7 @@ mod insert_recursive_layout {
|
|||
])));
|
||||
Layout {
|
||||
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
|
||||
/// for. Semantic representations disambiguate types that have the same runtime memory layout, but
|
||||
/// 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)]
|
||||
pub enum SemanticRepr<'a> {
|
||||
enum Inner<'a> {
|
||||
None,
|
||||
Record(SemaRecord<'a>),
|
||||
Tuple(SemaTuple),
|
||||
}
|
||||
|
||||
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 {
|
||||
Self::Record(SemaRecord { fields })
|
||||
pub(super) const fn record(fields: &'a [&'a str]) -> Self {
|
||||
Self(Inner::Record(SemaRecord { fields }))
|
||||
}
|
||||
|
||||
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)]
|
||||
pub struct SemaRecord<'a> {
|
||||
pub fields: &'a [&'a str],
|
||||
struct SemaRecord<'a> {
|
||||
fields: &'a [&'a str],
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub struct SemaTuple {
|
||||
pub size: usize,
|
||||
struct SemaTuple {
|
||||
size: usize,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue