Commit Graph

2604 Commits

Author SHA1 Message Date
Slava Pestov
6982b90c6e Serialization: Round-trip primary associated type list 2022-04-16 22:36:29 -04:00
Pavel Yaskevich
4ecc05d276 Merge pull request #42264 from xedin/err-in-default-expr
[TypeChecker] Fix a crash in inherited default argument type-checking
2022-04-08 19:24:50 -07:00
Pavel Yaskevich
8f55238f16 [TypeChecker] Fix a crash in inherited default argument type-checking
In some circumstances request for default type is made before
inherited constructor has been validated and storage has been
allocated for invalid type which then triggered a crash during
declaration checking.
2022-04-08 12:22:01 -07:00
Doug Gregor
eef2704c86 Reimplement actor isolation checking for referencing a declaration.
Start collapsing the several implementations of actor isolation checking
into a single place that determines what it means to reference a declaration
from a given context, potentially supplying an instance for an actor. This
is partly cleanup, and partly staging for the implementation of the
Sendable restrictions introduced in SE-0338. The result of this check
falls into one of three categories:

* Reference occurs within the same concurrency domain (actor/task)
* Reference leaves an actor context to a nonisolated context (SE-0338)
* Reference enters the context of the actor, which might require a
combination of implicit async, implicit throws, and a "distributed" check.

Throughout this change I've sought to maintain the existing semantics,
even where I believe they are incorrect. The changes to the test cases
are not semantic changes, but reflect the unification of some
diagnostic paths that changed the diagnostic text but not when or how
those diagnostics are produced. Additionally, SE-0338 has not yet been
implemented, although this refactoring makes it easier to implement
SE-0338.

Use this new actor isolation checking scheme to implement the most
common actor-isolation check, which occurs when accessing a member of
an instance.
2022-04-07 09:07:36 -07:00
Anthony Latsis
15839ffba6 Merge pull request #42049 from AnthonyLatsis/dyn-self-inherit
findGenericParameterReferences: Do better at honoring 'treatNonResultCovarianceAsInvariant' and 'hasCovariantSelfResult'
2022-04-07 09:07:16 +03:00
swift-ci
6af73245c6 Merge pull request #42136 from ktoso/wip-identifiable-synthesis-fix
[Distributed] ID synthesis must be eager, or we run into issues in real projects
2022-04-04 02:51:22 -07:00
Slava Pestov
8c47cd75fd Sema: The primary associated type list references existing associated types instead of declaring new ones 2022-04-03 22:03:49 -04:00
Konrad `ktoso` Malawski
c88951354f [Distributed] ID synthesis must be eager, or we run into issues in real projects 2022-04-01 18:47:25 +09:00
Anthony Latsis
4c2e88b207 Merge pull request #41849 from AnthonyLatsis/dyn_unbound_ref
CS: Handle unbound references to @objc optional methods
2022-03-31 04:01:20 +03:00
Pavel Yaskevich
c143c55989 [AST] OpaqueDecl: Simplify storage of conditionally available alternatives
Instead of using a special type with a set of trailing objects, let's
just re-allocate array of substitutions into a permanent storage directly.
2022-03-29 21:52:15 -07:00
Anthony Latsis
def23f45a1 findGenericParameterReferences: Do better at honoring 'treatNonResultCovarianceAsInvariant' and 'hasCovariantSelfResult' 2022-03-29 13:10:49 +03:00
Pavel Yaskevich
67311e5465 [AST] Augment OpaqueTypeDecl to store conditionally available alternatives
In preparation to support cases like this:

```
func test() -> some P {
  if #available(...) {
    return X()
  }

  return Y()
}
```

where both `X` and `Y` conform to `P` but are different types.
2022-03-28 16:22:08 -07:00
Anthony Latsis
f25725279e [NFC] CSApply: Introduce a generalized routine for building single curry thunk bodies 2022-03-26 18:28:20 +03:00
Pavel Yaskevich
5b9b4977e0 [TypeChecker] SE-0347: Avoid type inference from caller-site defaults
Such default expressions are injected as an argument to each call site,
so they cannot participate in inference at declaration site.
2022-03-25 13:10:04 -07:00
Konrad `ktoso` Malawski
8d3e7d91c0 [Distributed] ResultHandler.onReturn must be ad-hoc because SerializationRequirement (#41916)
* [Distributed] Invoke handler.onReturn ad hoc via ast synthesized func

* reformat and cleanup

* remove unused var
2022-03-24 21:44:37 +09:00
Doug Gregor
38c9d2e8dd Merge pull request #41992 from DougGregor/implicit-existential-opening-erase-or-reject 2022-03-23 21:03:54 -07:00
Doug Gregor
50b113e222 Don't open an existential call argument if its type information is needed earlier.
To ensure that we do not accept code that would require an existential call argument
to be evaluated prior to the call, don't open existential call
arguments if the generic parameter that would capture the opened
existential type is used in any prior parameter.

Note that code generation currently moves the opening of the
existential call argument outside of the call, which is a compiler bug.
This change ensures that we don't accept code would *require* this
out-of-order evaluation and adds a test so we know when we fix this.
2022-03-23 16:34:32 -07:00
Evan Wilde
aa51bdf17a Add noasync availability kind to available attr
This patch adds the `noasync` availability kind to `@available`. The
spelling is `@available(*, noasync)`.
2022-03-22 15:12:51 -07:00
Kavon Farvardin
9b1fcedf2f backtrack on part of SE-327 dealing with default-value exprs
This effectively reverts 6823744779

The blanket removal of isolation in default-value expressions had
unintented consequences for important workflows. It's still
a problem that needs to be addressed, but we need to be more precise
about the problematic situations.
2022-03-18 18:41:05 -07:00
Evan Wilde
ea355fd8fe Merge pull request #41805 from etcwilde/ewilde/enable-top-level-concurrency
SE-0343: De-experimentalify async top-level context
2022-03-15 21:39:25 -07:00
Evan Wilde
1afaf74f3c top-level is @MainActor(unsafe) below swift 6
Co-authored-by: Doug Gregor <dgregor@apple.com>
2022-03-15 16:35:51 -07:00
Konrad `ktoso` Malawski
8c13370242 [Distributed] rename _Distributed to underscoreless module 2022-03-16 08:35:35 +09:00
Evan Wilde
c34f7055f8 Detach enable-experimental-async-top-level flag
SE-0343 is approved so it's time to pull the feature out from behind the
experimental feature flag. This patch pulls it out and deprecates
passing the flag to the frontend so that we can pull it out entirely
eventually.
2022-03-15 16:07:03 -07:00
Robert Widmann
0d2b2f2a55 Stabilize VarDecl::isLet for ParamDecls
For ParamDecl instances, the value of this property is not just a function of the introducer (let/var which is a poorly-defined concept for parameters), it's a function of the specifier (inout/__owned/__shared etc). However, computing the specifier also has the side effect of flipping the introducer bits. This appears to be because while the AST uses `isLet` in a syntactic sense "did the user write 'let'?", SIL uses it in a semantic sense "is this property semantically immutable?". These two queries need to be split from one another and the callers migrated. But that is a much larger task for a later time. For now, provide the value of `ParamDecl::isImmutable` to callers since that's the more conservative of the two behaviors.

The bug here is that it's possible for `getSpecifier` to *not* be called before `isLet` is called (usually in SIL). This manifested as a test output divergence on the non-asserts bots since the ASTVerifier was always calling getSpecifier, and most engineers do not build without asserts on at their desk.

rdar://89237318
2022-03-15 13:01:02 -07:00
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