mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 16:21:11 +00:00
more wip; now we just need to generate the exposed procs at the right time
This commit is contained in:
commit
6c15284a8f
255 changed files with 11686 additions and 3025 deletions
|
@ -24,8 +24,8 @@ use inkwell::types::{
|
|||
};
|
||||
use inkwell::values::BasicValueEnum::{self, *};
|
||||
use inkwell::values::{
|
||||
BasicMetadataValueEnum, BasicValue, CallSiteValue, FunctionValue, InstructionValue, IntValue,
|
||||
PhiValue, PointerValue, StructValue,
|
||||
BasicMetadataValueEnum, CallSiteValue, FunctionValue, InstructionValue, IntValue, PhiValue,
|
||||
PointerValue, StructValue,
|
||||
};
|
||||
use inkwell::OptimizationLevel;
|
||||
use inkwell::{AddressSpace, IntPredicate};
|
||||
|
@ -37,7 +37,6 @@ use roc_collections::all::{ImMap, MutMap, MutSet};
|
|||
use roc_debug_flags::dbg_do;
|
||||
#[cfg(debug_assertions)]
|
||||
use roc_debug_flags::ROC_PRINT_LLVM_FN_VERIFICATION;
|
||||
use roc_error_macros::internal_error;
|
||||
use roc_module::symbol::{Interns, ModuleId, Symbol};
|
||||
use roc_mono::ir::{
|
||||
BranchInfo, CallType, CrashTag, EntryPoint, GlueLayouts, JoinPointId, ListLiteralElement,
|
||||
|
@ -157,7 +156,7 @@ macro_rules! debug_info_init {
|
|||
/* current_scope */ lexical_block.as_debug_info_scope(),
|
||||
/* inlined_at */ None,
|
||||
);
|
||||
$env.builder.set_current_debug_location(&$env.context, loc);
|
||||
$env.builder.set_current_debug_location(loc);
|
||||
}};
|
||||
}
|
||||
|
||||
|
@ -686,7 +685,7 @@ fn promote_to_wasm_test_wrapper<'a, 'ctx, 'env>(
|
|||
|
||||
let output_type = match roc_main_fn.get_type().get_return_type() {
|
||||
Some(return_type) => {
|
||||
let output_type = return_type.ptr_type(AddressSpace::Generic);
|
||||
let output_type = return_type.ptr_type(AddressSpace::default());
|
||||
output_type.into()
|
||||
}
|
||||
None => {
|
||||
|
@ -880,7 +879,7 @@ fn small_str_ptr_width_8<'a, 'ctx, 'env>(
|
|||
let len = env.ptr_int().const_int(word2, false);
|
||||
let cap = env.ptr_int().const_int(word3, false);
|
||||
|
||||
let address_space = AddressSpace::Generic;
|
||||
let address_space = AddressSpace::default();
|
||||
let ptr_type = env.context.i8_type().ptr_type(address_space);
|
||||
let ptr = env.builder.build_int_to_ptr(ptr, ptr_type, "to_u8_ptr");
|
||||
|
||||
|
@ -907,7 +906,7 @@ fn small_str_ptr_width_4<'a, 'ctx, 'env>(
|
|||
let len = env.ptr_int().const_int(word2 as u64, false);
|
||||
let cap = env.ptr_int().const_int(word3 as u64, false);
|
||||
|
||||
let address_space = AddressSpace::Generic;
|
||||
let address_space = AddressSpace::default();
|
||||
let ptr_type = env.context.i8_type().ptr_type(address_space);
|
||||
let ptr = env.builder.build_int_to_ptr(ptr, ptr_type, "to_u8_ptr");
|
||||
|
||||
|
@ -1049,7 +1048,7 @@ fn struct_pointer_from_fields<'a, 'ctx, 'env, I>(
|
|||
.builder
|
||||
.build_bitcast(
|
||||
input_pointer,
|
||||
struct_type.ptr_type(AddressSpace::Generic),
|
||||
struct_type.ptr_type(AddressSpace::default()),
|
||||
"struct_ptr",
|
||||
)
|
||||
.into_pointer_value();
|
||||
|
@ -1310,7 +1309,7 @@ pub fn build_exp_expr<'a, 'ctx, 'env>(
|
|||
|
||||
let data_ptr = env.builder.build_pointer_cast(
|
||||
opaque_data_ptr,
|
||||
struct_type.ptr_type(AddressSpace::Generic),
|
||||
struct_type.ptr_type(AddressSpace::default()),
|
||||
"to_data_pointer",
|
||||
);
|
||||
|
||||
|
@ -1528,14 +1527,14 @@ fn build_tag_field_value<'a, 'ctx, 'env>(
|
|||
value: BasicValueEnum<'ctx>,
|
||||
tag_field_layout: InLayout<'a>,
|
||||
) -> BasicValueEnum<'ctx> {
|
||||
if let Layout::RecursivePointer = layout_interner.get(tag_field_layout) {
|
||||
if let Layout::RecursivePointer(_) = layout_interner.get(tag_field_layout) {
|
||||
debug_assert!(value.is_pointer_value());
|
||||
|
||||
// we store recursive pointers as `i64*`
|
||||
env.builder
|
||||
.build_pointer_cast(
|
||||
value.into_pointer_value(),
|
||||
env.context.i64_type().ptr_type(AddressSpace::Generic),
|
||||
env.context.i64_type().ptr_type(AddressSpace::default()),
|
||||
"cast_recursive_pointer",
|
||||
)
|
||||
.into()
|
||||
|
@ -1751,7 +1750,7 @@ fn build_tag<'a, 'ctx, 'env>(
|
|||
);
|
||||
|
||||
if tag_id == *nullable_id as _ {
|
||||
let output_type = roc_union.struct_type().ptr_type(AddressSpace::Generic);
|
||||
let output_type = roc_union.struct_type().ptr_type(AddressSpace::default());
|
||||
|
||||
return output_type.const_null().into();
|
||||
}
|
||||
|
@ -2003,7 +2002,7 @@ fn lookup_at_index_ptr<'a, 'ctx, 'env>(
|
|||
|
||||
let ptr = env.builder.build_pointer_cast(
|
||||
value,
|
||||
struct_type.ptr_type(AddressSpace::Generic),
|
||||
struct_type.ptr_type(AddressSpace::default()),
|
||||
"cast_lookup_at_index_ptr",
|
||||
);
|
||||
|
||||
|
@ -2020,7 +2019,7 @@ fn lookup_at_index_ptr<'a, 'ctx, 'env>(
|
|||
"load_at_index_ptr_old",
|
||||
);
|
||||
|
||||
if let Some(Layout::RecursivePointer) = field_layouts
|
||||
if let Some(Layout::RecursivePointer(_)) = field_layouts
|
||||
.get(index as usize)
|
||||
.map(|l| layout_interner.get(*l))
|
||||
{
|
||||
|
@ -2058,7 +2057,7 @@ fn lookup_at_index_ptr2<'a, 'ctx, 'env>(
|
|||
|
||||
let data_ptr = env.builder.build_pointer_cast(
|
||||
value,
|
||||
struct_type.ptr_type(AddressSpace::Generic),
|
||||
struct_type.ptr_type(AddressSpace::default()),
|
||||
"cast_lookup_at_index_ptr",
|
||||
);
|
||||
|
||||
|
@ -2080,7 +2079,7 @@ fn lookup_at_index_ptr2<'a, 'ctx, 'env>(
|
|||
"load_at_index_ptr",
|
||||
);
|
||||
|
||||
if let Some(Layout::RecursivePointer) = field_layouts
|
||||
if let Some(Layout::RecursivePointer(_)) = field_layouts
|
||||
.get(index as usize)
|
||||
.map(|l| layout_interner.get(*l))
|
||||
{
|
||||
|
@ -2181,7 +2180,7 @@ pub fn allocate_with_refcount_help<'a, 'ctx, 'env>(
|
|||
)
|
||||
.into_pointer_value();
|
||||
|
||||
let ptr_type = value_type.ptr_type(AddressSpace::Generic);
|
||||
let ptr_type = value_type.ptr_type(AddressSpace::default());
|
||||
|
||||
env.builder
|
||||
.build_pointer_cast(ptr, ptr_type, "alloc_cast_to_desired")
|
||||
|
@ -2406,7 +2405,7 @@ pub fn store_roc_value_opaque<'a, 'ctx, 'env>(
|
|||
value: BasicValueEnum<'ctx>,
|
||||
) {
|
||||
let target_type =
|
||||
basic_type_from_layout(env, layout_interner, layout).ptr_type(AddressSpace::Generic);
|
||||
basic_type_from_layout(env, layout_interner, layout).ptr_type(AddressSpace::default());
|
||||
let destination =
|
||||
env.builder
|
||||
.build_pointer_cast(opaque_destination, target_type, "store_roc_value_opaque");
|
||||
|
@ -2481,7 +2480,10 @@ pub fn build_exp_stmt<'a, 'ctx, 'env>(
|
|||
let mut stack = Vec::with_capacity_in(queue.len(), env.arena);
|
||||
|
||||
for (symbol, expr, layout) in queue {
|
||||
debug_assert!(layout_interner.get(*layout) != Layout::RecursivePointer);
|
||||
debug_assert!(!matches!(
|
||||
layout_interner.get(*layout),
|
||||
Layout::RecursivePointer(_)
|
||||
));
|
||||
|
||||
let val = build_exp_expr(
|
||||
env,
|
||||
|
@ -2656,7 +2658,7 @@ pub fn build_exp_stmt<'a, 'ctx, 'env>(
|
|||
let basic_type = basic_type_from_layout(env, layout_interner, param.layout);
|
||||
|
||||
let phi_type = if layout_interner.is_passed_by_reference(param.layout) {
|
||||
basic_type.ptr_type(AddressSpace::Generic).into()
|
||||
basic_type.ptr_type(AddressSpace::default()).into()
|
||||
} else {
|
||||
basic_type
|
||||
};
|
||||
|
@ -3199,7 +3201,7 @@ fn complex_bitcast_from_bigger_than_to<'ctx>(
|
|||
// then read it back as a different type
|
||||
let to_type_pointer = builder.build_pointer_cast(
|
||||
argument_pointer,
|
||||
to_type.ptr_type(inkwell::AddressSpace::Generic),
|
||||
to_type.ptr_type(inkwell::AddressSpace::default()),
|
||||
name,
|
||||
);
|
||||
|
||||
|
@ -3222,7 +3224,7 @@ fn complex_bitcast_to_bigger_than_from<'ctx>(
|
|||
storage,
|
||||
from_value
|
||||
.get_type()
|
||||
.ptr_type(inkwell::AddressSpace::Generic),
|
||||
.ptr_type(inkwell::AddressSpace::default()),
|
||||
name,
|
||||
);
|
||||
|
||||
|
@ -3583,7 +3585,7 @@ fn expose_function_to_host_help_c_abi_generic<'a, 'ctx, 'env>(
|
|||
argument_types.insert(0, output_type);
|
||||
}
|
||||
Some(return_type) => {
|
||||
let output_type = return_type.ptr_type(AddressSpace::Generic);
|
||||
let output_type = return_type.ptr_type(AddressSpace::default());
|
||||
argument_types.insert(0, output_type.into());
|
||||
}
|
||||
}
|
||||
|
@ -3635,7 +3637,7 @@ fn expose_function_to_host_help_c_abi_generic<'a, 'ctx, 'env>(
|
|||
// bitcast the ptr
|
||||
let fastcc_ptr = env.builder.build_pointer_cast(
|
||||
arg.into_pointer_value(),
|
||||
fastcc_type.ptr_type(AddressSpace::Generic),
|
||||
fastcc_type.ptr_type(AddressSpace::default()),
|
||||
"bitcast_arg",
|
||||
);
|
||||
|
||||
|
@ -3730,7 +3732,7 @@ fn expose_function_to_host_help_c_abi_gen_test<'a, 'ctx, 'env>(
|
|||
let return_type = wrapper_return_type;
|
||||
|
||||
let c_function_spec = {
|
||||
let output_type = return_type.ptr_type(AddressSpace::Generic);
|
||||
let output_type = return_type.ptr_type(AddressSpace::default());
|
||||
argument_types.push(output_type.into());
|
||||
FunctionSpec::cconv(env, CCReturn::Void, None, &argument_types)
|
||||
};
|
||||
|
@ -3894,7 +3896,10 @@ fn expose_function_to_host_help_c_abi_v2<'a, 'ctx, 'env>(
|
|||
|
||||
let c_abi_roc_str_type = env.context.struct_type(
|
||||
&[
|
||||
env.context.i8_type().ptr_type(AddressSpace::Generic).into(),
|
||||
env.context
|
||||
.i8_type()
|
||||
.ptr_type(AddressSpace::default())
|
||||
.into(),
|
||||
env.ptr_int().into(),
|
||||
env.ptr_int().into(),
|
||||
],
|
||||
|
@ -4013,7 +4018,7 @@ fn expose_function_to_host_help_c_abi_v2<'a, 'ctx, 'env>(
|
|||
// bitcast the ptr
|
||||
let fastcc_ptr = env.builder.build_pointer_cast(
|
||||
arg.into_pointer_value(),
|
||||
fastcc_type.ptr_type(AddressSpace::Generic),
|
||||
fastcc_type.ptr_type(AddressSpace::default()),
|
||||
"bitcast_arg",
|
||||
);
|
||||
|
||||
|
@ -4190,7 +4195,7 @@ pub fn get_sjlj_buffer<'a, 'ctx, 'env>(env: &Env<'a, 'ctx, 'env>) -> PointerValu
|
|||
|
||||
env.builder.build_pointer_cast(
|
||||
global.as_pointer_value(),
|
||||
env.context.i32_type().ptr_type(AddressSpace::Generic),
|
||||
env.context.i32_type().ptr_type(AddressSpace::default()),
|
||||
"cast_sjlj_buffer",
|
||||
)
|
||||
}
|
||||
|
@ -4207,12 +4212,12 @@ pub fn build_setjmp_call<'a, 'ctx, 'env>(env: &Env<'a, 'ctx, 'env>) -> BasicValu
|
|||
let buf_type = env
|
||||
.context
|
||||
.i8_type()
|
||||
.ptr_type(AddressSpace::Generic)
|
||||
.ptr_type(AddressSpace::default())
|
||||
.array_type(5);
|
||||
|
||||
let jmp_buf_i8p_arr = env.builder.build_pointer_cast(
|
||||
jmp_buf,
|
||||
buf_type.ptr_type(AddressSpace::Generic),
|
||||
buf_type.ptr_type(AddressSpace::default()),
|
||||
"jmp_buf [5 x i8*]",
|
||||
);
|
||||
|
||||
|
@ -4253,7 +4258,7 @@ pub fn build_setjmp_call<'a, 'ctx, 'env>(env: &Env<'a, 'ctx, 'env>) -> BasicValu
|
|||
.builder
|
||||
.build_pointer_cast(
|
||||
jmp_buf,
|
||||
env.context.i8_type().ptr_type(AddressSpace::Generic),
|
||||
env.context.i8_type().ptr_type(AddressSpace::default()),
|
||||
"jmp_buf i8*",
|
||||
)
|
||||
.into();
|
||||
|
@ -4410,7 +4415,7 @@ fn roc_call_result_type<'a, 'ctx, 'env>(
|
|||
env.context.struct_type(
|
||||
&[
|
||||
env.context.i64_type().into(),
|
||||
zig_str_type(env).ptr_type(AddressSpace::Generic).into(),
|
||||
zig_str_type(env).ptr_type(AddressSpace::default()).into(),
|
||||
return_type,
|
||||
],
|
||||
false,
|
||||
|
@ -4486,7 +4491,7 @@ fn make_exception_catching_wrapper<'a, 'ctx, 'env>(
|
|||
basic_type_from_layout(env, layout_interner, return_layout),
|
||||
);
|
||||
|
||||
// argument_types.push(wrapper_return_type.ptr_type(AddressSpace::Generic).into());
|
||||
// argument_types.push(wrapper_return_type.ptr_type(AddressSpace::default()).into());
|
||||
|
||||
// let wrapper_function_type = env.context.void_type().fn_type(&argument_types, false);
|
||||
let wrapper_function_spec = FunctionSpec::cconv(
|
||||
|
@ -5050,7 +5055,7 @@ fn build_closure_caller<'a, 'ctx, 'env>(
|
|||
|
||||
for layout in arguments {
|
||||
let arg_type = basic_type_from_layout(env, layout_interner, *layout);
|
||||
let arg_ptr_type = arg_type.ptr_type(AddressSpace::Generic);
|
||||
let arg_ptr_type = arg_type.ptr_type(AddressSpace::default());
|
||||
|
||||
argument_types.push(arg_ptr_type.into());
|
||||
}
|
||||
|
@ -5059,7 +5064,7 @@ fn build_closure_caller<'a, 'ctx, 'env>(
|
|||
let basic_type =
|
||||
basic_type_from_layout(env, layout_interner, lambda_set.runtime_representation());
|
||||
|
||||
basic_type.ptr_type(AddressSpace::Generic)
|
||||
basic_type.ptr_type(AddressSpace::default())
|
||||
};
|
||||
argument_types.push(closure_argument_type.into());
|
||||
|
||||
|
@ -5068,7 +5073,7 @@ fn build_closure_caller<'a, 'ctx, 'env>(
|
|||
|
||||
let result_type = basic_type_from_layout(env, layout_interner, result);
|
||||
|
||||
let output_type = { result_type.ptr_type(AddressSpace::Generic) };
|
||||
let output_type = { result_type.ptr_type(AddressSpace::default()) };
|
||||
argument_types.push(output_type.into());
|
||||
|
||||
// STEP 1: build function header
|
||||
|
@ -5584,7 +5589,7 @@ fn to_cc_type_builtin<'a, 'ctx, 'env>(
|
|||
basic_type_from_builtin(env, builtin)
|
||||
}
|
||||
Builtin::Str | Builtin::List(_) => {
|
||||
let address_space = AddressSpace::Generic;
|
||||
let address_space = AddressSpace::default();
|
||||
let field_types: [BasicTypeEnum; 3] = [
|
||||
env.context.i8_type().ptr_type(address_space).into(),
|
||||
env.ptr_int().into(),
|
||||
|
@ -5699,7 +5704,7 @@ impl<'ctx> FunctionSpec<'ctx> {
|
|||
let (typ, opt_sret_parameter) = match cc_return {
|
||||
CCReturn::ByPointer => {
|
||||
// turn the output type into a pointer type. Make it the first argument to the function
|
||||
let output_type = return_type.unwrap().ptr_type(AddressSpace::Generic);
|
||||
let output_type = return_type.unwrap().ptr_type(AddressSpace::default());
|
||||
|
||||
let mut arguments: Vec<'_, BasicTypeEnum> =
|
||||
bumpalo::vec![in env.arena; output_type.into()];
|
||||
|
@ -5741,7 +5746,7 @@ impl<'ctx> FunctionSpec<'ctx> {
|
|||
return_type.fn_type(&function_arguments(env, &argument_types), false)
|
||||
}
|
||||
RocReturn::ByPointer => {
|
||||
argument_types.push(return_type.ptr_type(AddressSpace::Generic).into());
|
||||
argument_types.push(return_type.ptr_type(AddressSpace::default()).into());
|
||||
env.context
|
||||
.void_type()
|
||||
.fn_type(&function_arguments(env, &argument_types), false)
|
||||
|
@ -5989,7 +5994,7 @@ fn define_global_str_literal_ptr<'a, 'ctx, 'env>(
|
|||
|
||||
let ptr = env.builder.build_pointer_cast(
|
||||
global.as_pointer_value(),
|
||||
env.context.i8_type().ptr_type(AddressSpace::Generic),
|
||||
env.context.i8_type().ptr_type(AddressSpace::default()),
|
||||
"to_opaque",
|
||||
);
|
||||
|
||||
|
@ -6134,23 +6139,3 @@ pub fn add_func<'ctx>(
|
|||
|
||||
fn_val
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub(crate) enum WhenRecursive<'a> {
|
||||
Unreachable,
|
||||
Loop(UnionLayout<'a>),
|
||||
}
|
||||
|
||||
impl<'a> WhenRecursive<'a> {
|
||||
pub fn unwrap_recursive_pointer(&self, layout: Layout<'a>) -> Layout<'a> {
|
||||
match layout {
|
||||
Layout::RecursivePointer => match self {
|
||||
WhenRecursive::Loop(lay) => Layout::Union(*lay),
|
||||
WhenRecursive::Unreachable => {
|
||||
internal_error!("cannot compare recursive pointers outside of a structure")
|
||||
}
|
||||
},
|
||||
_ => layout,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue