Commit Graph

2390 Commits

Author SHA1 Message Date
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
Slava Pestov
95c4a97507 Merge pull request #34135 from slavapestov/simulate-parser-lookup
Implement backward-compatible closure capture behavior with parser lookup disabled
2020-10-02 11:45:39 -04:00
swift_jenkins
eea4e99548 Merge remote-tracking branch 'origin/main' into next 2020-10-01 22:56:39 -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
Slava Pestov
3ec4ced57d ASTScope: Don't handle top-level bindings in a SourceFile for now 2020-10-01 23:50:16 -04: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
swift_jenkins
55b4adb819 Merge remote-tracking branch 'origin/main' into next 2020-09-30 13:52:43 -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
Nathan Hawes
ad5b3152c0 Merge pull request #34062 from nathawes/fix-upstream-breakage-on-next
[next] Update for swiftNewTypeAttr capitalization change.
2020-09-30 12:07:28 -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
2dc8a13b62 [AST] Simplify ClassAncestryFlagsRequest. 2020-09-29 18:35:40 -07:00
Doug Gregor
d57a8d2c5a Simplify ClassDecl::walkSuperclasses().
It no longer needs to worry about circular inheritance.
2020-09-29 17:42:17 -07:00
Doug Gregor
6af690aaba Eliminate HasCircularInheritanceRequest.
This is now reliably detected by SuperclassDeclRequest.
2020-09-29 17:42:17 -07:00
Doug Gregor
4ddf6e565a Teach SuperclassDeclRequest to always diagnose circularity.
Rather than relying on clients to cope with the potential for circular
inheritance of superclass declarations, teach SuperclassDeclRequest to
establish whether circular inheritance has occurred and produce "null"
in such cases. This allows other clients to avoid having to think about

To benefit from this, have SuperclassTypeRequest evaluate
SuperclassDeclRequest first and, if null, produce a Type(). This
ensures that we don't get into an inconsistent situation where there
is a superclass type but no superclass declaration.
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
2a67c651ee [Property Wrappers] Generalize a few property wrapper decl context
checks to check for type context instead of local context.

This generalization will help us implement property wrappers on
global variables, which should use the same approach of not adding
synthesized accessors to the AST and instead lazily visit them in
SILGen.
2020-09-29 13:38:41 -07:00
Nathan Hawes
40b6798d35 Update usages of 'SwiftNewtypeAttr' for the new spelling 'SwiftNewTypeAttr' 2020-09-29 10:46:13 -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
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
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