Commit Graph

2390 Commits

Author SHA1 Message Date
Holly Borla
96f43153ee [Property Wrappers] Implement support for parameters with an implicit
property wrapper in the property wrapper requests.
2021-02-25 18:35:14 -08:00
Holly Borla
d9951bed23 [Property Wrappers] Add a request to synthesize the local wrapped value
variable for a parameter with an attached property wrapper.
2021-02-25 18:35:13 -08:00
Holly Borla
8325a52b41 [ConstraintSystem] Teach the constraint system about property wrapper
parameters.
2021-02-25 18:35:13 -08:00
Slava Pestov
111ae11302 SIL: Fix vtable layout with @usableFromInline methods
A @usableFromInline method is public at the ABI level, so we do not
need to introduce a new vtable entry.

Fixes <rdar://problem/74489981>.
2021-02-18 15:38:34 -05: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
Ben Barham
9de5afd92e Merge pull request #35846 from bnbarham/walk-pdb
[IDE] SourceEntityWalker should walk all explicit declarations
2021-02-12 07:41:13 +10:00
Slava Pestov
65df4ba26a Merge pull request #35864 from slavapestov/vtable-layout-vs-enable-testing
AST: Fix bad interaction between vtable layout, access control and -enable-testing
2021-02-10 20:33:28 -05:00
Ben Barham
33bc38cdb8 [IDE] SourceEntityWalker should walk all explicit declarations
`SourceEntityWalker` had an unbalanced `walkToDeclPre` and
`walkToDeclPost`, ie. `walkToDeclPost` could be called even though
`walkToDeclPre` was not. Specifically, this would occur for both
`OperatorDecl` and `PrecedenceGroupDecl` declarations.

These could both be added to the `if` in `walkToDeclPost`, but this
seems fairly errorprone in general - especially as new decls are added.
Indeed, there's already declarations that are being skipped because they
aren't explicitly tested for in `walkToDeclPre`, ie.
`PatternBindingDecl`.

Instead of skipping if not explcitly handled, only skip running the
`SEWalker` walk methods if the declaration is implicit (and not a
constructor decl, see TODO). This should probably also always visit
children, with various decls changed to become implicit (eg.
TopLevelCodeDecl), but we can do that later - breaks too many tests for
now.

This change exposed a few parameter declarations that were missing their
implicit flag, as well as unbalanced walk methods in `RangeResolver`.
2021-02-11 10:34:07 +10: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
fc41826da9 Rename 'actor class' -> 'actor'
This patch softly updates the spelling of actors from `actor class` to
`actor`. We still accept using `actor` as a modifying attribute of
class, but emit a warning and fix-it to make the change.

One of the challenges that makes this messier is that the modifier list
can be in any order. e.g, `public actor class Foo {}` is the same as
`actor public class Foo {}`.

Classes have been updated to include whether they were explicitly
declared as an actor. This change updates the swiftmodule serialization
version number to 0.591. The additional bit only gets set of the class
declaration was declared as an actor, not if the actor was applied as an
attribute. This allows us to correctly emit `actor class` vs `actor`
emitting the code back out.
2021-02-10 08:05:57 -08:00
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