Commit Graph

2390 Commits

Author SHA1 Message Date
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
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
Varun Gandhi
7b967a8030 Merge pull request #33085 from varungandhi-apple/vg-clang-types-in-sil-retry
Propagate Clang function types through SIL
2020-09-22 08:48:34 -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
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
Varun Gandhi
5e9bf1f7c6 [SIL] Store ClangTypeInfo in SILFunctionType.
This patch includes a large number of changes to make sure that:
1. When ExtInfo values are created, we store a ClangTypeInfo if applicable.
2. We reduce dependence on storing SIL representations in ASTExtInfo values.
3. Reduce places where we sloppily create ASTExtInfo values which should
   store a Clang type but don't. In certain places, this is unavoidable;
   see [NOTE: ExtInfo-Clang-type-invariant].

Ideally, we would check that the appropriate SILExtInfo does always store
a ClangTypeInfo. However, the presence of the HasClangFunctionTypes option
means that we would need to condition that assertion based on a dynamic check.
Plumbing the setting down to SILExtInfoBuilder's checkInvariants would be too
much work. So we weaken the check for now; we should strengthen it once we
"turn on" HasClangFunctionTypes and remove the dynamic feature switch.
2020-09-16 10:34:42 -07:00
Slava Pestov
8e83dd902f Sema: Don't compute isSimpleDidSet() from getStorageImplInfo() 2020-09-15 22:03:58 -04:00
Slava Pestov
05b872014b AST: Change isInvalid() on an accessor to delegate to the storage
This helps avoid a request cycle from the isInvalid() call inside
performAbstractFuncDeclDiagnostics().
2020-09-15 22:03:58 -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
Hamish Knight
efdc358eb4 Merge pull request #33806 from hamishknight/typed-def 2020-09-11 16:56:46 +01: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
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
111096236a Merge pull request #33862 from DougGregor/concurrency-async-overloading
[Concurrency] Allow overload 'async' with non-async and disambiguate uses.
2020-09-09 07:38:14 -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
Doug Gregor
0f18948bd5 [Concurrency] Allow @objc async methods.
Allow the declaration of @objc async methods, mapping them to a
completion-handler API in Objective-C. This covers most of the
checking and semantics within the type checker:
* Declaring @objc async methods and checking their parameter/result types
* Determining the default Objective-C selector by adding
completionHandler/WithCompletionHandler as appropriate
* Determining the type of the completion handler parameter
* Inferring @objc from protocol requirements
* Inferring @objc from an overridden method
2020-09-08 10:15:24 -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
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
Xi Ge
e107182f1a Merge remote-tracking branch 'apple/master' into master-rebranch 2020-09-02 18:36:37 -07: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
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
Nathan Hawes
9da1d89520 Manually merge remote-tracking branch 'upstream/master' into HEAD
Conflicts:
	lib/AST/ExtInfo.cpp
2020-08-31 10:50:54 -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
Nathan Hawes
0034cabe7b [AST] Fix missing include in Decl.cpp 2020-08-21 22:53:50 -07:00
Brent Royal-Gordon
6c18a03883 [NFC] Add ClangNode::dump() 2020-08-20 16:21:39 -07:00
Anthony Latsis
efa8f86193 [NFC] FuncDecl: Strip factory constructors out of TypeLocs 2020-08-19 00:09:10 +03:00
Anthony Latsis
f8d30ec216 [NFC] SubscriptDecl: Strip factory constructors out of TypeLocs 2020-08-19 00:09:10 +03:00
Anthony Latsis
492156c10f Remove SubscriptDecl::getBodyResultTypeLoc 2020-08-19 00:09:10 +03:00
Anthony Latsis
21faa48298 Remove FuncDecl::getBodyResultTypeLoc 2020-08-19 00:09:10 +03:00
Anthony Latsis
c35d84a905 [NFC] SubscriptDecl: Replace the const version of getElementTypeLoc with a TypeRepr accessor 2020-08-19 00:09:10 +03:00
Anthony Latsis
96bcc7a226 [NFC] FuncDecl: Replace the const version of getBodyResultTypeLoc with a TypeRepr accessor 2020-08-19 00:09:05 +03:00
Anthony Latsis
3de97908e4 [NFC] Avoid passing a TypeLoc to AccessorDecl::create 2020-08-18 23:01:34 +03:00
Doug Gregor
84a21d1769 Merge pull request #33488 from DougGregor/concurrency-infer-asynchandler
[Concurrency] Infer @asyncHandler from protocol requirements.
2020-08-14 20:32:39 -07:00
Doug Gregor
235be5e5bc [Concurrency] Factor "is @asyncHandler"? check into a request.
This is stating for inference of @asyncHandler.
2020-08-14 12:49:44 -07:00
David Zarzycki
1e940c2c7e [NFC] Fix -Wsuggest-override warnings
LLVM, as of 77e0e9e17daf0865620abcd41f692ab0642367c4, now builds with
-Wsuggest-override. Let's clean up the swift sources rather than disable
the warning locally.
2020-08-13 16:17:46 -04:00
Rintaro Ishizaki
ee6c6f4bf2 [CodeCompletion] Stop marking non-target function bodies 'Skipped' 2020-08-12 10:20:17 -07:00
Rintaro Ishizaki
1ab4a4742a [AST] Formalize getBodySourceRange() for fast completion
Fast completion replaces the body ('BraceStmt') of function decls with
other bodies parsed from different source buffers from the original
source buffer. That means the source range of the body and the location
of the function declaration itself might be in different buffers.

Previously, FuncDecl::getSourceRange() used to use the 'func' keyword decl
as the start loc and 'getBodySourceRange().End' as the end loc. This
breaks a SourceRange invariant where the start and end loc must be
in the same buffer.

This patch add a new function 'getOriginalBodySourceRange()' which
always return the source range of the original body of the function. And
use that from 'getSourceRange()' functions.

The orignal body source range is stored in a side table in ASTContext so
that normal compilation doesn't consume space for that extra info.
2020-08-11 17:08:27 -07:00
swift-ci
b2d2cf05b6 Merge pull request #33252 from zoecarver/cxx/rename-is-cxx-non-trivial 2020-08-04 11:23:31 -07:00
zoecarver
6e4e478047 [NFC] [cxx-interop] Rename IsCxxNotTriviallyCopyable -> IsCxxNonTrivial.
`IsCxxNonTrivial` is set for a variety or reasons, for example, it's set
when the struct contains bitfields, has a custom destructor, or a custom
copy constructor. The name `IsCxxNotTriviallyCopyable` only implies the
latter.
2020-08-04 08:45:15 -07:00
Matei Oprea
f971b349b4 [NFC] Refactor manual size calculations in memory allocation (#33256) 2020-08-03 22:02:31 -07:00
Varun Gandhi
3882beb85d [NFC] Use consistent naming scheme for predicate methods. (#33265)
bool throws() -> isThrowing(), bool async() -> isAsync()
2020-08-03 16:37:29 -07:00
Varun Gandhi
f219e58ada [NFC] Refactor ExtInfo to use a builder-pattern based API.
Since the two ExtInfos share a common ClangTypeInfo, and C++ doesn't let us
forward declare nested classes, we need to hoist out AnyFunctionType::ExtInfo
and SILFunctionType::ExtInfo to the top-level.

We also add some convenience APIs on (AST|SIL)ExtInfo for frequently used
withXYZ methods. Note that all non-default construction still goes through the
builder's build() method.

We do not add any checks for invariants here; those will be added later.
2020-07-31 13:55:55 -07:00
Doug Gregor
41817229d5 Merge pull request #33147 from DougGregor/async-function-types
[Concurrency] Add `async` to the Swift type system.
2020-07-29 08:59:34 -07:00
Slava Pestov
c46eb22fcd AST: Don't attach trailing where clause requirements to the GenericParamList
Previously we had two representations for the 'where' clause of a
parsed declaration; if the declaration had generic parameters of
its own, we would store them in the GenericParamList, otherwise
we would store them separately in a TrailingWhereClause instance.

Since the latter is more general and also used for protocols and
extensions, let's just use it for everything and simplify
GenericParamList in the process.
2020-07-28 02:07:16 -04:00
Slava Pestov
43e37b7895 AST: Move GenericParamListRequest::evaluate() to NameLookup.cpp 2020-07-28 02:07:16 -04:00
Slava Pestov
14dd4eef2d AST: Add a way to distinguish a parsed generic parameter list from a synthesized one
Add a new GenericContext::getParsedGenericParams(). This produces
the same value as GenericContext::getGenericParams() if the generic
parameter list was written in source. For extensions and protocols,
this returns nullptr without synthesizing anything.
2020-07-28 02:07:16 -04:00
Slava Pestov
32ceba8d2a AST: Add GenericParamList::setDeclContext() 2020-07-28 02:07:16 -04:00