Commit Graph

3561 Commits

Author SHA1 Message Date
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
Arnold Schwaighofer
b994bf3191 Add support for _specialize(exported: true, ...)
This attribute allows to define a pre-specialized entry point of a
generic function in a library.

The following definition provides a pre-specialized entry point for
`genericFunc(_:)` for the parameter type `Int` that clients of the
library can call.

```
@_specialize(exported: true, where T == Int)
public func genericFunc<T>(_ t: T) { ... }
```

Pre-specializations of internal `@inlinable` functions are allowed.

```
@usableFromInline
internal struct GenericThing<T> {
  @_specialize(exported: true, where T == Int)
  @inlinable
  internal func genericMethod(_ t: T) {
  }
}
```

There is syntax to pre-specialize a method from a different module.

```
import ModuleDefiningGenericFunc

@_specialize(exported: true, target: genericFunc(_:), where T == Double)
func prespecialize_genericFunc(_ t: T) { fatalError("dont call") }

```

Specially marked extensions allow for pre-specialization of internal
methods accross module boundries (respecting `@inlinable` and
`@usableFromInline`).

```
import ModuleDefiningGenericThing
public struct Something {}

@_specializeExtension
extension GenericThing {
  @_specialize(exported: true, target: genericMethod(_:), where T == Something)
  func prespecialize_genericMethod(_ t: T) { fatalError("dont call") }
}
```

rdar://64993425
2020-10-12 09:19:29 -07:00
Anthony Latsis
4ee517f65c AST: Refactor SelfReferenceKind in preparation for #33767
This will enable us to allow members containing references to Self or associated types
only in covariant position to be used on an existential
2020-10-12 17:01:11 +03:00
Anthony Latsis
826f17e534 Decouple detection of «Self ==» constraints from SelfReferenceKind 2020-10-12 15:01:40 +03:00
swift_jenkins
00fc6cffc1 Merge remote-tracking branch 'origin/main' into next 2020-10-11 02:44:50 -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
swift_jenkins
5abbb0f760 Merge remote-tracking branch 'origin/main' into next 2020-10-10 00:58:05 -07:00
Doug Gregor
4419f879ad Merge pull request #34201 from DougGregor/concurrency-global-actor
[Concurrency] Global actors
2020-10-10 00:19:33 -07:00
swift_jenkins
550c468718 Merge remote-tracking branch 'origin/main' into next 2020-10-09 23:25:02 -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
Anthony Latsis
8f43d888b8 Sema: Disallow usage of settable Self-returning storage requirements on existential base 2020-10-07 20:48:16 +03:00
swift_jenkins
79ac50258f Merge remote-tracking branch 'origin/main' into next 2020-10-06 08:25:36 -07:00
Argyrios Kyrtzidis
73727051fa [AST] Fix linker errors with the parser-only build 2020-10-05 10:54:41 -07:00
swift_jenkins
8963fd93b1 Merge remote-tracking branch 'origin/main' into next 2020-10-02 12:06:07 -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
swift_jenkins
00456ba628 Merge remote-tracking branch 'origin/main' into next 2020-10-02 09:08:59 -07:00