Commit Graph

2021 Commits

Author SHA1 Message Date
Anthony Latsis
826f17e534 Decouple detection of «Self ==» constraints from SelfReferenceKind 2020-10-12 15:01:40 +03:00
Doug Gregor
4419f879ad Merge pull request #34201 from DougGregor/concurrency-global-actor
[Concurrency] Global actors
2020-10-10 00:19:33 -07:00
Robert Widmann
59b00d115b [NFC] Make EnumRawTypeRequest Cached
Drop the extra bit of state in the AST for the semantic type.
2020-10-09 15:34:44 -07:00
Robert Widmann
ff8d5bc2c8 [NFC] MutableArrayRef<TypeLoc> -> ArrayRef<TypeLoc>
The first step on the road to splitting the semantic type information here from the syntactic information in the other half of the TypeLoc.
2020-10-09 15:29:55 -07:00
Doug Gregor
77584928da [Concurrency] Implement global actor isolation rules.
Extend the actor isolation checking rules to account for global
actors. For example, a function annotated with a given global actor
can invoke synchronous methods from the same global actor, but not
from a different global actor or a particular actor instance.
Similarly, a method of an (instance) actor that is annotated with a
global actor attribute is not part of the (instance) actor and,
therefore, cannot operate on its actor-isolated state.
2020-10-09 15:20:01 -07:00
Doug Gregor
df883f89ad [Concurrency] Allow global actor annotations on declarations.
Global actor types can be used as attributes on various kinds of
declarations to indicate that those declarations are part of the
isolated state of that global actor. Allow such annotation and perform
basic correctness checks.
2020-10-09 10:19:28 -07:00
Doug Gregor
98903b7cd2 [Concurrency] Add globalActor attribute.
The globalActor attribute indicates that a particular type describes a
global actor. Global actors allow the notion of actor state isolation
to be spread across various declarations throughout a program, rather
than being centered around a single actor class. There are useful
primarily for existing notions such as "main thread" or subsystems
accessed through global/singleton state.
2020-10-09 09:45:00 -07:00
Robert Widmann
92cb6808fe Merge pull request #34151 from CodaFi/body-paint
Remove Type Body Fingerprints Flags
2020-10-02 11:45:53 -07:00
Holly Borla
355fbb3a8b Merge pull request #34109 from hborla/local-property-wrappers
[Property Wrappers] Support local property wrappers
2020-10-01 22:45:41 -07:00
Robert Widmann
964f640636 Drop "Private Deps" Flag
In order for type body fingerprints to work, these declarations must always be included. Drop the ability to turn this off.
2020-10-01 14:40:45 -07:00
Doug Gregor
75b18ad90b Merge pull request #34111 from DougGregor/concurrency-actor-protocol
[Concurrency] Introduce Actor protocol to which actor classes all conform
2020-09-30 13:05:06 -07:00
Slava Pestov
039be66d25 Merge pull request #34120 from slavapestov/generics-header-cleanup
AST: Move GenericParamList and friends to GenericParamList.{h,cpp}
2020-09-30 12:02:17 -04:00
Doug Gregor
6af690aaba Eliminate HasCircularInheritanceRequest.
This is now reliably detected by SuperclassDeclRequest.
2020-09-29 17:42:17 -07:00
Slava Pestov
445d747622 AST: Move GenericParamList and friends to GenericParamList.{h,cpp} 2020-09-29 19:51:03 -04:00
Doug Gregor
aeef419de8 [Concurrency] Ensure that enqueue(partialTask:) is first in actor vtables.
Actor classes never have non-actor superclasses, so we can ensure that
all actor classes have a common vtable prefix for the
`enqueue(partialTask:)` operation. This allows us to treat all actor
classes uniformly, without having to go through the Actor witness
table every time.
2020-09-29 15:25:49 -07:00
Holly Borla
21cbdfa337 [Property Wrappers] Add a VarDecl helper method for visiting synthesized
property wrapper vars.
2020-09-28 19:31:50 -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
Doug Gregor
2ad5b43cf5 Merge pull request #34083 from DougGregor/function-builders-fixits-use-after-free
[Type checker] Eliminate a use-after-free due to C++ temporaries.
2020-09-26 08:19:58 -07:00
Slava Pestov
29ce77209c AST: Convert ConstructorDecl::getDelegatingOrChainedInitKind() into a request
This method had a messy contract:

- Setting the diags parameter to nullptr inhibited caching

- The initExpr out parameter could only used if no result
  had yet been cached

Let's instead use the request evaluator here.
2020-09-25 17:59:20 -04:00
Robert Widmann
360afd6034 Merge pull request #34073 from CodaFi/crossfire
Serialization for Incremental Swift Dependency Information
2020-09-24 22:25:21 -06:00
Doug Gregor
6fe5245899 Fix grammatical error in a new comment 2020-09-24 20:56:59 -07:00
Doug Gregor
4b1b0bbd9c Merge pull request #34065 from DougGregor/concurrency-objc-asynchandler-inference
[Concurrency] Import "did" delegate methods as @asyncHandler.
2020-09-24 19:43:30 -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
Robert Widmann
f1f5961e0f [NFC] Add Incremental Info Bits to ModuleDecl 2020-09-24 20:07:01 -06:00
Doug Gregor
9b808c67fa [Concurrency] Import "did" delegate methods as @asyncHandler.
Infer @asyncHandler on a protocol methods that follow the delegate
convention of reporting that something happened via a "did" method, so
long as they also meet the constraints for an @asyncHandler method in
Swift. This enables inference of @asyncHandler for witnesses of these
methods.
2020-09-24 14:01:08 -07:00
Slava Pestov
ccee48dae5 AST: Remove PatternBindingDecl::getNumBoundVariables() 2020-09-23 01:26:06 -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
Slava Pestov
d4cc35a938 AST: Remove VarDecl::hasNonPatternBindingInit() 2020-09-18 16:11:06 -04:00
Slava Pestov
d7f4b1a1bd AST: Capture list bindings now point back to their parent CaptureListExpr
We'll need this to get the right 'selfDC' when name lookup
finds a 'self' declaration in a capture list, eg

class C {
  func bar() {}
  func foo() {
    _ = { [self] in bar() }
  }
}
2020-09-18 02:59:15 -04:00
Slava Pestov
1298f71554 Merge pull request #33922 from slavapestov/sil-parser-overhaul
SILParser: Fix for removal of parse-time name lookup
2020-09-12 08:11:26 -04:00
Doug Gregor
3c49e46f4f Merge pull request #33906 from DougGregor/concurrency-actors
[Concurrency] Basic support for actor classes and actor isolation
2020-09-11 15:10:45 -07:00
Slava Pestov
d711c6defc AST: Add a GenericParamList::lookUpGenericParam() method 2020-09-11 17:45:58 -04:00
Slava Pestov
fec67d68a8 AST: Add a GenericParamList::walk() method 2020-09-11 17:45:58 -04:00
Hamish Knight
efdc358eb4 Merge pull request #33806 from hamishknight/typed-def 2020-09-11 16:56:46 +01:00
Brent Royal-Gordon
6f2853695b [NFC] Delete obsolete AccessPathTy-based code
This was all deprecated in earlier commits.
2020-09-10 19:08:29 -07:00
Brent Royal-Gordon
6da428a38e [NFC] Rename “DeclPath” -> “AccessPath”
To avoid ambiguity, ImportResolution and a few other things used the term “decl path” instead of “access path”. Switch back to the correct terminology now that the compiler is becoming more consistent about it.
2020-09-10 19:08:29 -07:00
Brent Royal-Gordon
cff4ddf13a [NFC] Adopt new ImportPath types and terminology
# Conflicts:
#	lib/IDE/CodeCompletion.cpp
2020-09-10 19:07:49 -07:00
Brent Royal-Gordon
5afe2f97e2 [NFC] Move ImportKind to a new Import.h header 2020-09-10 18:36:03 -07:00
Doug Gregor
22a350b1ac [Concurrency] Add parsing support for actor classes.
Introduce the "actor class" syntax. Ensure that it is only used for
root classes or classes that inherit from other actor classes.
2020-09-09 20:46:30 -07:00
Doug Gregor
b5759c9fd9 [Concurrency] Allow overload 'async' with non-async and disambiguate uses.
Allow an 'async' function to overload a non-'async' one, e.g.,

    func performOperation(_: String) throws -> String { ... }
    func performOperation(_: String) async throws -> String { ... }

Extend the scoring system in the type checker to penalize cases where
code in an asynchronous context (e.g., an `async` function or closure)
references an asychronous declaration or vice-versa, so that
asynchronous code prefers the 'async' functions and synchronous code
prefers the non-'async' functions. This allows the above overloading
to be a legitimate approach to introducing asynchronous functionality
to existing (blocking) APIs and letting code migrate over.
2020-09-08 16:51:10 -07:00
Hamish Knight
9b8b2068d2 Add AbstractFunctionDecl::getTypecheckedBody
Refactor TypeCheckFunctionBodyRequest to return
the type-checked body, and remove
`typeCheckAbstractFunctionBody` in favor of
a method on AbstractFunctionDecl. In addition,
start returning an ErrorExpr body instead of
a partially type-checked body if type-checking
fails.
2020-09-04 13:24:34 -07:00
Hamish Knight
a7a8d9fd26 [AST] Remove NewBodyKind default
A bunch of callers were accidentally misusing it.
2020-09-04 13:24:34 -07:00
Holly Borla
3332df6f89 Merge pull request #33777 from hborla/rename-storage-wrapper
[NFC][Property Wrappers] Rename "storage wrapper var" to "projection var/projected value"
2020-09-03 18:29:04 -07:00
Slava Pestov
fae8f944b8 AST: Add 'hoisted' flag to Decl 2020-09-03 16:16:50 -04:00
Holly Borla
3fd882cadf [NFC] Rename "storage wrapper var" to "projection var" or "projected value"
in property wrapper-related code.
2020-09-02 18:07:40 -07:00
Doug Gregor
650a8b25da [AST] Rename EmittedMembersRequest -> SemanticMembersRequest. 2020-09-01 13:21:59 -07:00
Doug Gregor
ae4fbb6716 [AST] Generalize and rename ClassDecl::getEmittedMembers()
Generalize `ClassDecl::getEmittedMembers()` to operate on an
`IterableDeclContext`, so that it can be for other nominal types,
extensions, etc. Rename to `getSemanticMembers()` to indicate that
these are all of the members that are semantically part of that
context.

Clean up the implementation slightly so it only forces type checking
for the conformances within that particular context (using
`getLocalConformances()`) and doesn't need to list out each of the
protocols it cares about.
2020-09-01 13:01:10 -07:00
Doug Gregor
1e5d30f5ca [Concurrency] Import Objective-C methods with completion handlers as async
When a given Objective-C method has a completion handler parameter
with an appropriate signature, import that Objective-C method as
async. For example, consider the following CloudKit API:

    - (void)fetchShareParticipantWithUserRecordID:(CKRecordID
*)userRecordID
            completionHandler:(void (^)(CKShareParticipant * _Nullable shareParticipant, NSError * _Nullable error))completionHandler;

With the experimental concurrency model, this would import as:

    func fetchShareParticipant(withUserRecordID userRecordID: CKRecord.ID) async throws -> CKShare.Participant?

The compiler will be responsible for turning the caller's continuation
into a block to pass along to the completion handler. When the error
parameter of the completion handler is non-null, the async call
will result in that error being thrown. Otherwise, the other arguments
passed to that completion handler will be returned as the result of
the async call.

async versions of methods are imported alongside their
completion-handler versions, to maintain source compatibility with
existing code that provides a completion handler.

Note that this only covers the Clang importer portion of this task.
2020-08-27 21:30:13 -07:00
Dan Zheng
0bd8b140db [AST] Fix declaration bitfields. (#33567)
Fix total bit count for Decl and AbstractFunctionDecl bitfields.
2020-08-21 19:44:12 -07:00
Brent Royal-Gordon
28ea3e1727 [NFC] Document TypeAliasDecl::isCompatibilityAlias 2020-08-20 16:21:50 -07:00