Commit Graph

757 Commits

Author SHA1 Message Date
Folkert
957140df64 remove builtin lookup function being passed around 2022-02-14 20:32:31 +01:00
hafiz
91483dbf55
Merge pull request #2471 from rtfeldman/fix_args_order
Swap arg order in `List` builtins to put the more-complex types first
2022-02-13 23:25:05 -05:00
ayazhafiz
ac680d0750 Aliases should not be public 2022-02-12 21:23:44 -05:00
ayazhafiz
e946b972f7 Only recursive tag unions are relevant in illegal cycles 2022-02-12 20:41:19 -05:00
Jan Van Bruggen
f47dbb5171
Swap List.mapWithIndex arg1 args order to put the element first 2022-02-11 16:10:29 -07:00
ayazhafiz
55769caad6 Redundant clone 2022-02-11 08:52:37 -05:00
ayazhafiz
c71854d5a4 Remove opt_rec_var 2022-02-11 08:51:08 -05:00
ayazhafiz
8c0e39211d Instantiate recursive aliases to their smallest closures
Now, when we have two aliases like

```
T a : [ A, B (U a) ]
U a : [ C, D (T a) ]
```

during the first pass, we simply canonicalize them but add neither to
the scope. This means that `T` will not be instantiated in the
definition of `U`. Only in the second pass, during correction, do we
instantiate both aliases **independently**:

```
T a : [ A, B [ C, D (T a) ] ]
U a : [ C, D [ A, B (U a) ] ]
```

and now we can mark each recursive, individually:

```
T a : [ A, B [ C, D <rec1> ] ] as <rec1>
U a : [ C, D [ A, B <rec2> ] ] as <rec2>
```

This means that the surface types shown to users might be a bit larger,
but it has the benefit that everything needed to understand a layout of
a type in later passes is stored on the type directly, and we don't need
to keep alias mappings.

Since we sort by connected components, this should be complete.

Closes #2458
2022-02-11 08:43:33 -05:00
ayazhafiz
c064c50036 Catch illegal alias cycles more strictly
Part of #2458
2022-02-10 22:12:33 -05:00
ayazhafiz
13552b11a6 Check self- and mutually-recursive aliases in the same pass 2022-02-10 08:15:48 -05:00
ayazhafiz
6d72971d6b Clippy and a ranged number unification bugfix 2022-02-06 15:04:12 -05:00
ayazhafiz
c5d918e68c Include floats in bounds for unspecified numbers 2022-02-06 15:04:12 -05:00
ayazhafiz
8dc92ccd97 Second pass 2022-02-06 15:04:12 -05:00
ayazhafiz
5e0d90ac53 First pass 2022-02-06 15:04:12 -05:00
Folkert
5e16515d22 only generate the functions that the user wants 2022-02-06 12:26:34 +01:00
Folkert
5f1e2c60f8 change how hosted declarations are pushed 2022-02-04 21:56:57 +01:00
Folkert
f1ebc523b6 Merge remote-tracking branch 'origin/trunk' into hook-up-hosted-modules 2022-02-04 00:07:23 +01:00
ayazhafiz
21d1cd786c Fix can tests 2022-02-03 00:43:04 -05:00
ayazhafiz
5362ed1e6c Clippy 2022-02-02 23:38:54 -05:00
ayazhafiz
097c5afc73 Check lower bounds for numeric literals, and permit 128-bit literals 2022-02-02 23:35:57 -05:00
Folkert
16a2b660c3 bookkeeping 2022-02-02 23:11:52 +01:00
Folkert
5699db99b3 generate hosted functions (foreign functions supplied by the linker) 2022-02-02 22:29:05 +01:00
Folkert
14c0caa275 generate the Effect type and after/map/etc methods in a hosted module 2022-02-02 16:49:56 +01:00
Folkert
c335a8b406 move effect_module.rs 2022-02-02 16:48:59 +01:00
Folkert
1fb746757c pipe module name into canonicalization of modules 2022-02-02 16:01:31 +01:00
ayazhafiz
e7dcc2daa5 Move NumWidth to roc_can 2022-02-02 00:23:43 -05:00
ayazhafiz
df8113ce32 Typecheck numeric suffixes in patterns 2022-02-01 23:35:14 -05:00
ayazhafiz
a6f7579c07 Parse and expand numeric bounds in canonicalization pass 2022-02-01 22:50:46 -05:00
ayazhafiz
f55e767035 Fix test_can tests 2022-02-01 22:49:52 -05:00
ayazhafiz
e03592930f Typecheck numeric literals with suffixes in expressions
Part of #2350
2022-02-01 22:49:50 -05:00
ayazhafiz
320827167f Parse number literal width suffixes
Supports [u,i][8,16,32,64,128] and [nat,dec]

Part of #2350
2022-02-01 22:48:48 -05:00
ayazhafiz
a9ed4ce4ce Removing references 2022-01-31 22:58:15 -05:00
ayazhafiz
4e942b3e5d Make nested datatypes into errors
I was hoping to add nested datatypes into the language, but it turns out
doing so is quite tricky and not all that useful with Roc's current
compilation model. Basically every implementation strategy I could think
of ended up requiring a uniform representation for the data layout
(or some ugly workaround). Furhermore it increased the complexity of the
checker/mono IR generator a little bit - basically, we must always pass
around the alias definitions of nested datatypes and instantiate them
at usage sites, rather than being able to unroll aliases as we currently
do during canonicalization.

So, especially because we don't support polymorphic recursion anyway, I
think it may be better to simply disallow any kind of nested datatypes
in the language. In any case, Stephanie Weirich [seems to think nested
datatypes are not needed](https://www.cis.upenn.edu/~plclub/blog/2020-12-04-nested-datatypes/).

Closes #2293
2022-01-31 22:58:01 -05:00
Folkert
b3d605cade fix failing debug_assert 2022-01-26 20:22:18 +01:00
Folkert
0298013346 fix logical error 2022-01-26 17:03:49 +01:00
ayazhafiz
095204ec7a Fix can tests 2022-01-23 12:35:31 -05:00
ayazhafiz
0eede1cd86 Generate unique symbols for shadowing identifiers
This code has a shadowing error:

```
b = False
f = \b -> b
f b
```

but prior to this commit, the compiler would hit an internal error
during monomorphization and not even get to report the error. The reason
was that when we entered the closure `\b -> b`, we would try to
introduce the identifier `b` to the scope, see that it shadows an
existing identifier, and not insert the identifier. But this meant that
when checking the body of `\b -> b`, we would think that we captured the
value `b` in the outer scope, but that's incorrect!

The present patch fixes the issue by generating new symbols for
shadowing identifiers, so deeper scopes pick up the correct reference.
This also means in the future we may be able to compile and execute code
with shadows, even though it will still be an error.

Closes #2343
2022-01-23 12:35:31 -05:00
Richard Feldman
0e8d20418a
Merge pull request #2387 from rtfeldman/add_builtins_Num.minmaxIU816
Add `Num.(min/max)(I/U)(8/16)` builtins
2022-01-22 22:40:35 -05:00
ayazhafiz
48a3e871e8 Report self-recursive aliases at their declaration site, not in usages
Closes #2380
2022-01-22 14:26:32 -05:00
Jan Van Bruggen
9a8a4c6ed7 Add Num.(min/max)(I/U)(8/16) builtins 2022-01-22 00:19:17 -07:00
Jan Van Bruggen
38f0a3717f Extract repeated min/max logic 2022-01-22 00:00:29 -07:00
Folkert
2c139100ca fix big error 2022-01-21 23:30:04 +01:00
Eric Newbury
a96d5e6abf Merge branch 'trunk' into enewbury/list-sort-desc 2022-01-21 17:06:52 -05:00
Eric Newbury
7e7104d9ba WIP 2022-01-21 16:46:47 -05:00
Eric Newbury
05c01a81f5 adding List.sortAsc builtin 2022-01-21 15:34:24 -05:00
Richard Feldman
83f12b6e53
Merge pull request #2361 from rtfeldman/cleanup_builtins_Num.minmaxI128
Remove leftover TODOs from #2354
2022-01-20 18:21:29 -05:00
Richard Feldman
eacbb956cf
Merge pull request #2360 from rtfeldman/builtins-using-builtins
using builtins from builtins
2022-01-20 18:20:50 -05:00
Richard Feldman
6d8277ad8d
Merge pull request #2367 from rtfeldman/remove_Num.minmaxInt
Remove `Num.(min/max)Int`
2022-01-20 00:19:44 -05:00
Jan Van Bruggen
8e4b6f0cab Remove Num.(min/max)Int
Replace all uses with `Num.(min/max)I64`,
since all uses expect an `I64`.
2022-01-19 09:55:06 -07:00
Jan Van Bruggen
1e9d2d1239 Remove accidental trailing spaces 2022-01-18 22:25:46 -07:00