Commit Graph

26323 Commits

Author SHA1 Message Date
Pavel Yaskevich
19f59ce0c1 Merge pull request #75087 from xedin/rdar-130776220-limited
[Concurrency] Fix disallowed override isolation to carry `@preconcurr…
2024-07-10 01:02:40 -07:00
Doug Gregor
817e1c18b0 Extend type checker hack for @_unsafeInheritExecutor functions to methods
With the re-introduction of `@_unsafeInheritExecutor` for `TaskLocal.withValue`,
we need to extend the type checker trick with `_unsafeInheritExecutor_`-prefixed
functions to work with methods. Do so to make `TaskLocal.withValue` actually
work this way.
2024-07-09 21:39:42 -07:00
Holly Borla
86f3fe1680 [Concurrency] Don't infer actor isolation from inherited conformances.
If a conformance is inherited from a superclass, the isolation
of the subclass should be inferred directly from the superclass.
If the superclass has opted out of global actor inference from a
protocol, such as by conforming to the protocol in an extension,
then the subclass should not infer isolation from the protocol.
2024-07-09 19:43:40 -07:00
Sima Nerush
2744413e69 Merge pull request #75084 from simanerush/sima/131339439
[Concurrency] Remove the global actor check when allowing 'nonisolated' on mutable Sendable storage.
2024-07-09 16:57:12 -07:00
Pavel Yaskevich
f7d3230535 [Concurrency] Fix disallowed override isolation to carry @preconcurrency bit
If ObjC member cannot be overridden due to isolation mismatch set `@preconcurrency`
bit to make the diagnostic a warning instead of an error in Swift 5 mode.

Resolves: rdar://130776220
2024-07-09 13:34:17 -07:00
Sima Nerush
e0a128fbd6 [Concurrency] Remove the global actor check when allowing 'nonisolated' on mutable Sendable storage. 2024-07-09 13:25:44 -07:00
Meghana Gupta
bbd54ae8a8 Ban annotating function type with lifetime dependence 2024-07-09 09:13:14 -07:00
Meghana Gupta
a91cb2819a Ban conversion between function types of different lifetime dependencies 2024-07-09 09:12:18 -07:00
Doug Gregor
a2038f92f8 Address code review feedback and fix rebase typo in a test 2024-07-09 08:13:24 -07:00
Holly Borla
48a888abc5 Merge pull request #75091 from hborla/isolated-key-path-init
[Concurrency] Consider isolated key-path components when computing the required isolation of a stored property initializer.
2024-07-09 06:53:59 -07:00
Kavon Farvardin
eb51b6f732 Merge pull request #75085 from kavon/fix-missing-return
NFC: add missing return
2024-07-09 00:15:19 -07:00
Doug Gregor
a2b2324e7f Use @_unsafeInheritExecutor forms of with*Continuation from @_unsafeInheritExecutor functions
The move from `@_unsafeInheritExecutor` to `#isolation` for the
with*Continuation breaks code that is using `@_unsafeInheritExecutor` and
calling these APIs. This originally caused silent breakage (which manifest
as runtime crashes), and is now detected by the compiler as an error.

However, despite `@_unsafeInheritExecutor` being an unsafe,
not-intended-to-be-user-facing feature, it is indeed being used, along
with these APIs. Introduce _unsafeInheritExecutor_-prefixed versions of
the `with*Continuation` and `withTaskCancellationHandler` APIs into
the _Concurrency library that use `@_unsafeInheritExecutor`. Then,
teach the type checker to swap in these
_unsafeInheritExecutor_-prefixed versions in lieu of the originals
when they are called from an `@_unsafeInheritExecutor` function. This
allows existing code using `@_unsafeInheritExecutor` with these APIs
to continue working as it has before, albeit with a warning that
`@_unsafeInheritExecutor` has been removed.

Fixes rdar://131151376.
2024-07-08 23:35:37 -07:00
Doug Gregor
45d4d975cd Deprecate @_unsafeInheritExecutor and remove it from Swift 6 2024-07-08 23:35:34 -07:00
Doug Gregor
c5457abaf7 Avoid using AsyncIteratorProtocol.next(isolation:) with @_unsafeInheritExecutor
`#isolation` in unsafe within a function that uses
`@_unsafeInheritExecutor`, so avoid the implicit use of the new
`AsyncIteratorProtocol.next(isolation:)` in such functions.
2024-07-08 23:34:28 -07:00
Doug Gregor
5f049b63ef Diagnose attempts to use #isolation within an @_unsafeInheritExecutor function
An `@_unsafeInheritExecutor` function is unsafe because it doesn't
really "inherit" the executor, it just avoids immediately hopping off
the executor. That means that using `#isolation` within such a
function is fundamentally broken. Ban the use of `#isolation` within
such a function, providing a Fix-It that removes the
`@_unsafeInheritExecutor` attribute and adds a defaulted parameter

    isolation: (any Actor)? = #isolation

instead. That's the real, safe pattern that want going forward.

We did say it was unsafe, after all. Part of rdar://131151376.
2024-07-08 23:34:28 -07:00
Holly Borla
c4f6793dbf [Concurrency] Consider isolated key-path components when computing the required
isolation of a stored property initializer.

This allows isolated key-path components to be used in stored property
initializers when the stored property itself is isolated to the same
global actor.
2024-07-08 19:20:59 -07:00
Kavon Farvardin
7968f8fd74 NFC: add missing return 2024-07-08 16:37:13 -07:00
Steven Wu
30737eb396 [Caching] Support swift style diagnostics for swift caching
Add support for swift style diagnostics for swift caching. This includes
pre-populate the GeneratedSourceInfo with macro name so it doesn't need
to infer from an ASTNode, which the caching mechanism cannot preserve.

Still leave the default diagnostic style to LLVM style because replaying
swift style diagnostics is still very slow and including parsing source
file using swift-syntax.

rdar://128615572
2024-07-08 16:15:44 -07:00
Michael Gottesman
1160951585 Merge pull request #75069 from gottesmm/pr-6b7256344bb1a1ceb9d13dae6d52db0d356b46a3
[region-isolation] Treat async let as a isolation inference boundary closure and fix diagnostics due to change.
2024-07-08 14:48:27 -07:00
Michael Gottesman
03b26fd65b [region-isolation] Treat async let as a isolation inference boundary closure and fix diagnostics due to change.
Otherwise, we will assume that an async let autoclosure infers isolation from
its DeclContext... which we do not want. An async let autoclosure should always
be nonisolated + sending.

The diagnostic change that I mentioned in the header is that we were emitting
unfortunate "sending task or actor isolated could result in races" error. I
eliminated this by adding a new diagnostic for transfer non transferrable errors
happening in autoclosures. So now we emit this:

```swift
  func asyncLetInferAsNonIsolated<T : Actor>(
    isolation actor: isolated T
  ) async throws {
    async let subTask: Void = {
      await useValueAsyncNoReturnWithInstance(self, actor)
      // expected-warning @-1:47 {{sending 'self' risks causing data races}}
      // expected-note @-2 {{sending 'actor'-isolated 'self' into async let risks causing data races between nonisolated and 'actor'-isolated uses}}
    }()
    await subTask
```

I also noticed that we did not have enough test cases for autoclosures in
general so I also added a bunch of tests just so we can see what the current
behavior is. I think there are a few issues therein (I believe some may have
been reported due to '??').

rdar://130151318
2024-07-08 11:22:29 -07:00
Hamish Knight
e630f66952 Merge pull request #75046 from hamishknight/out-of-placeholder
[CS] Improve placeholder diagnostics slightly
2024-07-08 18:13:10 +01:00
Pavel Yaskevich
cdf28bc482 [Concurrency] Allow sendability mismatches while overriding @preconcurrency properties in Swift 5 mode
Downgrade a mismatch on `any Sendable` -> `Any` to a warning until
Swift 6 to enable class authors to introduce concurrency annotations
to overridable properties.

Resolves: rdar://122193606
2024-07-08 09:29:50 -07:00
Hamish Knight
4beaaf32ad [CS] Improve placeholder diagnostics slightly
Make sure `CouldNotInferPlaceholderType` can
produce a diagnostic for a `PlaceholderType`
locator element, and avoid emitting an extra
diagnostic for a placeholder type in an invalid
position.
2024-07-07 23:42:33 +01:00
Kavon Farvardin
04454054b7 NCGenerics: add availability checking
Not all runtimes can correctly operate with types that use noncopyable
generics. When the generic argument of a type is noncopyable, old
runtimes can't recognize that to correctly check conformances that may
be conditional on those arguments being Copyable, etc.

resolves rdar://126239335
2024-07-07 15:38:00 -07:00
Hamish Knight
e2f8006450 Merge pull request #75011 from hamishknight/context-is-key
[Sema] Enforce PatternTypeRequest returns contextual type
2024-07-07 10:23:57 +01:00
Hamish Knight
18531b6bd3 [Sema] Enforce PatternTypeRequest returns contextual type
A bunch of synthesis code was getting this wrong
and setting an interface type for a TypedPattern.
Assert that we have a contextual type, and update
some synthesis logic.
2024-07-06 23:18:17 +01:00
Hamish Knight
fe68fab1e2 [AST] Simplify construction of EnumElementPattern
Add `EnumElementPattern::create` and
`EnumElementPattern::createImplicit`, and replace
existing constructions with them.
2024-07-06 22:56:30 +01:00
Hamish Knight
1490a27dec [Sema] Fix an IsPattern optional unwrap logic error
The case being handled is the input being more
optional than the cast type, so we need to inject
optional patterns to bring the input down to the
same optionality of the cast. Therefore we need
to take the optional types from the start of the
input optional types, not the end.

Luckily this issue doesn't currently cause any
issues because `coercePatternToType` will fixup
the right type.
2024-07-06 22:56:30 +01:00
Slava Pestov
ab0ffe395b Merge pull request #74998 from slavapestov/global-conformance-lookup
AST: Stop pretending that conformance lookup takes the module into account
2024-07-06 17:26:46 -04:00
Hamish Knight
b9149e9ae0 Merge pull request #75009 from hamishknight/remove-disable-avail
[Sema] NFC: Remove `DisableExprAvailabilityChecking`
2024-07-06 20:16:42 +01:00
Slava Pestov
ca9c09f8a1 Remove some unused variables 2024-07-06 12:05:47 -04:00
Slava Pestov
86d567f95a AST: ModuleDecl::lookupConformance() is a static method 2024-07-06 12:05:47 -04:00
Slava Pestov
e8d717bcd6 AST: Remove ModuleDecl parameter from checkRequirements() 2024-07-06 12:05:46 -04:00
Slava Pestov
8feb3bd819 Sema: Remove ModuleDecl parameter from substMemberTypeWithBase() 2024-07-06 12:05:46 -04:00
Slava Pestov
3fcda140bb AST: ModuleDecl::checkConformance() is a static method 2024-07-06 12:05:46 -04:00
Slava Pestov
fae01d9776 AST: Remove ModuleDecl parameter from more places 2024-07-06 12:05:46 -04:00
Slava Pestov
252abb5365 Sema: Key the implied Sendable conformance behavior off of -swift-version instead of -strict-concurrency
Also add some comments to explain what in the world is going on
with the new checks.
2024-07-06 12:05:45 -04:00
Hamish Knight
ee5df0041a [Sema] Remove DisableExprAvailabilityChecking 2024-07-06 16:20:21 +01:00
Sima Nerush
549566e037 Merge pull request #74958 from simanerush/130992526
[Concurrency] Allow 'nonisolated' to be applied to mutable storage of 'Sendable' type on a globally-isolated value type.
2024-07-05 14:18:42 -07:00
Hamish Knight
63e7c9380d Merge pull request #74890 from hamishknight/attr-etc
[Completion] Update type attribute completions
2024-07-04 17:57:15 +01:00
Sima Nerush
f726e7e3da [Concurrency] Allow 'nonisolated' to be applied to mutable storage of 'Sendable' type on a globally-isolated value type. 2024-07-04 08:46:42 -07:00
Doug Gregor
e50beb0a46 Merge pull request #74962 from DougGregor/typed-throws-backdeploy-fixes
Typed throws backdeploy fixes
2024-07-04 00:12:52 -07:00
Doug Gregor
21e5066249 Diagnose deployment constraints on type metadata involving typed throws
Fixes the rest of rdar://121530587.
2024-07-03 21:08:54 -07:00
Alejandro Alonso
427077b148 Merge pull request #74901 from Azoy/static-exclusive-requirements
[Sema] Let protocols define getter requirements for @_staticExclusiveOnly types
2024-07-03 14:33:19 -07:00
Hamish Knight
e3f8808532 [Sema] NFC: Remove isSILAttribute
`TypeAttribute::isSilOnly` does the same thing.
2024-07-03 11:41:06 +01:00
Hamish Knight
e4bec41717 [AST] Demote @noescape and @async to SIL attributes
These aren't currently claimed by anything other
than SILFunctions, and as such are invalid in
regular Swift code. Treat them as SIL type
attributes. Also while here, fix the SIL reference
attributes to be SIL attributes.
2024-07-03 11:41:06 +01:00
Slava Pestov
e899ff2a66 Merge pull request #74908 from slavapestov/fix-implied-sendable-conformance
Sema: Change behavior of implied 'Sendable' conformance
2024-07-02 21:41:54 -04:00
Slava Pestov
0696ec6d50 Sema: Ban implied 'Sendable' conformance when strict concurrency enabled
You can't do this anymore:

    struct G<T> {}
    protocol P: Sendable {}
    extension G: P where T: P {}

Fixes rdar://95695543.
2024-07-02 17:09:50 -04:00
Slava Pestov
bb48d32ec4 Sema: Implied 'Sendable' conformance should be unconditional
A conditional conformance to a protocol does not usually imply
a conformance to the protocol's inherited protocols, because
we have no way to guess what the conditional requirements
should be.

A carveout was added for 'Sendable', so that protocols could
inherit from 'Sendable' retroactively. However, the 'Sendable'
conformance would become conditional, which causes us to
reject a _second_ conditional conformance to such a protocol:

    struct G<T> {}
    protocol P: Sendable {}
    protocol Q: Sendable {}

    extension G: P where T: P {}
    extension G: Q where T: Q {}

To make this work, tweak the code so that an implied conformance
has the same generic signature as the conforming type, that is,
we force it to be unconditional.

Fixes rdar://122754849
Fixes https://github.com/swiftlang/swift/issues/71544
2024-07-02 17:04:41 -04:00
Michael Gottesman
34195ff213 Merge pull request #74610 from gottesmm/pr-324fd70c13e87a329334341aae4667f2d1be152c
[sending] Remove transferring.
2024-07-02 14:02:18 -07:00