Commit Graph

2530 Commits

Author SHA1 Message Date
Slava Pestov
377f23f5da Merge pull request #35863 from slavapestov/remove-spi-from-access-scope
AST: Remove SPI bit from AccessScope
2021-02-09 23:40:33 -05:00
Slava Pestov
94287ea6a9 AST: Fix bad interaction between vtable layout, access control and -enable-testing
Swift allows a method override to be more visible than the base method.

In practice, this means that since it might be possible for client
code to see the override but not the base method, we have to take
extra care when emitting the override.

Specifically, the override always receives a new vtable entry, and
a vtable thunk is emitted in place of the base method's vtable entry
which re-dispatches via the override's vtable entry.

This allows client code to further override the method without any
knowledge of the base method's vtable entry, which may be inaccessible
to the client.

In order for the above to work, three places in the code perform
co-ordinated checks:

- needsNewVTableEntry() determines whether the override is more
  visible than the base, in which case it receives a new vtable
  entry

- SILGenModule::emitVTableMethod() performs the same check in order
  to emit the re-dispatching vtable thunk in place of the base
  method's entry

- in the client, SILVTableVisitor then skips the base method's
  vtable entry entirely when emitting the derived class, since no
  thunk is to be emitted.

The problem was that the first two used effective access (where
internal declarations become public with -enable-testing), while
the last check used formal access. As a result, it was possible
for the method override vtable entry to never be emitted in the
client.

Consistently using either effective access or formal access would
fix the problem. I fixed the first two to rely on formal access;
the reason is that using effective access makes vtable layout
depend on whether the library was built with -enable-testing or
not, which is undesirable since we do not want -enable-testing to
impact the ABI, even for non-resilient frameworks.

Fixes rdar://problem/74108928.
2021-02-09 23:35:14 -05:00
Doug Gregor
923ccfdf97 [Concurrency] Fix actor isolation and restrictions on initializers.
Initializers are actor-isolated when they are part of an actor or have
a global actor. However, uses of actor initializers need to be treated
as cross-actor references so we proper `ConcurrentValue` checking for
values passed into the initializer.

Fixes rdar://74064751.
2021-02-09 16:19:37 -08:00
Slava Pestov
9ca2a708a6 AST: Remove SPI bit from AccessScope
As far as I can tell, it wasn't actually used for anything.
2021-02-09 18:22:29 -05:00
Slava Pestov
547057380f AST: Split off Effects.cpp from Decl.cpp 2021-02-09 00:11:01 -05:00
Slava Pestov
ed247a1fa1 Sema: Allow 'lazy' local variables 2021-02-06 08:56:38 -05:00
Doug Gregor
c9d66f0d35 Add "marker" protocols, indicated by @_marker.
A marker protocol is a protocol with no requirements and with no ABI
footprint. They can be used to indicate semantics, only, and one can
never have values of a marker protocol type.

We still mangle marker protocols when they are used as generic
requirements, because they are a distinguishing characteristic for
overloading, but "no ABI footprint" means no protocol descriptors,
conformance descriptors, or dynamic discovery of any kind.
2021-02-02 21:53:26 -08:00
swift-ci
91242dc694 Merge remote-tracking branch 'origin/main' into rebranch 2021-01-29 08:52:47 -08:00
Doug Gregor
4e96cefa37 Centralize logic for the actor isolation of a context 2021-01-28 15:58:49 -08:00
Doug Gregor
1d082e1fb4 Require that concurrently-executed local functions be @concurrent. 2021-01-28 13:03:13 -08:00
Doug Gregor
ba8819eb58 [Concurrent] Introduce concurrent function types.
Introduce `@concurrent` attribute on function types, including:
* Parsing as a type attribute
* (De-/re-/)mangling for concurrent function types
* Implicit conversion from @concurrent to non-@concurrent
- (De-)serialization for concurrent function types
- AST printing and dumping support
2021-01-27 14:22:32 -08:00
swift-ci
9f29b005b5 Merge remote-tracking branch 'origin/main' into rebranch 2021-01-25 18:52:44 -08:00
Philippe Hausler
6e05240426 AsyncSequence and protocol conformance rethrows (#35224)
* Initial draft of async sequences

* Adjust AsyncSequence associated type requirements

* Add a draft implementation of AsyncSequence and associated functionality

* Correct merge damage and rename from GeneratorProtocol to AsyncIteratorProtocol

* Add AsyncSequence types to the cmake lists

* Add cancellation support

* [DRAFT] Implementation of protocol conformance rethrowing

* Account for ASTVerifier passes to ensure throwing and by conformance rethrowing verifies appropriately

* Remove commented out code

* OtherConstructorDeclRefExpr can also be a source of a rethrowing kind function

* Re-order the checkApply logic to account for existing throwing calculations better

* Extract rethrowing calculation into smaller functions

* Allow for closures and protocol conformances to contribute to throwing

* Add unit tests for conformance based rethrowing

* Restrict rethrowing requirements to only protocols marked with @rethrows

* Correct logic for gating of `@rethrows` and adjust the determinates to be based upon throws and not rethrows spelling

* Attempt to unify the async sequence features together

* Reorder try await to latest syntax

* revert back to the inout diagnosis

* House mutations in local scope

* Revert "House mutations in local scope"

This reverts commit d91f1b25b59fff8e4be107c808895ff3f293b394.

* Adjust for inout diagnostics and fall back to original mutation strategy

* Convert async flag to source locations and add initial try support to for await in syntax

* Fix case typo of MinMax.swift

* Adjust rethrowing tests to account for changes associated with @rethrows

* Allow parsing and diagnostics associated with try applied to for await in syntax

* Correct the code-completion for @rethrows

* Additional corrections for the code-completion for @rethrows this time for the last in the list

* Handle throwing cases of iteration of async sequences

* restore building XCTest

* First wave of feedback fixes

* Rework constraints checking for async sequence for-try-await-in checking

* Allow testing of for-await-in parsing and silgen testing and add unit tests for both

* Remove async sequence operators for now

* Back out cancellation of AsyncIteratorProtocols

* Restructure protocol conformance throws checking and cache results

* remove some stray whitespaces

* Correct some merge damage

* Ensure the throwing determinate for applying for-await-in always has a valid value and adjust the for-await-in silgen test to reflect the cancel changes

* Squelch the python linter for line length
2021-01-25 18:48:50 -08:00
swift-ci
12023a9d6b Merge remote-tracking branch 'origin/main' into rebranch 2021-01-07 18:32:54 -08:00
Slava Pestov
e8c0e33ab6 AST: Fix actor isolation checking for lazy property initializers
The initializer DeclContext is not a ValueDecl; instead, fish out the
associated VarDecl using other means.

Also while I'm here, fix actor isolation checking in the case where
'self' is explicitly captured in a capture list as well.

Fixes <rdar://problem/72727986>.
2021-01-06 18:39:57 -05:00
swift_jenkins
60c7eaecdd Merge remote-tracking branch 'origin/main' into next 2021-01-05 15:17:44 -08:00
Slava Pestov
e675bee26c AST: Split off DependencyCollector.h from EvaluatorDependencies.h
Also remove some unnecessary #includes from DependencyCollector.h,
which necessitated adding #includes in various other files.
2020-12-23 00:00:25 -05:00
swift_jenkins
f779b56334 Merge remote-tracking branch 'origin/main' into next 2020-12-16 16:25:43 -08:00
Slava Pestov
c2b26671db AST: Fast path to skip evaluating requests on local variables without property wrappers 2020-12-15 23:43:04 -05:00
swift_jenkins
882c2853fd Merge remote-tracking branch 'origin/main' into next 2020-12-03 15:44:00 -08:00
Doug Gregor
1798e66c6e [Concurrency] Disallow 'async' and non-async overloading. 2020-12-03 09:34:15 -08:00
swift_jenkins
f1eec97e9d Merge remote-tracking branch 'origin/main' into next 2020-12-02 19:33:30 -08:00
John McCall
945011d39f Handle default actors by special-casing layout in IRGen instead
of adding a property.

This better matches what the actual implementation expects,
and it avoids some possibilities of weird mismatches.  However,
it also requires special-case initialization, destruction, and
dynamic-layout support, none of which I've added yet.

In order to get NSObject default actor subclasses to use Swift
refcounting (and thus avoid the need for the default actor runtime
to generally use ObjC refcounting), I've had to introduce a
SwiftNativeNSObject which we substitute as the superclass when
inheriting directly from NSObject.  This is something we could
do in all NSObject subclasses; for now, I'm just doing it in
actors, although it's all actors and not just default actors.
We are not yet taking advantage of our special knowledge of this
class anywhere except the reference-counting code.

I went around in circles exploring a number of alternatives for
doing this; at one point I basically had a completely parallel
"ForImplementation" superclass query.  That proved to be a lot
of added complexity and created more problems than it solved.
We also don't *really* get any benefit from this subclassing
because there still wouldn't be a consistent superclass for all
actors.  So instead it's very ad-hoc.
2020-12-02 18:47:13 -05:00
swift_jenkins
c7ffe688e2 Merge remote-tracking branch 'origin/main' into next 2020-11-11 13:28:17 -08:00
Zoe Carver
dfe92be435 Merge pull request #34424 from zoecarver/cxx/templated-constructors
[cxx-interop] Support templated constructors.
2020-11-11 12:10:38 -08:00
zoecarver
08e7160cec [cxx-interop] Support templated C++ constructors. 2020-11-11 09:38:10 -08:00
swift_jenkins
8f57f84eea Merge remote-tracking branch 'origin/main' into next 2020-11-10 21:31:28 -08:00
zoecarver
178dac0875 [cxx-interop] Add static "createImported" member to "ConstructorDecl". 2020-11-10 20:26:40 -08:00
Richard Wei
c9dc67d383 [AST] Fix AutoDiff crasher in optimized builds.
`getModuleScopeContext()` can produce a `ModuleDecl *` instead of a `FileUnit *`, which happens to be the case for generic-specialized derivative functions.

Resolves rdar://71191415.
2020-11-10 16:50:21 -08:00
swift_jenkins
6c8d31207e Merge remote-tracking branch 'origin/main' into next 2020-11-05 21:34:59 -08:00
Pavel Yaskevich
51bd8d93d6 Merge pull request #34510 from maustinstar/sr-11711
[SR-11711]  [Parse] Single-expression implicit returns within #if declarations
2020-11-05 21:14:44 -08:00
swift_jenkins
288a7c964c Merge remote-tracking branch 'origin/main' into next 2020-11-05 09:12:46 -08:00
Doug Gregor
dc4a11975a [Concurrency] Diagnose 'async let' declarations in non-async contexts. 2020-11-04 17:32:04 -08:00
Doug Gregor
9722df86e8 [Concurrency] Require references to 'async let' to have an 'await'.
Extend effects checking to ensure that each reference to a variable
bound by an 'async let' is covered by an "await" expression and occurs
in a suitable context.
2020-11-04 17:32:04 -08:00
maustinstar
f6c9769bf0 Statement setter for last element 2020-11-03 22:20:23 -05:00
maustinstar
37b17338e5 [SR-11711] Single-expression returns for #if declarations within functions 2020-11-03 12:47:39 -05:00
swift_jenkins
af851ab26e Merge remote-tracking branch 'origin/main' into next 2020-11-01 15:29:12 -08:00
Robert Widmann
16dec4c1d1 Merge pull request #34342 from AnthonyLatsis/3-liner
AST: Add a no-type-parameters early return to findProtocolSelfReferences
2020-11-01 15:23:33 -08:00
swift_jenkins
0ee715343f Merge remote-tracking branch 'origin/main' into next 2020-10-29 19:55:13 -07:00
Slava Pestov
b7bdca2407 Sema: Ban references to protocol extension members with opaque result types on an existential base
The substituted type of the member reference is an OpaqueTypeArchetypeType
whose substitution map sends Self to the opened existential type for the
base value. Sema erases opened existential types to their upper bound, but
this is not a valid transformation in this case, because the 'Self' type
reference is invariant. Calling this member on two different existential
values would produce the same erased type, but this is wrong, because
it actually depends on the concrete type stored in the existential.

Fixes <https://bugs.swift.org/browse/SR-13419>, <rdar://problem/67451810>.
2020-10-29 16:02:28 -04:00
David Smith
0180aca9fc Merge branch 'main' into david/fix-merge-conflict 2020-10-27 13:05:20 -07:00
Slava Pestov
8af4405f36 AST: 'lazy' property initializers are never @inlinable
In @frozen structs, stored properties and property wrappers must
have inlinable initial value expressions, since they are re-emitted
into designated initializer bodies, which themselves might be
@inlinable.

However, 'lazy' properties don't follow this pattern; the
initial value expression is emitted inside the getter, which
is never @inlinable.
2020-10-22 02:13:41 -04:00
Slava Pestov
b3dadc8973 AST: Use VarDecl::isInitExposedToClients() from DeclContext::getFragileFunctionKind()
getFragileFunctionKind() would report that all initializers in
non-resilient public types were inlinable, including static
properties.

This was later patched by VarDecl::isInitExposedToClients(),
which was checked in diagnoseInlinableDeclRefAccess().
However, the latter function only looked at the innermost
DeclContexts, not all parent contexts, so it would incorrectly
diagnose code with a nested DeclContext inside of a static
property initializer.

Fix this by changing getFragileFunctionKind() to call
isInitExposedToClients() and simplifying
diagnoseInlinableDeclRefAccess().

This commit also introduces a new isLayoutExposedToClients()
method, which is similar to isInitExposedToClients(), except
it also returns 'true' if the property does not have an
initializer (and in fact the latter is implemented in terms
of the former).
2020-10-22 01:11:39 -04:00
Zoe Carver
f0f2246793 [cxx-interop] Support C++ function templates in Swift. (#33053)
This patch adds rudimentary support for C++ template functions in swift.
2020-10-21 20:42:25 -07:00
Doug Gregor
6d41524fe6 [SE-0289] Finish renaming source code, tests to "result builders" 2020-10-20 22:18:51 -07:00
Anthony Latsis
d8dcf8f794 AST: Add a no-type-parameters early return to findProtocolSelfReferences 2020-10-17 05:10:33 +03:00
Arnold Schwaighofer
96a0d0e584 Rename various IncludeUsableFromInlineAndInlineable to IncludeUsableFromInline
`@inlinable` implies `@usableFromInline`.

NFC intended.
2020-10-14 07:57:25 -07:00
swift_jenkins
ac24c24279 Merge remote-tracking branch 'origin/main' into next 2020-10-13 08:06:23 -07:00
Arnold Schwaighofer
fd3e3cfdb8 Merge pull request #32657 from aschwaighofer/wip_prespecialize_exported
Preliminary support for `_specialize(exported: true, ...)`
2020-10-13 07:57:51 -07:00
swift_jenkins
7c1278a6c5 Merge remote-tracking branch 'origin/main' into next 2020-10-13 04:10:45 -07:00