Commit Graph

265 Commits

Author SHA1 Message Date
Hamish Knight
47541d86f7 [CS] Visit all fixed bindings for constraint re-activation
Start visiting transitive fixed bindings for type
variables, and stop visiting adjacencies for
`gatherConstraint`'s `AllMentions` mode.

This improves performance and fixes a correctness
issue with the old implementation where we could
fail to re-activate a coercion constraint, and
then let invalid code get past Sema, causing
either miscompiles or crashes later down the
pipeline.

Unfortunately this change requires us to
temporarily drop the non-ephemeral fix for a couple
of fairly obscure cases where the overload hasn't
yet been resolved. The logic was previously relying
on stale adjacency state in order to re-activate
the fix when the overload is bound, but it's not
connected on the constraint graph. We need to find
a way to connect constraints to unresolved
overloads they depend on.

Resolves SR-12369.
2020-04-10 10:16:07 -07:00
Pavel Yaskevich
4bc049b864 [TypeChecker] NFC: Add a perf test for rdar://problem/60961087 2020-04-03 15:56:27 -07:00
Holly Borla
c1c6a884a4 [ConstraintSystem] Respect the constraint solver performance thresholds,
including time and allocated memory, in mergePartialSolutions.
2020-03-09 14:44:12 -07:00
Pavel Yaskevich
20fc51d4f4 [CSBindings] Open collection before binding parameter only if original argument type failed
Instead of always opening argument type represented by a collection
without type variables (to support subtyping when element is a labeled tuple),
let's try original type first and if that fails use a slower path with
indirection which attempts `array upcast`. Doing it this way helps to
propagate contextual information faster which fixes a performance regression.

Resolves: rdar://problem/54580247
2020-02-27 16:26:13 -08:00
Doug Gregor
b94a5c8dd4 Update a test case's expected output 2020-02-25 20:39:42 -08:00
Pavel Yaskevich
dec2ad0f93 Merge pull request #29979 from xedin/rdar-56400265
[ConstraintSystem] Avoid exploring too much search space when call ar…
2020-02-21 11:16:33 -08:00
Argyrios Kyrtzidis
d082e90dbc Merge pull request #29975 from akyrtzi/fix-invalid-keypath-expr-crash
[Parse] Try to preserve the invariant that anything that contains KeyPathDotExpr must be wrapped in KeyPathExpr
2020-02-20 17:23:44 -08:00
Pavel Yaskevich
46d945fdcf [ConstraintSystem] Avoid exploring too much search space when call arguments are holes
Detect that disjunction is going to be applied to arguments which
don't provide any additional contextual information and allow only
a single choice to be attempted in such case to avoid triggering
exponential behavior in the solver.

The problem is most visible with operators e.g.

```swift
.foo == .bar || 1 == .baz
```

If neither member could be contextually determined and solver was
allowed to attempt all of the overloads for `==` and `||` that
would lead to exponential behavior (because each has 30+ overloads)
and generation of hundreds of partial solutions.

Resolves: rdar://problem/56400265
2020-02-20 16:52:30 -08:00
Argyrios Kyrtzidis
bbdada475b [Parse] Try to preserve the invariant that anything that contains KeyPathDotExpr must be wrapped in KeyPathExpr
Even in the presence of invalid code. Fixes typechecker crash in rdar://50666427
2020-02-20 15:07:00 -08:00
Tim Kientzle
8ad39887b5 Ignore output data that's not relevant for this test.
The previous code expects output like this:
```
define hidden swiftcc i8* @"$s6SR82094test10ObjectiveC8SelectorVyF"() #0 {
```

But in certain build modes, we get extra debug information that looks like this:
```
define hidden swiftcc i8* @"$s6SR82094test10ObjectiveC8SelectorVyF"() #0 !dbg !47 {
```

I stumbled over this while running tests with a variety of different
options.
2020-02-20 12:28:02 -08:00
Pavel Yaskevich
6d671020b9 [TypeChecker/BuilderTransform] Make sure implicit load expression updates types in AST
Can't use `ConstraintSystem::addImplicitLoadExpr` because that would
only cache types in constraint system and wouldn't propagate them to AST,
since that happens in `ExprRewritter::finalize` during regular solution
application. `TypeChecker::addImplicitLoadExpr` should be used directly
in cases like that.

Resolves: rdar://problem/58972627
2020-02-03 11:45:55 -08:00
Pavel Yaskevich
d412ea4d16 [Diagnostics] Unsatisfied requirement in reference diagnostics expect type context
Resolves: rdar://problem/50666427
2020-01-23 10:14:37 -08:00
Doug Gregor
8283a67648 Revert "Revert "Reimplement function builders as statement transformations."" 2020-01-21 10:07:20 -08:00
Doug Gregor
86c13d3c74 Revert "Reimplement function builders as statement transformations." 2020-01-17 15:52:49 -08:00
Doug Gregor
a49f0091cb [Constraint application] Skip error expressions when applying builders.
If we encountered an error, just skip it; there's nothing more to do.
2020-01-16 13:19:21 -08:00
Pavel Yaskevich
30876a42de [TypeChecker] NFC: Mark test-case for rdar://problem/22022980 as "slow"
It used to be "fast" before because `selectDisjunction` used to pick
inner `==`s before outer one (which compares arrays) but now, since
constraint generation for the closure body is delayed, it looks
like the opposite is happening which makes this test-case go exponential.
2020-01-14 00:09:33 -08:00
Pavel Yaskevich
09e45823e2 [Diagnostics] NFC: Adjust test-cases improved by changes to closure expression handling 2020-01-14 00:09:33 -08:00
Pavel Yaskevich
3f1083e6c3 [TypeChecker] NFC: Mark perf test-case for rdar://problem/20959612 as "fast"
This test-case has been improved by changes in closure expression
handling in constraint system, because the bodies are going to be
opened in order, the nesting yields linear performance.
2020-01-14 00:09:33 -08:00
Luciano Almeida
27b01e3eb0 [test] Adding validation test for generic function match 2020-01-09 14:10:37 -03:00
Pavel Yaskevich
8bcc192591 [Diagnostics] Diagnose inability to infer (complex) closure return type 2019-12-19 12:16:30 -08:00
Pavel Yaskevich
fa77285c62 Revert "[TypeChecker] NFC: Disable SwiftUI test-case due to possible infinite…" 2019-12-09 12:12:51 -08:00
Pavel Yaskevich
e0aa646310 [TypeChecker] NFC: Disable SwiftUI test-case due to possible infinite loop
Resolves: rdar://problem/57756956
2019-12-09 10:58:05 -08:00
Pavel Yaskevich
1d393ebdd4 [ConstraintSystem] Guard against infinite recursion in key path dynamic member lookup
It's possible to construct subscript member responsible for key path
dynamic member lookup in a way which is going to be self-recursive
and an attempt to lookup any non-existent member is going to trigger
infine recursion.

Let's guard against that by making sure that the base type of the
member lookup is different from root type of the key path.

Resolves: rdar://problem/50420029
Resolves: rdar://problem/57410798
2019-12-05 12:42:17 -08:00
Pavel Yaskevich
94b4052321 [CSDiag] NFC: Remove all of the obsolete diagnoseGeneral*Failures logic 2019-12-03 12:07:16 -08:00
Pavel Yaskevich
addc2b06ab [ConstraintSystem] Introduce notion of constraint system phase
Some constraint transformations require knowledge about what state
constraint system is currently in e.g. `constraint generation`,
`solving` or `diagnostics` to make a decision whether simplication
is possible. Notable example is `keypath dynamic member lookup`
which requires a presence of `applicable fn` constraint to retrieve
some contextual information.

Currently presence or absence of solver state is used to determine
whether constraint system is in `constraint generation` or `solving`
phase, but it's incorrect in case of `diagnoseFailureForExpr` which
tries to simplify leftover "active" constraints before it can attempt
type-check based diagnostics.

To make this more robust let's introduce (maybe temporarily until
type-check based diagnostics are completely obsoleted) a proper
notion of "phase" to constraint system so it is always clear what
transitions are allowed and what state constraint system is
currently in.

Resolves: rdar://problem/57201781
2019-11-20 18:34:51 -08:00
Alexis Laferrière
a8afb84031 [test] Disable sometimes slow test rdar54580427.swift
rdar://problem/57138194
https://bugs.swift.org/browse/SR-11770
2019-11-12 17:43:09 -08:00
Alexis Laferrière
7a3d2307f7 [test] type_checker_perf test rdar33688063 still fails, let's disable it 2019-11-11 12:06:00 -08:00
Alexis Laferrière
40f556e0a5 type_checker_perf test rdar33688063 is often too slow for the fast dir
rdar://problem/57050532
2019-11-11 09:19:10 -08:00
David Zarzycki
db78b3214b [Testing] Disable sema perf tests during ASAN testing
Also, add `-solver-expression-time-threshold=1` to a few tests.

This forces sr139, rdar25866240, and rdar23327871 to be moved from the
"fast" directory to the "slow" directory.
2019-11-09 15:31:20 +02:00
David Zarzycki
b1e253ee85 [Tests] Remove no_asserts from sema perf tests
This discourages regressions. Also add a timeout to a slow test.
2019-11-08 11:53:00 +02:00
David Zarzycki
b8122db49d Merge pull request #28078 from davezarzycki/pr28078
[Tests] Fix REQUIRES for two type checker perf tests
2019-11-08 10:49:55 +02:00
Alexis Laferrière
fd191bff43 Fix test rdar56710317.swift for the iOS simulator
Fix rdar://problem/56999504
2019-11-07 15:19:46 -08:00
Doug Gregor
f4c45e8057 [Type check diagnostics] Add already-fixed test case from rdar://problem/56710317.
Ensures that we don't regress diagnostics for this case in the future.
2019-11-07 09:41:36 -08:00
David Zarzycki
cc8acdce93 [Tests] Fix REQUIRES for two tests
The non-gyb type checker performance tests tend to require non-assert
and release builds. This makes two tests consistent with the others.

This also fixes sr139.swift, which was needlessly running the type checker twice.
2019-11-05 11:15:25 +02:00
Robert Widmann
e95cc4981b Revert "Remove Some Users of -solver-enable-operator-designated-types"
This reverts commit 46ae4757d2.
2019-10-29 10:33:16 -07:00
Robert Widmann
46ae4757d2 Remove Some Users of -solver-enable-operator-designated-types
There are now two regression tests that need this feature enabled to
pass.
2019-10-24 16:50:45 -07:00
Pavel Yaskevich
10b1baebb2 Merge pull request #27362 from xedin/port-missing-args
[Diagnostics] Port missing argument(s) diagnostics
2019-09-25 21:08:54 -07:00
Pavel Yaskevich
ec6a874ac8 [TypeChecker] NFC: Update test-cases improved by new missing arguments diagnostic 2019-09-25 10:47:26 -07:00
Slava Pestov
0ade7b70d9 AST: Type::subst() preserves TypeAliasType sugar
Fixes <rdar://problem/45313760>.
2019-09-24 17:42:15 -04:00
Holly Borla
29044e5d34 Merge pull request #27176 from hborla/type-cannot-conform-diag
[Diagnostics] Generalize the "protocol type cannot conform" error to work for all types that cannot conform to protocols.
2019-09-18 10:38:00 -07:00
Jordan Rose
1eaa767407 [test] Run scale-tests on Linux too (#27223)
It's likely that these were listed as "REQUIRES: OS=macosx" to not
redundantly run them for iOS et al, but they don't take that long and
so it's more useful for Linux devs to be able to run them locally if
need be. Or to catch something that really is different on non-macOS.
2019-09-18 08:27:37 -07:00
Holly Borla
bf80250c84 Merge remote-tracking branch 'upstream/master' into type-cannot-conform-diag 2019-09-17 11:54:03 -07:00
Holly Borla
2a7e0099d2 [Diagnostics] Add notes for the type_cannot_conform error that point
to the declaration that requires protocol conformance.
2019-09-17 09:22:07 -07:00
Holly Borla
173e4526ee [Diagnostics] Adjust wording of type_cannot_conform error message. 2019-09-16 14:55:38 -07:00
Pavel Yaskevich
a1643d94f7 [Diagnostics] NFC: Update all of the improved test-cases 2019-09-13 22:35:52 -07:00
Holly Borla
40985b6eb7 [Diagnostics] Generalize the "protocol type cannot conform" error to
work for all types that cannot conform to protocols.
2019-09-13 14:51:17 -07:00
Holly Borla
0434d58ff0 Merge pull request #27123 from hborla/missing-conformance-diag
[ConstraintSystem] Allow fixing missing conformance failures for `Void` and uninhabited types.
2019-09-12 17:41:19 -07:00
Holly Borla
b2ec5b97b9 [Test] Update type_checker_crashers_fixed/rdar50869732.swift with missing
conformance diagnostics.
2019-09-12 15:41:11 -07:00
Varun Gandhi
51db51e796 Add reduced test case for rdar://problem/54926602. 2019-09-06 15:32:44 -07:00
Varun Gandhi
e4f0f78020 Add minimal test case for rdar://problem/54580427.
The scale test says the behavior is exponential, but it should be
linear, given that (1) we provide a contextual type outside and
(2) there is precisely 1 type which has the corresponding cases.
2019-08-29 15:24:08 -07:00