Commit Graph

269 Commits

Author SHA1 Message Date
Holly Borla
12459cff80 [Diagnostics] Print 'any' in diagnostic arguments. 2022-03-05 14:26:45 -08:00
Anthony Latsis
6e8dcbe745 ConformanceChecker: Resolve value witnesses unless they depend on invalid type witnesses 2022-02-26 01:06:53 +03:00
Slava Pestov
250fbf2f3d Sema: Reject 'any P' in inheritance clauses 2022-02-23 23:10:10 -05:00
Becca Royal-Gordon
74dc00f091 Merge pull request #40677 from beccadax/sendable-to-the-whole-block
[ClangImporter] Make completion handlers Sendable
2022-02-04 14:51:21 -08:00
Becca Royal-Gordon
602fb3f3d0 Allow @Sendable contravariance in witness params
If a requirement calls for a parameter's function type to be @Sendable, Swift will now permit a witness that does *not* make that parameter @Sendable. This is fine because @Sendable does not affect the calling convention and the witness may not need to exploit the opportunity to send the closure anywhere.

In other words, this code is now valid:

```
protocol P {
    func fn(_: @Sendable () -> Void)
}
struct S: P {
    func fn(_: () -> Void)
}
```

There's an edge case where this still isn't allowed when an associated type is @Sendable.
2022-01-25 15:49:54 -08:00
Robert Widmann
d5c226d55f Propagate Qualified Type Printing in Ambiguous Situations In More Cases
Ultimately this is to support the disambiguation of protocol requirements when printing stubs. This allows us to disambiguate the case where two modules declare a nominal type, and when that type appears in a protocol requirement. In such a case, we now fully qualify the types involved.

Fixing this also appears to now be consistently printing module qualification in many more places, hence the updates to the IDE/SourceKit tests.

rdar://72830118
2022-01-25 14:03:11 -08:00
Holly Borla
ee331a8c01 [Type System] Enable explicit existential types. 2022-01-13 19:31:35 -08:00
Karoy Lorentey
47956908b7 [Concurrency] SwiftStdlib 5.5 ⟹ SwiftStdlib 5.1 (usages)
The concurrency runtime now deploys back to macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, which corresponds to the 5.1 release of the stdlib.

Adjust macro usages accordingly.
2021-10-28 14:36:36 -07:00
Suyash Srijan
396087d0d4 [Test] Update existing tests 2021-08-31 19:21:26 +03:00
Kavon Farvardin
c0607b345f Revert "Merge pull request #33767 from theblixguy/chore/remove-self-or-associated-type-diagnostic"
The following regression test added for this feature is not passing:

Swift(linux-x86_64) :: decl/protocol/protocols_with_self_or_assoc_reqs_executable.swift

with a compiler crash happening during SILFunctionTransform "Devirtualizer".

Reverting to unblock CI.

This reverts commit f96057e260, reversing
changes made to 3fc18f3603.
2021-08-26 16:46:42 -07:00
Suyash Srijan
7834120a87 [Test] Update existing tests 2021-08-16 18:30:26 +03:00
Doug Gregor
eeeea49764 Remove -enable-experimental-concurrency almost everywhere. 2021-07-26 21:24:43 -07:00
Doug Gregor
1608b1e5f9 Make derived hashValue/hash(into:) nonisolated.
Fixes rdar://80424527.
2021-07-24 22:25:16 -07:00
Doug Gregor
1e2012d816 Disable availability checking in tests that use concurrency 2021-07-20 12:46:26 -07:00
Anthony Latsis
a223d37ae7 Merge pull request #34140 from AnthonyLatsis/coself-array
AST, Sema: Teach findProtocolSelfReferences that some stdlib collections preserve variance
2021-02-13 19:45:15 +03:00
Slava Pestov
b81afe3c51 Sema: Don't need to explicitly calculate existentialTypeSupported() 2021-02-11 00:19:24 -05:00
Anthony Latsis
3d317938ad AST, Sema: Teach findProtocolSelfReferences that some stdlib collections preserve variance
* Swift.Array preserves variance in its 'Element' type
* Swift.Dictionary preserves variance in its 'Value' type
2021-02-11 03:22:20 +03:00
Evan Wilde
8b80331c3d Updating tests to use actor
This patch updates the `actor class` spelling to `actor` in almost all
of the tests. There are places where I verify that we sanely handle
`actor` as an attribute though. These include:

 - test/decl/class/actor/basic.swift
 - test/decl/protocol/special/Actor.swift
 - test/SourceKit/CursorInfo/cursor_info_concurrency.swift
 - test/attr/attr_objc_async.swift
 - test/ModuleInterface/actor_protocol.swift
2021-02-10 08:09:13 -08:00
Doug Gregor
f157c79a14 [Concurrency] Loosen isolation checking for overrides/witnesses to ObjC.
When overriding a method or witnessing a requirement that comes from
Objective-C and has no actor annotation, allow the overriding method
or witness to specify a global actor (any global actor, but probably
almost always the main actor) without triggering the actor-isolation
errors one would normally get if both entities were written in Swift.

This opens up a hole in actor-isolation checking, because nothing
guarantees that code won't call these methods through the superclass
or protocol from the wrong actor. On the other hand, it's a very
convenient hole, because it allows us to state when we "know" that an
Objective-C framework will only call a method on (e.g.) the main
actor, and make that known to Swift to be enforced everywhere else in
Swift. If this is a good idea, it's plausible to introduce runtime
assertions of some form to tell the user when such an annotation is
wrong.
2021-01-05 22:20:26 -08:00
Doug Gregor
4bcccecfda [Concurrency] Implicitly strip optionals for return type of translated "async throws".
Review over a large number of APIs has found that most of the time, the
result type of an Objective-C completion handler method that becomes
"async throws" should be optional. Change the default behavior to
match this, and replace _Nullable_on_error with _Nullable_result to
capture the case where the result should be optional.
2020-10-30 00:01:20 -07:00
Pavel Yaskevich
f24e5dbd26 [Diangostics] NFC: Adjust test-cases to expect that "type cannot conform" diagnostic has a note 2020-10-27 14:54:07 -07:00
John McCall
a8464dcaf1 Implicitly import _Concurrency under -enable-experimental-concurrency 2020-10-22 00:53:15 -04:00
Doug Gregor
50f870566a Handle conformance with multiple protocol requirements with the same selector.
When concurrency is enabled, the same Objective-C method on a protocol can
be imported as two different protocol requirements, both of which have the
same selector. When performing conformance checking, only treat a
given @objc protocol requirement as "unsatisfied" by a conformance if
none of the requirements with the same Objective-C selector (+
instance/class designation) are satisfied.
2020-10-02 22:15:04 -07:00
Anthony Latsis
103a821838 Sema: Allow non-final classes to satisfy properties and subscripts with covariant Self 2020-09-20 22:33:44 +03:00
Anthony Latsis
ec29edd5b0 Sema: Pass substitution options to swift::checkTypeWitness
...to propagate tentative type witnesses when validating a solution to associated type inference
2020-08-21 05:23:22 +03:00
Saleem Abdulrasool
6e62444840 test: use the swift_only_stable_abi feature instead of adhoc checks
Use the proper `swift_only_stable_abi` check to ensure that the tests do
not run on targets that do not support the pre-stable ABI.

Thanks to @slavapestov for pointing out that there was a better way!
2020-08-07 09:49:11 -07:00
Mishal Shah
92ca9fc924 [Apple Silicon] Generalize tests for other macOS architectures
Most of the changes fall into a few categories:
* Replace explicit "x86_64" with %target-cpu in lit tests
* Cope with architecture differences in IR/asm/etc. macOS-specific tests
2020-07-02 16:27:46 -07:00
Holly Borla
b871528179 Merge pull request #32524 from OnyekachiSamuel/fix-confusing-protocol-diagnostic
[Diagnostics] Fix Confusing Protocol Diagnostic
2020-07-02 13:01:19 -07:00
Anthony Latsis
057dbbd908 Sema: Filter out conflicting requirements for protocol stubs 2020-06-28 20:47:07 +03:00
Onyekachi Ezeoke
434607d004 fix broken tests 2020-06-27 05:53:47 +01:00
Anthony Latsis
2643a7d8cd Sema: Apply substitutions when checking type witnesses against associatedtype superclass bounds 2020-05-15 02:16:32 +03:00
Kuba Mracek
1bd425da67 [arm64e] Test changes to support arm64e 2020-02-27 16:10:48 -08:00
Rintaro Ishizaki
80dbf7e549 Add test case for https://bugs.swift.org/browse/SR-9868
rdar://problem/47871647
2019-12-17 16:42:47 -08:00
Doug Gregor
3fb77ea447 Provide a custom diagnostic for conformance to NSObjectProtocol
Swift classes cannot meaningfully conform to NSObjectProtocol.
Inheriting from NSObject is the appropriate fix, so suggest that.
Fixes rdar://problem/32543753.
2019-12-05 11:10:27 -08:00
Hamish Knight
eacca4ed0c Requestify circular inheritance checking
Add requests for checking whether a class,
protocol, or enum have circular references in
their inheritance lists.
2019-11-11 09:34:56 -08:00
Luciano Almeida
1184492d25 [Diagnostics] SR-11419 Diagnose protocol stub note in editor mode only (#28101)
* [TypeChecker] Enclosing stubs protocol note within editor mode

* [test] Removing note from test where there is no -diagnostics-editor-mode flag

* Formatting modified code

* [tests] Fixing tests under validation-tests
2019-11-06 07:42:48 -08:00
Anthony Latsis
9b77ae52fa Print property accessors for nonmutating setter requirements 2019-10-28 22:58:24 +03:00
fischertony
6f119b0286 Test protocol stubs for mutating getters 2019-10-25 18:20:54 +03:00
fischertony
18920881d9 ASTPrinter: Mutability fixes for protocol stubs 2019-10-25 18:19:44 +03:00
Robert Widmann
28717ca1b2 Restore the circular pattern binding validation hack
Overload resolution performs a lookup rooted at a pattern binding's
initializer that scoops up the var decl bound by the pattern.  This
forces it to validate the variable while type checking said variable's
initializer.  The old answer to this problem was to skip validation
which returns a temporary ErrorType.  We should patch lookup so it
doesn't consider these variables.
2019-10-14 12:06:50 -07:00
Robert Widmann
742f6b2102 Drastically Simplify VarDecl Validation
This is an amalgam of simplifications to the way VarDecls are checked
and assigned interface types.

First, remove TypeCheckPattern's ability to assign the interface and
contextual types for a given var decl.  Instead, replace it with the
notion of a "naming pattern".  This is the pattern that semantically
binds a given VarDecl into scope, and whose type will be used to compute
the interface type. Note that not all VarDecls have a naming pattern
because they may not be canonical.

Second, remove VarDecl's separate contextual type member, and force the
contextual type to be computed the way it always was: by mapping the
interface type into the parent decl context.

Third, introduce a catch-all diagnostic to properly handle the change in
the way that circularity checking occurs.  This is also motivated by
TypeCheckPattern not being principled about which parts of the AST it
chooses to invalidate, especially the parent pattern and naming patterns
for a given VarDecl.  Once VarDecls are invalidated along with their
parent patterns, a large amount of this diagnostic churn can disappear.
Unfortunately, if this isn't here, we will fail to catch a number of
obviously circular cases and fail to emit a diagnostic.
2019-10-14 12:06:50 -07:00
Holly Borla
7687293b7b [Diagnostics] Adjust the description of existential types for the
type_cannot_conform diagnostic message.
2019-09-17 11:52:43 -07:00
Holly Borla
2a7e0099d2 [Diagnostics] Add notes for the type_cannot_conform error that point
to the declaration that requires protocol conformance.
2019-09-17 09:22:07 -07:00
Holly Borla
40985b6eb7 [Diagnostics] Generalize the "protocol type cannot conform" error to
work for all types that cannot conform to protocols.
2019-09-13 14:51:17 -07:00
Holly Borla
9f19597f73 Sema: implement existentialTypeSupported using a request evaluator.
Add the request `ExistentialTypeSupportedRequest` to lazily determine
if we are allowed to refer to an existential type conforming to a
protocol.
2019-07-22 15:35:10 -07:00
Doug Gregor
bd9b18ef65 Add test for FB6114209 / rdar://problem/51413553
This was fixed by pull request #26174, but the test case there was
specific to property wrappers, while the fix also addresses issues
with other ambiguity name lookups such as protocol names in an
inheritance clause.
2019-07-19 06:53:53 -07:00
Slava Pestov
7786ac8c01 Sema: Move forcing of certain requests from finalizeDecl() to typeCheckDecl()
finalizeDecl() would kick off certain requests. This was necessary
before we had the long-lived type checker to ensure that requests
that required a type checker could be completed in time for SILGen.

It was also necessary to always emit diagnostics for declarations in
primary files.

Since we now have a long lived type checker, the first reason is no
longer valid, so we can move this work from finalizeDecl() to
typeCheckDecl(), where it will run for declarations in primary files
only.

To ensure that @objc selector conflict diagnostics still get emitted,
we also walk the superclass chain and force isObjC() to be computed
for each declaration in each superclass.
2019-07-11 20:55:42 -04:00
Xi Ge
1535bea268 FixCode: issue a separate note for protocol-stub fixit when the fixit location is in another file
Under non-editor mode, the fixit for inserting protocol stubs is associated with a note
pointing to the missing protocol member declaration which could stay in a separate file from
the conforming type, leading to the behavior of rdar://51534405. This change checks if
the fixit is in a separate file and issues another note to carry the fixit if so.

rdar://51534405
2019-07-10 12:30:54 -07:00
Slava Pestov
8f22da205a Sema: Stop wrapping Self returns in protocols with DynamicSelfType 2019-06-26 01:10:11 -04:00
Pavel Yaskevich
91dbcfdfcc [ConstraintSystem] Deplay opening generic requirements until after contextual self has been applied
While computing a type of member via `getTypeOfMemberReference`
let's delay opening generic requirements associated with function
type until after self constraint has been created, that would give
a chance for contextual types to get propagated and make mismatch
originated in generic requirements much easier to diagnose.

Consider following example:

```swift
struct S<T> {}

extension S where T == Int {
  func foo() {}
}

func test(_ s: S<String>) {
  s.foo()
}
```

`foo` would get opened as `(S<$T>) -> () -> Void` and contextual `self`
type is going to be `S<String>`, so applying that before generic requirement
`$T == Int` would make sure that `$T` gets bound to a contextual
type of `String` and later fails requirement constraint `$T == Int`.

This is much easier to diagnose comparing to `$T` being bound to
`Int` right away due to same-type generic requirement and then
failing an attempt to convert `S<String>` to `S<Int>` while simplifying
self constraint.

Resolves: rdar://problem/46427500
Resolves: rdar://problem/34770265
2019-05-24 11:33:30 -07:00