Commit Graph

18353 Commits

Author SHA1 Message Date
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
03d869ad8b [Diagnostics] Extract invalid result type from overload choice
Instead of threading it through the constraint system all the way
to a diagnostic, let's extract it from overload choice instead.
2021-02-23 11:33:10 -08:00
Pavel Yaskevich
5b55ea1312 [CSGen] Use new UnresolvedMemberChainBase constraint 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
9231acf202 [Diagnostics] Implement a tailored diagnostic for invalid static member refs on protocol metatypes 2021-02-23 11:32:24 -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
49cc21919b [CSBindings] Don't infer protocol types from the base of an unresolved member chain 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
ee8b87ecf9 [CSBindings] Allow base type of an unresolved member to be inferred from protocol requirements
To be able to infer base type in situations like:

```swift
func foo<T: P>(_: T) {}
foo(.bar)
```

Type variable used for a base type of the chain has to be allowed
to infer types from contextual protocol requirements e.g. `T: P`
in our example.
2021-02-23 11:32:23 -08:00
Pavel Yaskevich
b05678f18e [ConstraintSystem] Allow static member references on protocol metatypes 2021-02-23 11:31:43 -08:00
Robert Widmann
9756b8b9b8 Merge pull request #36102 from CodaFi/repr-kit 2021-02-23 08:18:15 -08:00
Robert Widmann
44e3db8979 Fix a Family of Crashers in Availability Checking
NIO exposed an issue in the new availability walkers where an implicit
check was not being performed. They were able to get this to crash by
using a defer statement - the body of which contains implicit
declarations that got run through the walker. This exposed a wider hole
in availability checking of defer statements. Namely, that it wasn't
happening.

Let's dilute the meaning of `isImplicit` in the availability walkers to
account for this desugaring.

rdar://74484150
2021-02-22 21:21:26 -08: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
Pavel Yaskevich
db7ee5f7eb Merge pull request #36059 from xedin/nfc-remove-argument-info-collector
[ConstraintSystem] NFC: Remove `ArgumentInfoCollector` which was part…
2021-02-22 10:48:31 -08:00
Robert Widmann
b8329b633e Merge pull request #36060 from CodaFi/codicil
Patch a Huge Soundness Hole in Codable Synthesis
2021-02-22 08:48:50 -08:00
Holly Borla
11028350a7 Merge pull request #35589 from Jumhyn/placeholder-types
[AST, Sema] Replace HoleType with PlaceholderType
2021-02-22 08:35:37 -08:00
Doug Gregor
ecf36ba6bc Enable ConcurrentValue checking as part of Concurrency mode.
Drop the separate flag guarding this checking.
2021-02-22 00:29:56 -08:00
Doug Gregor
65d6af6b98 Diagnose key paths that capture non-concurrent values. 2021-02-21 22:10:50 -08:00
Doug Gregor
26bbd8c7b3 [Concurrency] Remove dead ConcurrentValue checking code.
This code got duplicated and customized, but is no longer used.
2021-02-21 22:10:50 -08:00
Doug Gregor
d9e4184742 Make Error and CodingKey conform to ConcurrentValue.
Make both Error and CodingKey conform to ConcurrentValue, so that
thrown errors always conform to ConcurrentValue. Downgrade (to
warnings) and ConcurrentValue-related diagnostics that are triggered
by this change in existing Error and CodingKey-conforming types to
reduce the impact on source compatibility.
2021-02-20 22:01:28 -08:00
Doug Gregor
87ac6ce6a3 Ban use of marker protocols in conditional conformances to non-marker protocols
These conditional conformances could not be properly evaluated at
runtime, so ban them. We still allow conditional conformances to
marker protocols.
2021-02-20 21:12:39 -08:00
Doug Gregor
2c24592861 Allow implied conditional conformances to marker protocols.
This improves source compatibility in cases where a marker
protocol is introduced after-the-fact (e.g., for `Error`),
and is safe because there's no runtime component to marker protocols.
2021-02-20 21:12:39 -08:00
Ben Barham
b7a6bcbda2 Merge pull request #36027 from bnbarham/hasasyncalternative
[AST] Add a new attribute @hasAsyncAlternative
2021-02-20 11:15:18 +10:00
Robert Widmann
6c9fb0d55c Undo Bogus DiagnosticTransactions in Codable Synthesis
The order of diagnostic emission absolutely does not matter. What this transaction was actually doing was suppressing valid diagnostics. This is a deeply unsound thing to do since if errors are emitted but Codable synthesis succeeds then invalid code can make its way past Sema.

rdar://74392492
2021-02-19 16:58:38 -08:00
Robert Widmann
fa8f0300dd Split CodingKeys Synthesis From Validation 2021-02-19 16:04:01 -08:00
Robert Widmann
6df3fcf3ad Add Missing Definitions of canDerive{En,De}codable 2021-02-19 16:03:32 -08:00
Robert Widmann
55fd87900a [NFC] Lazily Construct ErrorTypes when PatternTypeRequest Fails
Doing this eagerly makes it more difficult to determine when something fails by observing the creation of ErrorTypes
2021-02-19 16:02:53 -08:00
Pavel Yaskevich
d394d7bb8f Merge pull request #36043 from LucianoPAlmeida/nfc-transitive-closure-defaults
[CSBindings] Avoid to infer transitive defaults for DefaultClosureType
2021-02-19 16:00:03 -08: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
Pavel Yaskevich
1eb478870a [ConstraintSystem] NFC: Remove ArgumentInfoCollector which was part of designated operator work 2021-02-19 13:45:40 -08:00
Frederick Kellison-Linn
8539782c9a [Sema] Rename convertInferableTypes to replaceInferableTypesWithTypeVars 2021-02-19 14:35:03 -05:00
Pavel Yaskevich
cbd2916a64 Merge pull request #36045 from xedin/handle-non-ambiguous-fixes-better
[CSFix] Handle some cases where the same fix appears in multiple solutions
2021-02-19 09:37:51 -08:00
Doug Gregor
66cd7d82ae Marker protocols are self-conforming. 2021-02-18 23:44:39 -08:00
Doug Gregor
85611dbf25 Allow marker protocols as existentials (but still ban casts)
There is no problem with having an existential value that involves a
marker protocol. However, since there is no runtime checking for
marker protocols, ban "as?" and "is" casts to them.
2021-02-18 23:44:39 -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
1b7795b5e3 [CSFix] Allow diagnosing invalid references in key path with multiple solutions
If multiple solutions have exactly a fix for exactly the same invalid member
reference in key path, let's diagnose that as if there is no ambiguity there.
2021-02-18 17:21:37 -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
Luciano Almeida
76564ea340 [CSBindings] Avoid to infer transitive defaults for DefaultClosureType 2021-02-18 21:39:38 -03:00
Pavel Yaskevich
b49be98c63 Merge pull request #36038 from xedin/add-retract-to-potential-bindings
[CSBindings] Add an ability to retract previously inferred bindings
2021-02-18 13:33:30 -08:00
Slava Pestov
cd724d4924 Merge pull request #35988 from slavapestov/simplify-does-storage-produce-lvalue
Sema: Simplify doesStorageProduceLValue() a bit
2021-02-18 12:29:04 -05:00
Ben Barham
3a7bf2301b [AST] Add a new attribute @hasAsyncAlternative
This attribute marks a function has having an async alternative,
optionally providing the name of that function as a string. Intended to
be used to allow warnings when using a function with an async
alternative in an asynchronous context, to make the async refactorings
more accurate, and for documentation.
2021-02-18 16:18:38 +10:00
Doug Gregor
077d96c68e Merge pull request #36012 from DougGregor/explicit-concurrent-closure
Add support for @Concurrent attribute on closures.
2021-02-17 21:16:08 -08:00
Slava Pestov
7fe1c9c8a0 Merge pull request #36028 from slavapestov/csapply-unreachable-type-cleanup
Sema: Remove some unreachable code from CSApply
2021-02-17 22:52:58 -05:00
Slava Pestov
082f09176b Merge pull request #36029 from slavapestov/reasync-part-2
Sema: Start abstracting out the 'effect' in rethrows-checking logic
2021-02-17 21:33:09 -05:00
Pavel Yaskevich
321cc07ba2 [CSBindings] Reset literal coverage when retracting constraint 2021-02-17 17:26:05 -08:00
Pavel Yaskevich
8e90882ee1 [CSBindings] Allow retracting constraints previously used to compute potential bindings
This allows to avoid having to recompute bindings when solver backtracks.
2021-02-17 17:25:42 -08:00
Pavel Yaskevich
1efcd3f822 Merge pull request #36022 from apple/revert-35503-SR-12033-autoclosure
Revert "[SR-12033] [Sema] Do not allow inferring defaultable closure `() -> $T` for autoclosure arguments result"
2021-02-17 16:40:46 -08:00