Commit Graph

1081 Commits

Author SHA1 Message Date
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
Slava Pestov
6c5e51621c Sema: Allow an enum case to witness a throwing static method requirement 2021-02-09 00:09:46 -05:00
Robert Widmann
0009209cba Correct the Location of a Protocol Requirement Fixit
The old fixit mistakenly used getLoc() instead of getEndLoc() on the
type repr, which for simple identifiers will do the right thing. For
compound ones like `[T]`, it instead points inside of the repr inside
which leads to nonsensical fixes like [ { get }T]

rdar://73632764
2021-02-01 16:50:26 -08:00
Doug Gregor
450bc77bea Merge pull request #35275 from DougGregor/looser-override-witness-isolation-objc 2021-01-30 18:47:11 -08:00
Rintaro Ishizaki
8a58107123 [Parse] Diagnose default argument for subscript in protocols
Protocol requirements don't support default arguments. Although this is
a "semantic" diagnostics, we currently do this for 'func' and 'init' in
Parser. So for fixing a crash, let's to it for 'subscript' in Parser
too.

rdar://problem/73159041
2021-01-22 17:21:17 -08:00
Slava Pestov
b18c7fb22b Sema: Allow re-declarations of typealiases in constrained extensions with different generic signatures
Associated type inference will synthesize typealiases in
constrained extensions for conditional conformances, but
then we might later flag them as re-declarations.

Let's not do this, since name lookup does check if generic
requirements are satisfied, so such redeclarations are not
in fact erroneous.

Fixes <rdar://problem/68933045>.
2021-01-13 21:59:27 -05: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
Evan Wilde
1d53d748d3 Cleanup actor protocol conformance error
This patch cleans up how we emit the errors for disallowing the
properties and methods of an actor to be applied to the protocol
conformance. Rather than having multiple error messages for each case,
we keep one error message saying that the actor-isolated
method/variable/what-have-you cannot be used to satisfy a protocol
requirement, then allow multiple notes with fix-its to allow the
programmer to choose what they want to do. The notes have a better
description of what each option does.
2020-12-17 16:12:41 -08:00
Robert Widmann
363b66a7ad Fully Qualify the Parent Type When Diagnosing Missing Member Types
Use the FullyQualified<Type> abstraction from the prior commit plus DescriptiveDeclKind to give a bit more information when issuing a missing member type diagnostic during type resolution.
2020-11-09 17:10:18 -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
Robert Widmann
4351bd374a Use The Location of the Pattern Binding in Codable Fixit
The code here used to use the location of the nearest place to insert
attributes, which makes no sense. Use the pattern binding's location
instead to ensure that we actually replace the 'let' part of the
pattern every time.

rdar://69971194
2020-10-13 14:12:19 -07:00
Anthony Latsis
3bc381ba0c Merge pull request #34214 from AnthonyLatsis/coself-mut
Sema: Disallow usage of settable Self-returning storage requirements …
2020-10-11 12:33:03 +03:00
Anthony Latsis
8f43d888b8 Sema: Disallow usage of settable Self-returning storage requirements on existential base 2020-10-07 20:48:16 +03:00
Doug Gregor
bb066b6fa6 [Concurrency] Make actor-isolated protocol witnesses an error.
With actor isolation checking for protocol witnesses moved out of the
witness-matching phase, move the corresponding diagnostics from notes
(that would have been on the "type does not conform" error) to
freestanding errors.
2020-10-02 23:41:44 -07:00
Doug Gregor
591e6e89e2 [Concurrency] Only infer @asyncHandler for witnesses within actor classes.
Actor classes are by definition new code, so only perform inference of
@asyncHandler from a protocol requirement to witnesses when those
witnesses are within an actor class. This is partly because
@asyncHandler might not have reasonable semantics outside of actor
classes anywhere (where would you execute the detached task?), and
partly because it is a source-compatibility problem due to the
combination of...

1) Inferring @asyncHandler on imported Objective-C protocol methods for
existing protocols,
2) Inferring @asyncHandler from those protocol methods to an existing
method in a class that conforms to that protocol, and
3) Using an API that is now overloaded for both synchronous and
asynchronous callers will end up preferring the asynchronous version,
then fail due to a missing "await".

The individual steps here are all reasonable, but the result is a
source break, so back off on @asyncHandler inference for witnesses
outside of actor classes. New code gets the more-asynchronous behavior
for free.
2020-10-02 22:15:05 -07: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
Doug Gregor
c2b8565a10 [Concurrency] Implicitly synthesize actor queue storage and enqueue.
When an actor class has its `enqueue(partialTask:)` implicitly
synthesized, also synthesize a stored property for the actor's queue.
The type of the property is defined by the _Concurrency library
(`_DefaultActorQueue`), and it will be initialized with a call to
`_defaultActorQueueCreate` (also provided by the _Concurrency
library).

Also synthesize the body of the implicitly-generated
`enqueue(partialTask:)`, which will be a call to
`_defaultActorQueueEnqueuePartialTask(actor:queue:partialTask:)`.
Together, all of these allow us to experiment with the form of the
queue and the queue operation without affecting the type checker.

When `enqueue(partialTask:)` is not implicitly synthesized, the queue
storage is not synthesized either. In such cases, the user has taken
over the execution of tasks for the actor, rather than using the
default implementation.
2020-09-29 13:50:32 -07:00
Doug Gregor
ab3c5dee3e [Concurrency] Introduce Actor protocol to which actor classes all conform.
Introduce a new Actor protocol, which is a class-bound protocol with only
one requirement:

    func enqueue(partialTask: PartialAsyncTask)

All actor classes implicitly conform to this protocol, and will synthesize
a (currently empty) definition of `enqueue(partialTask:)` unless a suitable
one is provided explicitly.
2020-09-28 16:59:21 -07:00
Anthony Latsis
d953fa646d Merge pull request #34005 from AnthonyLatsis/coself
Sema: Allow non-final classes to satisfy properties and subscripts with covariant Self
2020-09-25 05:23:34 +03:00
Slava Pestov
cf2d0d3c9b Sema: Fix crash on static -vs- non-static witness mismatch with deserialized witness
Deserialized computed properties don't get a PatternBindingDecl apparently.

Fixes <rdar://problem/68241758>.
2020-09-21 16:50:05 -04: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
8cae50aab4 AssociatedTypeInference: Generalize computeFixedTypeWitness to consider type parameters
While we're here, remove the return on a null generic signature. The request for
the generic signature of a protocol is a trivial computation that is never expected
to fail
2020-09-11 01:02:22 +03:00
Suyash Srijan
79b0a7ef75 [CSDiagnostics] Emit fix-its to insert requirement stubs for missing protocols in context (#33628)
* [CSDiagnostics] Emit fix-its to insert requirement stubs in editor mode for missing protocols in context

* [CSDiagnostics] Only include missing requirements in stub fix-it for missing protocols in context

The conforming type may already have declarations that could satisfy a requirement, so we shouldn't include it in the fix-it
2020-08-26 02:05:29 +01:00
Anthony Latsis
68dcbca696 Merge pull request #33581 from AnthonyLatsis/ripe-conformances/no-options
Sema: Pass substitution options to swift::checkTypeWitness
2020-08-25 04:39:12 +03:00
Robert Widmann
13cf37a2ee Patch A Regression in Lookup for CodingKeys
Codable's magic previously relied on the subject of every qualified lookup in an
unqualified lookup stack to force the synthesis of this member. This
allowed users to reference CodingKeys transitively through a non-primary input
without qualification. As part of the requestification of name lookup,
this synthesis was moved out of the normal qualified lookup path and into the
Type Checker's semantic lookup entrypoints in order to prevent wild
cycles caused by protocol conformance resolution. In the process, we
forget to restore the synthesis check at this entrypoint.

To patch up the source break this caused, we need to walk the context
stack again and force synthesis. Unfortunately, we're stuck with a hack like
this until we bring Codable's implementation back out of the realm of magic
once more. A future implementation of synthesizeSemanticMembersIfNeeded
should aim to just craft the AST for CodingKeys, but not actually run
any of the semantic checks until we check the conformance to CodingKey.

rdar://65088901, SR-13137
2020-08-20 21:49:13 -07: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
Slava Pestov
e05a7326f3 Sema: Fix crash-on-invalid on protocol requirements with 'where' clause constraints
RequirementEnvironment wasn't prepared to handle a protocol
requirement with additional 'where' clause constraints but
no generic parameters.

Since such a requirement necessarily runs afoul of the existing
"protocol requirements cannot constrain Self" rule, it suffices
to ignore such requirements when matching witnesses and let
the declaration checker diagnose this situation later.

Fixes <rdar://problem/61876053>.
2020-08-18 17:38:31 -04:00
Slava Pestov
6d84c18ba4 Sema: Check 'where' clause requirements on type witnesses
In the included test case, conformance checking of Wrapper : B would
pick up typealias Foo as a witness for the associated type B.Foo.

However, this typealias Foo is defined in a constrained extension where
T : A, and the underlying type references the associated type A.Foo
on T.

The resulting substitution is invalid when the conformance Wrapper : B
is used in a context where T does not conform to A.

Instead, we should ignore this typealias entirely, since it appears
in an unusable constrained extension.

Fixes <rdar://problem/60219705>, <https://bugs.swift.org/browse/SR-12327>,
<https://bugs.swift.org/browse/SR-12663>.
2020-08-15 01:43:13 -04:00
Anthony Latsis
b37491ad62 AssociatedTypeInference: Stop skipping the current protocol when looking for a fixed type witness 2020-08-10 01:52:07 +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
Slava Pestov
34650e8f3a Merge pull request #32799 from AnthonyLatsis/sself-is-fixed
AssociatedTypeInference: Allow Self as a fixed type witness
2020-08-06 19:43:56 -04:00
Joe Groff
f2a935338c Merge pull request #33192 from jckarter/internal-linkage-objc-symbols
IRGen: Give ObjC metadata symbols internal linkage.
2020-07-30 09:15:05 -07:00
Joe Groff
445bde5127 IRGen: Give ObjC metadata symbols internal linkage.
This preserves the symbol names in (unstripped) binaries, so we can use them for link ordering and
memory usage analysis.
2020-07-29 13:49:25 -07:00
Suyash Srijan
cc49c6105c [Diagnostics] Update diagnostic message for invalid overrides (#33097)
* [Diagnostics] Update 'does not override' diagnostic message to include protocol context as well

* [Sema] Check whether the override context is a class or a protocol for diagnostic purposes

* [Test] Update tests with new diagnostic message for overrides in protocol context

* [Sema] Adjust diagnostic for overrides in structs and enums to use the existing 'override_nonclass_decl' diagnostic
2020-07-27 15:15:28 +01:00
Nikhil
6428c1f9bb [Diagnostic] Fix diagnostic when checking conformance for IUO of gene… (#32987)
* [Diagnostic] Fix diagnostic when checking conformance for IUO of generic parameter

Prints TypeRepr in diagnostic if possible to throw
accurate diagnostic for IUO conformance checking
Fixes [rdar://problem/64953106]. Fixes SR-13119

* Nested name lookup tests update

Name lookup will see the innermost name anyway and
preferred over fully qualified name. Hence the test
cases are also updated.

* Replaced a letter in test case that inadvertently got added

* Code format, corrections and better comments

This commit includes better comments for easy
understanding, formatted the bug fix code with
clang-format and fixes wrong variables inadvertently
introduced.

* [Test] Update type in struct codable test

This commit changes diagnostic type from error type
to Int. Although this diagnostic updated is incorrect, this will
be resolved when 32371 gets pulled.
2020-07-21 09:07:44 -07:00
Anthony Latsis
28531141d2 AssociatedTypeInference: Self is a valid fixed type witness 2020-07-15 22:34:24 +03:00
Anthony Latsis
19f27d9c94 Merge pull request #32752 from AnthonyLatsis/plus-inference
AssociatedTypeInference: Delay substitutions into abstract type witnesses until after they have been computed
2020-07-15 17:27:26 +03:00
Suyash Srijan
0aabee59d6 [Typechecker] Emit specialized diagnostic notes on automatic synthesis failure to Comparable (#32797) 2020-07-14 22:03:08 +01:00
Anthony Latsis
54ccdc67e7 AssociatedTypeInference: Delay substitutions into abstract type witnesses until after they have been computed 2020-07-12 02:55:22 +03:00
Slava Pestov
1802ec9b20 Merge pull request #32753 from theblixguy/fix/associated-type-inference-enum-witness
[AssociatedTypeInference] Strip 'self' parameter from function type of an enum case witness
2020-07-08 19:15:41 -04:00
Suyash Srijan
be79d341e6 [AssociatedTypeInference] Strip 'self' parameter from function type of an enum case witness 2020-07-08 14:37:48 +01: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
Slava Pestov
8305d51365 Sema: Relax associated type default circularity check
We should allow an associated type's default to reference the
same associated type with a base other than 'Self'.

Note that it now becomes easier to defeat this check, but it
was never air-tight anyway -- for example, you could have a
cycle of length two if each associated type's default was the
other associated type.

This is fine, because this check is purely 'cosmetic'; nothing
goes really wrong if you have a cycle here, except that the
diagnostic shifts from the declaration of the protocol to the
conforming type.

Fixes <rdar://problem/62355224>.
2020-06-16 22:18:24 -04:00