Commit graph

312 commits

Author SHA1 Message Date
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
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
9126169fcb StorageSubs 2021-11-18 23:02:47 +01:00
Folkert
e030cd3da5 optimize restore 2021-11-17 16:33:32 +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