Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(compiler)!: Remove Exclusive/Inclusive Ranges, provide as record via compiler #1616

Merged
merged 9 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion compiler/src/typed/builtin_types.re
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ let ident_number = ident_create("Number")
and ident_exception = ident_create("Exception")
and ident_option = ident_create("Option")
and ident_result = ident_create("Result")
and ident_list = ident_create("List")
and ident_list = ident_create("List");
let ident_range = ident_create("Range")
and ident_range_start = ident_create("rangeStart")
and ident_range_end = ident_create("rangeEnd")
and ident_int32 = ident_create("Int32")
and ident_int64 = ident_create("Int64")
and ident_uint32 = ident_create("Uint32")
Expand Down Expand Up @@ -67,6 +70,7 @@ and path_exception = PIdent(ident_exception)
and path_option = PIdent(ident_option)
and path_result = PIdent(ident_result)
and path_list = PIdent(ident_list)
and path_range = PIdent(ident_range)
and path_int32 = PIdent(ident_int32)
and path_int64 = PIdent(ident_int64)
and path_uint32 = PIdent(ident_uint32)
Expand Down Expand Up @@ -95,6 +99,13 @@ and type_option = var =>
and type_result = (ok, err) =>
newgenty(TTyConstr(path_result, [ok, err], ref(TMemNil)))
and type_list = var => newgenty(TTyConstr(path_list, [var], ref(TMemNil)))
and type_range = var =>
newgenty(
TTyRecord([
(Ident.name(ident_range_start), var),
(Ident.name(ident_range_end), var),
]),
)
and type_int32 = newgenty(TTyConstr(path_int32, [], ref(TMemNil)))
and type_int64 = newgenty(TTyConstr(path_int64, [], ref(TMemNil)))
and type_uint32 = newgenty(TTyConstr(path_uint32, [], ref(TMemNil)))
Expand Down Expand Up @@ -201,6 +212,29 @@ and decl_list = {
]),
};
}
and decl_range = {
let tvar = newgenvar();
{
...decl_abstr(path_range),
type_params: [tvar],
type_arity: 1,
type_kind:
TDataRecord([
{
rf_name: ident_range_start,
rf_type: tvar,
rf_mutable: false,
rf_loc: Location.dummy_loc,
},
{
rf_name: ident_range_end,
rf_type: tvar,
rf_mutable: false,
rf_loc: Location.dummy_loc,
},
]),
};
}
and decl_box = {
let tvar = newgenvar();
{...decl_abstr(path_box), type_params: [tvar], type_arity: 1};
Expand Down Expand Up @@ -237,6 +271,7 @@ let initial_env = (add_type, add_extension, empty_env) =>
|> add_type(ident_option, decl_option)
|> add_type(ident_result, decl_result)
|> add_type(ident_list, decl_list)
|> add_type(ident_range, decl_range)
|> add_type(ident_int32, decl_abstr(path_int32))
|> add_type(ident_int64, decl_abstr(path_int64))
|> add_type(ident_uint32, decl_abstr(path_uint32))
Expand Down
6 changes: 3 additions & 3 deletions compiler/test/__snapshots__/arrays.0f9e7d37.0.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ arrays › array_access
)
(i32.store offset=12
(local.get $0)
(i32.const 55)
(i32.const 61)
)
(i32.store offset=16
(local.get $0)
Expand Down Expand Up @@ -183,7 +183,7 @@ arrays › array_access
)
(i32.store offset=12
(local.get $0)
(i32.const 57)
(i32.const 63)
)
(i32.store offset=16
(local.get $0)
Expand Down Expand Up @@ -249,7 +249,7 @@ arrays › array_access
)
(i32.store offset=12
(local.get $0)
(i32.const 55)
(i32.const 61)
)
(i32.store offset=16
(local.get $0)
Expand Down
6 changes: 3 additions & 3 deletions compiler/test/__snapshots__/arrays.1deb7b51.0.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ arrays › array_access5
)
(i32.store offset=12
(local.get $0)
(i32.const 55)
(i32.const 61)
)
(i32.store offset=16
(local.get $0)
Expand Down Expand Up @@ -183,7 +183,7 @@ arrays › array_access5
)
(i32.store offset=12
(local.get $0)
(i32.const 57)
(i32.const 63)
)
(i32.store offset=16
(local.get $0)
Expand Down Expand Up @@ -249,7 +249,7 @@ arrays › array_access5
)
(i32.store offset=12
(local.get $0)
(i32.const 55)
(i32.const 61)
)
(i32.store offset=16
(local.get $0)
Expand Down
6 changes: 3 additions & 3 deletions compiler/test/__snapshots__/arrays.28fcc534.0.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ arrays › array_access4
)
(i32.store offset=12
(local.get $0)
(i32.const 55)
(i32.const 61)
)
(i32.store offset=16
(local.get $0)
Expand Down Expand Up @@ -183,7 +183,7 @@ arrays › array_access4
)
(i32.store offset=12
(local.get $0)
(i32.const 57)
(i32.const 63)
)
(i32.store offset=16
(local.get $0)
Expand Down Expand Up @@ -249,7 +249,7 @@ arrays › array_access4
)
(i32.store offset=12
(local.get $0)
(i32.const 55)
(i32.const 61)
)
(i32.store offset=16
(local.get $0)
Expand Down
6 changes: 3 additions & 3 deletions compiler/test/__snapshots__/arrays.4c8c9f91.0.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ arrays › array_access2
)
(i32.store offset=12
(local.get $0)
(i32.const 55)
(i32.const 61)
)
(i32.store offset=16
(local.get $0)
Expand Down Expand Up @@ -183,7 +183,7 @@ arrays › array_access2
)
(i32.store offset=12
(local.get $0)
(i32.const 57)
(i32.const 63)
)
(i32.store offset=16
(local.get $0)
Expand Down Expand Up @@ -249,7 +249,7 @@ arrays › array_access2
)
(i32.store offset=12
(local.get $0)
(i32.const 55)
(i32.const 61)
)
(i32.store offset=16
(local.get $0)
Expand Down
6 changes: 3 additions & 3 deletions compiler/test/__snapshots__/arrays.6eac4e1f.0.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ arrays › array_access3
)
(i32.store offset=12
(local.get $0)
(i32.const 55)
(i32.const 61)
)
(i32.store offset=16
(local.get $0)
Expand Down Expand Up @@ -183,7 +183,7 @@ arrays › array_access3
)
(i32.store offset=12
(local.get $0)
(i32.const 57)
(i32.const 63)
)
(i32.store offset=16
(local.get $0)
Expand Down Expand Up @@ -249,7 +249,7 @@ arrays › array_access3
)
(i32.store offset=12
(local.get $0)
(i32.const 55)
(i32.const 61)
)
(i32.store offset=16
(local.get $0)
Expand Down
6 changes: 3 additions & 3 deletions compiler/test/__snapshots__/arrays.74d79181.0.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ arrays › array_access5
)
(i32.store offset=12
(local.get $0)
(i32.const 55)
(i32.const 61)
)
(i32.store offset=16
(local.get $0)
Expand Down Expand Up @@ -183,7 +183,7 @@ arrays › array_access5
)
(i32.store offset=12
(local.get $0)
(i32.const 57)
(i32.const 63)
)
(i32.store offset=16
(local.get $0)
Expand Down Expand Up @@ -249,7 +249,7 @@ arrays › array_access5
)
(i32.store offset=12
(local.get $0)
(i32.const 55)
(i32.const 61)
)
(i32.store offset=16
(local.get $0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ basic functionality › assert2
)
(i32.store offset=8
(local.get $0)
(i32.const 45)
(i32.const 51)
)
(i32.store offset=12
(local.get $0)
(i32.const 53)
(i32.const 59)
)
(i32.store offset=16
(local.get $0)
Expand Down
10 changes: 5 additions & 5 deletions compiler/test/stdlib/immutablearray.test.gr
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ let fromList = ImmutableArray.fromList
let arr = fromList([1, 2, 3])

// for testing the case where the tail is empty
let noTail = Range.map(identity, Range.Exclusive(0, 32))
let noTail = Range.map(identity, { rangeStart: 0, rangeEnd: 32 })
let noTailArr = fromList(noTail)

// for testing the case where the tree branches and has a tail of max length
let branchingLongTailLen = 32 * 33 + 31
let branchingLongTail = Range.map(
identity,
Range.Exclusive(0, branchingLongTailLen)
{ rangeStart: 0, rangeEnd: branchingLongTailLen }
)
let bltArr = fromList(branchingLongTail)

// for testing the case where the tree is about to branch
let almostBranchingLen = 32 * 32 + 31
let almostBranching = Range.map(
identity,
Range.Exclusive(0, almostBranchingLen)
{ rangeStart: 0, rangeEnd: almostBranchingLen }
)
let abArr = fromList(almostBranching)

Expand Down Expand Up @@ -92,10 +92,10 @@ assert ImmutableArray.append(bltArr, fromList([val, val + 1, val + 2])) ==
fromList(List.append(branchingLongTail, [val, val + 1, val + 2]))
assert ImmutableArray.append(fromList([-3, -2, -1]), bltArr) ==
fromList([-3, -2, -1, ...branchingLongTail])
let vals = Range.map(x => x + 32, Range.Exclusive(0, 128))
let vals = Range.map(x => x + 32, { rangeStart: 0, rangeEnd: 128 })
assert ImmutableArray.append(noTailArr, fromList(vals)) ==
fromList(List.append(noTail, vals))
let vals = Range.map(x => x + 32, Range.Exclusive(0, 128 + 31))
let vals = Range.map(x => x + 32, { rangeStart: 0, rangeEnd: 128 + 31 })
assert ImmutableArray.append(noTailArr, fromList(vals)) ==
fromList(List.append(noTail, vals))
assert ImmutableArray.append(noTailArr, noTailArr) ==
Expand Down
Loading