Commit graph

7030 commits

Author SHA1 Message Date
ayazhafiz
597a1cef3b Attach location to alias header name 2021-12-26 09:17:27 -06:00
ayazhafiz
11da888c07 Pull out alias header as its own struct 2021-12-26 09:07:12 -06:00
ayazhafiz
507f219d28 Satiate clippy 2021-12-26 08:44:10 -06:00
ayazhafiz
2cd5bf8c03 Parse "as" aliases into tag/args rather than arbitrary annotations 2021-12-26 08:44:09 -06:00
Folkert de Vries
4ddb8e10fb
Merge pull request #2272 from rtfeldman/joshuawarner32/parser-benchmark
Add simple benchmark for the parser: parse false-interpreter
2021-12-26 14:38:07 +01:00
Brian Carroll
44b4d2b3c9 Enable remaining gen_compare tests for wasm 2021-12-26 10:45:23 +00:00
Brian Carroll
e54ce0c975 Ensure procs are in the same order as the Symbols 2021-12-26 10:45:23 +00:00
Brian Carroll
9fb7048de0 Rename rec_ptr_layout -> recursive_union
I kept thinking it was of type Layout but it's not
2021-12-26 10:45:23 +00:00
Brian Carroll
ab7867d233 Separate specializations from procs
This was causing issues with recursive procs.
We need to be able to look up the proc's symbol
before we have finished generating it.
2021-12-26 10:45:23 +00:00
Brian Carroll
e10acd59ee Debug config for Wasm backend 2021-12-26 10:45:18 +00:00
Brian Carroll
1f86ad3438 Fix Wasm function indices for generated helpers 2021-12-26 10:40:45 +00:00
Brian Carroll
d08b79295c Fix unique names 2021-12-26 10:40:45 +00:00
Brian Carroll
da4cf721cc Fix equality on empty structures 2021-12-26 10:40:45 +00:00
Brian Carroll
a0afb64cb0 Fix bug storing linker data for generated procs 2021-12-26 10:40:45 +00:00
Brian Carroll
0fbe49dce9 Shorten some variable names 2021-12-26 10:40:45 +00:00
Brian Carroll
ca501fdcf1 Restructure CodeGenHelp to generate IR immediately, in depth-first traversal 2021-12-26 10:40:45 +00:00
Folkert
022b1ca83a use ROC_ZIG environment variable to configure which zig is used 2021-12-25 22:27:52 +01:00
Folkert
d70e803dff add test 2021-12-24 21:19:09 +01:00
Folkert
a5957d9982 sort aliases before adding them to scope 2021-12-24 21:14:29 +01:00
Joshua Warner
a0cf5d0e70 Add simple benchmark for the parser: parse false-interpreter 2021-12-24 11:54:42 -08:00
Folkert
40e57142c4 add symbol creation helper 2021-12-24 15:16:27 +01:00
Folkert de Vries
9f938b9610
Merge pull request #2249 from rtfeldman/i/1758-2
Presence constraints for tag union types
2021-12-24 12:38:55 +01:00
Joshua Warner
8b58d5cbc7 Switch to always encoding package names / paths as strings
This will simplify parsing and make it possible to have a uniform lexer for the language. Previously unquoted package names were allowed to include '-'s, which aren't valid identifiers.

In the future, we'll distinguish local paths from packages in the package-manager by looking for a ".roc" suffix, which should only be present in local paths.
2021-12-23 20:11:14 -08:00
ayazhafiz
409ced0ef2 Simply constraint matching in solve 2021-12-23 20:22:42 -06:00
ayazhafiz
52c84824ba Fix typo 2021-12-23 19:40:18 -06:00
ayazhafiz
1f81a598f7 Presence constraint flag -> Enum 2021-12-23 19:40:18 -06:00
ayazhafiz
9a813b6c49 Reorder constraint introduction
This avoids an unnecessary clone if the conditional is false
2021-12-23 19:40:18 -06:00
ayazhafiz
b4c9068676 Make pattern presence constraints an enum variant 2021-12-23 19:40:18 -06:00
ayazhafiz
95ad906c59 Fix clippy warning 2021-12-23 19:40:18 -06:00
ayazhafiz
8dda9929e5 Fix clippy warning 2021-12-23 19:40:18 -06:00
ayazhafiz
b97ff380e3 Presence constraints for tag union types
This work is related to restricting tag union sizes in input positions.
As an example, for something like

```
\x -> when x is
    A M -> X
    A N -> X
    A _ -> X
```

we'd like to infer `[A [M, N]* ]` rather than the `[A, [M, N]* ]*` we
infer today. Notice the difference is that the former type tells us we
only accepts `A`s, but the argument of the `A` can be `M`, `N` or
anything else (hence the `_`).

So what's the idea? It's an encoding of the "must have"/"might have"
design discussed in https://github.com/rtfeldman/roc/issues/1758. Let's
take our example above and walk through unification of each branch.

Suppose `x` starts off as a flex var `t`.

```
\x -> when x is
    A M -> X
```

Now we introduce a new kind of constraint called a "presence"
constraint. It says "t has at least [A [M]]". I'll notate this as `t +=
[A [M]]`. When `t` is free as it is here, this is equivalent to `t ~
[A [M]]`.

```
\x -> when x is
    ...
    A N -> X
```

At this branch we introduce the presence constraint `[A [M]] += [A [N]]`.
Notice that there's two tag unions we care about resolving here - one is
the toplevel one that says "I have an `A ...` inside of me", and the
other one is the tag union that's the tyarg to `A`. They are distinct
and at different depths.

For the toplevel one, we first figure out if the number of tags in the
union needs to expand. It does not - we're hoping to resolve the type
`[A [M, N]]`, which only has `A` in the toplevel union. So, we don't
need to do anything extra there, other than the merge the nested tag
unions.

We recurse on the shared tags, and now we have the presence constraint
`[M] += [N]`. At this point it's important to remember that the left and
right hand types are backed by type variables, so this is really
something like `t11 [M] += t12 [N]`, where `[M]` and `[N]` are just what
we know the variables `t11` and `t12` to be at this moment. So how do we
solve for `t11 [M, N]` from here? Well, we can encode this constraint as
a type variable definition and a unification constraint we already know
how to solve:

```
New definition: t11 [M]a    (a fresh)
New constraint: a ~ t12 [N]
```

That's it; upon unification, `t11 [M, N]` falls out.

Okay, last step.

```
\x -> when x is
    ...
    A _ -> X
```

We now have `[A [M, N]] += [A a]`, where `a` is a fresh unbound
variable. Again nothing has to happen on the toplevel. We walk down and
find `t11 [M, N] += t21 a`. This is actually called an "open constraint"; we
differentiate it at the time we generate constraints because it follows
syntactically from the presence of an `_`, but it's semantically
equivalent to the presence constraint `t11 [M, N] += t21 a`. It's just
called opening because literally the only way `t11 [M, N] += t21 a` can
be true is if we set `t11 a`. Well, actually, we assume `a` is a tag
union, so we just make `t11` the open tag union `[M, N]a`. Since `a` is
unbound, this eventually becomes a wildcard and hence falls out `[M, N]*`.
Also, once we open a tag union with an open constraint, we never close
it again.

That's it. The rest falls out recursively. This gives us a really easy
way to encode these ordering constraints in the unification-based system
we have today with minimal additional intervention. We do have to patch
variables in-place sometimes, and the additive nature of these
constraints feels about out-of-place relative to unification, but it
seems to work well.

Resolves #1758
2021-12-23 19:40:18 -06:00
ayazhafiz
6d9a5b6b0d Actually add the test files 2021-12-23 19:39:54 -06:00
ayazhafiz
46b4a3e6d5 Add test for nested if parsing
Closes #169

It seems the above issue was resolved a long time ago but there wasn't a
test for it
2021-12-23 19:39:54 -06:00
ayazhafiz
a626214852 Fix use of undeclared symbol
090a8923c5 changed `Located -> Loc`, but
5d7aff373c introduced another instance of
`Located` and didn't have the commit history of 090a8923c5
2021-12-23 17:58:12 -06:00
Folkert de Vries
da6950d67d
Merge pull request #2270 from rtfeldman/remove-stale-todos
Remove stale todos in load tests
2021-12-24 00:02:48 +01:00
Folkert de Vries
5f7476d54f
Merge pull request #2266 from rtfeldman/joshuawarner32/loc
Parser refactor: always group (Row, Col) into Position
2021-12-24 00:02:13 +01:00
ayazhafiz
352754960f Remove stale todos in load tests
These no longer seem to be issues.
2021-12-23 15:29:27 -06:00
Folkert de Vries
db44d03e66
Merge pull request #2259 from rtfeldman/i/2227-record-layout-hang
Turn invalid record field types into runtime errors
2021-12-23 20:17:34 +01:00
Folkert de Vries
5d7aff373c
Merge pull request #2262 from rtfeldman/ListDropIf
Implement List.dropIf
2021-12-23 20:15:14 +01:00
Folkert de Vries
639c2e91c8
Merge pull request #2264 from rtfeldman/i/2217
Mark tag unions to recursive when they become so during unification
2021-12-23 13:24:40 +01:00
Joshua Warner
090a8923c5 Improve Debug format of Position 2021-12-22 21:09:02 -08:00
Joshua Warner
22e2545fd6 format 2021-12-22 20:46:42 -08:00
Joshua Warner
f170509bf1 rename col -> column 2021-12-22 20:37:40 -08:00
Joshua Warner
4d7070ce3b Always combine line,column into Position 2021-12-22 20:32:46 -08:00
Joshua Warner
f19220473a Rename Located -> Loc 2021-12-22 19:18:22 -08:00
ayazhafiz
ac54a5e024 Remove nonsene panic 2021-12-22 19:38:10 -06:00
ayazhafiz
d6184e5529 1-branch match -> "if let" 2021-12-22 18:01:53 -06:00
ayazhafiz
88888b0854 Mark tag unions to recursive when they become so during unification
See the comment on line 811 of unify.rs in this commit for motivation
and justification.

Closes #2217
2021-12-22 17:51:07 -06:00
Richard Feldman
c66c845cd2
Merge pull request #2258 from rtfeldman/joshuawarner32/format-all-examples
Format all examples and add a test to assert they stay that way
2021-12-22 16:53:47 -05:00
ayazhafiz
0a94f82bc6 Simplify expect_runtime_error_panic 2021-12-22 12:43:48 -06:00