From 02acef68df6300a8df4fbd3db74aba4c7df15b4d Mon Sep 17 00:00:00 2001 From: satotake Date: Wed, 3 Nov 2021 14:33:53 +0000 Subject: [PATCH] remove Dict.hashTestOnly --- compiler/builtins/src/std.rs | 9 +- compiler/can/src/builtins.rs | 6 - compiler/module/src/symbol.rs | 18 +-- compiler/test_gen/src/gen_hash.rs | 218 ------------------------------ compiler/test_gen/src/lib.rs | 1 - 5 files changed, 8 insertions(+), 244 deletions(-) delete mode 100644 compiler/test_gen/src/gen_hash.rs diff --git a/compiler/builtins/src/std.rs b/compiler/builtins/src/std.rs index 1ced33cc9b..668913f660 100644 --- a/compiler/builtins/src/std.rs +++ b/compiler/builtins/src/std.rs @@ -5,7 +5,7 @@ use roc_region::all::Region; use roc_types::builtin_aliases::{ bool_type, dict_type, float_type, i128_type, int_type, list_type, nat_type, num_type, ordering_type, result_type, set_type, str_type, str_utf8_byte_problem_type, u16_type, u32_type, - u64_type, u8_type, + u8_type, }; use roc_types::solved_types::SolvedType; use roc_types::subs::VarId; @@ -1051,13 +1051,6 @@ pub fn types() -> MutMap { // Dict module - // Dict.hashTestOnly : U64, v -> U64 - add_top_level_function_type!( - Symbol::DICT_TEST_HASH, - vec![u64_type(), flex(TVAR2)], - Box::new(u64_type()) - ); - // len : Dict * * -> Nat add_top_level_function_type!( Symbol::DICT_LEN, diff --git a/compiler/can/src/builtins.rs b/compiler/can/src/builtins.rs index c51a2929cc..a9938fc91d 100644 --- a/compiler/can/src/builtins.rs +++ b/compiler/can/src/builtins.rs @@ -103,7 +103,6 @@ pub fn builtin_defs_map(symbol: Symbol, var_store: &mut VarStore) -> Option LIST_WALK_BACKWARDS => list_walk_backwards, LIST_WALK_UNTIL => list_walk_until, LIST_SORT_WITH => list_sort_with, - DICT_TEST_HASH => dict_hash_test_only, DICT_LEN => dict_len, DICT_EMPTY => dict_empty, DICT_SINGLE => dict_single, @@ -2592,11 +2591,6 @@ fn list_sort_with(symbol: Symbol, var_store: &mut VarStore) -> Def { lowlevel_2(symbol, LowLevel::ListSortWith, var_store) } -/// Dict.hashTestOnly : k, v -> Nat -fn dict_hash_test_only(symbol: Symbol, var_store: &mut VarStore) -> Def { - lowlevel_2(symbol, LowLevel::Hash, var_store) -} - /// Dict.len : Dict * * -> Nat fn dict_len(symbol: Symbol, var_store: &mut VarStore) -> Def { let arg1_var = var_store.fresh(); diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index 79510c3700..e0b568270a 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -1080,18 +1080,14 @@ define_builtins! { 7 DICT_INSERT: "insert" 8 DICT_LEN: "len" - // This should not be exposed to users, its for testing the - // hash function ONLY - 9 DICT_TEST_HASH: "hashTestOnly" + 9 DICT_REMOVE: "remove" + 10 DICT_CONTAINS: "contains" + 11 DICT_KEYS: "keys" + 12 DICT_VALUES: "values" - 10 DICT_REMOVE: "remove" - 11 DICT_CONTAINS: "contains" - 12 DICT_KEYS: "keys" - 13 DICT_VALUES: "values" - - 14 DICT_UNION: "union" - 15 DICT_INTERSECTION: "intersection" - 16 DICT_DIFFERENCE: "difference" + 13 DICT_UNION: "union" + 14 DICT_INTERSECTION: "intersection" + 15 DICT_DIFFERENCE: "difference" } 7 SET: "Set" => { 0 SET_SET: "Set" imported // the Set.Set type alias diff --git a/compiler/test_gen/src/gen_hash.rs b/compiler/test_gen/src/gen_hash.rs deleted file mode 100644 index 66282e053f..0000000000 --- a/compiler/test_gen/src/gen_hash.rs +++ /dev/null @@ -1,218 +0,0 @@ -#![cfg(test)] - -use crate::assert_evals_to; -// use crate::assert_wasm_evals_to as assert_evals_to; -use indoc::indoc; - -#[test] -fn basic_hash() { - assert_evals_to!( - indoc!( - r#" - Dict.hashTestOnly 0 0 - "# - ), - 9718519427346233646, - u64 - ); -} - -#[test] -fn hash_str_with_seed() { - assert_evals_to!("Dict.hashTestOnly 1 \"a\"", 0xbed235177f41d328, u64); - assert_evals_to!("Dict.hashTestOnly 2 \"abc\"", 0xbe348debe59b27c3, u64); -} - -#[test] -fn hash_record() { - assert_evals_to!("Dict.hashTestOnly 1 { x: \"a\" } ", 0xbed235177f41d328, u64); - assert_evals_to!( - "Dict.hashTestOnly 1 { x: 42, y: 3.14 } ", - 5348189196103430707, - u64 - ); -} - -#[test] -fn hash_result() { - assert_evals_to!( - "Dict.hashTestOnly 0 (List.get [ 0x1 ] 0) ", - 2878521786781103245, - u64 - ); -} - -#[test] -fn hash_linked_list() { - assert_evals_to!( - indoc!( - r#" - LinkedList a : [ Nil, Cons a (LinkedList a) ] - - input : LinkedList I64 - input = Nil - - Dict.hashTestOnly 0 input - "# - ), - 0, - u64 - ); - - assert_evals_to!( - indoc!( - r#" - LinkedList a : [ Nil, Cons a (LinkedList a) ] - - input : LinkedList I64 - input = Cons 4 (Cons 3 Nil) - - Dict.hashTestOnly 0 input - "# - ), - 8287696503006938486, - u64 - ); -} - -#[test] -fn hash_expr() { - assert_evals_to!( - indoc!( - r#" - Expr : [ Add Expr Expr, Mul Expr Expr, Val I64, Var I64 ] - - x : Expr - x = Val 1 - - add : Expr - add = Add x x - - Dict.hashTestOnly 0 add - "# - ), - 10825806964604997723, - u64 - ); -} - -#[test] -fn hash_nullable_expr() { - assert_evals_to!( - indoc!( - r#" - Expr : [ Add Expr Expr, Mul Expr Expr, Val I64, Empty ] - - x : Expr - x = Val 1 - - add : Expr - add = Add x x - - Dict.hashTestOnly 0 add - "# - ), - 1907558799788307114, - u64 - ); -} - -#[test] -fn hash_rosetree() { - assert_evals_to!( - indoc!( - r#" - Rose a : [ Rose (List (Rose a)) ] - - x : Rose I64 - x = Rose [] - - Dict.hashTestOnly 0 x - "# - ), - 0, - u64 - ); -} - -#[test] -fn hash_union_same_content() { - assert_evals_to!( - indoc!( - r#" - Foo : [ A I64, B I64 ] - - a : Foo - a = A 42 - - b : Foo - b = B 42 - - { a: Dict.hashTestOnly 0 a, b : Dict.hashTestOnly 0 b } - "# - ), - true, - (i64, i64), - |(a, b)| a != b - ); -} - -#[test] -fn hash_recursive_union_same_content() { - assert_evals_to!( - indoc!( - r#" - Expr : [ Add Expr Expr, Mul Expr Expr, Val1 I64, Val2 I64 ] - - v1 : Expr - v1 = Val1 42 - - v2 : Expr - v2 = Val2 42 - - { a: Dict.hashTestOnly 0 v1, b : Dict.hashTestOnly 0 v2 } - "# - ), - true, - (i64, i64), - |(a, b)| a != b - ); -} - -#[test] -fn hash_nullable_recursive_union_same_content() { - assert_evals_to!( - indoc!( - r#" - Expr : [ Add Expr Expr, Mul Expr Expr, Val1 I64, Val2 I64, Empty ] - - v1 : Expr - v1 = Val1 42 - - v2 : Expr - v2 = Val2 42 - - { a: Dict.hashTestOnly 0 v1, b : Dict.hashTestOnly 0 v2 } - "# - ), - true, - (i64, i64), - |(a, b)| a != b - ); -} - -#[test] -fn hash_list() { - assert_evals_to!( - indoc!( - r#" - x : List Str - x = [ "foo", "bar", "baz" ] - - Dict.hashTestOnly 0 x - "# - ), - 10731521034618280801, - u64 - ); -} diff --git a/compiler/test_gen/src/lib.rs b/compiler/test_gen/src/lib.rs index 8aaaf93648..c39c2a09d7 100644 --- a/compiler/test_gen/src/lib.rs +++ b/compiler/test_gen/src/lib.rs @@ -6,7 +6,6 @@ pub mod gen_compare; pub mod gen_dict; -pub mod gen_hash; pub mod gen_list; pub mod gen_num; pub mod gen_primitives;