diff --git a/compiler/can/src/builtins.rs b/compiler/can/src/builtins.rs index 96b2e1c21d..2b2ee02c2e 100644 --- a/compiler/can/src/builtins.rs +++ b/compiler/can/src/builtins.rs @@ -78,6 +78,7 @@ pub fn builtin_defs_map(symbol: Symbol, var_store: &mut VarStore) -> Option LIST_KEEP_IF => list_keep_if, LIST_WALK => list_walk, LIST_WALK_BACKWARDS => list_walk_backwards, + DICT_SIZE => dict_size, NUM_ADD => num_add, NUM_ADD_CHECKED => num_add_checked, NUM_ADD_WRAP => num_add_wrap, @@ -1755,7 +1756,7 @@ fn list_keep_if(symbol: Symbol, var_store: &mut VarStore) -> Def { ) } -// List.contains : List elem, elem, -> Bool +/// List.contains : List elem, elem -> Bool fn list_contains(symbol: Symbol, var_store: &mut VarStore) -> Def { let list_var = var_store.fresh(); let elem_var = var_store.fresh(); @@ -1803,6 +1804,26 @@ fn list_map(symbol: Symbol, var_store: &mut VarStore) -> Def { ) } +/// Dict.size : Dict * * -> Nat +fn dict_size(symbol: Symbol, var_store: &mut VarStore) -> Def { + let size_var = var_store.fresh(); + let dict_var = var_store.fresh(); + + let body = RunLowLevel { + op: LowLevel::DictSize, + args: vec![(dict_var, Var(Symbol::ARG_1))], + ret_var: size_var, + }; + + defn( + symbol, + vec![(dict_var, Symbol::ARG_1)], + var_store, + body, + size_var, + ) +} + /// Num.rem : Int, Int -> Result Int [ DivByZero ]* fn num_rem(symbol: Symbol, var_store: &mut VarStore) -> Def { let num_var = var_store.fresh(); diff --git a/compiler/gen/tests/gen_dict.rs b/compiler/gen/tests/gen_dict.rs index 307dad1646..a83fc01306 100644 --- a/compiler/gen/tests/gen_dict.rs +++ b/compiler/gen/tests/gen_dict.rs @@ -12,8 +12,7 @@ extern crate roc_gen; mod helpers; #[cfg(test)] -mod gen_hash { - +mod gen_dict { #[test] fn dict_empty_len() { assert_evals_to!( diff --git a/compiler/gen/tests/gen_hash.rs b/compiler/gen/tests/gen_hash.rs index d863c85ef3..fc577d16e6 100644 --- a/compiler/gen/tests/gen_hash.rs +++ b/compiler/gen/tests/gen_hash.rs @@ -13,6 +13,10 @@ mod gen_hash { #[test] fn basic_hash() { - let value = env.builder; + + // assert_llvm_evals_to( + // + // ) + // let value = env.builder; } }