Commit Graph

1976 Commits

Author SHA1 Message Date
Holly Borla
8325a52b41 [ConstraintSystem] Teach the constraint system about property wrapper
parameters.
2021-02-25 18:35:13 -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
Luciano Almeida
8b0b89ee34 Merge pull request #36076 from LucianoPAlmeida/SR-2705-ranking-autoclosure
[SR-2705][Sema] Always favor non-autoclosure parameter function overload
2021-02-24 07:00:42 -03:00
Luciano Almeida
7c92f7d5da [CSSimplify] Add autoclosure check for contravariant match and extra test case 2021-02-23 19:39:14 -03:00
Pavel Yaskevich
c4ee329991 [CSSimplify] NFC: Adjust to API change - isHole -> isPlaceholder 2021-02-23 12:19:27 -08:00
Pavel Yaskevich
cf5e1fff8d [Diagnostics] Add a tailored diagnostic for contextual lookup on protocols without Self requirement 2021-02-23 11:33:11 -08:00
Pavel Yaskevich
2d8f002299 [CSDiagnostics] Adjacent diagnostics for the new rules of static member lookup in generic context 2021-02-23 11:33:11 -08:00
Pavel Yaskevich
c44a92ae0b [ConstraintSystem] Implement new rule for static member lookup in generic contexts
Instead of requiring result type of the member to conform to declaring protocol,
as originally proposed by SE-0299, let's instead require `Self` to be bound to
some concrete type in extension that declares a static member.

This would make sure that:

1. Members are only visible on a particular type;
2. There is no ambiguity regarding what base of the member chain is going to be.
2021-02-23 11:33:11 -08:00
Pavel Yaskevich
74d2a6c700 [ConstraintSystem] Limit static member reference on protocol metatype to leading dot syntax only
Do not allow references to a static members with explicitly specified
protocol metatype base, limit that to leading dot syntax only.
2021-02-23 11:33:11 -08:00
Pavel Yaskevich
2b6d24eb99 [ConstraintSystem] NFC: Slightly clarify comment about existence static members on a protocol metatype 2021-02-23 11:33:11 -08:00
Pavel Yaskevich
e548366bb5 [TypeChecker] Add tests for static member refs on protocol metatypes feature 2021-02-23 11:33:11 -08:00
Pavel Yaskevich
30f255755b [Diagnostics] NFC: Adjust all diagnostics improved/changed by static member refs on protocol metatypes feature 2021-02-23 11:33:10 -08:00
Pavel Yaskevich
dcd746906f [ConstraintSystem] Mark member result type as a potential hole if base was incorrect
If it has been established that member found via static member
lookup on protocol metatype doesn't have correct result type,
chain's result type the should be treated as a hole.
2021-02-23 11:33:10 -08:00
Pavel Yaskevich
d1ab178471 [ConstraintSystem] Diagnose conformance failure with base of a static member lookup
Produce a tailored diagnostic when it has been established that
base type of a static member reference on protocol metatype doesn't
conform to a required protocol.
2021-02-23 11:33:10 -08:00
Pavel Yaskevich
5758ae2bcc [ConstraintSystem] Filtering for static member lookup on protocol metatypes
Detect and filter some of the overload choices which can't possibly
match because their result type cannot conform to the expected protocol.
2021-02-23 11:33:10 -08:00
Pavel Yaskevich
df76400fe5 [ConstraintSystem] Add a new reason for invalid member reference
This new reason indicates that result type of a static member
doesn't conform to a specific protocol so it can't be referenced
on a protocol metatype.
2021-02-23 11:33:10 -08:00
Pavel Yaskevich
497d42d90e [ConstraintSystem] Add a new constraint which connects base with result of the member chain
The first type represents a result of an unresolved member chain,
and the second type is its base type. This constraint acts almost
like `Equal` but also enforces following semantics:

- It's possible to infer a base from a result type by looking through
  this constraint, but it's only solved when both types are bound.

- If base is a protocol metatype, this constraint becomes a conformance
  check instead of an equality.
2021-02-23 11:33:10 -08:00
Pavel Yaskevich
eaabd24746 [CSFix] Add a new fix to diagnose invalid static member refs on protocol metatype 2021-02-23 11:32:24 -08:00
Pavel Yaskevich
7009207491 [ConstraintSystem] Adjust handling of incorrect member references on protocol metatypes
Since it's now possible to refer to static members declared on a protocol
metatype if result type conforms to the protocol we need to adjust failure
detection to identify that conformance failure means and invalid reference
in certain situations.
2021-02-23 11:32:24 -08:00
Pavel Yaskevich
3a145f5464 [CSSimplify] Change equality semantics between base and result of unresolved member ref
Since it's now possible to infer base type of an unresolved member
reference to be a protocol type we need to adjust `matchTypes` to
check conformance instead of type equality between base (represented
by a protocol) and chain's concrete result type.
2021-02-23 11:32:24 -08:00
Pavel Yaskevich
b05678f18e [ConstraintSystem] Allow static member references on protocol metatypes 2021-02-23 11:31:43 -08:00
Luciano Almeida
ef86e9edbe [ConstraintSystem] Adding new score kind SK_FunctionToAutoClosureConversion to increase impact of a function to autoclosure 2021-02-23 07:21:58 -03:00
Luciano Almeida
21a1d908b8 [CSSimplify] Increase score for closure argument when in a call autoclosure context to avoid ambiguity 2021-02-23 00:49:42 -03:00
Nathan Hawes
44e09bc246 Merge branch 'main' into dont-allow-missing-args-if-trailing-and-not-function-type 2021-02-23 12:53:50 +10:00
Nathan Hawes
cdcaa110e8 [CodeCompletion][Sema] Refine logic that ignores missing arguments after the code completion position when solving
If the completion loc was in a trailing closure arg, it only makes sense to
ignore later missing args if they have function type, as there's no way for the
user to complete the call for overload being matched otherwise.

Also fix a bug where we were incorrectly penalizing solutions with holes that
were ultimately due to missing arguments after the completion position.

Resolves rdar://problem/72412302
2021-02-20 08:59:47 +10:00
Frederick Kellison-Linn
e4ea1678dc Rename HoleType to PlaceholderType
HoleType basically served the same purpose as PlaceholderType. This commit unifies the two.
2021-02-16 22:59:19 -05:00
Frederick Kellison-Linn
d78d95ef0d [AST] Introduce PlaceholderType and ThePlaceholderType singleton 2021-02-16 22:59:18 -05:00
Luciano Almeida
d55eed46e8 [Sema][CSApply] Moving some checked cast diagnostics to a fix format (#34980)
* [Sema] Implementing is runtime check always true diagnostic as a fix

* [AST] Implement getWithoutThrows on function type

* [CSSimplify] Detect that checked cast types conversion is always true and record warning fix

* [test] Some additional test cases for SR-13789

* [Sema] Fixing typo on fix name

* [Sema] Move and adjust the ConditionalCast diagnostics to the fix format

* [Sema] Remove some checked cast diagnostics from check constraints and move to fix

* [Sema] Renaming checked cast coercible types fix

* [Sema] Some adjustments and rewrite on the logic for downcast record fix

* [Sema] Move logic of runtime function type to AllowUnsupportedRuntimeCheckedCast::attempt

* [Sema] Abstract checked cast fix logic to static function and minor adjustments

* [Sema] Renamings from review
2021-02-10 08:31:06 -03:00
Doug Gregor
f13167d9d1 Merge pull request #35628 from DougGregor/concurrent-function-types
[Concurrency] Add @concurrent function types
2021-01-29 08:34:59 -08:00
Pavel Yaskevich
a7e8034396 [ConstraintSystem] NFC: Print type variables embedded in common result type 2021-01-28 14:01:29 -08:00
Doug Gregor
b77ba9a77f [Concurrency] Infer @concurrent on closures from contextual type 2021-01-27 16:00:39 -08:00
Doug Gregor
ba8819eb58 [Concurrent] Introduce concurrent function types.
Introduce `@concurrent` attribute on function types, including:
* Parsing as a type attribute
* (De-/re-/)mangling for concurrent function types
* Implicit conversion from @concurrent to non-@concurrent
- (De-)serialization for concurrent function types
- AST printing and dumping support
2021-01-27 14:22:32 -08:00
Pavel Yaskevich
fda3dc5127 Merge pull request #35607 from xedin/type-vars-accepts-set
[AST] Adjust `TypeBase::getTypeVariables` to accept a set
2021-01-27 09:51:45 -08:00
Pavel Yaskevich
b03dc63634 [AST] Adjust TypeBase::getTypeVariables to accept a set
Currently the pattern is to collect the type variables and then unique
them. Instead of asking clients to do uniquing, let's just accept a set
as an argument.
2021-01-26 18:13:34 -08:00
Varun Gandhi
86b123a35c [Sema] Diagnose type error on Clang type mismatch.
Fixes rdar://71904525.
2021-01-25 18:51:13 -08:00
swift-ci
a86430b937 Merge pull request #35580 from LucianoPAlmeida/SR-14050 2021-01-25 18:20:25 -08:00
Luciano Almeida
18e604a750 [Sema] Removing check for argument locator at subtype validation at matchFunctionRepresentations 2021-01-25 20:35:44 -03:00
Holly Borla
1ef2174bc2 Merge pull request #35025 from hborla/generic-overload-search-space
[ConstraintSystem] Implement heuristics for pruning the generic operator overload search space
2021-01-22 09:12:50 -08:00
Robert Widmann
d4f92d4116 Merge pull request #35527 from CodaFi/context-clues
Use the Correct DeclContext When Simplifying Member Constraints
2021-01-20 19:07:28 -08:00
Robert Widmann
0943351fe7 Use the Correct DeclContext When Simplifying Member Constraints
Looking for the parent source file is going to fail when the paramter
we're interested in comes from a module context. Request the correct
top-level context in those situations.

rdar://73379770
2021-01-20 15:42:35 -08:00
Varun Gandhi
d9cd7e73cd Merge pull request #35457 from varungandhi-apple/vg-cleanup-rep-matching
[docs] Tidy and document permissible conversions based on calling conventions
2021-01-20 13:28:54 -08:00
Varun Gandhi
aac0a9a9ed [doc] Document function representation conversions inline. 2021-01-19 10:48:13 -08:00
Varun Gandhi
3301ae90e0 [NFC] Simplify function type representation checks. 2021-01-19 10:48:13 -08:00
Varun Gandhi
66dfea141c [doc] Document function representation subtyping rules. 2021-01-19 10:48:12 -08:00
Varun Gandhi
5d3984e027 [NFC] Flip polarity of matchFunctionRepresentations.
The existing polarity is sufficiently confusing that it has an
explanatory comment at a return statement.
2021-01-15 10:45:03 -08:00
Pavel Yaskevich
f6637276fd [ConstraintSystem] Increase score only if members found on Optional and its unwrapped type
Unresolved member lookup is allowed to perform implicit optional
unwrap of a base type to find members. Previously if there were
any members directly on `Optional`, lookup would stop there. But
since SR-13815 it became possible for solver to attempt members
found on unwrapped type even if there are viable ones on
`Optional` as well.

New score kind has been introduced to guard against possible ambiguities
with new scheme - `SK_UnresolvedMemberViaOptional`. It's used very
time member found via base type unwrap is attempted. Unfortunately,
doing so can lead to behavior changes in existing code because it's
possible that base was wrapped into optional implicitly based on
context e.g. unresolved member passed in as an argument to a parameter
of optional type.

To fix situations like that, `SK_UnresolvedMemberViaOptional` should
only be increased if there is a mix of members to attempt - both directly
on `Optional` and on unwrapped type, in all other cases score should stay
the same because there could be no ambiguity.

Resolves: rdar://73027153
2021-01-13 09:12:03 -08:00
Pavel Yaskevich
87cc597d19 [ConstraintSystem] Stop using CheckedConformances cache
It was necessary only for `applySolutionToForEachStmt` in `CSApply`,
diagnostic can avoid it and use information stored in the locator
instead.
2021-01-08 11:36:34 -08:00
Pavel Yaskevich
7fb4815d53 Merge pull request #35291 from xedin/sr-13951-followup
[Diagnostics] Attempt `.rawValue` fix only if both types are equally …
2021-01-07 12:48:33 -08:00
Pavel Yaskevich
26415547e0 [Diagnostics] Attempt .rawValue fix only if both types are equally optional
This is a follow-up to https://github.com/apple/swift/pull/35072.

Let's wait until both sides are equally optional before attempting
`.rawValue` fix, otherwise there is a risk that a valid code would
get diagnosed.

Extend test coverage of possible `.rawValue` situations to
contextual and argument positions to make sure that valid
code is accepted.

Resolves: SR-13951
2021-01-07 09:02:20 -08:00
Pavel Yaskevich
33f34d15f6 Merge pull request #35281 from xedin/rdar-72819046
[Diagnostics] Special case requirement failures related to `return` statement/expression
2021-01-07 08:56:15 -08:00