Commit Graph

236 Commits

Author SHA1 Message Date
Luciano Almeida
c069e86f83 [NFC][Sema] Changing API to facilitate recording pontential holes recursively 2021-05-01 23:06:25 -03:00
swift-ci
e152c14c0a Merge pull request #37162 from DougGregor/spawn-let 2021-04-30 02:19:16 -07:00
Doug Gregor
5d8174da57 [Concurrency] Introduce spawn let 2021-04-29 22:42:40 -07:00
Pavel Yaskevich
957e05cfb1 [Constraint] Allow constraints to be disabled only in "performance" mode 2021-04-27 16:11:47 -07:00
Rintaro Ishizaki
712e439fe9 Merge pull request #37069 from rintaro/ide-rdar76714968
[CodeCompletion] Peform complete `filterSolutions` in code completion
2021-04-26 18:21:41 -07:00
Rintaro Ishizaki
848031825e [CodeCompletion] Peform complete filterSolutions in code completion
Not-filtering solutions causes unacceptable slownesses in some cases.
For now, filter solutions as normal typechecking does to restore the
performance.

rdar://76714968
2021-04-26 13:03:32 -07:00
Pavel Yaskevich
51ff12d06e [ConstraintLocator] Augment ContextualType element to carry its purpose
Having purpose attached to the contextual type element makes it much
easier to diagnose contextual mismatches without involving constraint
system state.
2021-04-26 09:51:21 -07:00
Alejandro Alonso
444c35cf8d Merge pull request #36953 from Azoy/isType-isDeclType
[NFC] Introduce isDecl and getDeclType
2021-04-20 15:33:00 -04:00
Azoy
9ed732f0ab Introduce isDecl and getDeclType
fix enum logic issue

fix tests

guard against null types
2021-04-20 02:22:16 -04:00
Pavel Yaskevich
7e406a753d Merge pull request #36948 from Jumhyn/placeholder-type-get-fix
[Sema] Fix stale reference passed to PlaceholderType::get
2021-04-19 11:09:12 -07:00
Nathan Hawes
f75f5fe78d Merge pull request #36879 from nathawes/track-match-call-result
[ConstraintSystem] Record parameter bindings in solutions (NFC)
2021-04-18 06:10:23 +10:00
Frederick Kellison-Linn
237b73d7b2 [Sema] Fix stale reference passed to PlaceholderType::get 2021-04-16 23:00:12 -04:00
Nathan Hawes
c57c403ffa [ConstraintSystem] Record parameter bindings in solutions (NFC)
This saves us from needing to re-match args to params in CSApply and is also
useful for a forthcoming change migrating code completion in argument position
to use the solver-based typeCheckForCodeCompletion api.

rdar://76581093
2021-04-16 18:32:06 +10:00
Pavel Yaskevich
d57c112845 [ConstraintSystem] NFC: Replace isOperatorBindOverload with isOperatorDisjunction 2021-04-14 10:34:17 -07:00
Pavel Yaskevich
fef108f2ac [ConstraintSystem] NFC: Move partitioning methods to DisjunctionChoiceProducer 2021-04-14 09:54:39 -07:00
Pavel Yaskevich
c9a289e1b5 [ConstraintSystem] Add a method to determine whether disjunction represents an operator 2021-04-13 15:43:15 -07:00
Pavel Yaskevich
985843a21f [ConstraintSystem] Add a new transitive conformance constraint
Conformance constraints could be transferred through conversions,
but that would also require checking implicit conversions
such as optional and pointer promotions for conformance is the
type itself doesn't conform, for that let's add a special constraint
`TransitivelyConformsTo`.
2021-04-07 17:55:11 -07:00
Pavel Yaskevich
ed8491c15b Revert "[TypeChecker] Add a flag to disable Double<->CGFloat implicit conversion"
This reverts commit 3c731d8748.
2021-03-31 11:10:21 -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
Holly Borla
7cd8add885 [ConstraintSystem] Add a property wrapper constraint to delay checking
if an inferred wrapper type is a property wrapper until that type is
resolved.
2021-03-24 11:24:21 -07:00
Pavel Yaskevich
a559ca8c53 [TypeChecker/SE-0307] NFC: Fix typos and clarify a couple of comments
Thanks Xiaodi Wu!
2021-03-17 14:11:53 -07:00
Pavel Yaskevich
3c731d8748 [TypeChecker] Add a flag to disable Double<->CGFloat implicit conversion 2021-03-17 00:18:19 -07:00
Pavel Yaskevich
cd3ec8c508 [ConstraintSystem] Allow attempting generic unary operators in presence of Double<->CGFloat conversion
Not all of the unary operators have `CGFloat` overloads,
so in order to preserve previous behavior (and overall
best solution) with implicit Double<->CGFloat conversion
we need to allow  attempting generic operators for such cases.

```swift
let _: CGFloat = -.pi / 2
```

`-` doesn't have `CGFloat` overload (which might be an oversight),
so in order to preserve type-checking behavior solver can't be
allowed to pick `-(Double) -> Double` based on overload of `/`,
the best possible solution would be with `/` as `(CGFloat, CGFloat) -> CGFloat`
and `-` on a `FloatingPoint` protocol.
2021-03-17 00:18:19 -07:00
Pavel Yaskevich
9197f924cd [ConstraintSystem] Increase impact of implicit value-to-value conversion
This makes it possible to pick `CGFloat` function/operator overloads even
in the presence of literals, otherwise non-default literal score gets in
a way and solver ends up producing a lot more solutions with implicit
Double<->CGFloat conversion than it can disambiguate, so it's better to
just preserve the old behavior and pick `CGFloat` concrete overloads when
appropriate.
2021-03-17 00:18:18 -07:00
Pavel Yaskevich
c77d0862bb [ConstraintSystem] Record all Double <-> CGFloat conversions performed along a current solver path
This information makes it easier to compute a score for the next
implicit value conversion solver would have to perform.
2021-03-17 00:18:15 -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
6382e7be66 [ConstraintSystem] Favor overloads which match choice type exactly 2021-03-17 00:18:12 -07:00
Pavel Yaskevich
f9eb71ddad [ConstraintSystem] Attempt Double <-> CGFloat implicit conversion only once and re-use results 2021-03-17 00:18:11 -07:00
Pavel Yaskevich
7ab93250ba [ConstraintSystem] Add a new score kind to model implicit value conversions 2021-03-17 00:18:07 -07:00
Holly Borla
0948105fa3 Merge pull request #36368 from hborla/local-property-wrapper-crash
[SILGen] Don't emit property wrapper generator functions for local property wrappers with initializers.
2021-03-09 14:36:16 -08:00
Holly Borla
0a700b7c41 [SILGen] Don't emit property wrapper generator functions for local property
wrappers with initializers. Instead, call the property wrapper initializer
directly.
2021-03-09 10:29:07 -08:00
Anthony Latsis
79c0d93b86 Sema: Fix dynamic Self behavior for a «super» base expression 2021-03-09 19:20:43 +03:00
Anthony Latsis
8242d843cd NFC, Sema: Further propagate the locator through to doesStorageProduceLValue 2021-03-09 17:01:50 +03:00
Anthony Latsis
42e510c260 NFC, Sema: Derive base expr from locator in getTypeOfMemberReference 2021-03-09 17:01:45 +03:00
Pavel Yaskevich
31ccd6099a [ConstraintSystem] Maintain insertion order of all shrunk expressions and their overload sets 2021-03-05 00:07:30 -08:00
Doug Gregor
9ccf206feb [Concurrency] Tune overloading to to allow sync overloads in async contexts.
The existing overloading rules strongly prefer async functions within
async contexts, and synchronous functions in synchronous contexts.
However, when there are other differences in the
signature, particularly parameters of function type that differ in
async vs. synchronous, the overloading rule would force the use of the
synchronous function even in cases where the synchronous function
would be better. An example:

    func f(_: (Int) -> Int) { }
    func f(_: (Int) async -> Int) async { }

    func g(_ x: Int) -> Int { -x }

    func h() async {
      f(g) // currently selects async f, want to select synchronous f
    }

Effect the semantics change by splitting the "sync/async mismatch"
score in the constraint system into an "async in sync mismatch" score
that is mostly disqualifying (because the call will always fail) and a
less-important score for "sync used in an async context", which also
includes conversion from a synchronous function to an asynchronous
one. This way, only synchronous functions are still considered within
a synchronous context, but we get more natural overloading behavior
within an asynchronous context. The end result is intended to be
equivalent to what one would get with reasync:

  func f(_: (Int) async -> Int) async { ... }

Addresses rdar://74289867.
2021-03-02 23:14:08 -08:00
Pavel Yaskevich
b487b6956b [ConstraintSystem] Delay inference until let's clear that type variable attempt is successful
Currently bindings where inferred on every `bindTypeVariable` call,
but that's wasteful because not all binds are always correct. To
avoid unnecessary inference traffic let's wait until re-activated
constraints are simplified and notify binding inference about new
fixed type only if all of them are successful.
2021-03-01 10:52:29 -08:00
Nathan Hawes
fa7a6e6531 Merge pull request #36149 from nathawes/try-to-fix-missing-enum-completions-again
[CodeCompletion][CSRanking] Still do some filtering of solutions when solving for code completion to improve performance
2021-02-27 12:02:25 +10:00
Pavel Yaskevich
bcd58edcef [ConstraintSystem] Remove unused default parameter from ConstraintSystem::simplify 2021-02-26 13:11:26 -08:00
Nathan Hawes
8a660bb360 [CodeCompletion][CSRanking] Still allow some filtering of soltions when solving for code completion to improve performance
We were previously completely skipping the "best" solution filtering the solver
does to make sure we didn't miss any non-best but still viable solutions, as
the completions generated from them can make them become the best solution. E.g:

struct Foo { let onFoo = 10 }

func foo(_ x: Int) -> Int { return 1 }
func foo<T>(_ x: T) -> Foo { return Foo() }

foo(3).<here> // the "best" solution is the one with the more-specialized foo(x: Int) overload

In the example above we shouldn't remove the solution for foo(x: T) even though
there is a single "best" solution (`foo(x: Int)`) as picking a completion
result generated from it (`onFoo`) would make the foo(x: T) overload the best
and only viable solution.

Completely skipping this filtering as we were previously doing is overkill
though and adversely affects performance. E.g. it makes sense to filter out
and stop exploring solutions with overload choices for foo that required fixes
for missing arguments if there is another solution with an overload choice that
didn't require any fixes.

This patch restores best solution filtering during code completion and instead updates
the compareSolutions function it compare solutions based purely on their fixed score.

Resolves rdar://problem/73282163
2021-02-26 13:14:49 +10:00
Holly Borla
b7a170cd77 [NFC][ConstraintSystem] Rename applyPropertyWrapperParameter. 2021-02-25 18:35:14 -08:00
Holly Borla
99e066683c [ConstraintSystem] Inject implicit applied property wrapper expressions
around arguments to property wrapper parameters.
2021-02-25 18:35:14 -08:00
Holly Borla
ea3fe03c98 [Property Wrappers] Add a constraint fix and diagnostic for the case
where the programmer tries to pass a projection argument to a wrapped
parameter without 'var projectedValue'.
2021-02-25 18:35:14 -08:00
Holly Borla
31f7b1ac75 [ConstraintSystem] Change the type of an unapplied function reference
when it has property wrapper parameters.

The property wrapper type will be replaced with either the wrapped-value
or projected-value type, depending on the argument label/parameter name,
and CSApply will build a thunk to construct the property wrapper and call
the function.
2021-02-25 18:35:13 -08:00
Holly Borla
19a4f93586 [Property Wrappers] Teach the constraint system to build init(projectedValue:)
calls.
2021-02-25 18:35:13 -08:00
Holly Borla
8325a52b41 [ConstraintSystem] Teach the constraint system about property wrapper
parameters.
2021-02-25 18:35:13 -08:00
Pavel Yaskevich
1817ddcc5e [CSBindings] Always finalize binding set unless explicitly asked not to 2021-02-24 10:38:31 -08:00
Pavel Yaskevich
fbc11f410a [ConstraintSystem] Implement incremental binding computation 2021-02-24 10:37:20 -08:00
Pavel Yaskevich
df7af0078f [CSBindings] Separate inference storage from final product usable by the solver
`PotentialBindings` lost most of its responsibilities,
and are no longer comparable. Their main purpose now
is binding and metadata tracking (introduction/retraction).

New `BindingSet` type is something that represents a set
of bindings at the current step of the solver.
2021-02-24 10:37:20 -08:00
Pavel Yaskevich
b9b5bd214b Merge pull request #34523 from xedin/static-member-lookup-on-protocol
[SE-0299][TypeChecker] Allow static member references on protocol metatypes in generic contexts
2021-02-24 10:16:25 -08:00