Commit graph

98 commits

Author SHA1 Message Date
Ayaz Hafiz
d7a069675b
Lambda set compaction must preserve unique specializations of concrete types
There are times that multiple concrete types may appear in
unspecialized lambda sets that are being unified. The primary case is
during monomorphization, when unspecialized lambda sets join at the same
time that concrete types get instantiated. Since lambda set
specialization and compaction happens only after unifications are
complete, unifications that monomorphize can induce the above-described
situation.

In these cases,

- unspecialized lambda sets that are due to equivalent type variables
  can be compacted, since they are in fact the same specialization.
- unspecialized lambda sets that are due to different type variables
  cannot be compacted, even if their types unify, since they may point
  to different specializations. For example, consider the unspecialized
  lambda set `[[] + [A]:toEncoder:1 + [B]:toEncoder:1]` - this set wants
  two encoders, one for `[A]` and one for `[B]`, which is materially
  different from the set `[[] + [A, B]:toEncoder:1]`.
2023-02-20 18:50:07 -06:00
Ayaz
a7c415dc35
Merge pull request #4940 from joshuawarner32/tuple-solve
Initial implementation of tuples in type checking
2023-01-23 16:25:35 -06:00
Joshua Warner
de828416bf
Initial implementation of tuples in type checking
This leaves in place a bunch of TODOs and likely many bugs - notably, I haven't tested codegen/layout at all here.
2023-01-22 12:40:44 -08:00
Ayaz Hafiz
f6da8275ec
Record changed variables if any nested variable has changed
When we unify variables in mono, we must invalidate the sections of the
layout cache reached by those variables. Previously we did this by
recording changed variables as those that were `merge`d. However this is
not enough; we must also record all the parent types they came from. The
reason is we may have something like

```
Alias (Foo, a) ~ Alias (Bar, U8)
```

where we will merge `a = U8` but we do not merge the aliases.

Closes #4919
2023-01-21 12:37:21 -06:00
Ayaz Hafiz
20d0d62af7
Allow extending Openness constraints when doing specializations 2023-01-16 10:54:39 -06:00
Ayaz Hafiz
1d75934659
Don't match empty tag union in openness constraint 2023-01-16 10:54:39 -06:00
Ayaz Hafiz
91d61424ad
Lints 2023-01-16 10:54:39 -06:00
Ayaz Hafiz
2f74d0b1b9
Do not permit inferred-open-in-output-position extension variables to grow
Closes #4852
Closes #4845
2023-01-16 10:54:38 -06:00
Ayaz Hafiz
281b71cf94
Unification of Any and Openness tag extensions 2023-01-16 10:52:23 -06:00
Ayaz Hafiz
1c93727822
Add a notion of "openness" tag extensions suitable only for size-polymorphism 2023-01-16 10:52:23 -06:00
Ayaz Hafiz
1c58118dc7
Strip _new from tag unification functions 2023-01-16 10:52:22 -06:00
Joshua Warner
8abd5cf605
Fix bug in unification of tag args in polymorphic contexts 2022-12-26 13:01:31 -08:00
Joshua Warner
174f7d5e4d
Fix bug in unifying records
This was leading us to have an infinitely-recursive type, which eventually causes layout to stack-overflow

Fixes #4739
2022-12-17 11:37:19 -08:00
Ayaz Hafiz
63b0eb49d8
Explicit is_inside_lambda_set not needed 2022-12-13 09:00:46 -06:00
Ayaz Hafiz
79ee266f66
Snapshot/restore pool if lambda sets are disjoint 2022-12-12 18:06:50 -06:00
Ayaz Hafiz
0ef0638862
Remove more dead code 2022-12-12 15:48:30 -06:00
Ayaz Hafiz
22c8719eed
Dead code 2022-12-12 15:47:58 -06:00
Ayaz Hafiz
23932137ef
Avoid exponential unification paths
🤦 when we check whether lambdas can be unified or must be
treated as disjoint we previously had a code path that is actually
exponential in its runtime, regardless of whether it succeeds or fails.
Now, it is linear, though degraded (with a clone) if it fails.
2022-12-12 15:46:05 -06:00
Ayaz Hafiz
cd2b936a59
Ensure that disjoint nested lambda sets force parents to be disjoint
We must be careful to ensure that if unifying nested lambda sets
results in disjoint lambdas, that the parent lambda sets are
ultimately treated disjointly as well.
Consider

```
  v1: {} -[ foo ({} -[ bar Str ]-> {}) ]-> {}
~ v2: {} -[ foo ({} -[ bar U64 ]-> {}) ]-> {}
```

When considering unification of the nested sets

```
  [ bar Str ]
~ [ bar U64 ]
```

we should not unify these sets, even disjointly, because that would
ultimately lead us to unifying

```
v1 ~ v2
=> {} -[ foo ({} -[ bar Str, bar U64 ]-> {}) ] -> {}
```

which is quite wrong - we do not have a lambda `foo` that captures
either `bar captures: Str` or `bar captures: U64`, we have two
different lambdas `foo` that capture different `bars`. The target
unification is

```
v1 ~ v2
=> {} -[ foo ({} -[ bar Str ]-> {}),
         foo ({} -[ bar U64 ]-> {}) ] -> {}
```

Closes #4712
2022-12-12 14:51:18 -06:00
Ayaz Hafiz
0bae0aafb6
Unify ranged numbers with flex able, modulo obligation checking
Closes #4594
2022-12-01 09:50:29 -06:00
Ayaz Hafiz
e36618b9e9
Support custom abilities for opaques with immaterial lambda sets
If a specialization of an ability member has a lambda set that is not
reflected in the unspecialized lambda sets of the member's prototype
signature, then the specialization lambda set is deemed to be immaterial
to the specialization lambda set mapping, and we don't need to associate
it with a particular region from the prototype signature.

This can happen when an opaque contains functions that are some specific
than the generalized prototype signature; for example, when we are
defining a custom impl for an opaque with functions.

Addresses a bug found in 8c3158c3e0
2022-11-21 18:03:56 -06:00
Ayaz Hafiz
e1afd964c7
Correct when fixpoint-fixed type variables can be reunified
With fixpoint-fixing, we don't want to re-unify type variables that were
just fixed, because doing so may change their shapes in ways that we
explicitly just set them up not to be changed (as fixpoint-fixing
clobbers type variable contents).

However, this restriction need only apply when we re-unify two type
variables that were both involved in the same fixpoint-fixing cycle. If
we have a type variable T that was involved in fixpoint-fixing, and we
unify it with U that wasn't, we know that the $U \notin \bar{T}$, where
$\bar{T}$ is the recursive closure of T. In these cases, we do want to
permit the usual in-band unification of $T \sim U$.
2022-11-21 15:57:36 -06:00
Ayaz Hafiz
76a3e92088
Fix debug flags for release mode 2022-11-16 14:05:53 -06:00
Ayaz Hafiz
a8b55dc794
Admit occurs check under recursive tag unions when programs have type errors 2022-11-16 14:05:53 -06:00
Ayaz Hafiz
735685dd86
Include error vars in is_recursion_var checks 2022-11-16 14:05:53 -06:00
Ayaz Hafiz
bef9b54124
Avoid parsing doc comments as code 2022-11-16 14:05:53 -06:00
Ayaz Hafiz
2cba520839
Document fixpoint fixing algorithm 2022-11-16 14:05:51 -06:00
Ayaz Hafiz
8414c8e2de
Remove unneeded comments 2022-11-16 14:05:51 -06:00
Ayaz Hafiz
5a92947326
Use fixpoint-fixing in unification 2022-11-16 14:05:51 -06:00
Ayaz Hafiz
3c968b581d
Check in fixpoint-fixing algorithm 2022-11-16 14:05:51 -06:00
Ayaz Hafiz
fb643758bb
Remove Unified BadType 2022-11-08 14:11:25 -06:00
Ayaz Hafiz
09748aec48
Remove problems from error type API surface 2022-11-08 14:11:25 -06:00
Luke Boswell
a3f901427a
correct formatting and removed duplicate image 2022-11-03 20:02:10 +11:00
Luke Boswell
f3bdb5f321
updating rust package documentation 2022-11-03 20:00:06 +11:00
Ayaz Hafiz
a58d128d9e
Cover mode when unifying variable slices 2022-11-01 12:06:59 -05:00
Ayaz Hafiz
debe6332c5
Support OIOP for type aliases 2022-10-31 09:38:21 -05:00
Ayaz Hafiz
f3623b1e47
Close extension types extended wiht uninhabited types after their extension 2022-10-31 09:37:40 -05:00
Ayaz Hafiz
4d48ea7c2f
Materialize extension variable polarity in error type reporting 2022-10-31 09:37:40 -05:00
Ayaz Hafiz
c0257302a9
Address clippy lints 2022-10-24 14:00:45 -05:00
Ayaz Hafiz
3bd10698cf
Allow rigid able to unify with flex able when rigid bounds are a superset 2022-10-24 14:00:45 -05:00
Ayaz Hafiz
9c88534758
Obligation checking layers on extra abilities bound to a variable 2022-10-24 13:59:52 -05:00
Ayaz Hafiz
db7fe48d1c
Merge muliple abilities bound to flex var 2022-10-24 13:59:52 -05:00
Ayaz Hafiz
229548571b
Represent "able" variables with slices of abilities 2022-10-24 13:59:51 -05:00
Ayaz Hafiz
0f0678ce73
s/closure_names/symbol_names/g in subs 2022-10-24 13:59:51 -05:00
Ayaz Hafiz
05e8e6de6f
Disallow typing optional fields when required fields are annotated
Closes #4313
2022-10-18 15:50:20 -05:00
Ayaz Hafiz
81fa0407b6
Satiate must_use reason 2022-10-12 16:38:36 -05:00
Ayaz Hafiz
f3a6b45452
Add must_use to all unification results
Making sure that no unspecialized lambda sets slip through the cracks!
2022-10-12 16:37:50 -05:00
Ayaz
83b64c4fb3
Merge pull request #4209 from roc-lang/impl-tag-discriminant
Derive `Hash` implementations for tag unions
2022-10-10 22:23:05 -05:00
Ayaz Hafiz
16f43f5768
Clippy 2022-10-05 17:25:12 -05:00
Ayaz Hafiz
06e5110aa5
Unification of multiple tag-functions 2022-10-05 17:25:11 -05:00