Commit Graph

103370 Commits

Author SHA1 Message Date
Doug Gregor
dc27da053c [SE-0371] Back-deploy support for main-actor-isolated deinit
When targeting a platform that predates the introduction of isolated
deinit, make a narrow exception that allows main-actor-isolated deinit
to work through a special, inlineable entrypoint that is
back-deployed. This implementation

  1. Calls into the real implementation when available, otherwise
  2. Checks if we're on the main thread, destroying immediately when
we are, otherwise
  3. Creates a new task on the main actor to handle destruction.

This implementation is less efficient than the implementation in the
runtime, but allows us to back-deploy this functionality as far back
as concurrency goes.

Fixes rdar://151029118.
2025-06-30 17:40:00 -07:00
Doug Gregor
96583f1c6c [SE-0470] Check uses of isolated conformances in collection literals
Fixes rdar://151646584.
2025-06-30 16:08:17 -07:00
Konrad `ktoso` Malawski
9c9c8b6408 Merge pull request #82612 from ktoso/pick-wiup-cleanup-mergeconflict-potential 2025-07-01 07:25:14 +09:00
Daniil Kovalev
a86e717991 [AutoDiff] Use LinkEntity::SecondaryPointer for diff witness
If `LinkEntity::isTypeKind()` is true, `IRGenModule::getAddrOfLLVMVariable`
assumes that we can safely call `LinkEntity::getType()`, which does
`reinterpret_cast` of `LinkEntity::Pointer` to `TypeBase *`. However, for SIL
differentiability witness, the pointer has `SILDifferentiabilityWitness *`
type, which is not derived from `TypeBase`. So, such a cast is not allowed.

Just as with `ProtocolWitnessTableLazyAccessFunction` and
`ProtocolWitnessTableLazyCacheVariable` link entity kinds (which are
also type kinds), we should use `SecondaryPointer` instead of `Pointer` for
storing payload here, while setting `Pointer` to `nullptr`.

(cherry picked from commit 77a3873448)
2025-06-30 15:18:55 -06:00
Pavel Yaskevich
a651d020d8 [Concurrency] Fix a crash caused by misuse of isolated modifier
Adjust isolation checking to handle misused `isolated` attribute
and let attribute checker property diagnose it.

Resolves: rdar://148076903
Resolves: https://github.com/swiftlang/swift/issues/80363
(cherry picked from commit 358067917e)
2025-06-30 13:09:32 -07:00
Joe Groff
f299c6a856 Merge pull request #82344 from jckarter/addressable-for-dependencies-vw-flag-6.2
[6.2] Add an "addressable for dependencies" flag to value witness flags.
2025-06-30 12:54:25 -07:00
Adrian Prantl
9b67659a21 Merge pull request #82591 from swiftlang/dl/IRGen-Emit-objc-type-encoding-for-ivars
[6.2] IRGen: Emit objc type encoding for ivars
2025-06-30 12:50:08 -07:00
Hamish Knight
c74b7a5e75 Merge pull request #82617 from hamishknight/solve-escape-6.2
[6.2] [CS] Fix a couple of use-after-frees
2025-06-30 20:10:39 +01:00
Henrik G. Olsson
9de099a4b0 Merge pull request #81855 from hnrklssn/swiftify-availability-check-sdk
[Swiftify] Adjust _SwiftifyImport invocation to align with the signature

(cherry picked from commit e9ba8f8a03)
2025-06-30 12:02:55 -07:00
Henrik G. Olsson
8db1ad6222 Cherry-pick [Swiftify] Don't import counted_by with suffixed integer literals (#82469) (#82594)
Integer literal expressions with types that are not of type `int` are
printed with a suffix to indicate the type (e.g. `123U` or `456L` for
`unsigned` and `long`). This is not valid syntax for integer literals in
Swift, so until we fully translate the count expr syntax to Swift we
need to avoid importing these count expressions.

Also fixes some -Werror related stuff in test cases.

rdar://154141719
(cherry picked from commit 374658a)
2025-06-30 11:58:55 -07:00
Steven Wu
bf32a8bb14 [ScanDependencies] Fix a bug in rewrite from #81454
When improving the speed of dependency scanning when the new clang API
to speed up bridging, some unintended change was introduced. This
restore the scanner to the behavior before #81454

rdar://153851818
(cherry picked from commit cebe173ada)
2025-06-30 10:51:42 -07:00
Pavel Yaskevich
44a43df76b Merge pull request #82580 from xedin/rdar-153083848-6.2
[6.2][CSFix] Fix `getConcurrencyFixBehavior` to account for non-decl overloads
2025-06-30 10:11:02 -07:00
eeckstein
8c47b59d7d Merge pull request #82560 from eeckstein/fix-closure-specializer-6.2
[6.2] ClosureSpecializer: don't specialize captures of stack-allocated Objective-C blocks
2025-06-30 18:18:10 +02:00
Hamish Knight
f72c443ea6 [CS] Downgrade an assert for 6.2 2025-06-30 10:38:26 +01:00
Hamish Knight
dbc9dae27f [CS] Use the resolved type in NonOptionalUnwrapFailure::diagnoseAsError
Diagnostics can outlive the ConstraintSystem itself if we have a
diagnostic transaction for e.g `typeCheckParameterDefault`, make sure
we don't try to use a solver-allocated type as an argument.
2025-06-30 10:34:18 +01:00
Hamish Knight
2acacc9a74 [CS] Avoid escaping solver-allocated types in computeSubstitutions
Make sure we call `simplifyType` for the opened type bindings to
ensure holes get converted to UnresolvedType.

rdar://154553285
2025-06-30 10:34:18 +01:00
John McCall
06dec05473 Fix a bunch of bugs with the isolation of local funcs. Since we
use local funcs to implement `defer`, this also fixes several
bugs with that feature, such as it breaking in nonisolated
functions when a default isolation is in effect in the source file.

Change how we compute isolation of local funcs. The rule here is
supposed to be that non-`@Sendable` local funcs are isolated the
same as their enclosing context. Unlike closure expressions, this
is unconditional: in instance-isolated functions, the isolation
does not depend on whether `self` is captured. But the computation
was wrong: it didn't translate global actor isolation between
contexts, it didn't turn parameter isolation into capture isolation,
and it fell through for several other kinds of parent isolation,
causing the compiler to try to apply default isolation instead.
I've extracted the logic from the closure expression path into a
common function and used it for both paths.

The capture computation logic was forcing a capture of the
enclosing isolation in local funcs, but only for async functions.
Presumably this was conditional because async functions need the
isolation for actor hops, but sync functions don't really need it.
However, this was causing crashes with `-enable-actor-data-race-checks`.
(I didn't investigate whether it also failed with the similar
assertion we do with preconcurrency.) For now, I've switched this
to capture the isolated instance unconditionally. If we need to
be more conservative by either only capturing when data-race checks
are enabled or disabling the checks when the isolation isn't captured,
we can look into that.

Fix a bug in capture isolation checking. We were ignoring captures
of nonisolated declarations in order to implement the rule that
permits `nonisolated(unsafe)` variables to be captured in
non-sendable closures. This check needs to only apply to variables!
The isolation of a local func has nothing to do with its sendability
as a capture.

That fix exposed a problem where we were being unnecessarily
restrictive with generic local func declarations because we didn't
consider them to have sendable type. This was true even if the
genericity was purely from being declared in a generic context,
but it doesn't matter, they ought to be sendable regardless.

Finally, fix a handful of bugs where global actor types were not
remapped properly in SILGen.
2025-06-30 01:48:48 -04:00
John McCall
00463df058 [NFC] Encapsulate the parameter index of an ActorIsolation 2025-06-30 01:48:37 -04:00
Konrad 'ktoso' Malawski
6989f05abe Revert revert & fix distributed protocol and TBD handling
This reverts a revert that was done internally here https://stashweb.sd.apple.com/projects/DEVTOOLS/repos/swift/pull-requests/8697/overview
and corrects some issues with the reverted code while at it.

This fix is crucial to land for correctness and necessary to fix the
rdar://144568615 which had a fix submitted however that assumed that
THIS change also was present, so the fix submitted for 144568615 is
incomplete without this change as well.

This enables, and adds more TBD testing and was explicitly checked
against the GameKit reproducer project from rdar://144568615.

I will also upstream the necessary parts missing from OSS repo there so
we have alignment between all branches.
2025-06-30 11:47:29 +09:00
Doug Gregor
2f838823ee Merge pull request #82590 from DougGregor/no-main-actor-when-conforming-to-sendable-6.2
[6.2] [SE-0466 experimental amendment] Don't infer @mainactor on types conforming to Sendable
2025-06-28 05:57:50 -07:00
Doug Gregor
997a252da4 Merge pull request #82585 from DougGregor/nonisolated-deinit-availability-6.2
"nonisolated deinit" does not have back-deployment constraints
2025-06-28 03:27:38 -07:00
Hamish Knight
b50dcb1d0f Merge pull request #82570 from hamishknight/mac-n-cheese-6.2 2025-06-28 09:17:08 +01:00
Slava Pestov
f72260f85c Merge pull request #82586 from slavapestov/fix-issue-82160-6.2
[6.2] AST: Better cope with UnboundGenericType in TypeBase::getSuperclass()
2025-06-28 02:41:09 -04:00
Slava Pestov
68b9a52fc6 Merge pull request #82508 from slavapestov/warn-long-expression-type-checking-6.2
[6.2] Sema: Fix -warn-long-expression-type-checking when expression timer is disabled
2025-06-28 01:31:02 -04:00
nate-chandler
9b8e749027 Merge pull request #82573 from nate-chandler/cherrypick/release/6.2/rdar154407327
6.2: [DestroyAddrHoisting] Don't fold into read access.
2025-06-27 19:35:58 -07:00
Dave Lee
2d40d0e73d IRGen: Emit objc type encoding for ivars
ObjC ivar metadata has up to now emitted an empty string for the ivar's objc type encoding. Conversely, ObjC property metadata is emitted with an objc type encoding. This changes the compiler to also emit an objc type encoding for ivars.

The motivation for this change is for lldb to print ivars of classes declared in Objective-C but implemented in Swift, as defined in [SE-0436](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0436-objc-implementation.md). Without the presence of type encoding for ivars, lldb is unable to present to the user the ivars/properties of instances of such classes.

rdar://138569299
(cherry picked from commit ce7a3b39a4)
2025-06-27 16:24:49 -07:00
Doug Gregor
b5cce1f694 [SE-0466] Don't infer @MainActor on types conforming to Sendable
When the default isolation is main-actor, don't infer @MainActor
for a type that conforms to a protocol P in its primary definition when
P inherits from Sendable. Such types should remain non-isolated
because they're highly unlikely to be able to implement the P
conformance (which cannot be isolated).

Put this feature behind a new experimental flag,
SendableProhibitsMainActorInference.

Implements rdar://151029300
2025-06-27 15:14:26 -07:00
Slava Pestov
eabc8efb41 AST: Better cope with UnboundGenericType in TypeBase::getSuperclass()
Returning the unsubstituted superclass type is not correct,
because it may contain type parameters. Let's form a new
UnboundGenericType instead.

- Fixes https://github.com/swiftlang/swift/issues/82160.
- Fixes rdar://152989888.
2025-06-27 18:11:40 -04:00
Argyrios Kyrtzidis
0127926255 Merge pull request #82513 from sina-mahdavi/sina-mahdavi/cherry-pick-fix-llvm-prefix-mapping-calls
[6.2🍒] fix calls to llvm prefix mapping functions to use space-separated option format
2025-06-27 15:08:32 -07:00
Doug Gregor
2f6d21ebe6 "nonisolated deinit" does not have back-deployment constraints
Fixes rdar://150484159
2025-06-27 14:56:57 -07:00
Pavel Yaskevich
a381143495 [CSFix] Fix getConcurrencyFixBehavior to account for non-decl overloads
Adjust the downgrade check for static member references to
account for the fact that argument could come of a tuple or
some other reference that doesn't have a declaration associated
with it.

Resolves: rdar://153083848
(cherry picked from commit 3ae8d5680f)
2025-06-27 13:20:22 -07:00
Nate Chandler
9acdc921e0 [DestroyAddrHoisting] Don't fold into read access.
Narrowly fix a long-standing bug where destroy_addrs would be hoisted
into read access scopes, leaving the scope as a read despite the fact
that it modifies memory.  This is a problem for utilities which expect
access scopes to provide correct summaries.  Do this by refusing to fold
into access scopes which are marked `[read]`.

In a follow-up, we can reenable this folding, promoting each access
scope to a modify.  Doing so requires checking that there are no access
scopes which overlap with any of the access scopes which would be
promoted to modify.

rdar://154407327
2025-06-27 11:54:19 -07:00
Erik Eckstein
995264913f ClosureSpecializer: don't specialize captures of stack-allocated Objective-C blocks
Bail if the closure captures an ObjectiveC block which might _not_ be copied onto the heap, i.e optimized by SimplifyCopyBlock.
We can't do this because the optimization inserts retains+releases for captured arguments.
That's not possible for stack-allocated blocks.

Fixes a mis-compile
rdar://154241245
2025-06-27 20:08:51 +02:00
Hamish Knight
2add407ae8 [IDE] Bail from IDEInspectionSecondPassRequest if parserState is null
This shouldn't ever happen, but let's at least make sure we don't
crash.
2025-06-27 18:32:25 +01:00
Hamish Knight
0d10b579c9 [IDE] Avoid macro expansions in getEquivalentDeclContextFromSourceFile
Unfortunately haven't been able to come up with a test case for this,
but there seem to be cases where we're incorrectly picking up
a macro-expanded accessor from the cached AST when searching for the
original decl. Make sure we only consider decls that have been
written by the user.

rdar://151926231
2025-06-27 18:25:15 +01:00
Hamish Knight
4f40211259 [IDE] NFC: Use optional instead of ~0U 2025-06-27 18:25:15 +01:00
eeckstein
1aaae8514b Merge pull request #82559 from eeckstein/fix-semantic-arc-opt-6.2
[6.2] SemanticARCOpts: don't ignore dead-end blocks in the liverange analysis
2025-06-27 18:38:34 +02:00
Charles Zablit
35d94e7ac5 [demangling] add new wrapper API 2025-06-27 10:19:08 +01:00
Andrew Trick
92fd571d07 Merge pull request #82511 from atrick/62-inout-syntax
[6.2] Fix diagnostics for missing or invalid @_lifetime annotations on inout params
2025-06-26 23:33:16 -07:00
Doug Gregor
5373f52c40 Merge pull request #82546 from DougGregor/silgen-skip-isolated-deinit-6.2
[6.2] [SILGen] Ensure that we don't emit a skipped isolated deinit
2025-06-26 23:28:46 -07:00
Xi Ge
566a98dbeb Merge pull request #82544 from nkcsgexi/153683760-6.2
[6.2] ABI checker: drop usage of AllowDeserializingImplementationOnly
2025-06-26 22:18:48 -07:00
Slava Pestov
892e555310 Merge pull request #82543 from slavapestov/fix-rdar153730847-6.2
[6.2] ASTDemangler: Round-trip @isolated @sil_implicit_leading_param parameter attributes
2025-06-27 01:08:48 -04:00
Erik Eckstein
728f37abf0 SemanticARCOpts: don't ignore dead-end blocks in the liverange analysis
This can result in wrong ARC optimizations in dead-end blocks.
Fixes a SIL verification error.

rdar://154356277
2025-06-27 07:03:23 +02:00
Doug Gregor
7fa6999dc1 [SILGen] Ensure that we don't emit a skipped isolated deinit
Fixes rdar://154373088 / issue #82523
2025-06-26 14:03:58 -07:00
Xi Ge
87687a292f ABI checker: drop usage of AllowDeserializingImplementationOnly
AllowDeserializingImplementationOnly was historically added as a defensive
check against deserailzation issues introduced by @implementationOnly imports.
It's no longer specified by other tools, thus the ABI checker should drop
it as well.

rdar://153683760
2025-06-26 13:40:27 -07:00
Andrew Trick
0b0dbd9ee0 Diagnostic note for invalid @_lifetime annotations on inout params
Users commonly try to write a lifetime dependency on an 'inout' parameters as:

    @_lifetime(a: &a)
    func f_inout_useless(a: inout MutableRawSpan) {}

This is useless. Guide them toward what they really wanted:

    @_lifetime(a: copy a)

Fixes rdar://151618856 (@lifetime(..) gives inconsistent error messages)

(cherry picked from commit 87f2510a27)
2025-06-26 12:58:40 -07:00
Andrew Trick
102e5ecee1 Fix a compiler crash with '@'_lifetime(inout x), add diagnostic
This is a common mistake made more common be suggestions of existing diagnostic
that tell users not to use a 'copy' dependency.

Report a diagnostic error rather than crashing the compiler. Fix the diagnostic
output to make sense relative to the source location.

Fixes rdar://154136015 ([nonescapable] compiler assertion with @_lifetime(x: inout x))

(cherry picked from commit 080b68292d)
2025-06-26 12:58:40 -07:00
Andrew Trick
fcbcc8c1e4 Fix misleading Lifetime diagnostics for inout parameters
Correctly diagnose this as:
"invalid use of inout dependence on the same inout parameter

    @_lifetime(a: &a)
    func f_inout_useless(a: inout MutableRawSpan) {}

Correctly diagnose this as:
"lifetime-dependent parameter must be 'inout'":

    @_lifetime(a: borrow a)
    func f_inout_useless(a: borrowing MutableRawSpan) {}

(cherry picked from commit 05fa82b7a7)
2025-06-26 12:58:40 -07:00
Andrew Trick
e409752e00 Lifetime diagnostics: clarify @_lifetime usage for inout parameters
This comes up often when passing a MutableSpan as an 'inout' argument.  The
vague diagnostic was causing developers to attempt incorrect @_lifetime
annotations. Be clear about why the annotation is needed and which annotation
should be used.

(cherry picked from commit df0b81c88d)
2025-06-26 12:58:39 -07:00
Andrew Trick
52654095c1 Fix LifetimeDependence diagnostic formatting
Remove incorrectly nested single quotes from the suggested fix.

(cherry picked from commit 465d6a82e7)
2025-06-26 12:58:39 -07:00