Commit Graph

64 Commits

Author SHA1 Message Date
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
ba678d924d Remove unused variables 2021-11-25 11:16:18 -05:00
ayazhafiz
fe85af8d03 Fix failing compilation in Expr2 2021-11-25 11:16:18 -05:00
Folkert
2c1005fdf0 remove lowercases from Content 2021-11-22 21:15:58 +01:00
ayazhafiz
d4b2f17ac5 Implement inference variable solving in Expr2
Part of #1804
2021-11-21 23:20:40 -05:00
Folkert de Vries
71233fcfc1
Merge pull request #2012 from rtfeldman/i/1714
Take syntactic sugar into account when reporting errors
2021-11-19 10:26:24 +01:00
Folkert de Vries
a58c999d3e
Merge pull request #2008 from rtfeldman/improve-typo-suggestions
Minor improvements to "did you mean?" suggestions provided for missing identifiers
2021-11-19 10:24:52 +01:00
ayazhafiz
fe99d20be5 Apply review suggestions 2021-11-18 21:49:37 -05:00
ayazhafiz
8b7217847d Rename additional stale roc_module::operator refs and format 2021-11-18 20:20:33 -05:00
ayazhafiz
8a60162a1e Rename roc_module::operator -> roc_module::called_via
A bit of a nit, but this file is now more general than just keeping
track of operator methods.
2021-11-18 20:20:33 -05:00
ayazhafiz
30955a1eb8 Take syntactic sugar into account when reporting errors
Previously, a program like

```roc
word = "word"

if True then 1 else "\(word) is a word"
```

would report an error like

```
── TYPE MISMATCH ───────────────────────────────────────────────────────────────

This `if` has an `else` branch with a different type from its `then` branch:

3│  if True then 1 else "\(word) is a word"
                        ^^^^^^^^^^^^^^^^^^

This concat all produces:

    Str

but the `then` branch has the type:

    Num a

I need all branches in an `if` to have the same type!
```

but this is a little bit confusing, since the user shouldn't have to
know (or care) that string interpolations are equivalent to
concatenations under the current implementation.

Indeed we should make this fully transparent. We now word the error
message by taking into account the way calls are made. To support the
case shown above, we introduce the `CalledVia::Sugar` variant to
represent the fact that some calls may be the result of desugaring the
surface syntax.

This commit also demonstrates the usage of `CalledVia` to produce better
error messages where we use binary comparison operators like `<`. There
are more improvements we can make here for all `CalledVia` variants, but
this is a good starting point to demonstrate the usage of the new
procedure.

Closes #1714
2021-11-18 20:20:33 -05:00
Folkert
9aca302c39 Merge remote-tracking branch 'origin/trunk' into deep-copy-var-to 2021-11-18 13:16:24 +01:00
ayazhafiz
3d601ac02d Ensuer RuntimeError::ValueNotExposed is built properly in roc_ast 2021-11-17 22:58:16 -05:00
Joshua Warner
7f5b873357 Parse _ in type annotations as an 'Inferred' type 2021-11-17 17:59:40 -08:00
ayazhafiz
111a835b3c Add ignored tests for annotation-only declarations in Expr2
These tests fail currently because we have not implemented type
reconstruction in the presence of annonation-only declarations, but it's
good to keep track of them for later.
2021-11-17 13:38:00 -05:00
ayazhafiz
539c737123 Implement constraint generation for annotated Expr2::FunctionDefs
This is mostly the same as the procedure for unannotated `FunctionDef`s.
The only differences are that we need to

1. note the rigid type variables that are a part of the FunctionDef
2. generate fresh type variables for the function arguments, and
   constrain them to the types of the arguments passed to us in the
   annotation

This is enough to get the constraint generation working. There are more
interesting cases that properly typecheck in the main compiler but do
not typecheck given the current state of the editor AST (see the second
test in this commit), but this is a bug due to canonicalization, not
type reconstruction.
2021-11-17 13:38:00 -05:00
ayazhafiz
9399596d86 Store rigid var names during translation of closure defs to Expr2
We ened to store the mapping of `rigid type vars -> user-declared names`
for presentation later on when we reconstruct the type of an expression
and want to pretty-print it for the user. This information is most
naturally captured on `output.introduced_variables`, as the main
compiler does so there.

We don't currently record this mapping while translating `Annotation`s
to `Annotation2`s (though we could), so we store it when we hit an
annotated expression that now needs to become an `Expr2`.
2021-11-17 13:38:00 -05:00
ayazhafiz
477ecd6c3b Store rigid type and field names as Lowercase in Expr2
Moving from storing these as slices to `Lowercase`s makes it easier to
transform to shapes we'll need later during type reconstruction, for
example a mapping of rigid type variables to their lowercase variable
names.
2021-11-17 13:38:00 -05:00
ayazhafiz
efe6a8b7c8 Pass down rigids vars for substitution during type reconstruction
Rigid vars are added to types after solutions are already found and are
only relevant for pretty printing elaborated types, so we don't keep
track of/care about their rigid names until the end of solution.
Previously we didn't provide this information in tests, though - now we
do.
2021-11-17 13:38:00 -05:00
ayazhafiz
506086e3d7 Make sure Expr2 function annotation arguments fit in a PoolVec slot
The size of a `(PatternId, Type2)` tuple is 40 bytes (4 for the
`PatternId`, 4 bytes padding, 32 for the `Type2`). This doesn't fit in
an item slot allocated by the pool, which has a max of 32 bytes. So, we
allocate the Type2 itself on the pool, and then reference its pool ID in
the resulting tuple, which lowers the total size of the tuple to 8
bytes. This is a bit wasteful, but I couldn't find a better solution
without significantly more rework.

We also reorder the Type2 and PatternId fields in the tuple to better
align with the typical `(type|type variable, pattern|expression)` tuple
structure that exists in e.g. `FunctionDef::NoAnnotation`.
2021-11-17 13:38:00 -05:00
ayazhafiz
af8fad2618 Update sizes of Type2 variants to be correct
These are outdated; the new calculations reflect the current state of
the codebase.
2021-11-17 13:38:00 -05:00
Folkert
e6c561de7a Merge remote-tracking branch 'origin/trunk' into deep-copy-var-to 2021-11-17 16:34:01 +01:00
Folkert
237d8d1c0b fix the Default instance for subs
we later rely on some variables always existing (numbers, empty record, empty tag union)
but the default instance did not insert those
2021-11-17 16:29:16 +01:00
ayazhafiz
f342bb03af Resolve clippy lints 2021-11-16 16:20:40 -05:00
ayazhafiz
3fe29c9949 Implement constraint generation for Expr2::LetFunction
We do this by treating function definition bodies as equivalent to
closures, and piggy-backing on existing work to generate constraints
over closures. Then, we just bind the function name with the resolved
type of the function body.

Support for constraint generation in the presence of annotated functions
will be added later.
2021-11-16 15:26:47 -05:00
ayazhafiz
b824302ab3 Name resolved type variables during Expr2 constrain testing
Prior to this patch we would not explicitly name solved type variables,
causing the elaborated type to appear unconstrained even when the
internal representation was constrained. For example, given a definition
like

```
\a, b -> Pair a b
```

we would generate distinct, fresh type variables for `a` and `b` but not
name them after solution. So even though the compiler knows they are
distinct, printing to the surface syntax would emit

```
*, * -> [ Pair * * ]*
```

which is incorrect, as the result type is constrained on the input type.
Instead, we now properly emit

```
a, b -> [ Pair a b ]*
```

naming variables where dependencies do exist. Where type variables are
don't constrain anything else, we can and do continue to emit the
wildcard type.
2021-11-16 11:56:39 -05:00
Joshua Warner
1fabc64fdf Use Collection in Expr::TagUnion 2021-11-13 07:38:39 -08:00
Joshua Warner
d63405d824 Make Expr::List use a Collection 2021-11-13 07:38:11 -08:00
Joshua Warner
a4ca6a31a6 Use Collection in Expr::Record and related places 2021-11-13 07:36:05 -08:00
Joshua Warner
4df0880e7a Commit local changes (whoops!) 2021-11-11 18:57:26 -08:00
Joshua Warner
04d4a8ca79 Introduce Collection as a general abstraction in the ast 2021-11-11 14:49:33 -08:00
Anton-4
053fbbba0b
add unicode TODO 2021-11-11 09:52:11 +01:00
rvcas
af6c0a1be0 chore: document the assert with a document 2021-11-07 17:24:20 -05:00
rvcas
5f7823538a feat: make pool pointer operations sound 2021-11-07 11:51:37 -05:00
Brendan Hansknecht
73e2cbcb1e Make versions numbers consistent and matching the lock files 2021-11-06 13:24:45 -07:00
Anton-4
69f6ffadab
Merge branch 'trunk' into deps 2021-11-06 18:07:34 +01:00
Kevin Sjöberg
f6d055dc62 Correct minor spelling mistakes 2021-11-06 15:29:08 +01:00
Brendan Hansknecht
bddc08c977 Remove unused dependencies 2021-11-05 16:58:11 -07:00
Richard Feldman
0bc3ff4ca5 Use std and core over libc where equivalent 2021-11-02 19:37:05 -04:00
Richard Feldman
ffbf2b4276 Move some things to dev deps 2021-11-02 19:37:05 -04:00
Anton-4
bb715e0f84 cleanup 2021-10-19 17:51:47 +02:00
Anton-4
c7c421b2f5 fixed scope lookup bug 2021-10-19 16:45:28 +02:00
Anton-4
0a77b3f334 debugging wrong id in docs test 2021-10-18 19:58:03 +02:00
Anton-4
a272765fc7 started using scope properly, improved error backtrace conversion 2021-10-16 19:37:20 +02:00
Anton-4
2158686a0a fmt, improved todo 2021-10-15 19:29:48 +02:00
Anton-4
d3f2b95f7a addes test to docs for function 2021-10-15 15:02:37 +02:00
Anton-4
428b4574ae Merge branch 'trunk' of github.com:rtfeldman/roc into function_closure_to_mark_node 2021-10-15 12:04:51 +02:00
Anton-4
0058037ed2 bugfixes 2021-10-13 17:41:26 +02:00
Anton-4
4828c9ba62 fmt 2021-10-13 12:37:30 +02:00
Anton-4
810c7dce80 bug fixes 2021-10-12 20:16:03 +02:00