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

@ -610,7 +610,7 @@ pub fn build_compare_wrapper<'a, 'ctx>(
let closure_data_repr = closure_data_layout.runtime_representation();
let arguments_cast = match layout_interner.get(closure_data_repr).repr {
let arguments_cast = match layout_interner.get_repr(closure_data_repr) {
LayoutRepr::Struct(&[]) => {
// nothing to add
&default

View file

@ -783,7 +783,7 @@ pub fn build_exp_literal<'a, 'ctx>(
use roc_mono::ir::Literal::*;
match literal {
Int(bytes) => match layout_interner.get(layout).repr {
Int(bytes) => match layout_interner.get_repr(layout) {
LayoutRepr::Builtin(Builtin::Bool) => env
.context
.bool_type()
@ -797,7 +797,7 @@ pub fn build_exp_literal<'a, 'ctx>(
U128(bytes) => const_u128(env, u128::from_ne_bytes(*bytes)).into(),
Float(float) => match layout_interner.get(layout).repr {
Float(float) => match layout_interner.get_repr(layout) {
LayoutRepr::Builtin(Builtin::Float(float_width)) => {
float_with_precision(env, *float, float_width)
}
@ -1178,7 +1178,7 @@ pub fn build_exp_expr<'a, 'ctx>(
let tag_ptr = tag_ptr.into_pointer_value();
// reset is only generated for union values
let union_layout = match layout_interner.get(layout).repr {
let union_layout = match layout_interner.get_repr(layout) {
LayoutRepr::Union(ul) => ul,
_ => unreachable!(),
};
@ -1323,7 +1323,7 @@ pub fn build_exp_expr<'a, 'ctx>(
} => {
let (value, layout) = load_symbol_and_layout(scope, structure);
let layout = if let LayoutRepr::LambdaSet(lambda_set) = layout_interner.get(layout).repr
let layout = if let LayoutRepr::LambdaSet(lambda_set) = layout_interner.get_repr(layout)
{
lambda_set.runtime_representation()
} else {
@ -1331,7 +1331,7 @@ pub fn build_exp_expr<'a, 'ctx>(
};
// extract field from a record
match (value, layout_interner.get(layout).repr) {
match (value, layout_interner.get_repr(layout)) {
(StructValue(argument), LayoutRepr::Struct(field_layouts)) => {
debug_assert!(!field_layouts.is_empty());
@ -1625,7 +1625,7 @@ fn build_tag_field_value<'a, 'ctx>(
value: BasicValueEnum<'ctx>,
tag_field_layout: InLayout<'a>,
) -> BasicValueEnum<'ctx> {
if let LayoutRepr::RecursivePointer(_) = layout_interner.get(tag_field_layout).repr {
if let LayoutRepr::RecursivePointer(_) = layout_interner.get_repr(tag_field_layout) {
debug_assert!(value.is_pointer_value());
// we store recursive pointers as `i64*`
@ -2545,7 +2545,7 @@ pub fn build_exp_stmt<'a, 'ctx>(
for (symbol, expr, layout) in queue {
debug_assert!(!matches!(
layout_interner.get(*layout).repr,
layout_interner.get_repr(*layout),
LayoutRepr::RecursivePointer(_)
));
@ -2845,8 +2845,8 @@ pub fn build_exp_stmt<'a, 'ctx>(
DecRef(symbol) => {
let (value, layout) = load_symbol_and_layout(scope, symbol);
let lay = layout_interner.get(layout);
match lay.repr {
let lay = layout_interner.get_repr(layout);
match lay {
LayoutRepr::Builtin(Builtin::Str) => todo!(),
LayoutRepr::Builtin(Builtin::List(element_layout)) => {
debug_assert!(value.is_struct_value());
@ -3437,7 +3437,7 @@ fn build_switch_ir<'a, 'ctx>(
let cont_block = context.append_basic_block(parent, "cont");
// Build the condition
let cond = match layout_interner.get(cond_layout).repr {
let cond = match layout_interner.get_repr(cond_layout) {
LayoutRepr::Builtin(Builtin::Float(float_width)) => {
// float matches are done on the bit pattern
cond_layout = Layout::float_width(float_width);
@ -3463,7 +3463,7 @@ fn build_switch_ir<'a, 'ctx>(
// Build the cases
let mut incoming = Vec::with_capacity_in(branches.len(), arena);
if let LayoutRepr::Builtin(Builtin::Bool) = layout_interner.get(cond_layout).repr {
if let LayoutRepr::Builtin(Builtin::Bool) = layout_interner.get_repr(cond_layout) {
match (branches, default_branch) {
([(0, _, false_branch)], true_branch) | ([(1, _, true_branch)], false_branch) => {
let then_block = context.append_basic_block(parent, "then_block");
@ -3871,7 +3871,7 @@ fn expose_function_to_host_help_c_abi_gen_test<'a, 'ctx>(
// the C and Fast calling conventions agree
arguments_for_call.push(*arg);
} else {
match layout_interner.get(*layout).repr {
match layout_interner.get_repr(*layout) {
LayoutRepr::Builtin(Builtin::List(_)) => {
let list_type = arg_type
.into_pointer_type()
@ -4010,7 +4010,7 @@ fn expose_function_to_host_help_c_abi_v2<'a, 'ctx>(
};
for (i, layout) in arguments.iter().enumerate() {
if let LayoutRepr::Builtin(Builtin::Str) = layout_interner.get(*layout).repr {
if let LayoutRepr::Builtin(Builtin::Str) = layout_interner.get_repr(*layout) {
// Indicate to LLVM that this argument is semantically passed by-value
// even though technically (because of its size) it is passed by-reference
let byval_attribute_id = Attribute::get_named_enum_kind_id("byval");
@ -4110,7 +4110,7 @@ fn expose_function_to_host_help_c_abi_v2<'a, 'ctx>(
env.target_info.architecture,
roc_target::Architecture::X86_32 | roc_target::Architecture::X86_64
) {
let c_abi_type = match layout_interner.get(*layout).repr {
let c_abi_type = match layout_interner.get_repr(*layout) {
LayoutRepr::Builtin(Builtin::Str | Builtin::List(_)) => {
c_abi_roc_str_type
}
@ -5679,7 +5679,7 @@ fn to_cc_type<'a, 'ctx>(
layout_interner: &mut STLayoutInterner<'a>,
layout: InLayout<'a>,
) -> BasicTypeEnum<'ctx> {
match layout_interner.runtime_representation(layout).repr {
match layout_interner.runtime_representation(layout) {
LayoutRepr::Builtin(builtin) => to_cc_type_builtin(env, &builtin),
_ => {
// TODO this is almost certainly incorrect for bigger structs
@ -5726,7 +5726,7 @@ impl RocReturn {
target_info: TargetInfo,
layout: InLayout,
) -> bool {
match interner.get(layout).repr {
match interner.get_repr(layout) {
LayoutRepr::Builtin(builtin) => {
use Builtin::*;

View file

@ -154,7 +154,7 @@ fn build_eq<'a, 'ctx>(
rhs_layout
);
match layout_interner.get(*lhs_layout).repr {
match layout_interner.get_repr(*lhs_layout) {
LayoutRepr::Builtin(builtin) => build_eq_builtin(
env,
layout_interner,
@ -215,7 +215,7 @@ fn build_eq<'a, 'ctx>(
"i64_to_opaque",
);
let union_layout = match layout_interner.get(rec_layout).repr {
let union_layout = match layout_interner.get_repr(rec_layout) {
LayoutRepr::Union(union_layout) => {
debug_assert!(!matches!(union_layout, UnionLayout::NonRecursive(..)));
union_layout
@ -342,7 +342,7 @@ fn build_neq<'a, 'ctx>(
);
}
match layout_interner.get(lhs_layout).repr {
match layout_interner.get_repr(lhs_layout) {
LayoutRepr::Builtin(builtin) => build_neq_builtin(
env,
layout_interner,
@ -425,7 +425,7 @@ fn build_list_eq<'a, 'ctx>(
let symbol = Symbol::LIST_EQ;
let element_layout =
if let LayoutRepr::RecursivePointer(rec) = layout_interner.get(element_layout).repr {
if let LayoutRepr::RecursivePointer(rec) = layout_interner.get_repr(element_layout) {
rec
} else {
element_layout
@ -742,10 +742,10 @@ fn build_struct_eq_help<'a, 'ctx>(
.unwrap();
let are_equal = if let LayoutRepr::RecursivePointer(rec_layout) =
layout_interner.get(*field_layout).repr
layout_interner.get_repr(*field_layout)
{
debug_assert!(
matches!(layout_interner.get(rec_layout).repr, LayoutRepr::Union(union_layout) if !matches!(union_layout, UnionLayout::NonRecursive(..)))
matches!(layout_interner.get_repr(rec_layout), LayoutRepr::Union(union_layout) if !matches!(union_layout, UnionLayout::NonRecursive(..)))
);
let field_layout = rec_layout;

View file

@ -36,7 +36,7 @@ pub fn basic_type_from_layout<'a, 'ctx, 'env>(
) -> BasicTypeEnum<'ctx> {
use LayoutRepr::*;
match layout_interner.get(layout).repr {
match layout_interner.get_repr(layout) {
Struct(sorted_fields, ..) => basic_type_from_record(env, layout_interner, sorted_fields),
LambdaSet(lambda_set) => {
basic_type_from_layout(env, layout_interner, lambda_set.runtime_representation())
@ -150,7 +150,7 @@ pub fn argument_type_from_layout<'a, 'ctx>(
) -> BasicTypeEnum<'ctx> {
use LayoutRepr::*;
match layout_interner.get(layout).repr {
match layout_interner.get_repr(layout) {
LambdaSet(lambda_set) => {
argument_type_from_layout(env, layout_interner, lambda_set.runtime_representation())
}

View file

@ -296,7 +296,7 @@ fn build_clone<'a, 'ctx>(
value: BasicValueEnum<'ctx>,
layout: InLayout<'a>,
) -> IntValue<'ctx> {
match layout_interner.get(layout).repr {
match layout_interner.get_repr(layout) {
LayoutRepr::Builtin(builtin) => build_clone_builtin(
env,
layout_interner,
@ -396,7 +396,7 @@ fn build_clone<'a, 'ctx>(
"i64_to_opaque",
);
let union_layout = match layout_interner.get(rec_layout).repr {
let union_layout = match layout_interner.get_repr(rec_layout) {
LayoutRepr::Union(union_layout) => {
debug_assert!(!matches!(union_layout, UnionLayout::NonRecursive(..)));
union_layout

View file

@ -200,13 +200,13 @@ pub(crate) fn run_low_level<'a, 'ctx>(
// Str.toNum : Str -> Result (Num *) {}
arguments!(string);
let number_layout = match layout_interner.get(layout).repr {
let number_layout = match layout_interner.get_repr(layout) {
LayoutRepr::Struct(field_layouts) => field_layouts[0], // TODO: why is it sometimes a struct?
_ => unreachable!(),
};
// match on the return layout to figure out which zig builtin we need
let intrinsic = match layout_interner.get(number_layout).repr {
let intrinsic = match layout_interner.get_repr(number_layout) {
LayoutRepr::Builtin(Builtin::Int(int_width)) => &bitcode::STR_TO_INT[int_width],
LayoutRepr::Builtin(Builtin::Float(float_width)) => {
&bitcode::STR_TO_FLOAT[float_width]
@ -229,7 +229,7 @@ pub(crate) fn run_low_level<'a, 'ctx>(
intrinsic,
),
None => {
let return_type_name = match layout_interner.get(number_layout).repr {
let return_type_name = match layout_interner.get_repr(number_layout) {
LayoutRepr::Builtin(Builtin::Int(int_width)) => {
int_width.type_name()
}
@ -279,7 +279,7 @@ pub(crate) fn run_low_level<'a, 'ctx>(
}
}
PtrWidth::Bytes8 => {
let cc_return_by_pointer = match layout_interner.get(number_layout).repr {
let cc_return_by_pointer = match layout_interner.get_repr(number_layout) {
LayoutRepr::Builtin(Builtin::Int(int_width)) => {
(int_width.stack_size() as usize > env.target_info.ptr_size())
.then_some(int_width.type_name())
@ -325,7 +325,7 @@ pub(crate) fn run_low_level<'a, 'ctx>(
let (int, int_layout) = load_symbol_and_layout(scope, &args[0]);
let int = int.into_int_value();
let int_width = match layout_interner.get(int_layout).repr {
let int_width = match layout_interner.get_repr(int_layout) {
LayoutRepr::Builtin(Builtin::Int(int_width)) => int_width,
_ => unreachable!(),
};
@ -344,7 +344,7 @@ pub(crate) fn run_low_level<'a, 'ctx>(
let (float, float_layout) = load_symbol_and_layout(scope, &args[0]);
let float_width = match layout_interner.get(float_layout).repr {
let float_width = match layout_interner.get_repr(float_layout) {
LayoutRepr::Builtin(Builtin::Float(float_width)) => float_width,
_ => unreachable!(),
};
@ -854,7 +854,7 @@ pub(crate) fn run_low_level<'a, 'ctx>(
// Num.toStr : Num a -> Str
arguments_with_layouts!((num, num_layout));
match layout_interner.get(num_layout).repr {
match layout_interner.get_repr(num_layout) {
LayoutRepr::Builtin(Builtin::Int(int_width)) => {
let int = num.into_int_value();
@ -869,7 +869,7 @@ pub(crate) fn run_low_level<'a, 'ctx>(
LayoutRepr::Builtin(Builtin::Float(_float_width)) => {
let (float, float_layout) = load_symbol_and_layout(scope, &args[0]);
let float_width = match layout_interner.get(float_layout).repr {
let float_width = match layout_interner.get_repr(float_layout) {
LayoutRepr::Builtin(Builtin::Float(float_width)) => float_width,
_ => unreachable!(),
};
@ -908,7 +908,7 @@ pub(crate) fn run_low_level<'a, 'ctx>(
| NumCountOneBits => {
arguments_with_layouts!((arg, arg_layout));
match layout_interner.get(arg_layout).repr {
match layout_interner.get_repr(arg_layout) {
LayoutRepr::Builtin(arg_builtin) => {
use roc_mono::layout::Builtin::*;
@ -996,8 +996,8 @@ pub(crate) fn run_low_level<'a, 'ctx>(
use inkwell::FloatPredicate;
match (
layout_interner.get(lhs_layout).repr,
layout_interner.get(rhs_layout).repr,
layout_interner.get_repr(lhs_layout),
layout_interner.get_repr(rhs_layout),
) {
(LayoutRepr::Builtin(lhs_builtin), LayoutRepr::Builtin(rhs_builtin))
if lhs_builtin == rhs_builtin =>
@ -1152,7 +1152,7 @@ pub(crate) fn run_low_level<'a, 'ctx>(
NumToFloatCast => {
arguments_with_layouts!((arg, arg_layout));
match layout_interner.get(arg_layout).repr {
match layout_interner.get_repr(arg_layout) {
LayoutRepr::Builtin(Builtin::Int(width)) => {
// Converting from int to float
let int_val = arg.into_int_value();
@ -1291,7 +1291,7 @@ pub(crate) fn run_low_level<'a, 'ctx>(
"cast_to_i8_ptr",
);
let value_ptr = match layout_interner.get(data_layout).repr {
let value_ptr = match layout_interner.get_repr(data_layout) {
LayoutRepr::Union(union_layout)
if union_layout.stores_tag_id_in_pointer(env.target_info) =>
{
@ -1562,8 +1562,8 @@ pub fn build_num_binop<'a, 'ctx>(
op: LowLevel,
) -> BasicValueEnum<'ctx> {
match (
layout_interner.get(lhs_layout).repr,
layout_interner.get(rhs_layout).repr,
layout_interner.get_repr(lhs_layout),
layout_interner.get_repr(rhs_layout),
) {
(LayoutRepr::Builtin(lhs_builtin), LayoutRepr::Builtin(rhs_builtin))
if lhs_builtin == rhs_builtin =>
@ -2031,7 +2031,7 @@ fn build_int_unary_op<'a, 'ctx, 'env>(
NumToFrac => {
// This is an Int, so we need to convert it.
let target_float_type = match layout_interner.get(return_layout).repr {
let target_float_type = match layout_interner.get_repr(return_layout) {
LayoutRepr::Builtin(Builtin::Float(float_width)) => {
convert::float_type_from_float_width(env, float_width)
}
@ -2048,7 +2048,7 @@ fn build_int_unary_op<'a, 'ctx, 'env>(
NumToIntChecked => {
// return_layout : Result N [OutOfBounds]* ~ { result: N, out_of_bounds: bool }
let target_int_width = match layout_interner.get(return_layout).repr {
let target_int_width = match layout_interner.get_repr(return_layout) {
LayoutRepr::Struct(field_layouts) if field_layouts.len() == 2 => {
debug_assert!(layout_interner.eq_repr(field_layouts[1], Layout::BOOL));
field_layouts[0].to_int_width()
@ -2328,7 +2328,7 @@ fn build_float_unary_op<'a, 'ctx>(
NumSqrtUnchecked => call_bitcode_fn(env, &[arg.into()], &bitcode::NUM_SQRT[float_width]),
NumLogUnchecked => call_bitcode_fn(env, &[arg.into()], &bitcode::NUM_LOG[float_width]),
NumToFrac => {
let return_width = match layout_interner.get(layout).repr {
let return_width = match layout_interner.get_repr(layout) {
LayoutRepr::Builtin(Builtin::Float(return_width)) => return_width,
_ => internal_error!("Layout for returning is not Float : {:?}", layout),
};
@ -2350,7 +2350,7 @@ fn build_float_unary_op<'a, 'ctx>(
}
}
NumCeiling => {
let int_width = match layout_interner.get(layout).repr {
let int_width = match layout_interner.get_repr(layout) {
LayoutRepr::Builtin(Builtin::Int(int_width)) => int_width,
_ => internal_error!("Ceiling return layout is not int: {:?}", layout),
};
@ -2364,7 +2364,7 @@ fn build_float_unary_op<'a, 'ctx>(
}
}
NumFloor => {
let int_width = match layout_interner.get(layout).repr {
let int_width = match layout_interner.get_repr(layout) {
LayoutRepr::Builtin(Builtin::Int(int_width)) => int_width,
_ => internal_error!("Floor return layout is not int: {:?}", layout),
};
@ -2378,7 +2378,7 @@ fn build_float_unary_op<'a, 'ctx>(
}
}
NumRound => {
let int_width = match layout_interner.get(layout).repr {
let int_width = match layout_interner.get_repr(layout) {
LayoutRepr::Builtin(Builtin::Int(int_width)) => int_width,
_ => internal_error!("Round return layout is not int: {:?}", layout),
};
@ -2465,8 +2465,8 @@ pub(crate) fn run_higher_order_low_level<'a, 'ctx>(
let (function, closure, closure_layout) = function_details!();
match (
layout_interner.get(list_layout).repr,
layout_interner.get(return_layout).repr,
layout_interner.get_repr(list_layout),
layout_interner.get_repr(return_layout),
) {
(
LayoutRepr::Builtin(Builtin::List(element_layout)),
@ -2505,9 +2505,9 @@ pub(crate) fn run_higher_order_low_level<'a, 'ctx>(
let (function, closure, closure_layout) = function_details!();
match (
layout_interner.get(list1_layout).repr,
layout_interner.get(list2_layout).repr,
layout_interner.get(return_layout).repr,
layout_interner.get_repr(list1_layout),
layout_interner.get_repr(list2_layout),
layout_interner.get_repr(return_layout),
) {
(
LayoutRepr::Builtin(Builtin::List(element1_layout)),
@ -2551,10 +2551,10 @@ pub(crate) fn run_higher_order_low_level<'a, 'ctx>(
let (function, closure, closure_layout) = function_details!();
match (
layout_interner.get(list1_layout).repr,
layout_interner.get(list2_layout).repr,
layout_interner.get(list3_layout).repr,
layout_interner.get(return_layout).repr,
layout_interner.get_repr(list1_layout),
layout_interner.get_repr(list2_layout),
layout_interner.get_repr(list3_layout),
layout_interner.get_repr(return_layout),
) {
(
LayoutRepr::Builtin(Builtin::List(element1_layout)),
@ -2602,11 +2602,11 @@ pub(crate) fn run_higher_order_low_level<'a, 'ctx>(
let (function, closure, closure_layout) = function_details!();
match (
layout_interner.get(list1_layout).repr,
layout_interner.get(list2_layout).repr,
layout_interner.get(list3_layout).repr,
layout_interner.get(list4_layout).repr,
layout_interner.get(return_layout).repr,
layout_interner.get_repr(list1_layout),
layout_interner.get_repr(list2_layout),
layout_interner.get_repr(list3_layout),
layout_interner.get_repr(list4_layout),
layout_interner.get_repr(return_layout),
) {
(
LayoutRepr::Builtin(Builtin::List(element1_layout)),
@ -2659,7 +2659,7 @@ pub(crate) fn run_higher_order_low_level<'a, 'ctx>(
let (function, closure, closure_layout) = function_details!();
match layout_interner.get(list_layout).repr {
match layout_interner.get_repr(list_layout) {
LayoutRepr::Builtin(Builtin::List(element_layout)) => {
use crate::llvm::bitcode::build_compare_wrapper;
@ -2710,7 +2710,7 @@ fn load_symbol_and_lambda_set<'a, 'ctx>(
) -> (BasicValueEnum<'ctx>, LambdaSet<'a>) {
match scope
.get(symbol)
.map(|(l, v)| (layout_interner.get(*l).repr, v))
.map(|(l, v)| (layout_interner.get_repr(*l), v))
{
Some((LayoutRepr::LambdaSet(lambda_set), ptr)) => (*ptr, lambda_set),
Some((other, ptr)) => panic!("Not a lambda set: {:?}, {:?}", other, ptr),

View file

@ -470,7 +470,7 @@ fn modify_refcount_layout_help<'a, 'ctx>(
None => return,
};
match layout_interner.get(layout).repr {
match layout_interner.get_repr(layout) {
LayoutRepr::RecursivePointer(rec_layout) => {
let layout = rec_layout;
@ -527,7 +527,7 @@ fn modify_refcount_layout_build_function<'a, 'ctx>(
) -> Option<FunctionValue<'ctx>> {
use LayoutRepr::*;
match layout_interner.get(layout).repr {
match layout_interner.get_repr(layout) {
Builtin(builtin) => {
modify_refcount_builtin(env, layout_interner, layout_ids, mode, layout, &builtin)
}
@ -603,7 +603,7 @@ fn modify_refcount_list<'a, 'ctx>(
let di_location = env.builder.get_current_debug_location().unwrap();
let element_layout =
if let LayoutRepr::RecursivePointer(rec) = layout_interner.get(element_layout).repr {
if let LayoutRepr::RecursivePointer(rec) = layout_interner.get_repr(element_layout) {
rec
} else {
element_layout
@ -1290,7 +1290,7 @@ fn build_rec_union_recursive_decrement<'a, 'ctx>(
let mut deferred_nonrec = Vec::new_in(env.arena);
for (i, field_layout) in field_layouts.iter().enumerate() {
if let LayoutRepr::RecursivePointer(_) = layout_interner.get(*field_layout).repr {
if let LayoutRepr::RecursivePointer(_) = layout_interner.get_repr(*field_layout) {
// this field has type `*i64`, but is really a pointer to the data we want
let elem_pointer = env
.builder
@ -1767,7 +1767,7 @@ fn modify_refcount_nonrecursive_help<'a, 'ctx>(
for (i, field_layout) in field_layouts.iter().enumerate() {
if let LayoutRepr::RecursivePointer(union_layout) =
layout_interner.get(*field_layout).repr
layout_interner.get_repr(*field_layout)
{
// This field is a pointer to the recursive pointer.
let field_ptr = env