mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +00:00
Merge remote-tracking branch 'origin/trunk' into builtins-in-roc
This commit is contained in:
commit
adf4ad22a5
90 changed files with 3197 additions and 2191 deletions
|
@ -13,7 +13,7 @@ use crate::llvm::build_list::{
|
|||
self, allocate_list, empty_polymorphic_list, list_all, list_any, list_append, list_concat,
|
||||
list_contains, list_drop_at, list_find_unsafe, list_get_unsafe, list_join, list_keep_errs,
|
||||
list_keep_if, list_keep_oks, list_len, list_map, list_map2, list_map3, list_map4,
|
||||
list_map_with_index, list_prepend, list_range, list_repeat, list_reverse, list_set,
|
||||
list_map_with_index, list_prepend, list_range, list_repeat, list_replace_unsafe, list_reverse,
|
||||
list_single, list_sort_with, list_sublist, list_swap,
|
||||
};
|
||||
use crate::llvm::build_str::{
|
||||
|
@ -710,7 +710,7 @@ fn promote_to_main_function<'a, 'ctx, 'env>(
|
|||
top_level: ProcLayout<'a>,
|
||||
) -> (&'static str, FunctionValue<'ctx>) {
|
||||
let it = top_level.arguments.iter().copied();
|
||||
let bytes = roc_mono::alias_analysis::func_name_bytes_help(symbol, it, &top_level.result);
|
||||
let bytes = roc_alias_analysis::func_name_bytes_help(symbol, it, &top_level.result);
|
||||
let func_name = FuncName(&bytes);
|
||||
let func_solutions = mod_solutions.func_solutions(func_name).unwrap();
|
||||
|
||||
|
@ -4045,7 +4045,7 @@ pub fn build_proc_headers<'a, 'ctx, 'env>(
|
|||
// Populate Procs further and get the low-level Expr from the canonical Expr
|
||||
let mut headers = Vec::with_capacity_in(procedures.len(), env.arena);
|
||||
for ((symbol, layout), proc) in procedures {
|
||||
let name_bytes = roc_mono::alias_analysis::func_name_bytes(&proc);
|
||||
let name_bytes = roc_alias_analysis::func_name_bytes(&proc);
|
||||
let func_name = FuncName(&name_bytes);
|
||||
|
||||
let func_solutions = mod_solutions.func_solutions(func_name).unwrap();
|
||||
|
@ -4110,7 +4110,7 @@ fn build_procedures_help<'a, 'ctx, 'env>(
|
|||
|
||||
let it = procedures.iter().map(|x| x.1);
|
||||
|
||||
let solutions = match roc_mono::alias_analysis::spec_program(opt_level, entry_point, it) {
|
||||
let solutions = match roc_alias_analysis::spec_program(opt_level, entry_point, it) {
|
||||
Err(e) => panic!("Error in alias analysis: {}", e),
|
||||
Ok(solutions) => solutions,
|
||||
};
|
||||
|
@ -4118,7 +4118,7 @@ fn build_procedures_help<'a, 'ctx, 'env>(
|
|||
let solutions = env.arena.alloc(solutions);
|
||||
|
||||
let mod_solutions = solutions
|
||||
.mod_solutions(roc_mono::alias_analysis::MOD_APP)
|
||||
.mod_solutions(roc_alias_analysis::MOD_APP)
|
||||
.unwrap();
|
||||
|
||||
// Add all the Proc headers to the module.
|
||||
|
@ -4470,11 +4470,8 @@ pub fn build_proc<'a, 'ctx, 'env>(
|
|||
// * roc__mainForHost_1_Update_result_size() -> i64
|
||||
|
||||
let it = top_level.arguments.iter().copied();
|
||||
let bytes = roc_mono::alias_analysis::func_name_bytes_help(
|
||||
symbol,
|
||||
it,
|
||||
&top_level.result,
|
||||
);
|
||||
let bytes =
|
||||
roc_alias_analysis::func_name_bytes_help(symbol, it, &top_level.result);
|
||||
let func_name = FuncName(&bytes);
|
||||
let func_solutions = mod_solutions.func_solutions(func_name).unwrap();
|
||||
|
||||
|
@ -5666,12 +5663,12 @@ fn run_low_level<'a, 'ctx, 'env>(
|
|||
wrapper_struct,
|
||||
)
|
||||
}
|
||||
ListSet => {
|
||||
ListReplaceUnsafe => {
|
||||
let list = load_symbol(scope, &args[0]);
|
||||
let index = load_symbol(scope, &args[1]);
|
||||
let (element, element_layout) = load_symbol_and_layout(scope, &args[2]);
|
||||
|
||||
list_set(
|
||||
list_replace_unsafe(
|
||||
env,
|
||||
layout_ids,
|
||||
list,
|
||||
|
|
|
@ -291,52 +291,70 @@ pub fn list_drop_at<'a, 'ctx, 'env>(
|
|||
)
|
||||
}
|
||||
|
||||
/// List.set : List elem, Nat, elem -> List elem
|
||||
pub fn list_set<'a, 'ctx, 'env>(
|
||||
/// List.replace_unsafe : List elem, Nat, elem -> { list: List elem, value: elem }
|
||||
pub fn list_replace_unsafe<'a, 'ctx, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
layout_ids: &mut LayoutIds<'a>,
|
||||
_layout_ids: &mut LayoutIds<'a>,
|
||||
list: BasicValueEnum<'ctx>,
|
||||
index: IntValue<'ctx>,
|
||||
element: BasicValueEnum<'ctx>,
|
||||
element_layout: &Layout<'a>,
|
||||
update_mode: UpdateMode,
|
||||
) -> BasicValueEnum<'ctx> {
|
||||
let dec_element_fn = build_dec_wrapper(env, layout_ids, element_layout);
|
||||
let element_type = basic_type_from_layout(env, element_layout);
|
||||
let element_ptr = env
|
||||
.builder
|
||||
.build_alloca(element_type, "output_element_as_opaque");
|
||||
|
||||
let (length, bytes) = load_list(
|
||||
env.builder,
|
||||
list.into_struct_value(),
|
||||
env.context.i8_type().ptr_type(AddressSpace::Generic),
|
||||
);
|
||||
|
||||
let new_bytes = match update_mode {
|
||||
UpdateMode::InPlace => call_bitcode_fn(
|
||||
// Assume the bounds have already been checked earlier
|
||||
// (e.g. by List.replace or List.set, which wrap List.#replaceUnsafe)
|
||||
let new_list = match update_mode {
|
||||
UpdateMode::InPlace => call_list_bitcode_fn(
|
||||
env,
|
||||
&[
|
||||
bytes.into(),
|
||||
pass_list_cc(env, list),
|
||||
index.into(),
|
||||
pass_element_as_opaque(env, element, *element_layout),
|
||||
layout_width(env, element_layout),
|
||||
dec_element_fn.as_global_value().as_pointer_value().into(),
|
||||
pass_as_opaque(env, element_ptr),
|
||||
],
|
||||
bitcode::LIST_SET_IN_PLACE,
|
||||
bitcode::LIST_REPLACE_IN_PLACE,
|
||||
),
|
||||
UpdateMode::Immutable => call_bitcode_fn(
|
||||
UpdateMode::Immutable => call_list_bitcode_fn(
|
||||
env,
|
||||
&[
|
||||
bytes.into(),
|
||||
length.into(),
|
||||
pass_list_cc(env, list),
|
||||
env.alignment_intvalue(element_layout),
|
||||
index.into(),
|
||||
pass_element_as_opaque(env, element, *element_layout),
|
||||
layout_width(env, element_layout),
|
||||
dec_element_fn.as_global_value().as_pointer_value().into(),
|
||||
pass_as_opaque(env, element_ptr),
|
||||
],
|
||||
bitcode::LIST_SET,
|
||||
bitcode::LIST_REPLACE,
|
||||
),
|
||||
};
|
||||
|
||||
store_list(env, new_bytes.into_pointer_value(), length)
|
||||
// Load the element and returned list into a struct.
|
||||
let old_element = env.builder.build_load(element_ptr, "load_element");
|
||||
|
||||
let result = env
|
||||
.context
|
||||
.struct_type(
|
||||
&[super::convert::zig_list_type(env).into(), element_type],
|
||||
false,
|
||||
)
|
||||
.const_zero();
|
||||
|
||||
let result = env
|
||||
.builder
|
||||
.build_insert_value(result, new_list, 0, "insert_list")
|
||||
.unwrap();
|
||||
|
||||
env.builder
|
||||
.build_insert_value(result, old_element, 1, "insert_value")
|
||||
.unwrap()
|
||||
.into_struct_value()
|
||||
.into()
|
||||
}
|
||||
|
||||
fn bounds_check_comparison<'ctx>(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue