mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 19:58:18 +00:00
Merge branch 'list-unsafe-append' into can-builtins-cleanup
This commit is contained in:
commit
0f86886ab7
24 changed files with 249 additions and 470 deletions
|
@ -39,7 +39,7 @@ use inkwell::types::{
|
|||
};
|
||||
use inkwell::values::BasicValueEnum::{self, *};
|
||||
use inkwell::values::{
|
||||
BasicMetadataValueEnum, BasicValue, CallSiteValue, CallableValue, FloatValue, FunctionValue,
|
||||
BasicMetadataValueEnum, BasicValue, CallSiteValue, FloatValue, FunctionValue,
|
||||
InstructionOpcode, InstructionValue, IntValue, PhiValue, PointerValue, StructValue,
|
||||
};
|
||||
use inkwell::OptimizationLevel;
|
||||
|
@ -65,7 +65,7 @@ use roc_mono::layout::{
|
|||
};
|
||||
use roc_std::RocDec;
|
||||
use roc_target::{PtrWidth, TargetInfo};
|
||||
use std::convert::{TryFrom, TryInto};
|
||||
use std::convert::TryInto;
|
||||
use std::path::Path;
|
||||
use target_lexicon::{Architecture, OperatingSystem, Triple};
|
||||
|
||||
|
@ -2779,30 +2779,8 @@ pub fn build_exp_stmt<'a, 'ctx, 'env>(
|
|||
|
||||
match env.target_info.ptr_width() {
|
||||
roc_target::PtrWidth::Bytes8 => {
|
||||
let func = env
|
||||
.module
|
||||
.get_function(bitcode::UTILS_EXPECT_FAILED)
|
||||
.unwrap();
|
||||
// TODO get the actual line info instead of
|
||||
// hardcoding as zero!
|
||||
let callable = CallableValue::try_from(func).unwrap();
|
||||
let start_line = context.i32_type().const_int(0, false);
|
||||
let end_line = context.i32_type().const_int(0, false);
|
||||
let start_col = context.i16_type().const_int(0, false);
|
||||
let end_col = context.i16_type().const_int(0, false);
|
||||
|
||||
bd.build_call(
|
||||
callable,
|
||||
&[
|
||||
start_line.into(),
|
||||
end_line.into(),
|
||||
start_col.into(),
|
||||
end_col.into(),
|
||||
],
|
||||
"call_expect_failed",
|
||||
);
|
||||
|
||||
bd.build_unconditional_branch(then_block);
|
||||
// temporary native implementation
|
||||
throw_exception(env, "An expectation failed!");
|
||||
}
|
||||
roc_target::PtrWidth::Bytes4 => {
|
||||
// temporary WASM implementation
|
||||
|
|
|
@ -47,43 +47,6 @@ pub fn add_default_roc_externs(env: &Env<'_, '_, '_>) {
|
|||
}
|
||||
}
|
||||
|
||||
// roc_memcpy
|
||||
{
|
||||
// The type of this function (but not the implementation) should have
|
||||
// already been defined by the builtins, which rely on it.
|
||||
let fn_val = module.get_function("roc_memcpy").unwrap();
|
||||
let mut params = fn_val.get_param_iter();
|
||||
let dest_arg = params.next().unwrap();
|
||||
let dest_alignment = 1;
|
||||
let src_arg = params.next().unwrap();
|
||||
let src_alignment = 1;
|
||||
let bytes_arg = params.next().unwrap();
|
||||
|
||||
debug_assert!(params.next().is_none());
|
||||
|
||||
// Add a basic block for the entry point
|
||||
let entry = ctx.append_basic_block(fn_val, "entry");
|
||||
|
||||
builder.position_at_end(entry);
|
||||
|
||||
// Call libc memcpy()
|
||||
let _retval = builder
|
||||
.build_memcpy(
|
||||
dest_arg.into_pointer_value(),
|
||||
dest_alignment,
|
||||
src_arg.into_pointer_value(),
|
||||
src_alignment,
|
||||
bytes_arg.into_int_value(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
builder.build_return(None);
|
||||
|
||||
if cfg!(debug_assertions) {
|
||||
crate::llvm::build::verify_fn(fn_val);
|
||||
}
|
||||
}
|
||||
|
||||
// roc_realloc
|
||||
{
|
||||
let libc_realloc_val = {
|
||||
|
|
|
@ -89,15 +89,6 @@ macro_rules! run_jit_function {
|
|||
use roc_gen_llvm::run_roc::RocCallResult;
|
||||
use std::mem::MaybeUninit;
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
#[repr(C)]
|
||||
struct Failure {
|
||||
start_line: u32,
|
||||
end_line: u32,
|
||||
start_col: u16,
|
||||
end_col: u16,
|
||||
}
|
||||
|
||||
unsafe {
|
||||
let main: libloading::Symbol<unsafe extern "C" fn(*mut RocCallResult<$ty>)> = $lib
|
||||
.get($main_fn_name.as_bytes())
|
||||
|
@ -105,48 +96,8 @@ macro_rules! run_jit_function {
|
|||
.ok_or(format!("Unable to JIT compile `{}`", $main_fn_name))
|
||||
.expect("errored");
|
||||
|
||||
#[repr(C)]
|
||||
struct Failures {
|
||||
failures: *const Failure,
|
||||
count: usize,
|
||||
}
|
||||
|
||||
impl Drop for Failures {
|
||||
fn drop(&mut self) {
|
||||
use std::alloc::{dealloc, Layout};
|
||||
use std::mem;
|
||||
|
||||
unsafe {
|
||||
let layout = Layout::from_size_align_unchecked(
|
||||
mem::size_of::<Failure>(),
|
||||
mem::align_of::<Failure>(),
|
||||
);
|
||||
|
||||
dealloc(self.failures as *mut u8, layout);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let get_expect_failures: libloading::Symbol<unsafe extern "C" fn() -> Failures> = $lib
|
||||
.get(bitcode::UTILS_GET_EXPECT_FAILURES.as_bytes())
|
||||
.ok()
|
||||
.ok_or(format!(
|
||||
"Unable to JIT compile `{}`",
|
||||
bitcode::UTILS_GET_EXPECT_FAILURES
|
||||
))
|
||||
.expect("errored");
|
||||
let mut main_result = MaybeUninit::uninit();
|
||||
|
||||
main(main_result.as_mut_ptr());
|
||||
let failures = get_expect_failures();
|
||||
|
||||
if failures.count > 0 {
|
||||
// TODO tell the user about the failures!
|
||||
let failures =
|
||||
unsafe { core::slice::from_raw_parts(failures.failures, failures.count) };
|
||||
|
||||
panic!("Failed with {} failures. Failures: ", failures.len());
|
||||
}
|
||||
|
||||
match main_result.assume_init().into() {
|
||||
Ok(success) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue