Commit graph

317 commits

Author SHA1 Message Date
Folkert de Vries
5f7476d54f
Merge pull request #2266 from rtfeldman/joshuawarner32/loc
Parser refactor: always group (Row, Col) into Position
2021-12-24 00:02:13 +01:00
Folkert de Vries
db44d03e66
Merge pull request #2259 from rtfeldman/i/2227-record-layout-hang
Turn invalid record field types into runtime errors
2021-12-23 20:17:34 +01:00
Joshua Warner
f19220473a Rename Located -> Loc 2021-12-22 19:18:22 -08:00
ayazhafiz
88888b0854 Mark tag unions to recursive when they become so during unification
See the comment on line 811 of unify.rs in this commit for motivation
and justification.

Closes #2217
2021-12-22 17:51:07 -06:00
ayazhafiz
576f1293fd Turn invalid record field types into runtime errors
By emitting a runtime error rather than panicking when we can't layout
a record, we help programs like

```
main =
    get = \{a} -> a
    get {b: "hello world"}
```

execute as

```
Mismatch in compiler/unify/src/unify.rs Line 1071 Column 13
Trying to unify two flat types that are incompatible: EmptyRecord ~ { 'a' : Demanded(122), }<130>

🔨 Rebuilding host...
── TYPE MISMATCH ───────────────────────────────────────────────────────────────

The 1st argument to get is not what I expect:

8│      get {b: "hello world"}
            ^^^^^^^^^^^^^^^^^^

This argument is a record of type:

    { b : Str }

But get needs the 1st argument to be:

    { a : a }b

Tip: Seems like a record field typo. Maybe a should be b?

Tip: Can more type annotations be added? Type annotations always help
me give more specific messages, and I think they could help a lot in
this case

────────────────────────────────────────────────────────────────────────────────

'+fast-variable-shuffle' is not a recognized feature for this target (ignoring feature)
'+fast-variable-shuffle' is not a recognized feature for this target (ignoring feature)
Done!
Application crashed with message

    Can't create record with improper layout

Shutting down
```

rather than the hanging

```
Mismatch in compiler/unify/src/unify.rs Line 1071 Column 13
Trying to unify two flat types that are incompatible: EmptyRecord ~ { 'a' : Demanded(122), }<130>

thread '<unnamed>' panicked at 'invalid layout from var: UnresolvedTypeVar(104)', compiler/mono/s
rc/layout.rs:1510:52
```

that was previously produced.

Part of #2227
2021-12-21 19:11:59 -06:00
Richard Feldman
1ce648ac27
Merge pull request #2116 from rtfeldman/str_to_num
Str.toNum
2021-12-09 09:48:38 -05:00
rvcas
b7d48b2fe1 feat: add the rest of the num types for Str conversion 2021-12-06 23:24:02 -05:00
rvcas
e587e20de2 feat: switch to using a builtin per num type to convert from a string 2021-12-06 22:24:00 -05:00
Richard Feldman
064dc12145
fix typo in comment 2021-12-01 22:06:03 -05:00
Folkert
27269faa0b optimize alias to var conversion 2021-12-01 18:39:45 +01:00
Richard Feldman
d39ecfd12d
Merge pull request #2052 from rtfeldman/i/1931-2
Some improvements to error messages regarding unbound type variables
2021-11-26 21:17:37 -05:00
Folkert
6934e69240 make deep_copy_var_to allocate less 2021-11-27 02:09:08 +01:00
Folkert
ed455777a2 give deep_copy_var_to a scratchpad 2021-11-27 01:42:11 +01:00
Folkert
b4f21930bb cleanup 2021-11-25 20:49:44 +01:00
Folkert
612f868652 make VariableSubsSlice an alias 2021-11-25 20:29:34 +01:00
Folkert
69a80872e1 rename start -> index 2021-11-25 19:46:05 +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
31d4536449 Remove variable that no longer exists 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
817bb22f9e Improve error message when we try to unify two wildcards
Closes #1931
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
Folkert
093b733a2c add tag name dedup 2021-11-25 00:11:11 +01:00
Folkert
51c61ea449 fix number hierarchy 2021-11-24 22:39:58 +01:00
Folkert
3abdfce735 sort tags in builtin aliases 2021-11-24 21:16:04 +01:00
Folkert
cb8e9acb92 special-case the closure tags 2021-11-24 21:14:58 +01:00
Folkert
308b91153e add faster insertion path for tag unions 2021-11-24 20:38:52 +01:00
Folkert
5e76e3a97e more reserving into subs 2021-11-24 19:14:37 +01:00
Folkert
5663248a41 docs 2021-11-24 18:59:49 +01:00
Folkert
1fbd2a7e7b reserve variable slices 2021-11-24 16:02:55 +01:00
Folkert de Vries
6944c900c2
Merge pull request #2065 from rtfeldman/alias-remove-lowercases
Alias remove lowercases
2021-11-23 10:21:05 +01:00
hafiz
682043c16c
Merge pull request #2063 from rtfeldman/type-to-var-prealloc
preallocate variables to prevent extra vector allocations
2021-11-22 20:05:16 -06:00
Folkert
178eabf4dd make non-pub a function 2021-11-22 22:13:06 +01:00
Folkert
b2aa33f839 Merge remote-tracking branch 'origin/trunk' into alias-remove-lowercases 2021-11-22 21:19:27 +01:00
Folkert
2c1005fdf0 remove lowercases from Content 2021-11-22 21:15:58 +01:00
Folkert
e4ffe804ec remove lowercases from errortype alias 2021-11-22 20:26:50 +01:00
Folkert
2506875970 preallocate variables to prevent extra vector allocations 2021-11-22 20:17:03 +01:00
hafiz
b3ecc16b16
Merge pull request #2050 from rtfeldman/empty-tags-and-unions
Canonicalize to empty tags and unions
2021-11-22 08:00:07 -06:00
Folkert
69ad83a0d4 mark some Subs functions as alwaysinline 2021-11-21 23:49:51 +01:00
Folkert
8afdf282cb assert that no tag union or record with no fields/tags makes it into Subs 2021-11-21 22:25:03 +01:00
Folkert
3ab09322e0 don't copy variables that are the same in every subs 2021-11-20 02:15:26 +01:00
Folkert
594e754e1e manually track visited varibles in deep_copy_var_to 2021-11-20 01:39:57 +01:00
Folkert
d0abab1876 fix the updater; it did not really work?! 2021-11-20 01:24:17 +01:00
Folkert
497bc2db02 make instantiate_rigids_help use a loop/stack 2021-11-20 00:24:46 +01:00
Folkert
eb9bb12725 bumpalo type_to_var 2021-11-19 19:48:51 +01:00
Folkert
22fb31198a use bumpalo to reduce allocations in deep_copy_var_to 2021-11-19 19:21:26 +01:00
Folkert
2fe8537177 clean up deep_copy_var_help 2021-11-19 19:01:27 +01:00
Folkert
0f029f58c9 Merge remote-tracking branch 'origin/trunk' into storage-subs 2021-11-19 17:51:18 +01:00
Folkert
206c8889df Use StorageSubs for pending specializations 2021-11-19 13:22:17 +01:00
ayazhafiz
8b7217847d Rename additional stale roc_module::operator refs and format 2021-11-18 20:20:33 -05:00