Commit Graph

323 Commits

Author SHA1 Message Date
Pavel Yaskevich
6126bc06e0 [TypeChecker] NFC: Complicate perf test-case expression by adding more operators
This test has become flaky in different configurations due to a varying
number of available operator overloads, let's use more operators to make
sure that it's "too complex" regardless of configuration.

Resolves: rdar://77656775
2021-05-07 11:04:19 -07:00
Arnold Schwaighofer
b8b5edbf5c Disable test type_checker_perf/slow/rdar19737632.swift
It failed on a bot.

rdar://77656775
2021-05-07 08:10:05 -07:00
Pavel Yaskevich
2898b50b7f Revert "Revert "[TypeChecker] PreCheck: Don't strip away tuple/paren from subscripts …"" 2021-05-04 11:19:33 -07:00
Pavel Yaskevich
b12d57afac Revert "[TypeChecker] PreCheck: Don't strip away tuple/paren from subscripts …" 2021-05-03 11:55:25 -07:00
Pavel Yaskevich
f36ecf2fa1 [CSSimplify] Allow overload choices with missing labels to be considered for diagnostics
Let's make use of a newly added "disable for performance" flag to
allow solver to consider overload choices where the only issue is
missing one or more labels - this makes it for a much better
diagnostic experience without any performance impact for valid code.
2021-04-28 12:04:57 -07:00
Pavel Yaskevich
a21f323c16 Merge pull request #36946 from xedin/rdar-61749633
[TypeChecker] PreCheck: Don't strip away tuple/paren from subscripts …
2021-04-26 12:19:55 -07:00
Pavel Yaskevich
71372bce67 [Diagnostics] Switch to use contextual purpose associated with locator
`ContextualFailure` is the main beneficiary of additional information
associated with `ContextualType` element because it no longer has to
query solution for "purpose" of the contextual information.

Resolves: rdar://68795727
2021-04-26 09:51:25 -07:00
Pavel Yaskevich
593bbab880 [TypeChecker] PreCheck: Don't strip away tuple/paren from subscripts and ObjC literals
`PreCheckExpression` already skips calls, make sure that invalid subscripts,
dynamic subscript, ObjC literals preserve paren/tuple for an index/argument.

Resolves: rdar://61749633
2021-04-16 11:40:19 -07:00
Nate Chandler
1e45d161ab [Test] Disable a test on Linux at swift_test_mode_optimize_none.
Per @xedin, it's fine to leave this test disabled here.
2021-04-14 13:58:03 -07:00
Pavel Yaskevich
a4ced48946 [TypeChecker] NFC: Adjust "fast" test-case message to accommodate Amazon Linux 2 2021-04-13 10:32:25 -07:00
Pavel Yaskevich
ceeee459b4 Merge pull request #36631 from xedin/conformance-perf-experiment
[Perf][CSSimplify] Transfer conformance requirements of a parameter to an argument
2021-04-12 13:13:56 -07:00
Pavel Yaskevich
62c5e18710 [TypeChecker] NFC: Make test-case for rdar://74035425 more complex to avoid flaky behavior 2021-04-09 10:37:29 -07:00
Pavel Yaskevich
882cfdac67 [TypeChecker] NFC: Re-enable and move to "fast" tests for rdar://26564101 and rdar://33688063 2021-04-09 10:30:50 -07:00
Mishal Shah
22f61df98b Use %target-cpu in the tests to support running on Apple Silicon hardware 2021-04-08 23:26:18 -07:00
Pavel Yaskevich
49da89f3bb [TypeChecker] NFC: Add more chained operators to make rdar://22877285 "too complex" on Linux 2021-04-08 16:05:44 -07:00
Pavel Yaskevich
c509c030ea [CSSimplify] Transfer conformance requirements of a parameter to an argument
Performance optimization to help rule out generic overload choices sooner.

This is based on an observation of the constraint solver behavior,
consider following example:

```swift
func test<U: ExpressibleByStringLiteral>(_: U) {}

test(42)
```

Constraint System for call to `test` is going to look like this:

```
$T_test := ($T_U) -> $T_U
$T_U <conforms to> ExpressibleByStringLiteral
$T_42 <argument conversion> $T_U
$T_42 <literal conforms to> ExpressibleByIntegerLiteral
```

Currently to find out that `test` doesn't match, solver would have
to first find a binding for `$T_42`, then find a binding for `$T_U`
(through `<argument conversion>` constraint) and only later fail
while checking conformance of `Int` to `ExpressibleByStringLiteral`.

Instead of waiting for parameter to be bound, let's transfer conformance
requirements through a conversion constraint directly to an argument type,
since it has to conform to the same set of protocols as parameter to
be convertible (restrictions apply i.e. protocol composition types).

With that change it's possible to verify conformances early and reject
`test<U: ExpressibleByStringLiteral>` overload as soon as type of an
argument has been determined. This especially powerful for chained calls
because solver would only have to check as deep as first invald argument
binding.
2021-04-07 17:55:11 -07:00
Pavel Yaskevich
c82729bad9 [TypeChecker] NFC: Disable a couple of perf tests on Linux (they fail on community CI) 2021-04-06 21:07:56 -07:00
Pavel Yaskevich
225e2dbeed [ConstraintSystem] Bind external closure parameter type to a concrete contextual type
Performance optimization.

If there is a concrete contextual type we could use, let's bind
it to the external type right away because internal type has to
be equal to that type anyway (through `BindParam` on external type
i.e. <internal> bind param <external> conv <concrete contextual>).

```swift
func test(_: ([String]) -> Void) {}

test { $0 == ["a", "b"] }
```

Without this optimization for almost all overloads of `==`
expect for one on `Equatable` and one on `Array` solver would
have to repeatedly try the same `[String]` type for `$0` and
fail, which does nothing expect hurts performance.

Resolves: rdar://19836070
Resolves: rdar://19357292
Resolves: rdar://75476311
2021-04-02 22:11:03 -07:00
Pavel Yaskevich
e26ada5d06 [TypeChecker] NFC: Add an additional test-case for rdar://46713933 with literal arguments 2021-04-01 11:44:31 -07:00
Pavel Yaskevich
f00c578761 Merge pull request #34401 from xedin/implicit-cgfloat-conversion
[DNM][TypeChecker] Implement Double <-> CGFloat implicit conversion
2021-03-31 10:20:28 -07:00
Pavel Yaskevich
d155b5c209 [TypeChecker] NFC: Extend scale and move test-case for rdar://30606089 to "fast"
Resolves: SR-6520
2021-03-29 16:06:05 -07:00
Pavel Yaskevich
ee81665d6b [TypeChecker] NFC: Extend scale and move test-case for rdar://27585838 to "fast" 2021-03-29 16:00:05 -07:00
Pavel Yaskevich
6e628c4874 [CSGen] Fallback to a type variable if preferred type for placeholder is invalid
Type inside of an editor placeholder is more of a hint than anything else,
so if it's incorrect let's diagnose that and use type variable instead to
allow solver to make forward progress.

Resolves: SR-14213
Resolves: rdar://74356736
2021-03-23 18:56:21 -07:00
Pavel Yaskevich
4b01c8fd11 [ConstraintSystem] Adjust impact of implicit Double <-> CGFloat conversions
- Prefer CGFloat -> Double over the other way around to avoid
  ambiguities;

- Every new conversion impacts the score by factor of number of
  previously applied conversions to make it possible to select
  solutions that require the least such conversions.

- Prefer concrete overloads with Double <-> CGFloat conversion
  over generic ones.
2021-03-17 00:18:14 -07:00
Pavel Yaskevich
5e10f0822e [TypeChecker] NFC: Temporary mark test-case for rdar://46541800 as slow 2021-03-17 00:18:13 -07:00
Pavel Yaskevich
2a9903dfe4 [Diagnostics] Check whether missing conformance could be fixed by using .rawValue
A lot of operators (and most likely regular functions a well) have
overloads that accept i.e. a generic parameter that conforms to
`StringProtocol`, so the best fix in situations when argument is
a raw representable type would be to check whether `.rawValue`
conforms to the expected protocol and use it if so.

Resolves rdar://problem/75367157
2021-03-15 16:53:45 -07:00
Pavel Yaskevich
39b2ff92b3 [CSStep] Skip disabled overloads only if there are no fixes in diagnostic mode 2021-03-04 15:40:39 -08:00
Pavel Yaskevich
cd08350fe5 [Diagnostics] Prioritize type mismatches over labeling failures for calls
Since labels are considered part of the name, mismatches in labeling
should be invalidate overload choices. Let's prefer an overload with
correct labels but incorrect types over the one with incorrect labels.

This also means that it's possible to restore performance optimizations
related to early filtering in diagnostic mode, which is important for
deeply nested code i.e. SwiftUI views.
2021-03-03 18:50:06 -08:00
Pavel Yaskevich
b519695d0b [TypeChecker] NFC: Remove obsolete perf test-case (rdar://29358447)
There are no closures in this test-case and counter is only increased
when there are closures to check.
2021-03-03 01:21:08 -08:00
Pavel Yaskevich
2274e17843 [CSFix] Allow diagnosing the same out-of-order argument in ambiguity cases
Is the same argument is out-of-order in multiple solutions, let's
diagnose it as if there was no ambiguity.

Resolves: SR-14093
Resolves: rdar://73600328
2021-02-18 17:21:49 -08:00
Pavel Yaskevich
a7524e59f4 [CSFix] Allow diagnosing missing conformance in ambiguity cases
It's possible that different overload choices could have the same
conformance requirement, so diagnostics should be able to emit an
error in situations where multiple solutions point to the missing
conformance at the same location (both in AST and requirement list).

Resolves: rdar://74447308
2021-02-18 17:21:03 -08:00
Holly Borla
66de9e39cf [NFC] Add a slow type checker test involving string concatenation. 2021-02-05 16:15:59 -08:00
Holly Borla
752cf7f2ac [ConstraintSystem] Consider the number of resolved argument types
for applied overloads when selecting a disjunction to attempt.
2021-02-03 13:26:57 -08:00
Pavel Yaskevich
0d040e2420 [TypeChecker] Un-XFAIL perf test-case for rdar://23620262 2020-12-16 12:04:15 -08:00
Pavel Yaskevich
c6bdeea852 [ConstraintSystem] Strengthen dependent member type checks while inferring bindings
Look through specifier (inout, l-value) and optional types while
checking for presence of dependent member types to avoid inferring
incorrect bindings (which could lead to infinite recursion in the
solver).

Resolves: SR-13856
Resolves: rdar://problem/71383770
2020-12-14 16:39:13 -08:00
Pavel Yaskevich
dcc42bc0f3 Merge pull request #34673 from xedin/rdar-71167129
[AST] Preserve l-valueness of covariant result type after replacement
2020-11-11 10:52:37 -08:00
Pavel Yaskevich
5ef64c4584 [AST] Preserve l-valueness of covariant result type after replacement
It's possible that covariant result type is wrapped in l-value.
Just like currently preserved optionality, transformation should
maintain l-valueness of a result type as well.

Resolves: rdar://problem/71167129
2020-11-10 22:50:00 -08:00
Holly Borla
3b192b7c78 [NFC] Add back a higher polynomial threshold for rdar18360240.swift.gyb 2020-11-10 14:18:29 -05:00
Holly Borla
a647f0fb5b Merge pull request #34399 from hborla/optimize-linked-operator-solving
[Constraint System] Implement heuristics for linked operator expressions in the solver proper.
2020-11-08 13:22:40 -08:00
Pavel Yaskevich
80c4c90403 Merge pull request #34603 from xedin/rdar-70256351
[ResultBuilders] Account of a fact that re-write of a statement can fail
2020-11-06 14:07:29 -08:00
Pavel Yaskevich
1d3f3204ca [ResultBuilders] Account of a fact that re-write of a statement can fail
If one of the statements in the result builder body fails to
apply solution, let's fail entire rewrite attempt, otherwise
type-checker would end up with AST that has null pointers for
some child nodes.

Resolves: rdar://problem/70256351
2020-11-05 16:29:58 -08:00
Holly Borla
2507a3155d [Test] Add a slow type checker test case from source compatibility suite. 2020-11-05 10:31:34 -08:00
Pavel Yaskevich
8e95096e85 [TypeChecker] NFC: Add a test-case for rdar://70880670 2020-11-04 16:19:51 -08:00
Pavel Yaskevich
1c65a55633 [CSGen] Turn invalid decls into holes
Instead of failing constraint generation upon encountering
an invalid declaration, let's turn that declaration into a
potential hole and keep going. Doing so enables the solver
to reach a solution and diagnose any other issue with
expression.
2020-11-04 16:19:38 -08:00
Holly Borla
099560813e [ConstraintSystem] Only factor in existing operator bindings in
selectDisjunction if both disjunctions are operator bindings.
2020-11-04 15:23:12 -08:00
Rintaro Ishizaki
147015da55 [Test] Fix test cases (#34511) 2020-10-30 08:10:51 -07:00
swift-ci
28182942d9 Merge pull request #34505 from CodaFi/verifly 2020-10-29 19:52:40 -07:00
Holly Borla
8dd2008f7e [Test] Adjust type checker performance tests 2020-10-29 19:49:47 -07:00
Alejandro Alonso
424802fb34 Revert SE-0283 (#34492)
Reverted despite build failures.
2020-10-29 17:32:06 -07:00
Robert Widmann
6204b371f3 [Gardening] Strip -verify out of a test that doesn't need it 2020-10-29 17:19:07 -07:00