-
Notifications
You must be signed in to change notification settings - Fork 563
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Drop UnusableDeclaration; update NoInstanceFound error (#4513)
With the advent of visible type applications (VTAs), all type class instances can be determined via VTAs. This PR removes the `UnusableDeclaration` error. Whereas before, the code would throw the above error when type variables in the type class head are not mentioned in the type class member's type signature, now we simply track these "VTA-required" args. These args represent type variables that must be disambiguated using VTAs. If VTAs are used, the instance should be found. If they are not used, an updated `NoInstanceFound` error is thrown that notifies the user of these "VTA-required" args if possible. When a `NoInstanceFound` error is thrown, we do not attempt to do anything other than notify the user of the "VTA-required" args. In a previous and problematic approach, we did try to do more but found a number of difficult problems with this approach: - Suggesting a correct usage of `coerce` with VTAs in all of its complex cases - When a user does supply a VTA arg, assuming that that arg refers to a corresponding type in a valid type class instance: `foo @Int` when there is no `Foo Int` instance - User confusion due to a difference in order of VTA args with their usage within the type class member's type signature: `foo @1 @2` when `foo :: forall one two. two -> one` A side effect of dropping the `UnusableDeclaration` error is a scoping bug that was revealed in `moveQuantifiersToFront`. This bug has also been fixed. Other notes: - `replaceAllTypeSynonymsM` is removed as it's no longer used by anything. - The Externs files do not store the "VTA-required" args and instead recompute them after being loaded. - The "VTA-required" args are tracked via their indices so as to print them in their corresponding order later.
- Loading branch information
1 parent
2412101
commit 4f4672d
Showing
42 changed files
with
864 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
* Fix scoping issues in `moveQuantifiersToFront` | ||
|
||
As a side effect of replacing `UnusableDeclaration` with | ||
an updated `NoInstanceFound` error, a bug appeared in how | ||
scoping is handled when constraints are involved. | ||
|
||
```purs | ||
-- | a0 | ||
class Foo a where | ||
-- | a1 | ||
foo :: forall a. a | ||
``` | ||
Before this fix, `foo`'s type signature was being transformed to | ||
`foo :: forall @a a. Foo a => a` | ||
where two type variables with the same identifier | ||
are present rather than the correct signature of | ||
`foo :: forall @a0. Foo a0 => (forall a1. a1)`. | ||
|
||
With this fix, the above type class declaration | ||
will now compile and trigger a `ShadowedName` | ||
warning since the type class member's `a` | ||
(i.e. `a1` above) shadows the type class head's `a` | ||
(i.e. `a0` above). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
* Replace `UnusableDeclaration` with updated `NoInstanceFound` | ||
|
||
Previously, the following type class would be invalid | ||
because there was no way for the compiler to infer | ||
which type class instance to select because | ||
the type variable in the class head `a` was | ||
not mentioned in `bar`'s type signature: | ||
|
||
```purs | ||
class Foo a where | ||
bar :: Int | ||
``` | ||
|
||
The recently-added visible type applications (VTAs) | ||
can now be used to guide the compiler in such cases: | ||
|
||
```purs | ||
class Foo a where bar :: Int | ||
instance Foo String where bar = 0 | ||
someInt = bar @String -- use the `String` instance | ||
``` | ||
|
||
Without VTAs, the compiler | ||
will still produce an `InstanceNotFound` error, but this error | ||
has been updated to note which type variables in the class head | ||
can only be disambiguated via visible type applications. | ||
Given the following code | ||
|
||
```purs | ||
class Single tyVarDoesNotAppearInBody where | ||
useSingle :: Int | ||
single :: Int | ||
single = useSingle | ||
``` | ||
|
||
The error reported for `useSingle` will be: | ||
|
||
``` | ||
No type class instance was found for | ||
Main.Single t0 | ||
The instance head contains unknown type variables. | ||
Note: The following type class members found in the expression require visible type applications | ||
to be unambiguous (e.g. tyClassMember @Int). | ||
Main.useSingle | ||
tyNotAppearInBody | ||
``` | ||
|
||
For a multiparameter typeclass with functional dependencies... | ||
|
||
```purs | ||
class MultiFdBidi a b | a -> b, b -> a where | ||
useMultiFdBidi :: Int | ||
multiFdBidi :: Int | ||
multiFdBidi = useMultiFdBidi | ||
``` | ||
|
||
...the "Note" part is updated to read | ||
``` | ||
Note: The following type class members found in the expression require visible type applications | ||
to be unambiguous (e.g. tyClassMember @Int). | ||
Main.useMultiFdBidi | ||
One of the following sets of type variables: | ||
a | ||
b | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.