fix test hanging forever

This commit is contained in:
Folkert 2021-01-25 13:20:40 +01:00
parent 171e0358f3
commit 0166a4d915
7 changed files with 66 additions and 17 deletions

View file

@ -79,6 +79,7 @@ pub fn builtin_defs_map(symbol: Symbol, var_store: &mut VarStore) -> Option<Def>
LIST_WALK => list_walk,
LIST_WALK_BACKWARDS => list_walk_backwards,
DICT_LEN => dict_len,
DICT_EMPTY => dict_empty,
NUM_ADD => num_add,
NUM_ADD_CHECKED => num_add_checked,
NUM_ADD_WRAP => num_add_wrap,
@ -173,6 +174,8 @@ pub fn builtin_defs(var_store: &mut VarStore) -> MutMap<Symbol, Def> {
Symbol::LIST_KEEP_IF => list_keep_if,
Symbol::LIST_WALK => list_walk,
Symbol::LIST_WALK_BACKWARDS => list_walk_backwards,
Symbol::DICT_LEN => dict_len,
Symbol::DICT_EMPTY => dict_empty,
Symbol::NUM_ADD => num_add,
Symbol::NUM_ADD_CHECKED => num_add_checked,
Symbol::NUM_ADD_WRAP => num_add_wrap,
@ -1848,6 +1851,24 @@ fn dict_len(symbol: Symbol, var_store: &mut VarStore) -> Def {
)
}
/// Dict.empty : Dict * *
fn dict_empty(symbol: Symbol, var_store: &mut VarStore) -> Def {
let dict_var = var_store.fresh();
let body = RunLowLevel {
op: LowLevel::DictEmpty,
args: vec![],
ret_var: dict_var,
};
Def {
annotation: None,
expr_var: dict_var,
loc_expr: Located::at_zero(body),
loc_pattern: Located::at_zero(Pattern::Identifier(symbol)),
pattern_vars: SendMap::default(),
}
}
/// Num.rem : Int, Int -> Result Int [ DivByZero ]*
fn num_rem(symbol: Symbol, var_store: &mut VarStore) -> Def {
let num_var = var_store.fresh();

View file

@ -1,4 +1,4 @@
use crate::llvm::build_dict::dict_len;
use crate::llvm::build_dict::{dict_len, dict_empty};
use crate::llvm::build_hash::hash;
use crate::llvm::build_list::{
allocate_list, empty_list, empty_polymorphic_list, list_append, list_concat, list_contains,
@ -3854,7 +3854,14 @@ fn run_low_level<'a, 'ctx, 'env>(
hash(env, value, layout)
}
DictSize => dict_len(env, scope, args[0]),
DictSize => {
debug_assert_eq!(args.len(), 1);
dict_len(env, scope, args[0])
}
DictEmpty => {
debug_assert_eq!(args.len(), 0);
dict_empty(env, scope)
}
}
}

View file

@ -25,6 +25,28 @@ pub fn dict_len<'a, 'ctx, 'env>(
}
}
pub fn dict_empty<'a, 'ctx, 'env>(
env: &Env<'a, 'ctx, 'env>,
scope: &Scope<'a, 'ctx>,
) -> BasicValueEnum<'ctx> {
let ctx = env.context;
/*
let (_, dict_layout) = load_symbol_and_layout(env, scope, &dict_symbol);
match dict_layout {
Layout::Builtin(Builtin::Dict(_, _)) => {
let dict_as_int = dict_symbol_to_i128(env, scope, dict_symbol);
call_bitcode_fn(env, &[dict_as_int.into()], &bitcode::DICT_LEN)
}
Layout::Builtin(Builtin::EmptyDict) => ctx.i64_type().const_zero().into(),
_ => unreachable!("Invalid layout given to Dict.len : {:?}", dict_layout),
}
*/
todo!()
}
fn dict_symbol_to_i128<'a, 'ctx, 'env>(
env: &Env<'a, 'ctx, 'env>,
scope: &Scope<'a, 'ctx>,

View file

@ -181,7 +181,7 @@ pub fn basic_type_from_builtin<'ctx>(
Float64 => context.f64_type().as_basic_type_enum(),
Float32 => context.f32_type().as_basic_type_enum(),
Float16 => context.f16_type().as_basic_type_enum(),
Dict(_, _) | EmptyDict => panic!("TODO layout_to_basic_type for Builtin::Dict"),
Dict(_, _) | EmptyDict => collection(context, ptr_bytes).into(),
Set(_) | EmptySet => panic!("TODO layout_to_basic_type for Builtin::Set"),
List(_, _) | Str | EmptyStr => collection(context, ptr_bytes).into(),
EmptyList => BasicTypeEnum::StructType(collection(context, ptr_bytes)),

View file

@ -28,6 +28,7 @@ pub enum LowLevel {
ListWalkBackwards,
ListSum,
DictSize,
DictEmpty,
NumAdd,
NumAddWrap,
NumAddChecked,

View file

@ -589,5 +589,6 @@ pub fn lowlevel_borrow_signature(arena: &Bump, op: LowLevel) -> &[bool] {
StrFromInt => arena.alloc_slice_copy(&[irrelevant]),
Hash => arena.alloc_slice_copy(&[borrowed]),
DictSize => arena.alloc_slice_copy(&[borrowed]),
DictEmpty => &[],
}
}

View file

@ -642,21 +642,18 @@ mod test_mono {
"#,
indoc!(
r#"
procedure List.5 (#Attr.2, #Attr.3):
let Test.7 = lowlevel ListAppend #Attr.2 #Attr.3;
ret Test.7;
procedure Test.1 (Test.2):
let Test.6 = 42i64;
let Test.5 = CallByName List.5 Test.2 Test.6;
ret Test.5;
procedure Test.0 ():
let Test.8 = 1i64;
let Test.9 = 2i64;
let Test.4 = Array [Test.8, Test.9];
let Test.3 = CallByName Test.1 Test.4;
procedure Dict.2 ():
let Test.4 = lowlevel DictEmpty ;
ret Test.4;
procedure Dict.6 (#Attr.2):
let Test.3 = lowlevel DictSize #Attr.2;
ret Test.3;
procedure Test.0 ():
let Test.2 = FunctionPointer Dict.2;
let Test.1 = CallByName Dict.6 Test.2;
ret Test.1;
"#
),
)