Commit graph

201 commits

Author SHA1 Message Date
Ayaz Hafiz
b43078440f
Ensure ability-bound variables are registered in their generalization pool
When we attempt to bind a type argument to an ability in an alias/opaque
instantiation, we create a fresh flex var to represent satisfaction of
the ability, and then unify the type argument with that flex var.
Previously, we did not register this fresh var in the appropriate rank
pool.

Usually this is not a problem; however, our generalization algorithm is
such that we skip adjusting the rank of redundant variables. Redundant
variables are those that are in the same unification tree, but are not
the root of the unification trees.

This means that if such a flex able var becomes the root of a
unification tree with the type argument, and the type argument is itself
generalized, we will have missed generalization of the argument.

The fix is simple - make sure to register the flex able var into the
appropriate rank pool.

Closes #4408
2022-11-16 17:09:47 -06:00
Ayaz Hafiz
972e531431
Check in solve test
Closes #4077
2022-11-16 14:05:52 -06:00
Ayaz Hafiz
9c8a4ec027
Choose hash implementation for ranged number based on default width
Closes #4416
2022-11-16 13:57:03 -06:00
Ayaz Hafiz
ce160f28a2
Chase under aliases during occurs checking
Closes #4368
2022-11-15 16:22:01 -06:00
Brian Carroll
ed048c7c93
Fix more tests 2022-11-12 09:12:28 +00:00
Ayaz Hafiz
3362763e45
Coalesce signature types in value def constraining 2022-11-02 15:05:41 -05:00
Ayaz Hafiz
9854f5f2ac
Print alias's underlying structures if OIOP vars are material 2022-10-31 09:38:22 -05:00
Ayaz Hafiz
debe6332c5
Support OIOP for type aliases 2022-10-31 09:38:21 -05:00
Ayaz Hafiz
cfe7c8e5ef
Warn on the presence of unnecessary wildcards in output positions 2022-10-31 09:38:20 -05:00
Ayaz Hafiz
f3623b1e47
Close extension types extended wiht uninhabited types after their extension 2022-10-31 09:37:40 -05:00
Ayaz Hafiz
d77080529a
Introduce polarity for extension variable printing 2022-10-31 09:37:39 -05:00
Ayaz Hafiz
1f498b52d5
Better name solve test 2022-10-24 14:02:38 -05:00
Ayaz Hafiz
3bd10698cf
Allow rigid able to unify with flex able when rigid bounds are a superset 2022-10-24 14:00:45 -05:00
Ayaz Hafiz
0a96a93a67
Add test for inferring multiple ability bounds 2022-10-24 14:00:44 -05:00
Ayaz Hafiz
e75f3c3c79
Get rid of MemberImpl::Derived
We don't need this anymore, since derived members become Impls during
canonicalization now!
2022-10-23 20:48:07 -05:00
Ayaz Hafiz
1d885c4ab2
Support deriving Decode for opaques 2022-10-23 20:48:06 -05:00
Ayaz Hafiz
c4f9aa6fe6
Add deriving toEncoder for opaques 2022-10-23 20:47:42 -05:00
Ayaz Hafiz
83813afeaf
Derive Eq for opaques 2022-10-23 20:46:56 -05:00
Ayaz Hafiz
40e05d5a00
Add support for deriving Hash for opaques 2022-10-23 20:46:56 -05:00
Ayaz Hafiz
ecab8fa25a
Make sure self-recursive checks only happen after typechecking
Programs like

```
after : ({} -> a), ({} -> b) -> ({} -> b)

fx = after (\{} -> {}) \{} -> if Bool.true then fx {} else {}
```

are legal because they always decay to functions, even if they may not
look like functions syntactically. Rather than using a syntactic check
to check for illegally-recursive functions, we should only perform such
checks after we know the types of values.

Closes #4291
2022-10-17 09:59:32 -05:00
Ayaz Hafiz
20e4295eea
Make sure type variables bound to abilities are instantiated in aliases
Closes #4259
2022-10-14 13:56:00 -05:00
Ayaz Hafiz
a256947a9f
Move Eq to Bool 2022-10-12 16:37:51 -05:00
Ayaz Hafiz
1c753ae031
Update solve tests 2022-10-12 16:37:49 -05:00
Ayaz Hafiz
16d12a51c2
Add Eq to the standard library 2022-10-12 16:37:48 -05:00
Richard Feldman
3d5728d82c
Merge pull request #4257 from roc-lang/i4246
Correctly check mutual functional recursion between opaque types
2022-10-08 16:20:27 -07:00
Ayaz
51c687df54
Merge branch 'main' into i4150
Signed-off-by: Ayaz <20735482+ayazhafiz@users.noreply.github.com>
2022-10-08 16:08:35 -05:00
Ayaz Hafiz
d9863cbbaa
Correctly check mutual functional recursion between opaque types
The mutual-recursion checks does not admit types that are not function
types; because Roc is strict, only functional values can be involved in
mutual recursion. However, this check was exercised by checking the head
constructor of a type, which is not the correct way to do it. Aliases
and opaque types may in fact be function types as well, so we must chase
their actual contents.

Closes #4246
2022-10-08 10:09:55 -05:00
Ayaz Hafiz
912cebc33d
Add tests for inferring char ranged number 2022-10-05 17:28:01 -05:00
Ayaz Hafiz
178b634266
Treat single quote literals as ranged numbers for inference purposes 2022-10-05 17:28:00 -05:00
Ayaz Hafiz
06e5110aa5
Unification of multiple tag-functions 2022-10-05 17:25:11 -05:00
Ayaz Hafiz
f68cb3b0ed
Flip order of hash signature 2022-10-04 12:14:07 -05:00
Ayaz Hafiz
eadbc0912a
Update the compiler to be aware of Hash 2022-10-04 10:22:22 -05:00
Ayaz Hafiz
06bef34829
Import Decode by default in all modules 2022-09-21 12:29:07 -05:00
Ayaz Hafiz
b7b0af0d45
Update solve tests 2022-09-21 12:29:06 -05:00
Ayaz Hafiz
454f3634fd
Import all types from Encode by default 2022-09-21 12:29:06 -05:00
Ayaz
211c297230
Merge pull request #4041 from KilianVounckx/opaque-bool
Opaque bool
2022-09-21 11:15:41 -05:00
kilianv
9717747a54
Update tests
not all tests pass yet. Will look at them with Ayaz.
2022-09-20 14:42:03 -05:00
Ayaz Hafiz
412c73c54c
Add test cases for uninhabited variant collapsing with destructure patterns
Closes #4080
2022-09-20 14:22:40 -05:00
Ayaz Hafiz
be853b65c5
Support unification of extension types with uninhabited branches 2022-09-19 10:32:39 -05:00
Ayaz Hafiz
ac752adc7c
Check in some more work 2022-09-16 16:09:21 -05:00
Ayaz Hafiz
c2452ff751
Lose rigidity of annotated optional fields before generalization
We have this idea of "rigid optional" fields to annotate record fields
that must necessarily be optional. That avoids the admission of programs
we cannot faithfully compile, like

```
f : {a: Str, b ? U64}
f = {a: "b", b: 1}
```

We want to lose the rigidity restriction when a generalized symbol is
used as at a specialized site; for example it should be possible to call
`f : {x ? Str} -> {}` with both `{}` and `{x : Str}`, neither of which
have a rigidly optional field unless they were to be annotated.

Prior to this commit we would loosen the rigidity restriction upon
specialization of a generalized type at a use site. However, what we
really want to do is apply the loosening during calculation of
generalization. The reason is that otherwise, we must make types that
would be ground (like `{x ? Str} -> {}`) generalized just for the sake
of the optional field annotation. But since the rigidity constraint is
irrelevant after an annotated body has been checked, we can loosen the
rigidity restriction then, which conveniently happens to coincide with
the generalization calculation.

Closes #3955
2022-09-06 17:44:04 -05:00
Ayaz Hafiz
641169854e
Ignore unused branch patterns in tests 2022-08-20 10:05:22 -05:00
Ayaz Hafiz
6bcd682dde
Support captures between mutually recursive closures 2022-08-13 10:25:18 -07:00
Ayaz Hafiz
e97ce32b88
Fixup transient closure captures during canonicalization
Closure captures can be transient, but previously, we did not handle
that correctly. For example, in

```
x = ""
inner = \{} -> x
outer = \{} -> inner {}
```

`outer` captures `inner`, but `inner` captures `x`, and in the body of
`outer`, we would not construct the closure data for `inner` correctly
before calling it.

There are a couple ways around this.

1. Update mono to do something when we are passed the captured
   environment of a closure, rather than attempting to construct a
   call-by-name's captured environment before callign it.
2. Fix-up closures during canonicalization to remove captured closures
   that themselves capture, and replace them with their captures.

This patch does (2), since (1) is much more involved and is not likely
to bring a lot of wins. In general I think it's reasonable to expect
captured environments, even if transient, to be fairly shallow, so I
don't think this will produce very large closure environments.

Closes #2894
2022-08-13 10:25:17 -07:00
Richard Feldman
97e2900bf5
s/rtfeldman/roc-lang/g in links to GitHub repos 2022-08-12 15:24:09 -04:00
Folkert de Vries
0798f787c5
Merge pull request #3736 from rtfeldman/i3687
Creation of a record whose type has an optional value is an error
2022-08-11 15:51:41 +02:00
Ayaz Hafiz
a1445c25bd
Update solve test 2022-08-10 20:24:20 -07:00
Ayaz Hafiz
40c73b4138
Add more names 2022-08-09 18:13:25 -07:00
Ayaz Hafiz
e1fb21fc59
Reproduce recursive lambda set inference 2022-08-09 14:09:57 -07:00
Ayaz Hafiz
6ebb0bfa6d
Fix solve tests 2022-08-02 16:15:35 -05:00