Commit graph

345 commits

Author SHA1 Message Date
Ayaz Hafiz
7c3a0807c2
Suggest binding type variables to an ability when they're unsatisfied 2022-11-23 16:37:50 -06:00
Ayaz Hafiz
c70b23ac9c
Debug Work 2022-11-22 13:04:27 -06:00
Ayaz Hafiz
dce4d6c4c7
Force occurs check for introduced types after checking annotated bodies
The current type inference scheme is such that we first introduce the
types for annotation functions, then check their bodies without
additional re-generalization. As part of generalization, we also perform
occurs checks to fix-up recursive tag unions.

However, type annotations can contain type inference variables that are
neither part of the generalization scheme, nor are re-generalized later
on, and in fact end up forming a closure of a recursive type. If we do
not catch and break such closures into recursive types, things go bad
soon after in later stages of the compiler.

To deal with this, re-introduce the values of recursive values after we
check their definitions, forcing an occurs check. This introduction is
benign because we already generalized appropriate type variables anyway.
Though, the introduction is somewhat unnecessary, and I have ideas on
how to make all of this simpler and more performant. That will come in
the future.
2022-11-22 12:58:51 -06:00
Ayaz Hafiz
414a320358
Constrain flex inference variables without re-generalization
When constraining a recursive function like

```
f : _ -> {}
f : \_ -> f {}
```

our first step is to solve the value type of `f` relative to its
annotation. We have to be careful that the inference variable in the
signature of `f` is not generalized until after the body of `f` is
solved. Otherwise, we end up admitting polymorphic recursion.
2022-11-22 10:43:59 -06:00
Ayaz Hafiz
e36618b9e9
Support custom abilities for opaques with immaterial lambda sets
If a specialization of an ability member has a lambda set that is not
reflected in the unspecialized lambda sets of the member's prototype
signature, then the specialization lambda set is deemed to be immaterial
to the specialization lambda set mapping, and we don't need to associate
it with a particular region from the prototype signature.

This can happen when an opaque contains functions that are some specific
than the generalized prototype signature; for example, when we are
defining a custom impl for an opaque with functions.

Addresses a bug found in 8c3158c3e0
2022-11-21 18:03:56 -06:00
Ayaz Hafiz
e1afd964c7
Correct when fixpoint-fixed type variables can be reunified
With fixpoint-fixing, we don't want to re-unify type variables that were
just fixed, because doing so may change their shapes in ways that we
explicitly just set them up not to be changed (as fixpoint-fixing
clobbers type variable contents).

However, this restriction need only apply when we re-unify two type
variables that were both involved in the same fixpoint-fixing cycle. If
we have a type variable T that was involved in fixpoint-fixing, and we
unify it with U that wasn't, we know that the $U \notin \bar{T}$, where
$\bar{T}$ is the recursive closure of T. In these cases, we do want to
permit the usual in-band unification of $T \sim U$.
2022-11-21 15:57:36 -06:00
Richard Feldman
721841fa1f
Provide roc_cache_dir everywhere 2022-11-20 19:53:48 -05:00
Ayaz
1a3119e4c5
Merge pull request #4525 from roc-lang/fix-fixpoints-2
Implement fixpoint-fixing and unconditionally emplace variables into type indices
2022-11-19 17:47:02 -06:00
Ayaz
a74d7e14b7
Merge branch 'main' into i4416
Signed-off-by: Ayaz <20735482+ayazhafiz@users.noreply.github.com>
2022-11-17 09:07:00 -06:00
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
f7bc3148ae
Address lints 2022-11-16 14:05:53 -06:00
Ayaz Hafiz
972e531431
Check in solve test
Closes #4077
2022-11-16 14:05:52 -06:00
Ayaz Hafiz
0a9a20a53c
Correct emplace variables in type indices during translation
Prior to this commit, we emplace type variables into `Index<TypeTag>`
only for translated top-level types. However, we need to be careful to
do this emplacement for nested types as well! This patch ensures we do,
but immediately emplacing the destination variable of a type when we
allocate a variable for it.
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
3305041316
Add Debug derives in lambda set compaction 2022-11-16 13:55:15 -06:00
Ayaz Hafiz
ce160f28a2
Chase under aliases during occurs checking
Closes #4368
2022-11-15 16:22:01 -06:00
Folkert de Vries
5e5218fc7e
Merge pull request #4501 from roc-lang/types-soa-variable-opt
Emplace variables after converting SoA types, and remove types from constraining
2022-11-15 18:35:56 +01:00
Ayaz Hafiz
b30e8fc9b2
Remove Cells from Types 2022-11-15 09:00:16 -06:00
Folkert de Vries
de472015f6
Merge pull request #4505 from roc-lang/fix-web-repl-palette
Fix web REPL error formatting by routing the active Palette everywhere
2022-11-15 15:49:37 +01:00
Ayaz Hafiz
a52e9d605d
Remove unneeded type storage in constraining 2022-11-14 15:15:21 -06:00
Ayaz Hafiz
5564796927
SoA Types get variable emplacement (!)
We're now reaching the steady state we want to be closert to - when a
type is translated to a variable, emplace the variable we created for it
in the type index, so that types are never converted again!
2022-11-14 15:15:19 -06:00
Folkert
662bf1de99
more workspace dependencies 2022-11-13 16:10:02 +01:00
Brian Carroll
ed048c7c93
Fix more tests 2022-11-12 09:12:28 +00:00
Ayaz Hafiz
a2e90c3709
Fix types SoA usage in solve 2022-11-11 21:16:23 -06:00
Ayaz Hafiz
6b5f632364
[skip-ci] Fix borrow issues in constraining 2022-11-11 21:16:22 -06:00
Ayaz Hafiz
e3ef9828c7
Store solve aliases as TypeTag 2022-11-11 21:16:05 -06:00
Ayaz Hafiz
e3dbf5c09c
Use capacity when constructing aliases 2022-11-11 21:16:04 -06:00
Ayaz Hafiz
0d642929aa
Remove builtin aliases in favor of alias instantiation optimizations 2022-11-11 21:16:04 -06:00
Ayaz Hafiz
314b75b0e5
Feed SoA Types from load into solve 2022-11-11 21:16:03 -06:00
Ayaz Hafiz
28c3709ddf
Miscellaneous cleanup 2022-11-08 14:11:26 -06:00
Ayaz Hafiz
fb643758bb
Remove Unified BadType 2022-11-08 14:11:25 -06:00
Ayaz Hafiz
09748aec48
Remove problems from error type API surface 2022-11-08 14:11:25 -06:00
Ayaz Hafiz
281bc94b55
Remove FlatType::Erroneous 2022-11-08 14:11:25 -06:00
Ayaz Hafiz
c9953129cb
Remove problem storage in Type::Erroneous 2022-11-08 14:11:24 -06:00
Ayaz
b984351514
Merge pull request #4489 from roc-lang/types-soa-more-in-solve
Types SoA for aliases instantiated during solving
2022-11-08 14:06:57 -06:00
Folkert de Vries
95f8bac859
Merge pull request #4485 from roc-lang/types-soa
Types SoA and Type -> Variable conversion via SoA
2022-11-08 20:32:27 +01:00
Ayaz Hafiz
7034a4d692
Types SoA for aliases instantiated during solving 2022-11-08 12:57:30 -06:00
Ayaz Hafiz
db8e135a05
Simplify AbilitySet storage 2022-11-08 09:00:25 -06:00
Ayaz Hafiz
191798cfd6
Address clippy 2022-11-08 09:00:25 -06:00
Ayaz Hafiz
b735188542
Life is short, no need to spell it out 2022-11-08 09:00:25 -06:00
Ayaz Hafiz
09ec545995
Fix indent 2022-11-08 09:00:25 -06:00
Ayaz Hafiz
e240b18b27
Recover Erroneous in type 2022-11-08 09:00:25 -06:00
Ayaz Hafiz
58020a55d6
Type to variable through Types SoA 2022-11-08 09:00:24 -06:00
Ayaz Hafiz
dad9a8e537
Pass Types SoA repr in types to Variable translation 2022-11-08 09:00:24 -06:00
Luke Boswell
2c2a70b8e7 Merge remote-tracking branch 'upstream/main' into rust-docs 2022-11-06 09:15:57 +11:00
Folkert
66a1ba00eb
1.65 clippy fixes 2022-11-03 16:20:37 +01:00
Luke Boswell
a3f901427a
correct formatting and removed duplicate image 2022-11-03 20:02:10 +11:00
Luke Boswell
f3bdb5f321
updating rust package documentation 2022-11-03 20:00:06 +11:00
Ayaz Hafiz
3362763e45
Coalesce signature types in value def constraining 2022-11-02 15:05:41 -05:00
Ayaz Hafiz
34cd1fb825
Pattern expectation takes a type index 2022-11-02 15:05:40 -05:00