Commit graph

208 commits

Author SHA1 Message Date
Richard Feldman
e9acbe983f
Use array over vec for exists_many 2022-04-09 10:09:03 -04:00
Richard Feldman
dd56fdb61c
Fix regression with ZeroArgumentTag constraint gen
Turns out it can't share quite that much code with Tag,
because doing so skips the important function-based
constraints.
2022-04-08 21:31:19 -04:00
Richard Feldman
b2ff785a5e
Another clip bites the clip 2022-04-08 19:56:43 -04:00
Richard Feldman
45b5df3a23
Extract constrain_tag helper function 2022-04-08 11:52:57 -04:00
Folkert
7b86a4b29e
optimize variable substitution in instantiate_rigids 2022-03-21 23:57:40 +01:00
hafiz
418e71e95c
Merge pull request #2755 from rtfeldman/dense-let-constraints
Constraint gen tweaks
2022-03-19 20:39:55 -04:00
Folkert
a1dbdf34d5
simplify empty let constraint 2022-03-19 23:41:56 +01:00
Folkert
a20a828ee1
refactor typed function constraint gen 2022-03-19 23:41:33 +01:00
Folkert
9b63e6a3a9
simplify IntroducedVariables 2022-03-18 23:47:39 +01:00
Folkert
b1612384c7
implement constrain crate 2022-03-17 19:17:52 +01:00
ayazhafiz
3da34fc843 Report unbound type variables in aliases, opaques
Closes #2726
2022-03-14 17:42:45 -05:00
Folkert
872d32652a
remove clone, yay 2022-03-13 22:58:16 +01:00
Folkert
f7ba9918fa
use equal_types_with_storage in opaque type constraining 2022-03-13 22:54:13 +01:00
Folkert
80af910c4f
use equal_types_with_storage in tag constraining 2022-03-13 22:53:22 +01:00
Folkert
7df4465a6e
use equal_types_with_storage in Lambda constraining 2022-03-13 22:47:25 +01:00
Folkert
f23945ad94
use equal_types_with_storage in record constraining 2022-03-13 22:47:07 +01:00
Folkert
e8bf5fa378
prevent clone for all function signatures 2022-03-13 22:35:56 +01:00
Folkert
8b2c1707d4
don't even create a type if we only need a variable 2022-03-13 02:12:45 +01:00
Folkert
b3d9f9c2de
use EitherIndex<Type, Variable> to halve number of types stored 2022-03-13 01:46:49 +01:00
hafiz
de9da2d8a5
Merge pull request #2657 from rtfeldman/i/2567
Register accessor closures when they are bound
2022-03-06 12:59:55 -05:00
ayazhafiz
0692caf7ba Consolidate Accessor data 2022-03-06 11:07:31 -05:00
ayazhafiz
3bff99b0a2 Register accessor closures when they are bound
Previously we only registered record accessor closures in anonymous
contexts, where we assume they must already be specialized based on the
surrounding contexts. This is not true in general since one might bind
an accessor to a name.

Closes #2567
2022-03-06 10:53:12 -05:00
Folkert
9f11245b22
add comment 2022-03-05 22:29:30 +01:00
Folkert
6380a9edf9
remove collection that went unused 2022-03-05 22:29:22 +01:00
Folkert
587c89e003
use empty array for empty DefTypes sequence 2022-03-05 21:51:20 +01:00
Folkert
6392e42166
prevent frequent expectation cloning 2022-03-05 21:32:22 +01:00
Folkert
53962a4799
mark infer variables as flex 2022-03-05 17:27:33 +01:00
Folkert
48b0bbe874
cleanup 2022-03-05 14:55:45 +01:00
Folkert
97b0e3df9b
more efficient approach for finding new rigids 2022-03-05 14:50:23 +01:00
Folkert
9302f2ca5e
partially revert to working state 2022-03-05 13:18:35 +01:00
ayazhafiz
e0aa246c5e Merge remote-tracking branch 'origin/trunk' into instantiate-rigids-speedup-again 2022-03-04 21:55:16 -05:00
Folkert
39c4b878e5
remove comment 2022-03-04 23:27:05 +01:00
Folkert
db06c10b5f
be smarter 2022-03-04 23:02:10 +01:00
Folkert
38d3d3169a
drop final suffixes 2022-03-02 21:30:38 +01:00
Folkert
828483393a
move expr/pattern constraint gen 2022-03-02 21:25:13 +01:00
Folkert
ec099bbdec
WIP 2022-03-02 14:46:30 +01:00
ayazhafiz
059c324268 Error reporting for type mismatches involving opaques 2022-02-27 00:10:12 -05:00
ayazhafiz
b6d7229525 Infer + checking tests for opaques 2022-02-27 00:10:12 -05:00
ayazhafiz
86aa0df661 Add constraint generation for opaque types 2022-02-27 00:10:11 -05:00
Brendan Hansknecht
f7c0e2ef19 Merge remote-tracking branch 'origin/trunk' into single-quote-literal 2022-02-24 10:13:39 -08:00
ayazhafiz
f8c7349193 Simplify pattern constraint generation
At the time we introduced presence constraints for tag unions, I added a
"destruct_position" variable so that we didn't change the typechecking
semantics for everything all at once, and because I wasn't totally sure
what I was doing was correct. But now we're more confident in this
approach, and every pattern is by definition a destructuring, so there
is no need for this flag.

Also should fix some potential bugs we didn't notice before with presence
constraints in closure variables, though I can't find a good test to
reproduce this, since closure variables are hidden from the user.
2022-02-24 01:08:18 -05:00
ayazhafiz
6b53692aac Canonicalize opaque types 2022-02-20 13:47:01 -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
8e7ca57458 Close tag unions that are in the left hand side of an assignment 2021-12-30 19:51:14 -06:00
ayazhafiz
fda6c70835 Mark patterns in lambda argument position as having a presence constraint
Closes #2299
2021-12-30 18:21:28 -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
Joshua Warner
22e2545fd6 format 2021-12-22 20:46:42 -08:00
Joshua Warner
f19220473a Rename Located -> Loc 2021-12-22 19:18:22 -08:00
Anton-4
cf80f510cb change import for rust analyzer 2021-12-09 14:55:43 +01:00