Merge pull request #4041 from KilianVounckx/opaque-bool

Opaque bool
This commit is contained in:
Ayaz 2022-09-21 11:15:41 -05:00 committed by GitHub
commit 211c297230
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
81 changed files with 1835 additions and 1744 deletions

View file

@ -54,15 +54,10 @@ fn int_list_literal() {
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn bool_list_literal() {
// NOTE: make sure to explicitly declare the elements to be of type bool, or
// use both True and False; only using one of them causes the list to in practice be
// of type `List [True]` or `List [False]`, those are tag unions with one constructor
// and not fields, and don't have a runtime representation.
assert_evals_to!(
indoc!(
r#"
false : Bool
false = False
false = Bool.false
[false]
"#
@ -72,7 +67,7 @@ fn bool_list_literal() {
);
assert_evals_to!(
"[True, False, True]",
"[Bool.true, Bool.false, Bool.true]",
RocList::from_slice(&[true, false, true]),
RocList<bool>
);
@ -81,7 +76,7 @@ fn bool_list_literal() {
indoc!(
r#"
false : Bool
false = False
false = Bool.false
[false]
"#
@ -94,7 +89,7 @@ fn bool_list_literal() {
indoc!(
r#"
true : Bool
true = True
true = Bool.true
List.repeat true 23
"#
@ -107,7 +102,7 @@ fn bool_list_literal() {
indoc!(
r#"
true : Bool
true = True
true = Bool.true
List.repeat { x: true, y: true } 23
"#
@ -120,7 +115,7 @@ fn bool_list_literal() {
indoc!(
r#"
true : Bool
true = True
true = Bool.true
List.repeat { x: true, y: true, a: true, b: true, c: true, d : true, e: true, f: true } 23
"#
@ -503,7 +498,7 @@ fn list_drop_at_shared() {
indoc!(
r#"
list : List I64
list = [if True then 4 else 4, 5, 6]
list = [if Bool.true then 4 else 4, 5, 6]
{ newList: List.dropAt list 0, original: list }
"#
@ -527,7 +522,7 @@ fn list_drop_if_empty_list_of_int() {
empty : List I64
empty = []
List.dropIf empty \_ -> True
List.dropIf empty \_ -> Bool.true
"#
),
RocList::<i64>::from_slice(&[]),
@ -542,7 +537,7 @@ fn list_drop_if_empty_list() {
indoc!(
r#"
alwaysTrue : I64 -> Bool
alwaysTrue = \_ -> True
alwaysTrue = \_ -> Bool.true
List.dropIf [] alwaysTrue
"#
@ -558,7 +553,7 @@ fn list_drop_if_always_false_for_non_empty_list() {
assert_evals_to!(
indoc!(
r#"
List.dropIf [1,2,3,4,5,6,7,8] (\_ -> False)
List.dropIf [1,2,3,4,5,6,7,8] (\_ -> Bool.false)
"#
),
RocList::from_slice(&[1, 2, 3, 4, 5, 6, 7, 8]),
@ -572,7 +567,7 @@ fn list_drop_if_always_true_for_non_empty_list() {
assert_evals_to!(
indoc!(
r#"
List.dropIf [1,2,3,4,5,6,7,8] (\_ -> True)
List.dropIf [1,2,3,4,5,6,7,8] (\_ -> Bool.true)
"#
),
RocList::<i64>::from_slice(&[]),
@ -635,7 +630,7 @@ fn list_drop_last_mutable() {
indoc!(
r#"
list : List I64
list = [if True then 4 else 4, 5, 6]
list = [if Bool.true then 4 else 4, 5, 6]
{ newList: List.dropLast list, original: list }
"#
@ -734,7 +729,7 @@ fn list_append_to_empty_list_of_int() {
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn list_append_bools() {
assert_evals_to!(
"List.append [True, False] True",
"List.append [Bool.true, Bool.false] Bool.true",
RocList::from_slice(&[true, false, true]),
RocList<bool>
);
@ -793,7 +788,7 @@ fn list_prepend() {
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn list_prepend_bools() {
assert_evals_to!(
"List.prepend [True, False] True",
"List.prepend [Bool.true, Bool.false] Bool.true",
RocList::from_slice(&[true, true, false]),
RocList<bool>
);
@ -971,7 +966,7 @@ fn list_keep_if_empty_list_of_int() {
empty =
[]
List.keepIf empty \_ -> True
List.keepIf empty \_ -> Bool.true
"#
),
RocList::<i64>::from_slice(&[]),
@ -987,7 +982,7 @@ fn list_keep_if_empty_list() {
r#"
alwaysTrue : I64 -> Bool
alwaysTrue = \_ ->
True
Bool.true
List.keepIf [] alwaysTrue
@ -1006,7 +1001,7 @@ fn list_keep_if_always_true_for_non_empty_list() {
r#"
alwaysTrue : I64 -> Bool
alwaysTrue = \_ ->
True
Bool.true
oneThroughEight : List I64
oneThroughEight =
@ -1028,7 +1023,7 @@ fn list_keep_if_always_false_for_non_empty_list() {
r#"
alwaysFalse : I64 -> Bool
alwaysFalse = \_ ->
False
Bool.false
List.keepIf [1,2,3,4,5,6,7,8] alwaysFalse
"#
@ -2308,7 +2303,7 @@ fn quicksort() {
partitionHelp : Nat, Nat, List (Num a), Nat, Num a -> [Pair Nat (List (Num a))]
partitionHelp = \i, j, list, high, pivot ->
# if j < high then
if False then
if Bool.false then
when List.get list j is
Ok value ->
if value <= pivot then
@ -2791,7 +2786,7 @@ fn list_any() {
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn list_any_empty_with_unknown_element_type() {
assert_evals_to!("List.any [] (\\_ -> True)", false, bool);
assert_evals_to!("List.any [] (\\_ -> Bool.true)", false, bool);
}
#[test]
@ -2806,7 +2801,7 @@ fn list_all() {
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn list_all_empty_with_unknown_element_type() {
assert_evals_to!("List.all [] (\\_ -> True)", true, bool);
assert_evals_to!("List.all [] (\\_ -> Bool.true)", true, bool);
}
#[test]
@ -2825,7 +2820,7 @@ fn lists_with_incompatible_type_param_in_if() {
list2 = [""]
x = if True then list1 else list2
x = if Bool.true then list1 else list2
""
"#
@ -2864,7 +2859,7 @@ fn empty_list_of_function_type() {
myClosure = \_ -> "bar"
choose =
if False then
if Bool.false then
myList
else
[myClosure]
@ -3003,7 +2998,7 @@ fn list_find_empty_layout() {
assert_evals_to!(
indoc!(
r#"
List.findFirst [] \_ -> True
List.findFirst [] \_ -> Bool.true
"#
),
// [Ok [], Err [NotFound]] gets unwrapped all the way to just [NotFound],
@ -3015,7 +3010,7 @@ fn list_find_empty_layout() {
assert_evals_to!(
indoc!(
r#"
List.findLast [] \_ -> True
List.findLast [] \_ -> Bool.true
"#
),
// [Ok [], Err [NotFound]] gets unwrapped all the way to just [NotFound],