Commit Graph

28352 Commits

Author SHA1 Message Date
Pavel Yaskevich
d40c37e20d [Sema/SILGen] Import ObjC async functions as nonisolated(nonsending) by default
These functions already have special code generation that keeps them
in the caller's isolation context, so there is no behavior change here.

Resolves: rdar://145672343
(cherry picked from commit 07bad98f6d)
2025-04-21 11:22:18 -07:00
Pavel Yaskevich
cdc02a4c8d Merge pull request #80924 from xedin/rdar-149107104-6.2
[6.2][TypeChecker] Allow closures to assume `nonisolated(nonsending)`
2025-04-21 11:10:38 -07:00
Doug Gregor
2bc7b5747b [Strict memory safety] Treat the implicit call to a 'defer' function as implicitly 'unsafe'
This eliminates stray warnings.

(cherry picked from commit b7d41a55a5)
2025-04-21 09:03:32 -07:00
Doug Gregor
ac56b63bd3 [Strict memory safety] Type alias types are only unsafe if their underlying type is
(cherry picked from commit 53ca902267)
2025-04-21 09:03:28 -07:00
Doug Gregor
93fbce0ce2 [Strict memory safety] Nested types are safe/unsafe independent of their enclosing type
When determining whether a nested type is safe, don't consider whether
its enclosing type is safe. They're independent.

(cherry picked from commit 8ec52c825c)
2025-04-21 09:03:25 -07:00
Doug Gregor
4c5ba0c5cb [Strict memory safety] Only diagnose unsafe types in the canonical type
Typealiases involving unsafe types that resolve to safe types
should not be diagnosed.

(cherry picked from commit 0405f61207)
2025-04-21 09:03:21 -07:00
Pavel Yaskevich
7d77c615b3 Merge pull request #80922 from xedin/rdar-148996589-6.2
[6.2][Concurrency] Downgrade non-Sendable type captures to warnings if clo…
2025-04-19 19:07:03 -07:00
Pavel Yaskevich
134f5def36 [TypeChecker] Allow closures to assume nonisolated(nonsending)
Always infer `nonisolated(nonsending)` from context directly on
a closure unless the closure is marked as `@concurrent`, otherwise
the closure is not going to get correct isolation and going to hop
to the wrong executor in its preamble.

Resolves: rdar://149107104
(cherry picked from commit 3de72c5452)
2025-04-18 16:41:34 -07:00
Pavel Yaskevich
55c2af0886 [Concurrency] Downgrade non-Sendable type captures to warnings if closure is in @preconcurrency context
The original check examined only the immediate closure, but it's
possible that the closure happens to be in a preconcurrency context
which also requires a downgrade.

Resolves: rdar://148996589
(cherry picked from commit cad2df3d5c)
2025-04-18 16:09:39 -07:00
Hamish Knight
b2b37eb766 [Sema] Downgrade noasync diagnostic to warning for closure macro args
Downgrade to a warning until the next language mode. This is
necessary since we previously missed coercing macro arguments to
parameter types, resulting in cases where closure arguments weren't
being treated as `async` when they should have been.

rdar://149328745
2025-04-18 11:58:14 +01:00
Hamish Knight
15c7467f37 NFC: Abstract away the use of '7' to represent the next language mode
Introduce `Version::getFutureMajorLanguageVersion` to make it easier
to find clients that will need to be updated once we have a new
language mode.
2025-04-18 11:58:14 +01:00
Pavel Yaskevich
65f78f3c01 Merge pull request #80807 from xedin/se-0461-renamings-6.2
[6.2][SE-0461] Replace `@execution(...)` with `@concurrent` and `nonisolated(nonsending)`
2025-04-16 20:47:14 -07:00
Pavel Yaskevich
826176a28a [AST] NFC: Add a convenient way to create implicit NonisolatedAttrs 2025-04-16 13:20:16 -07:00
Pavel Yaskevich
031d3bcc2b [Sema/SILGen] NFC: Remove all mentions of @execution from comments 2025-04-16 13:18:57 -07:00
Pavel Yaskevich
06f880e65c [AST/ASTGen/Sema/Serialization] Remove @execution attribute
Complete the transition from `@execution` to `@concurrent` and `nonisolated(nonsending)`
2025-04-16 13:18:52 -07:00
Nate Chandler
de1d5ae894 [CoroutineAccessors] Only reference when available
Don't bind references to storage to use (new ABI) coroutine accessors
unless they're guaranteed to be available.  For example, when building
against a resilient module that has coroutine accessors, they can only
be used if the deployment target is >= the version of Swift that
includes the feature.

rdar://148783895
2025-04-16 11:05:02 -07:00
Nate Chandler
85860f6960 [NFC] AST: Extract helper method.
Several callers of `AbstractStorageDecl::getAccessStrategy` only cared
about whether the the access would be via physical storage.  Before
adding more arguments to `getAccessStrategy` for which such callers
would have to pass a sentinel value, add a convenience method for this.
2025-04-16 11:05:01 -07:00
Pavel Yaskevich
fde841704c [AST/Parse] Implement nonisolated(nonsending) type modifier 2025-04-16 10:06:08 -07:00
Pavel Yaskevich
d8c64c1ff0 [AST/Sema] Intoduce nonisolated(nonsending) as a replacement for @execution(caller) 2025-04-16 10:06:08 -07:00
Pavel Yaskevich
4a973f7b4b [AST/Sema] Replace @execution(concurrent) with @concurrent 2025-04-16 10:06:08 -07:00
Pavel Yaskevich
873f562a4a [AST/Sema] Support for @concurrent attribute in type context 2025-04-16 10:06:08 -07:00
Pavel Yaskevich
8598ec670d [AST/ASTGen] Introduce @concurrent attribute to replace @execution(concurrent) spelling 2025-04-16 10:06:08 -07:00
Pavel Yaskevich
cd9741507b [Diagnostics] Adjust @execution(...) diagnostic to take DeclAttribute or StringRef
It has been decided to split the attribute into `@concurrent` and
`nonisolated(nonsending`. Adjusting diagnostics to accept the attribute
makes the transition easier.
2025-04-16 10:06:08 -07:00
Doug Gregor
271eebbb87 [Constraint solver] Delay Sendable on static method references involving possibly-nonsendable metatypes
Thank you, Pavel!

(cherry picked from commit 88d630446c)
2025-04-14 16:38:42 -07:00
Doug Gregor
b02a1a6ac5 Downgrade more sendability errors involving metatypes to warnings
(cherry picked from commit c7c152b14c)
2025-04-14 16:38:39 -07:00
Doug Gregor
b9ace6fb3c Downgrade sendability errors to warnings when they involve non-Sendable metatypes
The introduction of non-Sendable metatypes in Swift 6.2 (via SE-0470)
will break some existing Swift 6 code. Downgrade concurrency errors
involving non-Sendable metatypes to warnings until some future
language mode to ease the transition.

(cherry picked from commit 95b18d3482)
2025-04-14 16:38:37 -07:00
Doug Gregor
649cf9d656 [SE-0470] Teach @Sendable inference on static methods about non-sendable metatypes
The code that determines whether a reference to a static method (that
is not a call) assumed that metatypes were always Sendable. This is no
longer the case, so update this code to go through the normal Sendable
checking on the metatype.

(cherry picked from commit 3ed1d6c390)
2025-04-14 16:38:34 -07:00
Doug Gregor
678ea3df35 Fix deserialization assertion involving isolated conformances
(cherry picked from commit f09cdc2893)
2025-04-14 16:38:31 -07:00
Doug Gregor
65a7b189ba Fix crash involving captured-type checking for sendable metatypes
(cherry picked from commit e4f1b62c57)
2025-04-14 16:38:28 -07:00
Doug Gregor
5e29333d6b [SE-0470] Enable isolated conformances by default
The IsolatedConformances feature moves to a normal, supported feature.
Remove all of the experimental-feature flags on test cases and such.

The InferIsolatedConformances feature moves to an upcoming feature for
Swift 7. This should become an adoptable feature, adding "nonisolated"
where needed.

(cherry picked from commit 3380331e7e)
2025-04-14 16:38:22 -07:00
Doug Gregor
69758f6213 [SE-0470] Downgrade some isolated conformance-related errors to warnings in Swift 5
(cherry picked from commit e8b3065293)
2025-04-14 16:36:57 -07:00
Doug Gregor
49ebfcbab2 Move generic signature check for isolated conformances into GenericSignatureImpl
This is going to need a proper implementation in the requirement
machine. For the moment, provide a slightly-less-broken implementation
but leave a test case where we incorrectly accept racey code.

(cherry picked from commit 92774e0a3c)
2025-04-14 16:36:54 -07:00
Hamish Knight
9fccfa6255 [Sema] Try limit kicking interface type in filterForEnumElement
Kicking the interface type request of the base decl here is wrong
if the decl is e.g a `self` capture in a closure, since we'll be in
the middle of type-checking the closure. I'm planning on properly
fixing this by folding the lookup into the constraint system, but for
now let's at least avoid kicking the request if we don't have an enum
case or enum var. That at least prevents it from affecting cases where
e.g you're pattern matching against a property in a class.

We could potentially tighten up the checking here even further, but
that could potentially impact source compatibility for ambiguous
cases. I'd like to keep this patch low risk, and then deal with any
fallout as part of the pattern type-checking work.

rdar://146952007
2025-04-10 18:46:40 +01:00
Slava Pestov
3a4215d1a5 Merge pull request #80536 from slavapestov/fix-issue-79367-6.2
[6.2] Sema: Fix regression with 'Failure' type witness inference hack
2025-04-08 11:26:48 -04:00
Allan Shortlidge
cb444b6229 Merge pull request #80567 from tshortli/module-import-visibility-fixes-6.2
[6.2] `MemberImportVisibility` bug fixes
2025-04-08 07:13:19 -07:00
Allan Shortlidge
92346384e4 Merge pull request #80614 from tshortli/require-explicit-availability-conformances-6.2
[6.2] Sema: Fix another `-require-explicit-availability` regression
2025-04-08 04:51:55 -07:00
Hamish Knight
ead547d989 Merge pull request #80605 from hamishknight/macro-arg-apply-6.2
[6.2] [CS] Make sure macro arguments go through `coerceCallArguments`
2025-04-08 11:51:42 +01:00
Anthony Latsis
2784fe6cb0 Merge pull request #80602 from AnthonyLatsis/ammanita-pantherina-6.2
[6.2][NFC] Sema: Factor out derived conformance sources into subdirectory
2025-04-08 06:49:18 +01:00
Allan Shortlidge
3f825591de Sema: Fix another -require-explicit-availability regression.
Extensions that extend non-public types should never be required to have
explicit availability, even if they declare conformances to public protocols.

Resolves rdar://148697770.
2025-04-07 14:57:13 -07:00
Hamish Knight
ce260ae75a [CS] Make sure macro arguments go through coerceCallArguments
Previously we would avoid rewriting the arguments in CSApply, but
that can result in incorrect behavior in MiscDiagnostics passes, e.g
incorrectly treating all closure arguments as escaping. Make sure
we rewrite the arguments as we would in regular type-checking.

rdar://148665502
2025-04-07 19:00:27 +01:00
Anthony Latsis
b1c4ead097 [NFC] Sema: Factor out derived conformance sources into subdirectory 2025-04-07 18:38:32 +01:00
Hamish Knight
6d287beb93 [Sema] Remove redundant check
The initializer for a lazy property is always subsumed, so we should
have already bailed.
2025-04-07 17:29:36 +01:00
Hamish Knight
999169e7ae [Sema] Requestify PatternBindingDecl capture computation
Introduce `PatternBindingCaptureInfoRequest`, and kick it after
contextualizing a property initializer. This ensures it gets run
for stored properties added by macro expansions.

rdar://143429551
2025-04-07 17:29:36 +01:00
Allan Shortlidge
746cddc330 Sema: Improve MemberImportVisibility diags for for-in loops.
Ensure that source locations are attached to the implicit calls to
`makeIterator()` and `next()` for diagnostics.

Partially resolves rdar://144535697.
2025-04-06 09:53:18 -07:00
Slava Pestov
69ebffbace Sema: Fix regression with 'Failure' type witness inference hack
We have a special hack to infer the 'Failure' type witness in
'AsyncIteratorProtocol' by considering the type of 'next()'
witness.

In eaf06eae0e I added a check to
fix some assertions that could happen if 'next()' was witnessed
by a declaration in a protocol extension or superclass, which
has a different generic signature.

However my check was too narrow, because it also prohibited
this form of inference when 'next()' was in a different
extension of the same nominal type.

Allow this again.

Fixes https://github.com/swiftlang/swift/issues/79367.
Fixes rdar://problem/145341658.
2025-04-04 10:28:17 -04:00
Hamish Knight
918d4b54cf Merge pull request #80461 from hamishknight/in-sequence
[ASTScope] Allow `try` in unfolded sequence to cover following elements
2025-04-03 20:23:51 +01:00
Allan Shortlidge
5cd5f31c9c Sema: Fix a regression in -require-explicit-availability diagnostics.
The changes in https://github.com/swiftlang/swift/pull/80040 caused the
compiler to start diagnosing extensions containing only members that are
either `@_spi`, `@_alwaysEmitIntoClient`, or unavailable when the
`-require-explicit-availability` flag is passed. Extensions should not be
diagnosed when they only contain members that would not be diagnosed
themselves.

Resolves rdar://148275432.
2025-04-02 17:12:38 -07:00
Joe Groff
562d7dc832 Merge pull request #80438 from jckarter/substitute-away-escapable-lifetime-deps
Type substitution eliminates dependencies with Escapable targets.
2025-04-02 16:56:54 -07:00
Pavel Yaskevich
f61a3c941b Merge pull request #80443 from xedin/rdar-148256978
[CSBindings] Avoid delaying leading-dot inference only if chain is di…
2025-04-02 11:08:44 -07:00
Allan Shortlidge
192da54004 Merge pull request #80450 from tshortli/fix-parentheses-warning 2025-04-02 10:40:17 -07:00