Commit Graph

561 Commits

Author SHA1 Message Date
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
Azoy
05cc4aa8af [Runtime] Emit non lazy stub pointers for 32 bit x86 for tuple conformances 2020-10-22 18:28:38 -04:00
Doug Gregor
6a40a3a8aa [SE-0289] Add support for @resultBuilder.
"Function builders" are being renamed to "result builders". Add the
corresponding `@resultBuilder` attribute, with `@_functionBuilder` as
an alias for it, Update test cases to use @resultBuilder.
2020-10-20 13:24:51 -07:00
Holly Borla
1e0038c3be [ConstraintSystem] Remove implementation of operator designated types
in the solver.
2020-10-14 16:05:54 -07:00
Holly Borla
989a432898 [NFC] Update array literal type checking performance validation tests. 2020-08-06 12:30:45 -07:00
Mishal Shah
2b18b5067c [XFAIL] Sema/SwiftUI/rdar57201781.swift and Constraints/trailing_closures_objc.swift to support Xcode 12 beta 3 2020-07-26 23:24:26 -07:00
Onyekachi Ezeoke
a08f421c1a fix failing tests 2020-07-02 12:09:07 +01:00
Pavel Yaskevich
82fcee7bc7 [Diagnostics] NFC: Adjust diagnostic test-cases improved by new ambiguity diagnosis 2020-06-12 13:13:27 -07:00
Varun Gandhi
a1716fe2a6 [Diagnostics] Update compiler diagnostics to use less jargon. (#31315)
Fixes rdar://problem/62375243.
2020-04-28 14:11:39 -07:00
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