Commit Graph

68 Commits

Author SHA1 Message Date
Folkert
afd11e1cb1 move target -> roc_target 2022-01-26 23:33:29 +01:00
Folkert
b9c318e9fb update the tests 2022-01-26 15:59:21 +01:00
Folkert
74932a4cab phase 2 2022-01-26 14:30:37 +01:00
Folkert
8aae60ddda fix reporting tests 2022-01-25 10:25:05 +01:00
Folkert de Vries
6dd769aa38
Merge pull request #2393 from rtfeldman/i/2343
Generate unique symbols for shadowing identifiers
2022-01-24 11:49:51 +01:00
Mats Sigge
71f359fbdc Move macros from roc_reporting to new roc_error_macros module
The `internal_error!` and `user_error!´ macros can't be used everywhere
when they live in `roc_reporting` due to circular dependencies.
2022-01-23 18:40:04 +01:00
ayazhafiz
c6d47dbca5 Fix reporting tests 2022-01-23 12:35:31 -05:00
ayazhafiz
48a3e871e8 Report self-recursive aliases at their declaration site, not in usages
Closes #2380
2022-01-22 14:26:32 -05:00
Jan Van Bruggen
1e9d2d1239 Remove accidental trailing spaces 2022-01-18 22:25:46 -07:00
ayazhafiz
5058e3cfc4 Fix panic during reporting
Closes #2326
2022-01-12 22:02:51 -05:00
Joshua Warner
f22f96843e Refactor ParseProblem
* Remove the `pos` field, which was always being assigned Position::default()
* Remove one use of this `pos`, by removing the never-used SyntaxError::ConditionFailed variant
* Adjust the other use to do what was probably intended - which is to say, pointing to the beginning of the def with the error
* Rename to FileError, reuse `SourceError` as an inner field, to avoid duplicating the `bytes`
2022-01-03 20:10:50 -08:00
Joshua Warner
650c29de3c Change LineColumn::column to u32 to avoid overflow, and remove LineTooLong error 2022-01-02 21:50:42 -08:00
Joshua Warner
8092f31a29 fmt 2022-01-01 18:20:05 -08:00
Joshua Warner
5c1084c453 Introduce SourceError to represent an error + original source 2022-01-01 18:20:05 -08:00
Joshua Warner
cb8cf44596 fmt 2022-01-01 18:20:05 -08:00
Joshua Warner
70156b0a90 Simplify advancing 2022-01-01 18:20:05 -08:00
Joshua Warner
4b04ec6bbc Add Position::offset, and recompute line/column info based on source 2022-01-01 18:20:05 -08:00
Joshua Warner
443d738f9b Make Position::{line, column} fields private 2022-01-01 18:20:05 -08:00
Joshua Warner
34e24fa2ba improve test_reporting error reports 2022-01-01 18:20:05 -08:00
Joshua Warner
82d2be0635 Introduce LineColumnRegion and force conversion 2022-01-01 18:20:05 -08: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
dae94f4aaa Improve error message 2021-12-26 08:51:35 -06:00
ayazhafiz
3b209b1164 Report type alias issues 2021-12-26 08:44:10 -06: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
005d7c391c Add an extra reporting test 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
Joshua Warner
22e2545fd6 format 2021-12-22 20:46:42 -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
Joshua Warner
96e8916594 Refactor BadOperator to take a &str rather than &[u8] 2021-12-18 14:42:48 -08:00
Joshua Warner
49818343dd extract state 2021-12-16 17:13:53 -08:00
Jan Van Bruggen
d03a51c75b Rename base package to pf everywhere, to match tutorial 2021-12-12 05:57:39 -07:00
Folkert
e110f5137f fix test compilation failure 2021-11-28 15:41:36 +01:00
Folkert
1241d5ccbd make UpdateModeIds a proper type 2021-11-28 14:03:48 +01:00
ayazhafiz
d352d2cdf8 Revert "Include annotation type signatures in Expected struct"
This reverts commit 6e4fd5f06a1ae6138659b0073b4e2b375a499588.

This idea didn't work out because cloning the type and storing it on a
variable still resulted in the solver trying to uify the variable with
the type. When there were errors, which there certainly would be if we
tried to unify the variable with a structure that had nested flex/rigid
vars, the nested flex/rigid vars would inherit those errors, and the
program wouldn't typecheck.

Since the motivation here was to expose the signature type to
`reporting` so that we could modify it with suggestions, we should
instead pass that information along in something analogous to the
`Expected` struct.
2021-11-25 13:24:42 -05:00
ayazhafiz
a8e38172ac Remove redundant refs 2021-11-25 11:22:19 -05:00
ayazhafiz
7f6a8cbaea Improve wildcard collision error message from Richard's review 2021-11-25 11:16:18 -05:00
ayazhafiz
3b7596dd34 Remove redundant clones 2021-11-25 11:16:18 -05:00
ayazhafiz
5542441d42 Add an additional test for wildcard conflicts and type var suggestions 2021-11-25 11:16:18 -05:00
ayazhafiz
3f3a34382c Suggest non-conflicting type variable name for wildcard renaming
There is still a potential for conflicts here, because we don't look at
type variables introduced _prior_ to this annotation. However, this
should be okay in most cases.
2021-11-25 11:16:18 -05:00
ayazhafiz
ee34e79790 Include annotation type signatures in Expected struct
To provide better error messages and suggestions related to changing
type annotations, we now pass annotation type signatures all the way
down through the constraint solver. At constraint generation we
associate the type signature with a unique variable, and during error
reporting, we pull out an `ErrorType` corresponding to the original type
signature, by looking up the unique variable. This gives us two nice
things:

1. It means we don't have to pass the original, AST-like type
   annotation, which can be quite large, to everyone who looks at an
   expectation.
2. It gives us a translation from a `Type` to an `ErrorType` for free
   using the existing translation procedure in `roc_types::subs`,
   without having to create a new translation function.
2021-11-25 11:16:17 -05:00
ayazhafiz
8726e38dad Improve error message when nested wildcards are connected
We now push analysis of when two wildcards are associated with each
other to the time when we try to give tips for a diff between types. Two
wildcards always have a diff, since they are associated with different
types.
2021-11-25 11:15:31 -05:00
ayazhafiz
817bb22f9e Improve error message when we try to unify two wildcards
Closes #1931
2021-11-25 11:15:31 -05:00
ayazhafiz
8f1878bc42 Print type annotation in all type errors related to annotations 2021-11-25 11:15:31 -05:00
ayazhafiz
62873fed81 Propogate original annotation region down in AnnotationSource
This makes it easier for error reporting to find the relevant
annotations that were part of a type error, and display that in the
error message presented to a user.
2021-11-25 11:15:31 -05:00
ayazhafiz
7a0ecbd262 Fix grammar issue in rigids type annotation tip 2021-11-25 11:15:31 -05:00
ayazhafiz
d47c52c422 Fix grammar in comment 2021-11-25 11:15:31 -05:00
Folkert de Vries
816e390e36
Merge pull request #2057 from rtfeldman/reporting-cfg-windows
Use cfg to check if we're compiling for windows (in reporting)
2021-11-24 13:29:48 +01:00
Folkert
8ce195998a clean up comment 2021-11-23 20:05:11 +01:00