mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 08:34:33 +00:00
clippy
This commit is contained in:
parent
f2f9897187
commit
718aa34b19
4 changed files with 4 additions and 196 deletions
|
@ -17,8 +17,8 @@ use crate::llvm::build_str::{
|
||||||
};
|
};
|
||||||
use crate::llvm::compare::{generic_eq, generic_neq};
|
use crate::llvm::compare::{generic_eq, generic_neq};
|
||||||
use crate::llvm::convert::{
|
use crate::llvm::convert::{
|
||||||
basic_type_from_builtin, basic_type_from_function_layout, basic_type_from_layout,
|
basic_type_from_builtin, basic_type_from_layout, block_of_memory, block_of_memory_slices,
|
||||||
block_of_memory, block_of_memory_slices, ptr_int,
|
ptr_int,
|
||||||
};
|
};
|
||||||
use crate::llvm::refcounting::{
|
use crate::llvm::refcounting::{
|
||||||
decrement_refcount_layout, increment_refcount_layout, PointerToRefcount,
|
decrement_refcount_layout, increment_refcount_layout, PointerToRefcount,
|
||||||
|
@ -53,7 +53,6 @@ use roc_mono::ir::{
|
||||||
TopLevelFunctionLayout, Wrapped,
|
TopLevelFunctionLayout, Wrapped,
|
||||||
};
|
};
|
||||||
use roc_mono::layout::{Builtin, InPlace, LambdaSet, Layout, LayoutIds, UnionLayout};
|
use roc_mono::layout::{Builtin, InPlace, LambdaSet, Layout, LayoutIds, UnionLayout};
|
||||||
use std::convert::TryFrom;
|
|
||||||
|
|
||||||
/// This is for Inkwell's FunctionValue::verify - we want to know the verification
|
/// This is for Inkwell's FunctionValue::verify - we want to know the verification
|
||||||
/// output in debug builds, but we don't want it to print to stdout in release builds!
|
/// output in debug builds, but we don't want it to print to stdout in release builds!
|
||||||
|
@ -3400,122 +3399,6 @@ pub fn build_closure_caller<'a, 'ctx, 'env>(
|
||||||
build_host_exposed_alias_size(env, def_name, alias_symbol, layout);
|
build_host_exposed_alias_size(env, def_name, alias_symbol, layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_function_caller<'a, 'ctx, 'env>(
|
|
||||||
env: &'a Env<'a, 'ctx, 'env>,
|
|
||||||
def_name: &str,
|
|
||||||
alias_symbol: Symbol,
|
|
||||||
arguments: &[Layout<'a>],
|
|
||||||
result: &Layout<'a>,
|
|
||||||
) {
|
|
||||||
let context = &env.context;
|
|
||||||
let builder = env.builder;
|
|
||||||
|
|
||||||
// STEP 1: build function header
|
|
||||||
|
|
||||||
// e.g. `roc__main_1_Fx_caller`
|
|
||||||
let function_name = format!(
|
|
||||||
"roc_{}_{}_caller",
|
|
||||||
def_name,
|
|
||||||
alias_symbol.ident_string(&env.interns)
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut argument_types = Vec::with_capacity_in(arguments.len() + 3, env.arena);
|
|
||||||
|
|
||||||
for layout in arguments {
|
|
||||||
let arg_type = basic_type_from_layout(env, layout);
|
|
||||||
let arg_ptr_type = arg_type.ptr_type(AddressSpace::Generic);
|
|
||||||
|
|
||||||
argument_types.push(arg_ptr_type.into());
|
|
||||||
}
|
|
||||||
|
|
||||||
let function_pointer_type = {
|
|
||||||
let mut args = Vec::new_in(env.arena);
|
|
||||||
args.extend(arguments.iter().cloned());
|
|
||||||
|
|
||||||
// pretend the closure layout is empty
|
|
||||||
args.push(Layout::Struct(&[]));
|
|
||||||
|
|
||||||
// this is already a (function) pointer type
|
|
||||||
basic_type_from_function_layout(env, &args, result)
|
|
||||||
};
|
|
||||||
argument_types.push(function_pointer_type);
|
|
||||||
|
|
||||||
let closure_argument_type = {
|
|
||||||
let basic_type = basic_type_from_layout(env, &Layout::Struct(&[]));
|
|
||||||
|
|
||||||
basic_type.ptr_type(AddressSpace::Generic)
|
|
||||||
};
|
|
||||||
argument_types.push(closure_argument_type.into());
|
|
||||||
|
|
||||||
let result_type = basic_type_from_layout(env, result);
|
|
||||||
|
|
||||||
let roc_call_result_type =
|
|
||||||
context.struct_type(&[context.i64_type().into(), result_type], false);
|
|
||||||
|
|
||||||
let output_type = { roc_call_result_type.ptr_type(AddressSpace::Generic) };
|
|
||||||
argument_types.push(output_type.into());
|
|
||||||
|
|
||||||
let function_type = context.void_type().fn_type(&argument_types, false);
|
|
||||||
|
|
||||||
let function_value = add_func(
|
|
||||||
env.module,
|
|
||||||
function_name.as_str(),
|
|
||||||
function_type,
|
|
||||||
Linkage::External,
|
|
||||||
C_CALL_CONV,
|
|
||||||
);
|
|
||||||
|
|
||||||
// STEP 2: build function body
|
|
||||||
|
|
||||||
let entry = context.append_basic_block(function_value, "entry");
|
|
||||||
|
|
||||||
builder.position_at_end(entry);
|
|
||||||
|
|
||||||
let mut parameters = function_value.get_params();
|
|
||||||
let output = parameters.pop().unwrap().into_pointer_value();
|
|
||||||
let _closure_data_ptr = parameters.pop().unwrap().into_pointer_value();
|
|
||||||
let function_ptr = parameters.pop().unwrap().into_pointer_value();
|
|
||||||
|
|
||||||
let actual_function_type = basic_type_from_function_layout(env, arguments, result);
|
|
||||||
|
|
||||||
let function_ptr = builder
|
|
||||||
.build_bitcast(function_ptr, actual_function_type, "cast")
|
|
||||||
.into_pointer_value();
|
|
||||||
|
|
||||||
let mut parameters = parameters;
|
|
||||||
|
|
||||||
for param in parameters.iter_mut() {
|
|
||||||
debug_assert!(param.is_pointer_value());
|
|
||||||
*param = builder.build_load(param.into_pointer_value(), "load_param");
|
|
||||||
}
|
|
||||||
|
|
||||||
let call_result = invoke_and_catch(
|
|
||||||
env,
|
|
||||||
function_value,
|
|
||||||
CallableValue::try_from(function_ptr).unwrap(),
|
|
||||||
C_CALL_CONV,
|
|
||||||
¶meters,
|
|
||||||
result_type,
|
|
||||||
);
|
|
||||||
|
|
||||||
builder.build_store(output, call_result);
|
|
||||||
|
|
||||||
builder.build_return(None);
|
|
||||||
|
|
||||||
// STEP 3: build a {} -> u64 function that gives the size of the return type
|
|
||||||
build_host_exposed_alias_size_help(
|
|
||||||
env,
|
|
||||||
def_name,
|
|
||||||
alias_symbol,
|
|
||||||
Some("result"),
|
|
||||||
roc_call_result_type.into(),
|
|
||||||
);
|
|
||||||
|
|
||||||
// STEP 4: build a {} -> u64 function that gives the size of the function
|
|
||||||
let layout = Layout::Struct(&[]);
|
|
||||||
build_host_exposed_alias_size(env, def_name, alias_symbol, layout);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn build_host_exposed_alias_size<'a, 'ctx, 'env>(
|
fn build_host_exposed_alias_size<'a, 'ctx, 'env>(
|
||||||
env: &'a Env<'a, 'ctx, 'env>,
|
env: &'a Env<'a, 'ctx, 'env>,
|
||||||
def_name: &str,
|
def_name: &str,
|
||||||
|
@ -3584,7 +3467,6 @@ pub fn build_proc<'a, 'ctx, 'env>(
|
||||||
) {
|
) {
|
||||||
use roc_mono::ir::HostExposedLayouts;
|
use roc_mono::ir::HostExposedLayouts;
|
||||||
let copy = proc.host_exposed_layouts.clone();
|
let copy = proc.host_exposed_layouts.clone();
|
||||||
let fn_name = fn_val.get_name().to_string_lossy();
|
|
||||||
match copy {
|
match copy {
|
||||||
HostExposedLayouts::NotHostExposed => {}
|
HostExposedLayouts::NotHostExposed => {}
|
||||||
HostExposedLayouts::HostExposed { rigids: _, aliases } => {
|
HostExposedLayouts::HostExposed { rigids: _, aliases } => {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#![allow(clippy::too_many_arguments)]
|
#![allow(clippy::too_many_arguments)]
|
||||||
use crate::llvm::bitcode::{
|
use crate::llvm::bitcode::{
|
||||||
build_dec_wrapper, build_eq_wrapper, build_inc_n_wrapper, build_inc_wrapper,
|
build_dec_wrapper, build_eq_wrapper, build_inc_n_wrapper, build_inc_wrapper, call_bitcode_fn,
|
||||||
build_transform_caller, call_bitcode_fn, call_void_bitcode_fn,
|
call_void_bitcode_fn,
|
||||||
};
|
};
|
||||||
use crate::llvm::build::{
|
use crate::llvm::build::{
|
||||||
allocate_with_refcount_help, cast_basic_basic, complex_bitcast, Env, RocFunctionCall,
|
allocate_with_refcount_help, cast_basic_basic, complex_bitcast, Env, RocFunctionCall,
|
||||||
|
@ -658,53 +658,6 @@ pub fn list_keep_errs<'a, 'ctx, 'env>(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn list_keep_result<'a, 'ctx, 'env>(
|
|
||||||
env: &Env<'a, 'ctx, 'env>,
|
|
||||||
layout_ids: &mut LayoutIds<'a>,
|
|
||||||
transform: FunctionValue<'ctx>,
|
|
||||||
transform_layout: Layout<'a>,
|
|
||||||
closure_data: BasicValueEnum<'ctx>,
|
|
||||||
closure_data_layout: Layout<'a>,
|
|
||||||
list: BasicValueEnum<'ctx>,
|
|
||||||
before_layout: &Layout<'a>,
|
|
||||||
after_layout: &Layout<'a>,
|
|
||||||
op: &str,
|
|
||||||
) -> BasicValueEnum<'ctx> {
|
|
||||||
let builder = env.builder;
|
|
||||||
|
|
||||||
let result_layout = match transform_layout {
|
|
||||||
Layout::Closure(_, _, ret) => ret,
|
|
||||||
_ => unreachable!("not a callable layout"),
|
|
||||||
};
|
|
||||||
|
|
||||||
let closure_data_ptr = builder.build_alloca(closure_data.get_type(), "closure_data_ptr");
|
|
||||||
env.builder.build_store(closure_data_ptr, closure_data);
|
|
||||||
|
|
||||||
let stepper_caller =
|
|
||||||
build_transform_caller(env, transform, closure_data_layout, &[*before_layout])
|
|
||||||
.as_global_value()
|
|
||||||
.as_pointer_value();
|
|
||||||
|
|
||||||
let inc_closure = build_inc_wrapper(env, layout_ids, &transform_layout);
|
|
||||||
let dec_result_fn = build_dec_wrapper(env, layout_ids, result_layout);
|
|
||||||
|
|
||||||
call_bitcode_fn(
|
|
||||||
env,
|
|
||||||
&[
|
|
||||||
pass_list_as_i128(env, list),
|
|
||||||
pass_as_opaque(env, closure_data_ptr),
|
|
||||||
stepper_caller.into(),
|
|
||||||
env.alignment_intvalue(&before_layout),
|
|
||||||
layout_width(env, before_layout),
|
|
||||||
layout_width(env, after_layout),
|
|
||||||
layout_width(env, result_layout),
|
|
||||||
inc_closure.as_global_value().as_pointer_value().into(),
|
|
||||||
dec_result_fn.as_global_value().as_pointer_value().into(),
|
|
||||||
],
|
|
||||||
op,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// List.sortWith : List a, (a, a -> Ordering) -> List a
|
/// List.sortWith : List a, (a, a -> Ordering) -> List a
|
||||||
pub fn list_sort_with<'a, 'ctx, 'env>(
|
pub fn list_sort_with<'a, 'ctx, 'env>(
|
||||||
env: &Env<'a, 'ctx, 'env>,
|
env: &Env<'a, 'ctx, 'env>,
|
||||||
|
|
|
@ -4,24 +4,6 @@ use inkwell::types::{BasicType, BasicTypeEnum, IntType, StructType};
|
||||||
use inkwell::AddressSpace;
|
use inkwell::AddressSpace;
|
||||||
use roc_mono::layout::{Builtin, Layout, UnionLayout};
|
use roc_mono::layout::{Builtin, Layout, UnionLayout};
|
||||||
|
|
||||||
pub fn basic_type_from_function_layout<'a, 'ctx, 'env>(
|
|
||||||
env: &crate::llvm::build::Env<'a, 'ctx, 'env>,
|
|
||||||
args: &[Layout<'_>],
|
|
||||||
ret_layout: &Layout<'_>,
|
|
||||||
) -> BasicTypeEnum<'ctx> {
|
|
||||||
let ret_type = basic_type_from_layout(env, &ret_layout);
|
|
||||||
let mut arg_basic_types = Vec::with_capacity_in(args.len(), env.arena);
|
|
||||||
|
|
||||||
for arg_layout in args.iter() {
|
|
||||||
arg_basic_types.push(basic_type_from_layout(env, arg_layout));
|
|
||||||
}
|
|
||||||
|
|
||||||
let fn_type = ret_type.fn_type(arg_basic_types.into_bump_slice(), false);
|
|
||||||
let ptr_type = fn_type.ptr_type(AddressSpace::Generic);
|
|
||||||
|
|
||||||
ptr_type.as_basic_type_enum()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn basic_type_from_record<'a, 'ctx, 'env>(
|
fn basic_type_from_record<'a, 'ctx, 'env>(
|
||||||
env: &crate::llvm::build::Env<'a, 'ctx, 'env>,
|
env: &crate::llvm::build::Env<'a, 'ctx, 'env>,
|
||||||
fields: &[Layout<'_>],
|
fields: &[Layout<'_>],
|
||||||
|
|
|
@ -203,15 +203,6 @@ impl<'a> LambdaSet<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extend_function_layout(
|
|
||||||
&self,
|
|
||||||
arena: &'a Bump,
|
|
||||||
argument_layouts: &'a [Layout<'a>],
|
|
||||||
ret_layout: &'a Layout<'a>,
|
|
||||||
) -> Layout<'a> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn extend_argument_list(
|
pub fn extend_argument_list(
|
||||||
&self,
|
&self,
|
||||||
arena: &'a Bump,
|
arena: &'a Bump,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue