mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
checkout trunk
This commit is contained in:
parent
c8f7a98d74
commit
b8340b47c6
5 changed files with 31 additions and 48 deletions
|
@ -1084,7 +1084,9 @@ define_builtins! {
|
||||||
7 DICT_INSERT: "insert"
|
7 DICT_INSERT: "insert"
|
||||||
8 DICT_LEN: "len"
|
8 DICT_LEN: "len"
|
||||||
|
|
||||||
9 DICT_TEST_HASH: "#hashTestOnly" // for testing the hash function ONLY
|
// This should not be exposed to users, its for testing the
|
||||||
|
// hash function ONLY
|
||||||
|
9 DICT_TEST_HASH: "hashTestOnly"
|
||||||
|
|
||||||
10 DICT_REMOVE: "remove"
|
10 DICT_REMOVE: "remove"
|
||||||
11 DICT_CONTAINS: "contains"
|
11 DICT_CONTAINS: "contains"
|
||||||
|
|
|
@ -5,11 +5,6 @@ authors = ["The Roc Contributors"]
|
||||||
license = "UPL-1.0"
|
license = "UPL-1.0"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[features]
|
|
||||||
# If enabled, parser accepts `Dict.#hashTestOnly` etc.
|
|
||||||
# For development puporpse.
|
|
||||||
keep_shadowed_builtins = []
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
roc_collections = { path = "../collections" }
|
roc_collections = { path = "../collections" }
|
||||||
roc_region = { path = "../region" }
|
roc_region = { path = "../region" }
|
||||||
|
|
|
@ -220,10 +220,6 @@ pub enum BadIdent {
|
||||||
BadPrivateTag(Row, Col),
|
BadPrivateTag(Row, Col),
|
||||||
}
|
}
|
||||||
|
|
||||||
fn chomp_lowercase_part_keep_shadowed_builtins(buffer: &[u8]) -> Result<&str, Progress> {
|
|
||||||
chomp_part(|c: char| c.is_lowercase() || c == '#', buffer)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn chomp_lowercase_part(buffer: &[u8]) -> Result<&str, Progress> {
|
fn chomp_lowercase_part(buffer: &[u8]) -> Result<&str, Progress> {
|
||||||
chomp_part(|c: char| c.is_lowercase(), buffer)
|
chomp_part(|c: char| c.is_lowercase(), buffer)
|
||||||
}
|
}
|
||||||
|
@ -503,24 +499,19 @@ fn chomp_access_chain<'a>(buffer: &'a [u8], parts: &mut Vec<'a, &'a str>) -> Res
|
||||||
|
|
||||||
while let Some(b'.') = buffer.get(chomped) {
|
while let Some(b'.') = buffer.get(chomped) {
|
||||||
match &buffer.get(chomped + 1..) {
|
match &buffer.get(chomped + 1..) {
|
||||||
Some(slice) => {
|
Some(slice) => match chomp_lowercase_part(slice) {
|
||||||
let res = match cfg!(feature = "keep_shadowed_builtins") {
|
Ok(name) => {
|
||||||
true => chomp_lowercase_part_keep_shadowed_builtins(slice),
|
let value = unsafe {
|
||||||
false => chomp_lowercase_part(slice),
|
std::str::from_utf8_unchecked(
|
||||||
};
|
&buffer[chomped + 1..chomped + 1 + name.len()],
|
||||||
match res {
|
)
|
||||||
Ok(name) => {
|
};
|
||||||
let value = unsafe {
|
parts.push(value);
|
||||||
std::str::from_utf8_unchecked(
|
|
||||||
&buffer[chomped + 1..chomped + 1 + name.len()],
|
chomped += name.len() + 1;
|
||||||
)
|
|
||||||
};
|
|
||||||
parts.push(value);
|
|
||||||
chomped += name.len() + 1;
|
|
||||||
}
|
|
||||||
Err(_) => return Err(chomped as u16 + 1),
|
|
||||||
}
|
}
|
||||||
}
|
Err(_) => return Err(chomped as u16 + 1),
|
||||||
|
},
|
||||||
None => return Err(chomped as u16 + 1),
|
None => return Err(chomped as u16 + 1),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ roc_mono = { path = "../mono" }
|
||||||
roc_reporting = { path = "../reporting" }
|
roc_reporting = { path = "../reporting" }
|
||||||
roc_load = { path = "../load" }
|
roc_load = { path = "../load" }
|
||||||
roc_can = { path = "../can" }
|
roc_can = { path = "../can" }
|
||||||
roc_parse = { path = "../parse" , features = []}
|
roc_parse = { path = "../parse" }
|
||||||
roc_build = { path = "../build" }
|
roc_build = { path = "../build" }
|
||||||
roc_std = { path = "../../roc_std" }
|
roc_std = { path = "../../roc_std" }
|
||||||
test_wasm_util = { path = "../test_wasm_util" }
|
test_wasm_util = { path = "../test_wasm_util" }
|
||||||
|
@ -40,7 +40,6 @@ wasmer = { version = "2.0.0", default-features = false, features = ["default-cra
|
||||||
wasmer-wasi = "2.0.0"
|
wasmer-wasi = "2.0.0"
|
||||||
tempfile = "3.2.0"
|
tempfile = "3.2.0"
|
||||||
indoc = "1.0.3"
|
indoc = "1.0.3"
|
||||||
roc_parse = { path = "../parse" , features = ["keep_shadowed_builtins"]}
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
|
|
|
@ -9,7 +9,7 @@ fn basic_hash() {
|
||||||
assert_evals_to!(
|
assert_evals_to!(
|
||||||
indoc!(
|
indoc!(
|
||||||
r#"
|
r#"
|
||||||
Dict.#hashTestOnly 0 0
|
Dict.hashTestOnly 0 0
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
9718519427346233646,
|
9718519427346233646,
|
||||||
|
@ -19,19 +19,15 @@ fn basic_hash() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn hash_str_with_seed() {
|
fn hash_str_with_seed() {
|
||||||
assert_evals_to!("Dict.#hashTestOnly 1 \"a\"", 0xbed235177f41d328, u64);
|
assert_evals_to!("Dict.hashTestOnly 1 \"a\"", 0xbed235177f41d328, u64);
|
||||||
assert_evals_to!("Dict.#hashTestOnly 2 \"abc\"", 0xbe348debe59b27c3, u64);
|
assert_evals_to!("Dict.hashTestOnly 2 \"abc\"", 0xbe348debe59b27c3, u64);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn hash_record() {
|
fn hash_record() {
|
||||||
|
assert_evals_to!("Dict.hashTestOnly 1 { x: \"a\" } ", 0xbed235177f41d328, u64);
|
||||||
assert_evals_to!(
|
assert_evals_to!(
|
||||||
"Dict.#hashTestOnly 1 { x: \"a\" } ",
|
"Dict.hashTestOnly 1 { x: 42, y: 3.14 } ",
|
||||||
0xbed235177f41d328,
|
|
||||||
u64
|
|
||||||
);
|
|
||||||
assert_evals_to!(
|
|
||||||
"Dict.#hashTestOnly 1 { x: 42, y: 3.14 } ",
|
|
||||||
5348189196103430707,
|
5348189196103430707,
|
||||||
u64
|
u64
|
||||||
);
|
);
|
||||||
|
@ -40,7 +36,7 @@ fn hash_record() {
|
||||||
#[test]
|
#[test]
|
||||||
fn hash_result() {
|
fn hash_result() {
|
||||||
assert_evals_to!(
|
assert_evals_to!(
|
||||||
"Dict.#hashTestOnly 0 (List.get [ 0x1 ] 0) ",
|
"Dict.hashTestOnly 0 (List.get [ 0x1 ] 0) ",
|
||||||
2878521786781103245,
|
2878521786781103245,
|
||||||
u64
|
u64
|
||||||
);
|
);
|
||||||
|
@ -56,7 +52,7 @@ fn hash_linked_list() {
|
||||||
input : LinkedList I64
|
input : LinkedList I64
|
||||||
input = Nil
|
input = Nil
|
||||||
|
|
||||||
Dict.#hashTestOnly 0 input
|
Dict.hashTestOnly 0 input
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
0,
|
0,
|
||||||
|
@ -71,7 +67,7 @@ fn hash_linked_list() {
|
||||||
input : LinkedList I64
|
input : LinkedList I64
|
||||||
input = Cons 4 (Cons 3 Nil)
|
input = Cons 4 (Cons 3 Nil)
|
||||||
|
|
||||||
Dict.#hashTestOnly 0 input
|
Dict.hashTestOnly 0 input
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
8287696503006938486,
|
8287696503006938486,
|
||||||
|
@ -92,7 +88,7 @@ fn hash_expr() {
|
||||||
add : Expr
|
add : Expr
|
||||||
add = Add x x
|
add = Add x x
|
||||||
|
|
||||||
Dict.#hashTestOnly 0 add
|
Dict.hashTestOnly 0 add
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
10825806964604997723,
|
10825806964604997723,
|
||||||
|
@ -113,7 +109,7 @@ fn hash_nullable_expr() {
|
||||||
add : Expr
|
add : Expr
|
||||||
add = Add x x
|
add = Add x x
|
||||||
|
|
||||||
Dict.#hashTestOnly 0 add
|
Dict.hashTestOnly 0 add
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
1907558799788307114,
|
1907558799788307114,
|
||||||
|
@ -131,7 +127,7 @@ fn hash_rosetree() {
|
||||||
x : Rose I64
|
x : Rose I64
|
||||||
x = Rose []
|
x = Rose []
|
||||||
|
|
||||||
Dict.#hashTestOnly 0 x
|
Dict.hashTestOnly 0 x
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
0,
|
0,
|
||||||
|
@ -152,7 +148,7 @@ fn hash_union_same_content() {
|
||||||
b : Foo
|
b : Foo
|
||||||
b = B 42
|
b = B 42
|
||||||
|
|
||||||
{ a: Dict.#hashTestOnly 0 a, b : Dict.#hashTestOnly 0 b }
|
{ a: Dict.hashTestOnly 0 a, b : Dict.hashTestOnly 0 b }
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
true,
|
true,
|
||||||
|
@ -174,7 +170,7 @@ fn hash_recursive_union_same_content() {
|
||||||
v2 : Expr
|
v2 : Expr
|
||||||
v2 = Val2 42
|
v2 = Val2 42
|
||||||
|
|
||||||
{ a: Dict.#hashTestOnly 0 v1, b : Dict.#hashTestOnly 0 v2 }
|
{ a: Dict.hashTestOnly 0 v1, b : Dict.hashTestOnly 0 v2 }
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
true,
|
true,
|
||||||
|
@ -196,7 +192,7 @@ fn hash_nullable_recursive_union_same_content() {
|
||||||
v2 : Expr
|
v2 : Expr
|
||||||
v2 = Val2 42
|
v2 = Val2 42
|
||||||
|
|
||||||
{ a: Dict.#hashTestOnly 0 v1, b : Dict.#hashTestOnly 0 v2 }
|
{ a: Dict.hashTestOnly 0 v1, b : Dict.hashTestOnly 0 v2 }
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
true,
|
true,
|
||||||
|
@ -213,7 +209,7 @@ fn hash_list() {
|
||||||
x : List Str
|
x : List Str
|
||||||
x = [ "foo", "bar", "baz" ]
|
x = [ "foo", "bar", "baz" ]
|
||||||
|
|
||||||
Dict.#hashTestOnly 0 x
|
Dict.hashTestOnly 0 x
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
10731521034618280801,
|
10731521034618280801,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue