Make repr private and accessible only via the interner

This commit is contained in:
Ayaz Hafiz 2023-05-11 10:12:18 -05:00
parent 107c6b0777
commit 457cdabc5c
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
30 changed files with 294 additions and 288 deletions

View file

@ -24,7 +24,7 @@ pub fn eq_generic<'a>(
) -> Stmt<'a> {
use crate::layout::Builtin::*;
use LayoutRepr::*;
let main_body = match layout_interner.get(layout).repr {
let main_body = match layout_interner.get_repr(layout) {
Builtin(Int(_) | Float(_) | Bool | Decimal) => {
unreachable!(
"No generated proc for `==`. Use direct code gen for {:?}",
@ -468,7 +468,7 @@ fn eq_tag_fields<'a>(
// (If there are more than one, the others will use non-tail recursion)
let rec_ptr_index = field_layouts.iter().position(|field| {
matches!(
layout_interner.get(*field).repr,
layout_interner.get_repr(*field),
LayoutRepr::RecursivePointer(_)
)
});

View file

@ -286,7 +286,7 @@ impl<'a> CodeGenHelp<'a> {
self.debug_recursion_depth += 1;
let layout = if matches!(
layout_interner.get(called_layout).repr,
layout_interner.get_repr(called_layout),
LayoutRepr::RecursivePointer(_)
) {
let union_layout = ctx.recursive_union.unwrap();
@ -532,8 +532,9 @@ impl<'a> CodeGenHelp<'a> {
layout_interner: &mut STLayoutInterner<'a>,
layout: InLayout<'a>,
) -> InLayout<'a> {
let lay = layout_interner.get(layout);
let repr = match lay.repr {
let lay = layout_interner.get_repr(layout);
let semantic = layout_interner.get_semantic(layout);
let repr = match lay {
LayoutRepr::Builtin(Builtin::List(v)) => {
let v = self.replace_rec_ptr(ctx, layout_interner, v);
LayoutRepr::Builtin(Builtin::List(v))
@ -580,7 +581,7 @@ impl<'a> CodeGenHelp<'a> {
LayoutRepr::RecursivePointer(_) => LayoutRepr::Union(ctx.recursive_union.unwrap()),
};
layout_interner.insert(Layout::new(repr, lay.semantic()))
layout_interner.insert(Layout::new(repr, semantic))
}
fn union_tail_recursion_fields(
@ -822,7 +823,7 @@ fn layout_needs_helper_proc<'a>(
layout: InLayout<'a>,
op: HelperOp,
) -> bool {
match layout_interner.get(layout).repr {
match layout_interner.get_repr(layout) {
LayoutRepr::Builtin(
Builtin::Int(_) | Builtin::Float(_) | Builtin::Bool | Builtin::Decimal,
) => false,

View file

@ -75,7 +75,7 @@ pub fn refcount_stmt<'a>(
}
ModifyRc::DecRef(structure) => {
match layout_interner.get(layout).repr {
match layout_interner.get_repr(layout) {
// Str has no children, so Dec is the same as DecRef.
LayoutRepr::Builtin(Builtin::Str) => {
ctx.op = HelperOp::Dec;
@ -182,7 +182,7 @@ pub fn refcount_generic<'a>(
layout: InLayout<'a>,
structure: Symbol,
) -> Stmt<'a> {
match layout_interner.get(layout).repr {
match layout_interner.get_repr(layout) {
LayoutRepr::Builtin(
Builtin::Int(_) | Builtin::Float(_) | Builtin::Bool | Builtin::Decimal,
) => {
@ -301,7 +301,7 @@ pub fn refcount_reset_proc_body<'a>(
let is_unique = root.create_symbol(ident_ids, "is_unique");
let addr = root.create_symbol(ident_ids, "addr");
let union_layout = match layout_interner.get(layout).repr {
let union_layout = match layout_interner.get_repr(layout) {
LayoutRepr::Union(u) => u,
_ => unimplemented!("Reset is only implemented for UnionLayout"),
};
@ -483,7 +483,7 @@ pub fn refcount_resetref_proc_body<'a>(
let is_unique = root.create_symbol(ident_ids, "is_unique");
let addr = root.create_symbol(ident_ids, "addr");
let union_layout = match layout_interner.get(layout).repr {
let union_layout = match layout_interner.get_repr(layout) {
LayoutRepr::Union(u) => u,
_ => unimplemented!("Resetref is only implemented for UnionLayout"),
};