mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 23:04:49 +00:00
drop the tag!
This commit is contained in:
parent
897bc41b6b
commit
c1265574b3
6 changed files with 48 additions and 34 deletions
|
@ -28,7 +28,7 @@ use inkwell::debug_info::{
|
|||
use inkwell::memory_buffer::MemoryBuffer;
|
||||
use inkwell::module::{Linkage, Module};
|
||||
use inkwell::passes::{PassManager, PassManagerBuilder};
|
||||
use inkwell::types::{BasicTypeEnum, FunctionType, IntType, PointerType, StructType};
|
||||
use inkwell::types::{BasicTypeEnum, FunctionType, IntType, StructType};
|
||||
use inkwell::values::BasicValueEnum::{self, *};
|
||||
use inkwell::values::{
|
||||
BasicValue, CallSiteValue, FloatValue, FunctionValue, InstructionOpcode, InstructionValue,
|
||||
|
@ -1149,6 +1149,8 @@ pub fn build_exp_expr<'a, 'ctx, 'env>(
|
|||
tag_name,
|
||||
..
|
||||
} => {
|
||||
let other_fields = &other_fields[1..];
|
||||
|
||||
let tag_struct_type =
|
||||
block_of_memory_slices(env.context, &[other_fields], env.ptr_bytes);
|
||||
|
||||
|
@ -1175,8 +1177,8 @@ pub fn build_exp_expr<'a, 'ctx, 'env>(
|
|||
|
||||
debug_assert!(!matches!(tag_name, TagName::Closure(_)));
|
||||
|
||||
let tag_field_layouts = &other_fields[0..];
|
||||
let arguments = &arguments[0..];
|
||||
let tag_field_layouts = other_fields;
|
||||
let arguments = &arguments[1..];
|
||||
|
||||
debug_assert_eq!(arguments.len(), tag_field_layouts.len());
|
||||
|
||||
|
@ -1317,17 +1319,16 @@ pub fn build_exp_expr<'a, 'ctx, 'env>(
|
|||
field_types.push(field_type);
|
||||
}
|
||||
|
||||
// Create the struct_type
|
||||
let struct_type = env
|
||||
.context
|
||||
.struct_type(field_types.into_bump_slice(), false);
|
||||
|
||||
// cast the argument bytes into the desired shape for this tag
|
||||
let (argument, structure_layout) = load_symbol_and_layout(env, scope, structure);
|
||||
|
||||
let struct_layout = Layout::Struct(field_layouts);
|
||||
match argument {
|
||||
StructValue(value) => {
|
||||
let struct_layout = Layout::Struct(field_layouts);
|
||||
let struct_type = env
|
||||
.context
|
||||
.struct_type(field_types.into_bump_slice(), false);
|
||||
|
||||
let struct_value = cast_struct_struct(builder, value, struct_type);
|
||||
|
||||
let result = builder
|
||||
|
@ -1403,24 +1404,36 @@ pub fn build_exp_expr<'a, 'ctx, 'env>(
|
|||
"select_tag_id",
|
||||
)
|
||||
} else {
|
||||
let struct_layout = Layout::Struct(&field_layouts[1..]);
|
||||
let struct_type = env
|
||||
.context
|
||||
.struct_type(&field_types.into_bump_slice()[1..], false);
|
||||
|
||||
lookup_at_index_ptr(
|
||||
env,
|
||||
field_layouts,
|
||||
*index as usize,
|
||||
&field_layouts[1..],
|
||||
*index as usize - 1,
|
||||
value,
|
||||
&struct_layout,
|
||||
struct_type,
|
||||
)
|
||||
}
|
||||
}
|
||||
_ => lookup_at_index_ptr(
|
||||
env,
|
||||
field_layouts,
|
||||
*index as usize,
|
||||
value,
|
||||
&struct_layout,
|
||||
struct_type,
|
||||
),
|
||||
_ => {
|
||||
let struct_layout = Layout::Struct(field_layouts);
|
||||
let struct_type = env
|
||||
.context
|
||||
.struct_type(field_types.into_bump_slice(), false);
|
||||
|
||||
lookup_at_index_ptr(
|
||||
env,
|
||||
field_layouts,
|
||||
*index as usize,
|
||||
value,
|
||||
&struct_layout,
|
||||
struct_type,
|
||||
)
|
||||
}
|
||||
},
|
||||
_ => panic!("cannot look up index in {:?}", argument),
|
||||
}
|
||||
|
|
|
@ -143,7 +143,7 @@ pub fn basic_type_from_layout<'ctx>(
|
|||
block.ptr_type(AddressSpace::Generic).into()
|
||||
}
|
||||
NullableUnwrapped { other_fields, .. } => {
|
||||
let block = block_of_memory_slices(context, &[other_fields], ptr_bytes);
|
||||
let block = block_of_memory_slices(context, &[&other_fields[1..]], ptr_bytes);
|
||||
block.ptr_type(AddressSpace::Generic).into()
|
||||
}
|
||||
NonRecursive(_) => block_of_memory(context, layout, ptr_bytes),
|
||||
|
|
|
@ -359,10 +359,12 @@ pub fn decrement_refcount_layout<'a, 'ctx, 'env>(
|
|||
NullableUnwrapped { other_fields, .. } => {
|
||||
debug_assert!(value.is_pointer_value());
|
||||
|
||||
let other_fields = &other_fields[1..];
|
||||
|
||||
build_dec_rec_union(
|
||||
env,
|
||||
layout_ids,
|
||||
&*env.arena.alloc([*other_fields]),
|
||||
&*env.arena.alloc([other_fields]),
|
||||
value.into_pointer_value(),
|
||||
true,
|
||||
);
|
||||
|
@ -468,10 +470,12 @@ pub fn increment_refcount_layout<'a, 'ctx, 'env>(
|
|||
NullableUnwrapped { other_fields, .. } => {
|
||||
debug_assert!(value.is_pointer_value());
|
||||
|
||||
let other_fields = &other_fields[1..];
|
||||
|
||||
build_inc_rec_union(
|
||||
env,
|
||||
layout_ids,
|
||||
&*env.arena.alloc([*other_fields]),
|
||||
&*env.arena.alloc([other_fields]),
|
||||
value.into_pointer_value(),
|
||||
true,
|
||||
);
|
||||
|
|
|
@ -564,7 +564,7 @@ mod gen_primitives {
|
|||
Cons _ rest -> 1 + len rest
|
||||
|
||||
main =
|
||||
nil : LinkedList {}
|
||||
nil : LinkedList F64
|
||||
nil = Nil
|
||||
|
||||
len nil
|
||||
|
@ -584,7 +584,7 @@ mod gen_primitives {
|
|||
|
||||
LinkedList a : [ Nil, Cons a (LinkedList a) ]
|
||||
|
||||
nil : LinkedList (Int *)
|
||||
nil : LinkedList I64
|
||||
nil = Nil
|
||||
|
||||
length : LinkedList a -> Int *
|
||||
|
@ -1407,9 +1407,9 @@ mod gen_primitives {
|
|||
balance 0 Empty
|
||||
"#
|
||||
),
|
||||
1,
|
||||
&i64,
|
||||
|x: &i64| *x
|
||||
false,
|
||||
*const i64,
|
||||
|x: *const i64| x.is_null()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1500,14 +1500,14 @@ mod gen_primitives {
|
|||
_ ->
|
||||
Node color key value left right
|
||||
|
||||
main : RedBlackTree (Int *) (Int *)
|
||||
main : RedBlackTree F64 F64
|
||||
main =
|
||||
balance Red 0 0 Empty Empty
|
||||
"#
|
||||
),
|
||||
1,
|
||||
&i64,
|
||||
|x: &i64| *x
|
||||
false,
|
||||
*const i64,
|
||||
|x: *const i64| x.is_null()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -1020,7 +1020,6 @@ fn path_to_expr_help<'a>(
|
|||
..
|
||||
} => {
|
||||
use std::cmp::Ordering;
|
||||
dbg!(nullable_id, tag_id);
|
||||
match (*tag_id as usize).cmp(&(*nullable_id as usize)) {
|
||||
Ordering::Equal => {
|
||||
// the nullable tag is going to pretend it stores a tag id
|
||||
|
|
|
@ -6225,8 +6225,6 @@ fn from_can_pattern_help<'a>(
|
|||
} => {
|
||||
debug_assert!(!other_fields.is_empty());
|
||||
|
||||
dbg!(nullable_id, &nullable_name);
|
||||
|
||||
ctors.push(Ctor {
|
||||
tag_id: TagId(nullable_id as u8),
|
||||
name: nullable_name.clone(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue