use RocUnion constants for tag index

This commit is contained in:
Folkert 2022-07-22 16:14:38 +02:00
parent 366429303c
commit 4977d1c65e
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
4 changed files with 20 additions and 20 deletions

View file

@ -2,9 +2,9 @@
use crate::debug_info_init;
use crate::llvm::build::{
complex_bitcast_check_size, load_roc_value, struct_from_fields, to_cc_return, CCReturn, Env,
C_CALL_CONV, FAST_CALL_CONV, TAG_DATA_INDEX,
C_CALL_CONV, FAST_CALL_CONV,
};
use crate::llvm::convert::basic_type_from_layout;
use crate::llvm::convert::{basic_type_from_layout, RocUnion};
use crate::llvm::refcounting::{
decrement_refcount_layout, increment_n_refcount_layout, increment_refcount_layout,
};
@ -314,7 +314,7 @@ fn build_has_tag_id_help<'a, 'ctx, 'env>(
let tag_data_ptr = {
let ptr = env
.builder
.build_struct_gep(tag_value, TAG_DATA_INDEX, "get_data_ptr")
.build_struct_gep(tag_value, RocUnion::TAG_DATA_INDEX, "get_data_ptr")
.unwrap();
env.builder.build_bitcast(ptr, i8_ptr_type, "to_opaque")

View file

@ -65,7 +65,7 @@ use std::convert::TryInto;
use std::path::Path;
use target_lexicon::{Architecture, OperatingSystem, Triple};
use super::convert::zig_with_overflow_roc_dec;
use super::convert::{zig_with_overflow_roc_dec, RocUnion};
#[inline(always)]
fn print_fn_verification_output() -> bool {
@ -1162,9 +1162,6 @@ pub fn build_exp_call<'a, 'ctx, 'env>(
}
}
pub const TAG_ID_INDEX: u32 = 1;
pub const TAG_DATA_INDEX: u32 = 0;
pub fn struct_from_fields<'a, 'ctx, 'env, I>(
env: &Env<'a, 'ctx, 'env>,
struct_type: StructType<'ctx>,
@ -1599,7 +1596,7 @@ fn build_wrapped_tag<'a, 'ctx, 'env>(
if union_layout.stores_tag_id_as_data(env.target_info) {
let tag_id_ptr = builder
.build_struct_gep(raw_data_ptr, TAG_ID_INDEX, "tag_id_index")
.build_struct_gep(raw_data_ptr, RocUnion::TAG_ID_INDEX, "tag_id_index")
.unwrap();
let tag_id_type = basic_type_from_layout(env, &tag_id_layout).into_int_type();
@ -1608,7 +1605,7 @@ fn build_wrapped_tag<'a, 'ctx, 'env>(
.build_store(tag_id_ptr, tag_id_type.const_int(tag_id as u64, false));
let opaque_struct_ptr = builder
.build_struct_gep(raw_data_ptr, TAG_DATA_INDEX, "tag_data_index")
.build_struct_gep(raw_data_ptr, RocUnion::TAG_DATA_INDEX, "tag_data_index")
.unwrap();
struct_pointer_from_fields(
@ -1758,7 +1755,7 @@ fn build_tag<'a, 'ctx, 'env>(
// store the tag id
let tag_id_ptr = env
.builder
.build_struct_gep(result_alloca, TAG_ID_INDEX, "tag_id_ptr")
.build_struct_gep(result_alloca, RocUnion::TAG_ID_INDEX, "tag_id_ptr")
.unwrap();
let tag_id_intval = tag_id_type.const_int(tag_id as u64, false);
@ -1771,7 +1768,7 @@ fn build_tag<'a, 'ctx, 'env>(
let struct_opaque_ptr = env
.builder
.build_struct_gep(result_alloca, TAG_DATA_INDEX, "opaque_data_ptr")
.build_struct_gep(result_alloca, RocUnion::TAG_DATA_INDEX, "opaque_data_ptr")
.unwrap();
let struct_ptr = env.builder.build_pointer_cast(
struct_opaque_ptr,
@ -2178,7 +2175,7 @@ fn lookup_at_index_ptr2<'a, 'ctx, 'env>(
.into_pointer_value();
let data_ptr = builder
.build_struct_gep(ptr, TAG_DATA_INDEX, "at_index_struct_gep_tag")
.build_struct_gep(ptr, RocUnion::TAG_DATA_INDEX, "at_index_struct_gep_tag")
.unwrap();
let elem_ptr = builder
@ -3263,7 +3260,7 @@ fn get_tag_id_wrapped<'a, 'ctx, 'env>(
) -> IntValue<'ctx> {
let tag_id_ptr = env
.builder
.build_struct_gep(from_value, TAG_ID_INDEX, "tag_id_ptr")
.build_struct_gep(from_value, RocUnion::TAG_ID_INDEX, "tag_id_ptr")
.unwrap();
env.builder
@ -3276,7 +3273,7 @@ pub fn get_tag_id_non_recursive<'a, 'ctx, 'env>(
tag: StructValue<'ctx>,
) -> IntValue<'ctx> {
env.builder
.build_extract_value(tag, TAG_ID_INDEX, "get_tag_id")
.build_extract_value(tag, RocUnion::TAG_ID_INDEX, "get_tag_id")
.unwrap()
.into_int_value()
}

View file

@ -278,8 +278,11 @@ pub(crate) struct RocUnion<'ctx> {
}
impl<'ctx> RocUnion<'ctx> {
pub const TAG_ID_INDEX: u32 = 2;
pub const TAG_DATA_INDEX: u32 = 1;
// pub const TAG_ID_INDEX: u32 = 2;
// pub const TAG_DATA_INDEX: u32 = 1;
pub const TAG_ID_INDEX: u32 = 1;
pub const TAG_DATA_INDEX: u32 = 0;
fn new(
context: &'ctx Context,

View file

@ -2,10 +2,10 @@ use crate::debug_info_init;
use crate::llvm::bitcode::call_void_bitcode_fn;
use crate::llvm::build::{
add_func, cast_basic_basic, get_tag_id, tag_pointer_clear_tag_id, use_roc_value, Env,
FAST_CALL_CONV, TAG_DATA_INDEX, TAG_ID_INDEX,
FAST_CALL_CONV,
};
use crate::llvm::build_list::{incrementing_elem_loop, list_len, load_list};
use crate::llvm::convert::basic_type_from_layout;
use crate::llvm::convert::{basic_type_from_layout, RocUnion};
use bumpalo::collections::Vec;
use inkwell::basic_block::BasicBlock;
use inkwell::module::Linkage;
@ -1597,7 +1597,7 @@ fn modify_refcount_union_help<'a, 'ctx, 'env>(
// read the tag_id
let tag_id_ptr = env
.builder
.build_struct_gep(arg_ptr, TAG_ID_INDEX, "tag_id_ptr")
.build_struct_gep(arg_ptr, RocUnion::TAG_ID_INDEX, "tag_id_ptr")
.unwrap();
let tag_id = env
@ -1634,7 +1634,7 @@ fn modify_refcount_union_help<'a, 'ctx, 'env>(
debug_assert!(wrapper_type.is_struct_type());
let opaque_tag_data_ptr = env
.builder
.build_struct_gep(arg_ptr, TAG_DATA_INDEX, "field_ptr")
.build_struct_gep(arg_ptr, RocUnion::TAG_DATA_INDEX, "field_ptr")
.unwrap();
let cast_tag_data_pointer = env.builder.build_pointer_cast(