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

@ -1014,7 +1014,7 @@ fn to_relevant_branch_help<'a>(
// the test matches the constructor of this pattern
match layout {
UnionLayout::NonRecursive([[arg]])
if matches!(interner.get(*arg).repr, LayoutRepr::Struct([_],)) =>
if matches!(interner.get_repr(*arg), LayoutRepr::Struct([_],)) =>
{
// a one-element record equivalent
// Theory: Unbox doesn't have any value for us
@ -1573,7 +1573,7 @@ fn path_to_expr_help<'a>(
PathInstruction::TagIndex { index, tag_id } => {
let index = *index;
match layout_interner.chase_recursive(layout).repr {
match layout_interner.chase_recursive(layout) {
LayoutRepr::Union(union_layout) => {
let inner_expr = Expr::UnionAtIndex {
tag_id: *tag_id,
@ -1626,7 +1626,7 @@ fn path_to_expr_help<'a>(
PathInstruction::ListIndex { index } => {
let list_sym = symbol;
match layout_interner.get(layout).repr {
match layout_interner.get_repr(layout) {
LayoutRepr::Builtin(Builtin::List(elem_layout)) => {
let (index_sym, new_stores) = build_list_index_probe(env, list_sym, index);
@ -1673,7 +1673,7 @@ fn test_to_comparison<'a>(
// (e.g. record pattern guard matches)
debug_assert!(union.alternatives.len() > 1);
match layout_interner.chase_recursive(test_layout).repr {
match layout_interner.chase_recursive(test_layout) {
LayoutRepr::Union(union_layout) => {
let lhs = Expr::Literal(Literal::Int((tag_id as i128).to_ne_bytes()));
@ -1763,7 +1763,7 @@ fn test_to_comparison<'a>(
let list_layout = test_layout;
let list_sym = rhs_symbol;
match layout_interner.get(list_layout).repr {
match layout_interner.get_repr(list_layout) {
LayoutRepr::Builtin(Builtin::List(_elem_layout)) => {
let real_len_expr = Expr::Call(Call {
call_type: CallType::LowLevel {
@ -2310,7 +2310,7 @@ fn decide_to_branching<'a>(
// We have learned more about the exact layout of the cond (based on the path)
// but tests are still relative to the original cond symbol
let inner_cond_layout_raw = layout_cache.interner.chase_recursive(inner_cond_layout);
let mut switch = if let LayoutRepr::Union(union_layout) = inner_cond_layout_raw.repr {
let mut switch = if let LayoutRepr::Union(union_layout) = inner_cond_layout_raw {
let tag_id_symbol = env.unique_symbol();
let temp = Stmt::Switch {
@ -2332,7 +2332,7 @@ fn decide_to_branching<'a>(
union_layout.tag_id_layout(),
env.arena.alloc(temp),
)
} else if let LayoutRepr::Builtin(Builtin::List(_)) = inner_cond_layout_raw.repr {
} else if let LayoutRepr::Builtin(Builtin::List(_)) = inner_cond_layout_raw {
let len_symbol = env.unique_symbol();
let switch = Stmt::Switch {

View file

@ -83,7 +83,7 @@ pub fn make_num_literal<'a>(
num_str: &str,
num_value: IntOrFloatValue,
) -> NumLiteral {
match interner.get(layout).repr {
match interner.get_repr(layout) {
LayoutRepr::Builtin(Builtin::Int(width)) => match num_value {
IntOrFloatValue::Int(IntValue::I128(n)) => NumLiteral::Int(n, width),
IntOrFloatValue::Int(IntValue::U128(n)) => NumLiteral::U128(n),

View file

@ -344,7 +344,7 @@ fn from_can_pattern_help<'a>(
StrLiteral(v) => Ok(Pattern::StrLiteral(v.clone())),
SingleQuote(var, _, c, _) => {
let layout = layout_cache.from_var(env.arena, *var, env.subs);
match layout.map(|l| layout_cache.get_in(l).repr) {
match layout.map(|l| layout_cache.get_repr(l)) {
Ok(LayoutRepr::Builtin(Builtin::Int(width))) => {
Ok(Pattern::IntLiteral((*c as i128).to_ne_bytes(), width))
}
@ -583,12 +583,11 @@ fn from_can_pattern_help<'a>(
// problems down the line because we hash layouts and an unrolled
// version is not the same as the minimal version.
let whole_var_layout = layout_cache.from_var(env.arena, *whole_var, env.subs);
let layout = match whole_var_layout
.map(|l| layout_cache.interner.chase_recursive(l).repr)
{
Ok(LayoutRepr::Union(ul)) => ul,
_ => internal_error!(),
};
let layout =
match whole_var_layout.map(|l| layout_cache.interner.chase_recursive(l)) {
Ok(LayoutRepr::Union(ul)) => ul,
_ => internal_error!(),
};
use WrappedVariant::*;
match variant {
@ -1552,7 +1551,7 @@ fn store_tag_pattern<'a>(
for (index, (argument, arg_layout)) in arguments.iter().enumerate().rev() {
let mut arg_layout = *arg_layout;
if let LayoutRepr::RecursivePointer(_) = layout_cache.get_in(arg_layout).repr {
if let LayoutRepr::RecursivePointer(_) = layout_cache.get_repr(arg_layout) {
// TODO(recursive-layouts): fix after disjoint rec ptrs
arg_layout = layout_cache.put_in_no_semantic(LayoutRepr::Union(union_layout));
}
@ -1630,7 +1629,7 @@ fn store_newtype_pattern<'a>(
for (index, (argument, arg_layout)) in arguments.iter().enumerate().rev() {
let mut arg_layout = *arg_layout;
if let LayoutRepr::RecursivePointer(_) = layout_cache.get_in(arg_layout).repr {
if let LayoutRepr::RecursivePointer(_) = layout_cache.get_repr(arg_layout) {
arg_layout = layout;
}