mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 21:39:07 +00:00
remove dict/set layout
This commit is contained in:
parent
5aef349f09
commit
4d55b756bb
16 changed files with 8 additions and 321 deletions
|
@ -2810,12 +2810,6 @@ pub fn build_exp_stmt<'a, 'ctx, 'env>(
|
|||
|
||||
build_list::decref(env, value.into_struct_value(), alignment);
|
||||
}
|
||||
Layout::Builtin(Builtin::Dict(key_layout, value_layout)) => {
|
||||
todo!()
|
||||
}
|
||||
Layout::Builtin(Builtin::Set(key_layout)) => {
|
||||
todo!()
|
||||
}
|
||||
|
||||
_ if layout.is_refcounted() => {
|
||||
if value.is_pointer_value() {
|
||||
|
@ -6146,10 +6140,6 @@ fn to_cc_type_builtin<'a, 'ctx, 'env>(
|
|||
|
||||
struct_type.ptr_type(address_space).into()
|
||||
}
|
||||
Builtin::Dict(_, _) | Builtin::Set(_) => {
|
||||
// TODO verify this is what actually happens
|
||||
basic_type_from_builtin(env, builtin)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -58,25 +58,7 @@ pub fn dict_len<'a, 'ctx, 'env>(
|
|||
let (_, dict_layout) = load_symbol_and_layout(scope, &dict_symbol);
|
||||
|
||||
match dict_layout {
|
||||
Layout::Builtin(Builtin::Dict(_, _)) => {
|
||||
// let dict_as_int = dict_symbol_to_i128(env, scope, dict_symbol);
|
||||
let dict_as_zig_dict = dict_symbol_to_zig_dict(env, scope, dict_symbol);
|
||||
|
||||
let length_i64 = call_bitcode_fn(
|
||||
env,
|
||||
&[pass_dict_c_abi(env, dict_as_zig_dict.into())],
|
||||
bitcode::DICT_LEN,
|
||||
);
|
||||
|
||||
env.builder
|
||||
.build_int_cast_sign_flag(
|
||||
length_i64.into_int_value(),
|
||||
env.ptr_int(),
|
||||
false,
|
||||
"to_usize",
|
||||
)
|
||||
.into()
|
||||
}
|
||||
Layout::Builtin(Builtin::Dict(_, _)) =>
|
||||
_ => unreachable!("Invalid layout given to Dict.len : {:?}", dict_layout),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -130,12 +130,6 @@ fn hash_builtin<'a, 'ctx, 'env>(
|
|||
call_bitcode_fn(env, &[seed.into(), val], bitcode::DICT_HASH_STR).into_int_value()
|
||||
}
|
||||
|
||||
Builtin::Dict(_, _) => {
|
||||
todo!("Implement hash for Dict")
|
||||
}
|
||||
Builtin::Set(_) => {
|
||||
todo!("Implement Hash for Set")
|
||||
}
|
||||
Builtin::List(element_layout) => build_hash_list(
|
||||
env,
|
||||
layout_ids,
|
||||
|
|
|
@ -135,8 +135,6 @@ fn build_eq_builtin<'a, 'ctx, 'env>(
|
|||
rhs_val.into_struct_value(),
|
||||
when_recursive,
|
||||
),
|
||||
Builtin::Set(_elem) => todo!("equality on Set"),
|
||||
Builtin::Dict(_key, _value) => todo!("equality on Dict"),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -312,8 +310,6 @@ fn build_neq_builtin<'a, 'ctx, 'env>(
|
|||
|
||||
result.into()
|
||||
}
|
||||
Builtin::Set(_elem) => todo!("equality on Set"),
|
||||
Builtin::Dict(_key, _value) => todo!("equality on Dict"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -103,8 +103,6 @@ pub fn basic_type_from_builtin<'a, 'ctx, 'env>(
|
|||
Float(float_width) => float_type_from_float_width(env, *float_width).as_basic_type_enum(),
|
||||
Bool => context.bool_type().as_basic_type_enum(),
|
||||
Decimal => context.i128_type().as_basic_type_enum(),
|
||||
Dict(_, _) => zig_dict_type(env).into(),
|
||||
Set(_) => zig_dict_type(env).into(),
|
||||
List(_) => zig_list_type(env).into(),
|
||||
Str => zig_str_type(env).into(),
|
||||
}
|
||||
|
@ -260,10 +258,6 @@ pub fn str_list_int(ctx: &Context, target_info: TargetInfo) -> IntType<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn zig_dict_type<'a, 'ctx, 'env>(env: &Env<'a, 'ctx, 'env>) -> StructType<'ctx> {
|
||||
env.module.get_struct_type("dict.RocDict").unwrap()
|
||||
}
|
||||
|
||||
pub fn zig_list_type<'a, 'ctx, 'env>(env: &Env<'a, 'ctx, 'env>) -> StructType<'ctx> {
|
||||
env.module.get_struct_type("list.RocList").unwrap()
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
pub mod bitcode;
|
||||
pub mod build;
|
||||
pub mod build_dict;
|
||||
pub mod build_hash;
|
||||
pub mod build_list;
|
||||
pub mod build_str;
|
||||
|
|
|
@ -423,35 +423,6 @@ fn modify_refcount_builtin<'a, 'ctx, 'env>(
|
|||
|
||||
Some(function)
|
||||
}
|
||||
Set(element_layout) => {
|
||||
let key_layout = element_layout;
|
||||
let value_layout = &Layout::UNIT;
|
||||
|
||||
let function = modify_refcount_dict(
|
||||
env,
|
||||
layout_ids,
|
||||
mode,
|
||||
when_recursive,
|
||||
layout,
|
||||
key_layout,
|
||||
value_layout,
|
||||
);
|
||||
|
||||
Some(function)
|
||||
}
|
||||
Dict(key_layout, value_layout) => {
|
||||
let function = modify_refcount_dict(
|
||||
env,
|
||||
layout_ids,
|
||||
mode,
|
||||
when_recursive,
|
||||
layout,
|
||||
key_layout,
|
||||
value_layout,
|
||||
);
|
||||
|
||||
Some(function)
|
||||
}
|
||||
|
||||
Str => Some(modify_refcount_str(env, layout_ids, mode, layout)),
|
||||
|
||||
|
@ -960,141 +931,6 @@ fn modify_refcount_box_help<'a, 'ctx, 'env>(
|
|||
builder.build_return(None);
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn modify_refcount_dict<'a, 'ctx, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
layout_ids: &mut LayoutIds<'a>,
|
||||
mode: Mode,
|
||||
when_recursive: &WhenRecursive<'a>,
|
||||
layout: &Layout<'a>,
|
||||
key_layout: &Layout<'a>,
|
||||
value_layout: &Layout<'a>,
|
||||
) -> FunctionValue<'ctx> {
|
||||
let block = env.builder.get_insert_block().expect("to be in a function");
|
||||
let di_location = env.builder.get_current_debug_location().unwrap();
|
||||
|
||||
let (_, fn_name) = function_name_from_mode(
|
||||
layout_ids,
|
||||
&env.interns,
|
||||
"increment_dict",
|
||||
"decrement_dict",
|
||||
layout,
|
||||
mode,
|
||||
);
|
||||
|
||||
let function = match env.module.get_function(fn_name.as_str()) {
|
||||
Some(function_value) => function_value,
|
||||
None => {
|
||||
let basic_type = basic_type_from_layout(env, layout);
|
||||
let function_value = build_header(env, basic_type, mode, &fn_name);
|
||||
|
||||
modify_refcount_dict_help(
|
||||
env,
|
||||
layout_ids,
|
||||
mode,
|
||||
when_recursive,
|
||||
layout,
|
||||
key_layout,
|
||||
value_layout,
|
||||
function_value,
|
||||
);
|
||||
|
||||
function_value
|
||||
}
|
||||
};
|
||||
|
||||
env.builder.position_at_end(block);
|
||||
env.builder
|
||||
.set_current_debug_location(env.context, di_location);
|
||||
|
||||
function
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn modify_refcount_dict_help<'a, 'ctx, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
layout_ids: &mut LayoutIds<'a>,
|
||||
mode: Mode,
|
||||
when_recursive: &WhenRecursive<'a>,
|
||||
layout: &Layout<'a>,
|
||||
key_layout: &Layout<'a>,
|
||||
value_layout: &Layout<'a>,
|
||||
fn_val: FunctionValue<'ctx>,
|
||||
) {
|
||||
debug_assert_eq!(
|
||||
when_recursive,
|
||||
&WhenRecursive::Unreachable,
|
||||
"TODO pipe when_recursive through the dict key/value inc/dec"
|
||||
);
|
||||
|
||||
let builder = env.builder;
|
||||
let ctx = env.context;
|
||||
|
||||
// Add a basic block for the entry point
|
||||
let entry = ctx.append_basic_block(fn_val, "entry");
|
||||
|
||||
builder.position_at_end(entry);
|
||||
|
||||
debug_info_init!(env, fn_val);
|
||||
|
||||
// Add args to scope
|
||||
let arg_symbol = Symbol::ARG_1;
|
||||
let arg_val = fn_val.get_param_iter().next().unwrap();
|
||||
|
||||
arg_val.set_name(arg_symbol.as_str(&env.interns));
|
||||
|
||||
let parent = fn_val;
|
||||
|
||||
let wrapper_struct = arg_val.into_struct_value();
|
||||
|
||||
let len = builder
|
||||
.build_extract_value(wrapper_struct, 1, "read_dict_len")
|
||||
.unwrap()
|
||||
.into_int_value();
|
||||
|
||||
// the block we'll always jump to when we're done
|
||||
let cont_block = ctx.append_basic_block(parent, "modify_rc_dict_cont");
|
||||
let modification_block = ctx.append_basic_block(parent, "modify_rc");
|
||||
|
||||
let is_non_empty = builder.build_int_compare(
|
||||
IntPredicate::SGT,
|
||||
len,
|
||||
env.ptr_int().const_zero(),
|
||||
"is_non_empty",
|
||||
);
|
||||
|
||||
builder.build_conditional_branch(is_non_empty, modification_block, cont_block);
|
||||
builder.position_at_end(modification_block);
|
||||
|
||||
if key_layout.contains_refcounted() || value_layout.contains_refcounted() {
|
||||
crate::llvm::build_dict::dict_elements_rc(
|
||||
env,
|
||||
layout_ids,
|
||||
wrapper_struct.into(),
|
||||
key_layout,
|
||||
value_layout,
|
||||
mode,
|
||||
);
|
||||
}
|
||||
|
||||
let data_ptr = env
|
||||
.builder
|
||||
.build_extract_value(wrapper_struct, 0, "get_data_ptr")
|
||||
.unwrap()
|
||||
.into_pointer_value();
|
||||
|
||||
let refcount_ptr = PointerToRefcount::from_ptr_to_data(env, data_ptr);
|
||||
let call_mode = mode_to_call_mode(fn_val, mode);
|
||||
refcount_ptr.modify(call_mode, layout, env);
|
||||
|
||||
builder.build_unconditional_branch(cont_block);
|
||||
|
||||
builder.position_at_end(cont_block);
|
||||
|
||||
// this function returns void
|
||||
builder.build_return(None);
|
||||
}
|
||||
|
||||
/// Build an increment or decrement function for a specific layout
|
||||
fn build_header<'a, 'ctx, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue