Commit Graph

2530 Commits

Author SHA1 Message Date
swift-ci
94de12b022 Merge pull request #41788 from tshortli/back-deploy-accessors
SILGen: Fix accessor functions with `@_backDeploy`
2022-03-11 14:51:33 -08:00
Allan Shortlidge
c1e326cbb0 SILGen: Fix SILGen for accessor functions with @_backDeploy. Previously, the @_backDeploy attribute was ignored when generating SIL for accessors on declarations with the attribute since the accessor decls themselves were not directly annotated.
Also, emit an error when `@_backDeploy` is applied to coroutine accessors since they are not supported yet.

Resolves rdar://90112441
2022-03-11 11:07:04 -08:00
Doug Gregor
c979b9fb66 Merge pull request #41763 from etcwilde/ewilde/warn-concurrency-async-top-level
Make toplevel vars MainActor with `-warn-concurrency`
2022-03-11 08:44:29 -08:00
Konrad `ktoso` Malawski
5ab8e0834d [Distributed] Reimplement distributed call thunks completely in AST (#41616)
* [Distributed] dist actor always has default executor (currently)

* [Distributed] extra test for missing makeEncoder

* [DistributedDecl] Add DistributedActorSystem to known SDK types

* [DistributedActor] ok progress on getting the system via witness

* [Distributed] allow hop-to `let any: any X` where X is DistActor

* [Distributed] AST: Add an accessor to determine whether type is distributed actor

- Classes have specialized method on their declarations
- Archetypes and existentials check their conformances for
  presence of `DistributedActor` protocol.

* [Distributed] AST: Account for distributed members declared in class extensions

`getConcreteReplacementForProtocolActorSystemType` should use `getSelfClassDecl`
otherwise it wouldn't be able to find actor if the member is declared in an extension.

* [Distributed] fix ad-hoc requirement checks for 'mutating'

[PreChecker] LookupDC might be null, so account for that

* [Distributed] Completed AST synthesis for dist thunk

* [Distributed][ASTDumper] print pretty distributed in right color in AST dumps

* wip on making the local/remote calls

* using the _local to mark the localCall as known local

* [Distributed] fix passing Never when not throwing

* fix lifetime of mangled string

* [Distributed] Implement recordGenericSubstitution

* [Distributed] Dont add .

* [Distributed] dont emit thunk when func broken

* [Distributed] fix tests; cleanups

* [Distributed] cleanup, move is... funcs to DistributedDecl

* [Distributed] Remove SILGen for distributed thunks, it is in Sema now!

* [Distributed]  no need to check stored props in protocols

* remote not used flag

* fix mangling test

* [Distributed] Synthesis: Don't re-use AST nodes for `decodeArgument` references

* [Distributed] Synthesis: Make sure that each thunk parameter has an internal name

* [Distributed/Synthesis] NFC: Add a comment regarding empty internal parameter names

* [Distributed] NFC: Adjust distributed thunk manglings in the accessor section test-cases

* cleanup

* [Distributed] NFC: Adjust distributed thunk manglings in the accessor thunk test-cases

* review follow ups

* xfail some linux tests for now so we can land the AST thunk

* Update distributed_actor_remote_functions.swift

Co-authored-by: Pavel Yaskevich <xedin@apache.org>
2022-03-10 23:58:23 +09:00
Evan Wilde
d2c3e464e8 Make toplevel vars MainActor with warn-concurrency
This is the last part to implement SE-0343. When `-warn-concurrency` is
passed to the compiler invocation, we want to protect top-level
variables behind the MainActor regardless of whether the top-level is an
asynchronous context. Note that this does not make the top-level an
asynchronous context, but it does annotate the top-level as being a
main-actor-protected context.
2022-03-09 23:57:57 -08:00
Slava Pestov
3f8e4e7442 AST: Fix mistake with generic signature in findExistentialSelfReferences()
We used to concatenate the DeclContext's generic signature with the
protocol requirement's signature, then look for occurrences of the
first generic parameter from the DeclContext's signature in the
requirement's type.

This almost worked, except when the first generic parameter from the
DeclContext's signature didn't conform to a protocol referenced by
an associated type. In that case, we would falsely report that there
are no 'Self' references.

Note that the CHECK lines in test/SILGen/witnesses_class.swift change
to what they were before 01d9d61cc8.
2022-03-09 02:38:09 -05:00
Slava Pestov
21def03700 Revert "AST: Temporarily remove calls to TypeBase::getMinimalCanonicalType()"
This reverts commit 0b612a4143.
2022-03-08 16:42:57 -05:00
Robert Widmann
ab44a07045 Convert DeclContext Parameters to their Associated Generic Signatures Instead 2022-03-07 22:54:23 -08:00
Robert Widmann
01d9d61cc8 Add a Facility to Compute an Opened Archetype's Self Parameter 2022-03-07 22:54:23 -08:00
Robert Widmann
d6186c9cfb Add a DeclContext Parameter to Opened Archetype Construction
This ensures that opened archetypes always inherit any outer generic parameters from the context in which they reside. This matters because class bounds may bind generic parameters from these outer contexts, and without the outer context you can wind up with ill-formed generic environments like

<τ_0_0, where τ_0_0 : C<T>, τ_0_0 : P>

Where T is otherwise unbound because there is no entry for it among the generic parameters of the environment's associated generic signature.
2022-03-07 22:54:22 -08:00
Slava Pestov
7ad9d891fe Merge pull request #41640 from slavapestov/primary-associated-type-syntax
New syntax for declaring primary associated types
2022-03-03 21:59:46 -05:00
Xi Ge
1843d49ec0 Merge pull request #41626 from nkcsgexi/experiment-final-in-isPotentiallyOverridable 2022-03-03 07:49:06 -08:00
Slava Pestov
a013cd2076 AST: Replace PrimaryAssociatedTypeAttr with AssociatedTypeDecl::isPrimary() flag 2022-03-03 10:15:02 -05:00
Slava Pestov
06dabe91ec Merge pull request #41630 from slavapestov/rqm-abstract-signatures-fixes
RequirementMachine: Fix test failures with -requirement-machine-abstract-signatures=verify
2022-03-02 22:13:45 -05:00
Xi Ge
1bc7039679 AST: consider syntactic final in isPotentiallyOverridable(). NFC
Also, rename isPotentiallyOverridable() to isSyntacticallyOverridable().
2022-03-02 15:50:06 -08:00
Slava Pestov
0b612a4143 AST: Temporarily remove calls to TypeBase::getMinimalCanonicalType()
This is the transform that minimizes a protocol composition according
to generic signature rules, so for example P & C where C already
conforms to P will minimize down to just C.

Unfortunately this calls ASTContext::getOpenedArchetypeSignature(),
which is broken when the protocol composition involves a superclass
constraint containing an interface type.

For example, calling ASTContext::getOpenedArchetypeSignature() on
P & C<T> will build a signature

    <Self where Self : P, Self : C<T>>

The generic parameter 'T' occurs as a "free variable", which is
invalid. What we ought to do is build a generic signature with the
outer parameters and requirements of the DeclContext where the
opened existential type appears, and then add 'Self' at the end
of the parameter list.

Until that is implemented, replace these calls with
getCanonicalType() to avoid triggering Requirement Machine
assertions.
2022-03-02 17:07:33 -05:00
Allan Shortlidge
f6ab0ae7a3 Merge pull request #41612 from tshortli/back-deploy-diagnose-decls
Update @_backDeploy ABI semantics and diagnose invalid declarations
2022-03-02 12:52:47 -08:00
Zoe Carver
10b5031e93 Merge pull request #41610 from zoecarver/import-subscript-in-base
[cxx-interop] Add support for subscripts in base classes.
2022-03-02 08:40:33 -08:00
swift-ci
ad903094c0 Merge pull request #41386 from beccadax/your-library-is-overdue
Weaken some type checks for @preconcurrency decls
2022-03-01 16:13:59 -08:00
zoecarver
2e0398f867 [cxx-interop] Add support for subscripts in base classes. 2022-03-01 15:13:10 -08:00
Allan Shortlidge
d203876d36 SILGen: Use the OS version specified in the @_backDeploy attribute instead of the version specified in the @available attribute when emitting the if #available condition in back deployment thunks. 2022-02-25 17:51:12 -08:00
Allan Shortlidge
9e4ba442a2 Merge pull request #41416 from tshortli/back-deploy-thunk
Emit and call thunks for back deployed functions
2022-02-25 17:49:08 -08:00
Pavel Yaskevich
6c8a05d714 [AST] Implement default expression type request and accessors 2022-02-21 09:59:53 -08:00
Slava Pestov
8082e9ad94 Merge pull request #41473 from slavapestov/parameterized-protocol-multiple-args
Support parameterized protocols with multiple arguments
2022-02-19 08:28:17 -05:00
Slava Pestov
d7f8f2067a Sema: Generalize ProtocolDecl::getPrimaryAssociatedType() to ProtocolDecl::getPrimaryAssociatedTypes() 2022-02-18 22:24:25 -05:00
Becca Royal-Gordon
c2ccb874ab Soften actor isolation in closures passed to @preconcurrency
When a closure is not properly actor-isolated, but we know that we inferred its isolation from a `@preconcurrency` declaration, we now emit the errors as warnings in Swift 5 mode to avoid breaking source compatibility if the isolation was added retroactively.
2022-02-18 14:29:16 -08:00
Doug Gregor
51abd3d56f Prevent opening existentials when the corresponding parameter is variant
Ensure that we only open existentials in an argument when the corresponding
parameter's type is a generic parameter that is only used in covariant
positions, because either invariant or contravariant uses mean that we
won't be able to type-erase other uses of that parameter. This mirrors
the requirement placed when opening existentials as a member of protocol
type.
2022-02-18 11:22:57 -08:00
Doug Gregor
fa6c3c15d8 Opaque types are only invariant when they involve same-type constraints.
An opaque type is only invariant with respect to the existential Self
when the constraints on the opaque type involve Self. Such constraints
are not expressible in the type-erased value, so treat them as
invariant. This loosens the restriction on using members of protocol
type that return an opaque type, such that (e.g.) the following is
still well-formed:

    protocol P { }
    protocol Q { }

    extension P {
      func getQ() -> some Q { ... }
    }

    func test(p: any P) {
      let q = p.getQ() // formerly an error, now returns an "any Q"
    }

However, this does not permit uses of members such as:

    extension P {
      func getCollection() -> some Collection<Self> { ... } // error
    }

because the type system cannot express the corresponding existential
type `any Collection<Self>`.
2022-02-18 11:22:56 -08:00
Allan Shortlidge
212043840f SIL: Add flag to SILDeclRef for back deployment thunks. 2022-02-17 11:28:12 -08:00
Konrad `ktoso` Malawski
7c145cc55b Merge pull request #41179 from ktoso/wip-improved-adhoc-checks
[Distributed] improve ad-hoc requirement typechecking
2022-02-17 09:16:42 +09:00
Slava Pestov
a1c03db381 AST: Generalize ProtocolDecl::getRequirementSignature() to a new RequirementSignature type
The RequirementSignature generalizes the old ArrayRef<Requirement>
which stores the minimal requirements that a conforming type's
witnesses must satisfy, to also record the protocol typealiases
defined in the protocol.
2022-02-13 00:24:23 -05:00
Konrad `ktoso` Malawski
bffd956033 [Distributed] improve ad-hoc requirement typechecking 2022-02-11 19:25:48 +09:00
Slava Pestov
46bfbde812 Merge pull request #41303 from slavapestov/rqm-superclass-unification
RequirementMachine: Record rewrite loops during superclass unification
2022-02-10 12:11:36 -05:00
Slava Pestov
4c6cef062a AST: Const-ify some methods on ClassDecl 2022-02-09 16:49:24 -05:00
Doug Gregor
a37f291c18 Remove ActorIsolation::DistributedActorInstance.
The distributed case is distinguishable from the non-distributed case
based on the actor type itself for those rare cases where we care. The
vast majority of code is simplified by treating this identically to
`ActorInstance`.
2022-02-09 11:16:23 -08:00
Konrad `ktoso` Malawski
42108f33e5 [Distributed] allow get only distributed computed properties 2022-02-08 23:06:29 +09:00
Allan Shortlidge
70a7d85e4a Merge pull request #41112 from tshortli/diagnose-available-wrapped-properties
[Sema] Diagnose @available attribute on wrapped and lazy properties
2022-02-07 10:26:53 -08:00
swift-ci
d5568199df Merge pull request #40868 from kavon/drop-redundant-isolation 2022-02-04 21:08:42 -08:00
Rintaro Ishizaki
747c7cfa8a Merge pull request #41139 from rintaro/ide-completion-rdar80602940
[CodeCompletion] Handle clang async attributes for visibilities
2022-02-04 15:00:08 -08:00
Kavon Farvardin
057e69668a replace NominalTypeDecl::isValueType with a direct struct test
enums don't and will never have stored properties, so just be direct.
2022-02-04 14:41:49 -07:00
Kavon Farvardin
bd024caca9 [SE-327] Remove redundant global-actor isolation.
As part of SE-327, global-actor isolation applied to
the instance-stored properties of a value type do
not require any isolation, since there is no way to
create a race on access to that storage.

https://github.com/apple/swift-evolution/blob/main/proposals/0327-actor-initializers.md#removing-redundant-isolation

This change turns global-actor annotations on such
properties into an error in Swift 6+, and a warning
in Swift 5 and earlier.

In addition, inference for global-actor isolation
no longer applies global-actor isolation to such
properties. Since this latter change only results
in warnings in existing Swift 5 code, about a now
superflous 'await', this change will happen in
Swift 5+.

Fixes rdar://87568381
2022-02-03 15:19:59 -07:00
Allan Shortlidge
093b8d32db [Sema] Emit an error for attempts to use @available on var declarations that have attached property wrappers. Availability is not supported on stored properties, and properties with property wrappers are stored properties with a layer of indirection. Also, add the same missing diagnostic for lazy vars.
Resolves rdar://82713248
2022-02-03 09:02:59 -08:00
Kavon Farvardin
4f28b87de9 basic implementation of flow-isolation for SE-327
Flow-isolation is a diagnostic SIL pass that finds
unsafe accesses to properties in initializers and
deinitializers that cannot gain isolation to otherwise
protect those accesses from concurrent modifications.
See SE-327 for more details about how and why it exists.

This commit includes changes and features like:

- The removal of the escaping-use restriction
- Flow-isolation that works properly with `defer` statements
- Flow-isolation with an emphasis on helpful diagnostics.

It also includes known issues like:

- Local / nonescaping functions are not analyzed by
  flow-isolation, despite it being technically possible.
  The main challenge in supporting it efficiently is that
  such functions do not have a single exit-point, like
  a `defer`. In particular, arbitrary functions can throw
  so there are points where nonisolation should _not_ flow
  out of the function at a call-site in the initializer, etc.

- The implementation of the flow-isolation pass is not
  particularly memory efficient; it relies on BitDataflow
  even though the particular flow problem is simple.
  So, a more efficient implementation would be specialized for
  this particular problem, etc.

There are also some changes to the Swift language itself: defer
will respect its context when deciding its property access kind.

Previously, a defer in an initializer would always access a stored
property through its accessor methods, instead of doing so directly
like its enclosing function might. This inconsistency is unfortunate,
so for Swift 6+ we make this consistent. For Swift 5, only a defer
in a function that is a member of the following kinds of types
will gain this consistency:

- an actor type
- any nominal type that is actor-isolated, excluding UnsafeGlobalActor.

These types are still rather new, so there is much less of a chance of
breaking expected behaviors around defer. In particular, the danger is
that users are relying on the behavior of defer triggering a property
observer within an init or deinit, when it would not be triggering it
without the defer.
2022-02-02 13:31:14 -07:00
Anthony Latsis
c7fd60f2dd Merge pull request #39492 from AnthonyLatsis/se-309-2
SE-309: Covariant erasure for dependent member types
2022-02-02 07:07:17 +03:00
Anthony Latsis
6a25198ff8 AST: Minor optimization for ProtocolCompositionType handling in 'findExistentialSelfReferences' 2022-02-02 02:10:06 +03:00
Anthony Latsis
b3ee4b0718 AST, Sema: Use the opened archetype's generic signature to determine existential member availability 2022-02-02 02:09:59 +03:00
Rintaro Ishizaki
a9bbc1f727 [CodeCompletion] Handle clang async attributes for visibilities
Control 'async' variant of imported ObjC methods.

For non-'async' variant:
1) if 'swift_private' is specified, hide.

For 'async' variant:
1) if 'swift_async(swift_private)' is specified, hide.
2) if 'swift_async(not_swift_private)' is specified, show.
3) if 'swift_async_name()' is specified, show.
4) if 'swift_private' is specified, hide.

rdar://80602940
2022-02-01 14:53:23 -08:00
Anthony Latsis
b2fe028885 [NFC] Turn SelfReferenceKind into a standalone utility type 2022-02-01 20:55:47 +03:00
Anthony Latsis
3206f5ab34 [NFC] Preemptively relocate ProtocolDecl::isAvailableInExistential() and co. 2022-02-01 20:55:46 +03:00
Evan Wilde
7188f40a3b Replace experimental-async flag with checking decl context
This patch replaces the use of the experimental-async-top-level flag
with checking the decl context of the top-level variable to determine
whether the top-level contexts should be async.
2022-01-28 07:55:14 -08:00