use morphic update mode

This commit is contained in:
Folkert 2021-06-22 20:53:55 +02:00
parent 059cac3b98
commit 27308e98b7
5 changed files with 73 additions and 20 deletions

View file

@ -42,7 +42,9 @@ use inkwell::values::{
};
use inkwell::OptimizationLevel;
use inkwell::{AddressSpace, IntPredicate};
use morphic_lib::{CalleeSpecVar, FuncName, FuncSpec, FuncSpecSolutions, ModSolutions};
use morphic_lib::{
CalleeSpecVar, FuncName, FuncSpec, FuncSpecSolutions, ModSolutions, UpdateMode, UpdateModeVar,
};
use roc_builtins::bitcode;
use roc_collections::all::{ImMap, MutMap, MutSet};
use roc_module::ident::TagName;
@ -826,8 +828,21 @@ pub fn build_exp_call<'a, 'ctx, 'env>(
)
}
CallType::LowLevel { op, update_mode: _ } => {
run_low_level(env, layout_ids, scope, parent, layout, *op, arguments)
CallType::LowLevel { op, update_mode } => {
let bytes = update_mode.to_bytes();
let update_var = UpdateModeVar(&bytes);
let update_mode = func_spec_solutions.update_mode(update_var).unwrap();
run_low_level(
env,
layout_ids,
scope,
parent,
layout,
*op,
arguments,
update_mode,
)
}
CallType::HigherOrderLowLevel {
@ -4190,6 +4205,7 @@ fn run_low_level<'a, 'ctx, 'env>(
layout: &Layout<'a>,
op: LowLevel,
args: &[Symbol],
update_mode: UpdateMode,
) -> BasicValueEnum<'ctx> {
use LowLevel::*;
@ -4665,6 +4681,7 @@ fn run_low_level<'a, 'ctx, 'env>(
index.into_int_value(),
element,
element_layout,
update_mode,
),
_ => unreachable!("invalid dict layout"),
}

View file

@ -13,6 +13,7 @@ use inkwell::context::Context;
use inkwell::types::{BasicType, BasicTypeEnum, PointerType};
use inkwell::values::{BasicValueEnum, FunctionValue, IntValue, PointerValue, StructValue};
use inkwell::{AddressSpace, IntPredicate};
use morphic_lib::UpdateMode;
use roc_builtins::bitcode;
use roc_mono::layout::{Builtin, Layout, LayoutIds};
@ -350,6 +351,7 @@ pub fn list_set<'a, 'ctx, 'env>(
index: IntValue<'ctx>,
element: BasicValueEnum<'ctx>,
element_layout: &'a Layout<'a>,
update_mode: UpdateMode,
) -> BasicValueEnum<'ctx> {
let dec_element_fn = build_dec_wrapper(env, layout_ids, element_layout);
@ -359,6 +361,11 @@ pub fn list_set<'a, 'ctx, 'env>(
env.context.i8_type().ptr_type(AddressSpace::Generic),
);
let symbol = match update_mode {
UpdateMode::InPlace => bitcode::LIST_SET_IN_PLACE,
UpdateMode::Immutable => bitcode::LIST_SET,
};
let new_bytes = call_bitcode_fn(
env,
&[
@ -370,7 +377,7 @@ pub fn list_set<'a, 'ctx, 'env>(
layout_width(env, element_layout),
dec_element_fn.as_global_value().as_pointer_value().into(),
],
&bitcode::LIST_SET,
&symbol,
);
store_list(env, new_bytes.into_pointer_value(), length)