Commit Graph

4105 Commits

Author SHA1 Message Date
Kavon Farvardin
13cbe0dd15 adding the @_compilerInitialized attribute
This attribute is designed for let-bound variables whose initializing
assignment is synthesized by the compiler. This assignment is
expected to happen at some point before DefiniteInitialization has
run, which is the pass that verifies whether the compiler truly
initialized the variable.

I generally expect that this will never be a user-facing feature, and
that the synthesized assignment happens in SILGen.
2022-03-24 16:18:49 -07:00
Kavon Farvardin
1f47442147 remove restrictions on dist-actor init parameters
we will no longer require exactly one ActorSystem-conforming parameter.
2022-03-24 16:18:49 -07:00
Allan Shortlidge
019a345932 SILGen: Generate appropriate SIL for @_backDeploy thunks that wrap coroutine functions (such as the _read and _modify accessors). Remove the temporary diagnostics that rejected use of @_backDeploy on decls that would result in coroutines. 2022-03-24 15:42:14 -07:00
Evan Wilde
13c71c668d Merge pull request #40769 from etcwilde/ewilde/noasync-unavailability
SE-0340: `noasync` availability kind
2022-03-22 21:42:09 -07:00
Richard Wei
335b766b25 [ResultBuilders] Enable SE-0348 buildPartialBlock by default.
Enables SE-0348 `buildPartialBlock` feature by default. The frontend flag is kept for compatibility with existing clients, but is now ineffective.

Also includes some improved error messages for invalid result builder call sites.
2022-03-22 16:26:50 -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
9604304586 Downgrade more errors into warnings for actor inits.
In the replacement of the escaping-use restriction with
flow-isolation, I hadn't accounted for all of the situations
where the isolation changes would break backwards compatability
with Swift 5.5 programs. The escaping-use restriction permitted
a lot of very unsafe things with warnings that it would become
an error in Swift 6.

With the introduction of flow-isolation, it was a bit tricky to
get the right warnings back in place, while not unnessecarily
warning about property accesses that might actually be OK. There
is a very careful coordination between the type-checker and
the flow-isolation pass.

While I had done these downgrades for deinits, I also needed to
do them for inits as well, because member accesses to isolated
methods within actor initializer were still getting rejected
as an error. This patch should be pretty solid now.

fixes rdar://90595278
2022-03-22 14:38:02 -07:00
Cassie Jones
eecdfb9dea Merge pull request #41906 from porglezomp-misc/put-any-here
[Diagnostics] Change phrasing of the existential_requires_any warning
2022-03-19 11:15:35 -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
Cassie Jones
bc686e733e [Diagnostics] Change phrasing of the existential_requires_any warning
The previous warning "must be explicitly marked as 'any'" isn't clear if
you don't already know the feature, this new phrasing should make it
clearer by including the correct spelling of the type as an example.

Fixes rdar://90384448
2022-03-18 18:18:35 -07:00
Konrad `ktoso` Malawski
8c13370242 [Distributed] rename _Distributed to underscoreless module 2022-03-16 08:35:35 +09:00
Allan Shortlidge
5f5cc9f00b Sema: Diagnose use of availability macros in conditional statements in @_backDeploy functions. Add a test verifying that expected diagnostics are emitted when referencing non-public declarations from a @_backDeploy function body.
Resolves rdar://90270100
2022-03-14 17:16:17 -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
Konrad `ktoso` Malawski
f2d60e16f2 [Distributed] add note explaining DefaultDistributedActorSystem 2022-03-11 11:09:57 +09:00
Konrad `ktoso` Malawski
d42593a866 [Distributed] better diagnostics for missing actor system typealias 2022-03-11 10:01:38 +09: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
Slava Pestov
599bb79933 Sema: Generalize the 'invariant Self requirement' check to handle a related case
There are three kinds of invariant 'Self' uses here:

- 'Self' appears as the left hand side of a same-type requirement between type parameters
- 'Self' appears as a structural component of the right hand side of a concrete type requirement
- 'Self' appears as a structural component of the right hand side of a superclass requirement

My previous fix only handled the first case. Generalize it to handle all three.

Fixes rdar://problem/74944514.
2022-03-09 18:50:14 -05:00
Xi Ge
610a4a5e41 Merge pull request #41692 from nkcsgexi/spi-available 2022-03-06 12:40:20 -08:00
Holly Borla
70197c8557 Merge pull request #41693 from hborla/any-in-diagnositcs
[Diagnostics] Print `any` in diagnostics.
2022-03-06 10:09:12 -08:00
Holly Borla
80a2eee2bf [Diagnostics] Remove a few special cases of printing 'any' for specific
error messages.
2022-03-05 14:26:45 -08:00
Holly Borla
12459cff80 [Diagnostics] Print 'any' in diagnostic arguments. 2022-03-05 14:26:45 -08:00
Xi Ge
59896a1dd2 typecheck: diagnose malformed @_spi_available 2022-03-04 21:45:03 -08:00
Richard Wei
f9b2395676 Merge pull request #41576 from rxwei/buildpartialblock
[ResultBuilders] `buildPartialBlock` support
2022-03-04 09:20:52 -08:00
Richard Wei
b1f020bf38 [ResultBuilders] buildPartialBlock support
This PR implements support for `buildPartialBlock` as proposed in https://forums.swift.org/t/pitch-buildpartialblock-for-result-builders/55561. This is similar to the existing support for `buildBlock(combining:into:)` except that it also checks for availability when deciding whether to fall back to plain old `buildBlock`.

> In the result builder transform, the compiler will look for static members `buildPartialBlock(first:)` and `buildPartialBlock(accumulated:next:)` in the builder type. If the following conditions are met:
> - Both methods `buildPartialBlock(first:)` and `buildPartialBlock(accumulated:next:)` exist.
> - The availability of the enclosing declaration is greater than or equal to the availability of `buildPartialBlock(first:)` and `buildPartialBlock(accumulated:next:)`.

When there's no available `buildPartialBlock` to call and there's no `buildBlock`, emit a diagnostic:
```console
result builder 'Builder' does not implement any 'buildBlock' or a combination of 'buildPartialBlock(first:)' and 'buildPartialBlock(accumulated:next:)' with sufficient availability for this call site
```
2022-03-04 00:24:35 -08: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
Allan Shortlidge
0f890b86fa Sema: Diagnose use of the @_backDeploy attribute on non-final and @objc decls. 2022-03-01 16:37:32 -08:00
Kavon Farvardin
8dcb7616b6 downgrade actor deinit accesses to warnings in more contexts
previous downgrade did not properly account for accesses within
closures, because it was done hastily.
2022-03-01 15:55:17 -07:00
Allan Shortlidge
e39c55023f AST: Add support for @_backDeploy on computed properties, subscripts, and accessors. 2022-03-01 13:29:09 -08:00
Allan Shortlidge
da2ae43b4f Sema: Diagnose invalid back deployed declarations. Back deployed declarations must:
- have public visibility
- have at most one back deployment version per-platform
- specify an introduced version for each platform with a back deployment version using @available
- have a back deployment version that is greater than the introduced version
- not have conflicting attributes like @_alwaysEmitIntoClient

Refactor to share code with type checking for @_originallyDefinedIn which has overlapping diagnostics.
2022-02-28 16:00:28 -08:00
Slava Pestov
ab6584cf05 Merge pull request #41545 from slavapestov/non-final-class-self-same-type-requirement-conformance
Sema: Warn about non-final classes conforming to protocols with a same-type requirement on 'Self'
2022-02-25 10:46:14 -05:00
Slava Pestov
c98ddb99e2 Sema: Warn about non-final classes conforming to protocols with a same-type requirement on 'Self'
This is unsound because it breaks covariance of protocol conformances
on classes. See the test case and changelog entry for details.
2022-02-24 14:23:00 -05:00
Pavel Yaskevich
8cfdb9999c Merge pull request #41436 from xedin/allow-specialization-from-default-expr
[TypeChecker] Allow inference from default expressions in certain scenarios (under a flag)
2022-02-24 08:57:42 -08:00
Slava Pestov
250fbf2f3d Sema: Reject 'any P' in inheritance clauses 2022-02-23 23:10:10 -05:00
Anthony Latsis
d36aecca49 Diag: Make 'could_not_use_member_on_existential' less assertive 2022-02-23 10:24:51 +03:00
Pavel Yaskevich
eaa737cf72 [TypeChecker] Allow inference from default even when type could be inferred from result as well
This enables support for inference in initializers of generic types
and in `case`s of generic enums e.g.

```
struct S<T> {
  init(_: T = 42) {}
}

enum E<T: Collection> {
case test(_: T = [42])
}
```
2022-02-21 09:59:54 -08:00
Pavel Yaskevich
82b955b93c [CSDiagnostics] Detect and diagnose contextual mismatches with default value 2022-02-21 09:59:54 -08:00
Pavel Yaskevich
aea76ca358 [TypeChecker] Extend type inference from default expressions to handle nested generic parameters
Adds support for parameter types like `[T?]` or `[(T, U?)]`,
and relaxes restriction on same-type generic parameters.

A same-type requirement is acceptable if it only includes
in-scope generic parameters and concrete types i.e. `T.X == Int`
if accepted if `T` is referenced only by a parameter default
expression is being applied to.
2022-02-21 09:59:54 -08:00
Pavel Yaskevich
a6e84b3d05 [ConstraintSystem] Add call site support for type inference from default expressions 2022-02-21 09:59:53 -08:00
Holly Borla
9297ba13d6 Merge pull request #41481 from hborla/missing-any-diagnostics
[Diagnostics] Fix missing `any` warnings for type aliases.
2022-02-21 09:23:39 -08:00
Holly Borla
801168f7ac [Diagnostics] Fix missing 'any' warnings for type aliases.
Only warn when using a type alias if the underlying type is directly
a constraint type. Also check the underlying type for missing 'any'
if the underlying type is not directly a constraint type.
2022-02-19 15:20:44 -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
Kavon Farvardin
ef72c5b4df accept serialized modules with superflous global-actor annotations
When compiling with Swift 6 mode, but using a serialized module
that is using Swift 5 that contains a struct with global-actor
isolation on its stored property, we should not emit an error
for that stored property. Only a warning was emitted when compiling
that module, but the checks here were treating that module as being
type-checked again under a Swift 6 world.
2022-02-18 18:43:04 -07:00
Holly Borla
c2594d1338 [FrontendOptions] Remove the -enable-explicit-existential-types flag. 2022-02-17 17:54:59 -08:00
Doug Gregor
27056a0ed7 Enable SE-0341 "Opaque Parameter Declarations" by default.
This proposal has been accepted, so enable it by default and update
some diagnostics to stop implying that this feature cannot be used.
2022-02-17 13:57:45 -08:00
Doug Gregor
7991c66cb2 [SE-0341]: Disable use of opaque parameters in consuming positions.
Based on the review discussion of this proposal, prohibit the use of
opaque parameters in "consuming" positions of function types, as we did
with opaque result types in SE-0328.
2022-02-17 12:06:59 -08:00
Mishal Shah
3708676142 Merge pull request #41335 from apple/revert-41325-revert-41275-regex-update-dev-6
Revert "Revert "[Regex] Switch regex match to Swift tuples.""
2022-02-15 00:29:07 -08:00
John McCall
b3b6701a50 Implement @_unsafeInheritExecutor.
SE-0338 changed the execution of non-actor async functions
so that they always hop to the generic executor, but some
functions need a way to suppress this so that they inherit
the caller's executor.

The right way to implement this is to have the caller pass
down the target executor in some reliable way and then
switch to it in all the appropriate places in the caller.
We might reasonably be able to build this on top of isolated
parameters, using some sort of default argument, or we might
need a wholly novel mechanism.

But those things are all ABI-breaking absent some sort of
guarantee about switching that we probably don't want to make,
and unfortunately we have functions in the library which we
need to export that need to inherit executors.  So in the
short term, we need some unsafe way of getting back to the
previous behavior.
2022-02-14 20:46:03 -05:00
Richard Wei
1b83efb512 Revert "Revert "[Regex] Switch regex match to Swift tuples."" 2022-02-11 01:32:45 -08:00