Commit Graph

103370 Commits

Author SHA1 Message Date
Slava Pestov
7ed5d2bfc2 ASTDemangler: Round-trip @isolated @sil_implicit_leading_param parameter attributes
We sometimes mangle SILFunctionTypes when generating debug info
for reabstraction thunks, and these can have various exotic
parameter and result attributes. Two recent additions were
never plumbed through the mangler, causing assertion failures
when emitting debug info.

Fixes rdar://153730847.
2025-06-26 15:00:44 -04:00
Pavel Yaskevich
56383771fe [ClangImporter] SE-0463: Implement @Sendable inference exception for global actor isolated functions
Functions that are isolated to a global actor don't have completion
handlers imported as `@Sendable`. Main actor isolated functions with
completion handlers that are always called on the main actor is a
very common Objective-C pattern, and this carve out will eliminate
false positive warnings in the cases where the main actor annotation
is missing on the completion handler parameter.

Resolves: rdar://149811049
(cherry picked from commit ab227b401d)
2025-06-26 09:32:54 -07:00
Pavel Yaskevich
b2bcd21b10 [ClangImporter] Use DefaultsToSendable with completion handler parameter
This lifts the check for the feature flag up into the `importParameterType`
from `importType` and means that completion handler type for `async` variant
is no longer gains `@Sendable` attribute.

(cherry picked from commit 74471e858b)
2025-06-26 09:32:52 -07:00
Charles Zablit
e180d8bb38 Merge pull request #82479 from charles-zablit/charles-zablit/add-new-demangling-methods-to-6.2
🍒 [demangling] add new methods to the NodePrinter to enable range tracking possibilities when demangling a name
2025-06-26 11:07:26 +01:00
Hamish Knight
8e0749eea2 Merge pull request #82498 from hamishknight/tic-tac-toe-6.2 2025-06-26 09:07:26 +01:00
Doug Gregor
3094c8cfa0 Merge pull request #82495 from DougGregor/effects-subst-parameter-packs-6.2
[6.2] [Effects] Ensure that we properly substitute function types in ByClosure checks
2025-06-25 21:27:14 -07:00
Slava Pestov
017be57e9b Sema: Fix -warn-long-expression-type-checking when expression timer is turned off
My change 983b75e1cf broke
-warn-long-expression-type-checking because now the
ExpressionTimer is not instantiated by default and that
entire code path is skipped.

Change it so that if -warn-long-expression-type-checking
is passed in, we still start the timer, we just don't
ever consider it to have 'expired'.

Fixes rdar://problem/152998878.
2025-06-25 22:07:56 -04:00
Sina Mahdavi
fabbbc87c8 [6.2🍒] fix calls to llvm prefix mapping functions to use space-separated option format 2025-06-25 16:48:50 -07:00
Doug Gregor
e744e35086 Merge pull request #82384 from slavapestov/implied-isolated-conformance-6.2
[6.2] Sema: Expand isolated conformance inference to consider conformances to inherited protocols
2025-06-25 15:36:39 -07:00
Hamish Knight
0c8468e0ee [SourceKit] Print backticks if needed in printDisplayName
Ensure we print raw identifier names with backticks for e.g the
document structure request.

rdar://152524780
2025-06-25 19:52:09 +01:00
Andrew Trick
54651d1b16 Merge pull request #82473 from atrick/62-explicit-init
[6.2] Disable surprising lifetime inference of implicit initializers
2025-06-25 11:32:40 -07:00
Doug Gregor
283cb60664 [Effects] Ensure that we properly substitute function types in ByClosure checks
We weren't substituting generic arguments into function types. In the
presence of parameter packs, this could mean that the parameter and
argument lists no longer match up, which would cause the effects
checker to prematurely bail out after treating this as "invalid" code.
The overall effect is that we would not properly check for throwing
behavior in this case, allowing invalid code (as in the example) and
miscompiling valid code by not treating the call as throwing.

Fixes rdar://153926820.
2025-06-25 10:12:51 -07:00
Pavel Yaskevich
9220e686b5 Merge pull request #82470 from xedin/rdar-154202375-6.2
[6.2][Concurrency] Global actor isolated conformances are only allowed to …
2025-06-25 08:58:57 -07:00
Pavel Yaskevich
10bd67630f Merge pull request #82471 from xedin/rdar-154221449-6.2
[6.2][CSSimplify] Narrow down tuple wrapping for pack expansion matching
2025-06-25 08:58:45 -07:00
Charles Zablit
e1a1609045 remove unused API 2025-06-25 13:13:36 +01:00
Charles Zablit
80fe2dce79 add new methods to the NodePrinter to enable range tracking possibilities when demangling a name 2025-06-25 13:13:23 +01:00
Charles Zablit
c31a07460a move NodePrinter declarations to a header 2025-06-25 13:12:03 +01:00
Andrew Trick
0839675e6d Merge pull request #82407 from atrick/62-fix-accessor-infer
[6.2] [nonescapable] remove '@_lifetime' requirement on implicit accessors
2025-06-25 00:57:45 -07:00
Pavel Yaskevich
36261876b6 Merge pull request #82459 from xedin/rdar-154010220-6.2
[6.2][CSSimplify] Prevent `missing call` fix from recording fixes while ma…
2025-06-24 20:51:17 -07:00
Slava Pestov
e78d7349d7 Merge pull request #82447 from slavapestov/fix-rdar152509409-6.2
[6.2] AST: Tweak ConformanceLookupTable::compareConformances() some more
2025-06-24 21:19:54 -04:00
Andrew Trick
78e8b5af50 Disable surprising lifetime inference of implicit initializers
Non-escapable struct definitions often have inicidental integer fields that are
unrelated to lifetime. Without an explicit initializer, the compiler would infer
these fields to be borrowed by the implicit intializer.

    struct CountedSpan: ~Escapable {
      let span: Span<Int>
      let i: Int

      /* infer: @lifetime(copy span, borrow i) init(...) */
    }

This was done because
- we always want to infer lifetimes of synthesized code if possible
- inferring a borrow dependence is always conservative

But this was the wrong decision because it inevitabely results in lifetime
diagnostic errors elsewhere in the code that can't be tracked down at the use
site:

    let span = CountedSpan(span: span, i: 3) // ERROR: span depends on the lifetime of this value

Instead, force the author of the data type to specify whether the type actually
depends on trivial fields or not. Such as:

    struct CountedSpan: ~Escapable {
      let span: Span<Int>
      let i: Int

      @lifetime(copy span) init(...) { ... }
    }

This fix enables stricter diagnostics, so we need it in 6.2.

Fixes rdar://152130977 ([nonescapable] confusing diagnostic message when a
synthesized initializer generates dependence on an Int parameter)

(cherry picked from commit 8789a686fed869e3cd7bc4e748a443e71df464e1)
2025-06-24 18:09:09 -07:00
Pavel Yaskevich
767dbc0d78 [CSSimplify] Narrow down tuple wrapping for pack expansion matching
Follow-up for https://github.com/swiftlang/swift/pull/82326.

The optional injection is only viable is the wrapped type is
not yet resolved, otherwise it's safe to wrap the optional.

(cherry picked from commit 4804f2131b)
2025-06-24 17:27:28 -07:00
Pavel Yaskevich
574537fc8a [Concurrency] Global actor isolated conformances are only allowed to override nonisolated.
Follow-up for https://github.com/swiftlang/swift/pull/79893.

More than one global actor isolated conformance at any level
creates a clash and conforming type should be inferred as `nonisolated`.

Resolves: rdar://154202375
(cherry picked from commit 2e1fe444a6)
2025-06-24 17:23:03 -07:00
Andrew Trick
d3002ed0b2 [nonescapable] remove '@_lifetime' requirement on implicit accessors
This avoids diagnostic errors on synthesized accessors, which are impossible for developers to understand.

Fixes rdar://153793344 (Lifetime-dependent value returned by generated accessor '_read')

(cherry picked from commit 855b3e4446)
2025-06-24 15:06:30 -07:00
Egor Zhdan
a686f323e5 Merge pull request #82420 from swiftlang/egorzhdan/6.2-namespace-printer-null-crash
🍒[cxx-interop] Fix printing of namespaces declared in bridging headers
2025-06-24 22:35:11 +01:00
Andrew Trick
2052d2c61e Fix MoveOnlyObjectCheckerPImpl::check() for mark_dependence.
Handle the presence of mark_dependence instructions after a begin_apply.

Fixes a compiler crash:
"copy of noncopyable typed value. This is a compiler bug. ..."

(cherry picked from commit 7a29d9d8b6)
2025-06-24 12:54:39 -07:00
Andrew Trick
4cd7f450a3 Fix MoveOnlyObjectCheckerPImpl::check() changed flag
Extract the special pattern matching logic that is otherwise unrelated to the
check() function. This makes it obvious that the implementation was failing to
set the 'changed' flag whenever needed.

(cherry picked from commit c41715ce8c)
2025-06-24 12:54:39 -07:00
Andrew Trick
1fa15f23fe Fix SILCombine of MarkDependenceInst.
Do not eliminate a mark_dependence on a begin_apply scope even though the token
has a trivial type.

Ideally, token would have a non-trivial Builtin type to avoid special cases.

(only relevant on 6.2)
2025-06-24 12:54:39 -07:00
Meghana Gupta
1d1f9b063f Merge pull request #82431 from meg-gupta/lifetimeenumcp
[6.2] Add lifetime dependencies on function types representing ~Escapable enum elements with ~Escapable payloads
2025-06-24 11:06:27 -07:00
Pavel Yaskevich
39a7138a0c [CSSimplify] Prevent missing call fix from recording fixes while matching types
We need to be very careful while matching types to test whether a
fix is applicable or not to avoid adding extraneous fixes and failing
the path early. This is a temporary workaround, the real fix would
be to let `matchTypes` to propagate `TMF_ApplyingFixes` down.

Resolves: rdar://154010220
Resolves: https://github.com/swiftlang/swift/issues/82397
(cherry picked from commit 7ecb1fd1db)
2025-06-24 09:49:02 -07:00
Allan Shortlidge
2371e1fec1 Merge pull request #82435 from tshortli/reorganize-availability-6.2
[6.2] SILGen: Reorganize some availability related code
2025-06-24 09:20:45 -07:00
Pavel Yaskevich
67449c91e4 Merge pull request #82432 from xedin/nonisolated_nonsending-fixes-6.2
[6.2][Concurrency] A few `nonisolated(nonsending)` fixes
2025-06-24 09:12:45 -07:00
Slava Pestov
e5af49a282 AST: Tweak ConformanceLookupTable::compareConformances() some more
If two conformances imply a conformance to the same marker
protocol, don't diagnose redundancy if they differ by
unavailability. Instead, allow the more available conformance
to win.

This allows declaring a type that conforms to a protocol
that inherits from SendableMetatype, followed by an
unavailable Sendable conformance on the same type.

Fixes rdar://152509409.
2025-06-23 22:57:05 -04:00
Doug Gregor
c251897278 Allow '@unsafe' on import declarations to silence '@preconcurrency' warning
'@preconcurrency' imports open up memory safety holes with respect to
Sendable, which are diagnosed under strict memory safety + strict
concurrency checking. Allow one to write '@unsafe' on those imports to
silence the diagnostic about it.
2025-06-23 19:12:24 -07:00
Dario Rexin
96d6eb87ee Merge pull request #82352 from drexin/wip-153681688-6.2
[6.2][IRGen] Fix placeholder logic for emission of conditionally inverted protocols
2025-06-23 18:22:26 -07:00
Allan Shortlidge
059688fa02 SILGen: Reorganize code related to availability.
NFC.
2025-06-23 15:57:17 -07:00
Allan Shortlidge
b1b1e00865 SILGen: Rename SILGenBackDeploy.cpp to SILGenAvailability.cpp.
NFC.
2025-06-23 15:57:16 -07:00
Pavel Yaskevich
61c480f852 [Concurrency] References to nonisolated(nonsending) properties don't leave caller's isolation
Make sure that referencing `nonisolated(nonsending)` properties,
especially through a witness is as not treated as leaving the
isolation domain of the caller.

Resolves: rdar://153922620
(cherry picked from commit 35a41ab9cf)
2025-06-23 13:58:18 -07:00
Pavel Yaskevich
c68a17b8c4 [Concurrency] Don't infer nonisolated(nonsending) on synchronous witnesses
If the requirement is `nonisolated(nonsending)` but witness is
synchronous, prevent actor isolation inference from requirements
because this isolation only applies to asynchronous declarations
at the moment.

Resolves: rdar://153680826
(cherry picked from commit a964282275)
2025-06-23 13:58:07 -07:00
Meghana Gupta
41881a85af Avoid circular reference errors by adding an early bailout for imported enums 2025-06-23 13:50:33 -07:00
Meghana Gupta
9604081c46 Serialize/deserialize lifetime dependencies on enum elements 2025-06-23 13:50:13 -07:00
Meghana Gupta
3e359e4774 Support lifetime dependence inference on enum elements 2025-06-23 13:48:57 -07:00
Meghana Gupta
8e5a047ae8 [NFC] Prepare LifetimeDependenceInfo to hold EnumElementDecl* 2025-06-23 13:48:39 -07:00
Slava Pestov
f9a6432ffd Sema: Expand isolated conformance inference to consider conformances to inherited protocols
Otherwise, if PDerived inherits from P and P's requirements are
witnessed by @MainActor-isolated members, we fail to infer
@MainActor isolation on the conformance to PDerived.

- Fixes https://github.com/swiftlang/swift/issues/82222.
- Fixes rdar://153219831.
2025-06-23 15:19:55 -04:00
Egor Zhdan
782f26e726 [cxx-interop] Fix printing of namespaces declared in bridging headers
If a C++ namespace has redeclarations in a bridging header, printing AST for the namespace would crash the compiler. This is because such a redeclaration would not have an owning Clang module, and the AST printer did not account for that.

This change fixes the crash.

rdar://151715540
(cherry picked from commit cc9c51deea)
2025-06-23 18:56:19 +01:00
Egor Zhdan
bf20dab48c Merge pull request #82185 from swiftlang/susmonteiro/6.2-class-metadata-private-fields
🍒 [cxx-interop] Support for printing C++ foreign references
2025-06-23 17:52:00 +01:00
Gábor Horváth
2f7ea38223 Merge pull request #82305 from swiftlang/gaborh/shared-references-are-safe-on-6.2
[6.2][cxx-interop] Shared references are considered safe
2025-06-23 18:48:10 +02:00
Gábor Horváth
70f1a0f9aa Merge pull request #82175 from swiftlang/gaborh/using-shadow-decl-mangling-on-6.2
[6.2][cxx-interop] Fix crash in ASTMangler triggered by UsingShadowDecls
2025-06-23 18:46:14 +02:00
Michael Gottesman
8f3c0aed52 Merge pull request #82388 from gottesmm/release/6.2-153082633
[6.2][silgen] Make async_Main compatible with calling nonisolated(nonsending) functions.
2025-06-23 09:40:08 -07:00
nate-chandler
99f3547e55 Merge pull request #82402 from jamieQ/6-2-copy-prop-ossa-dead-ends-build-time-fix
[6.2][SILOptimizer]: slow OSSA lifetime canonicalization mitigation
2025-06-23 01:02:47 -07:00