Commit Graph

21519 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
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
Andrew Trick
4fa7e136e9 Add Feature: NonescapableAccessorOnTrivial
To guard the new UnsafeMutablePointer.mutableSpan APIs.

This allows older compilers to ignore the new APIs. Otherwise, the type checker
will crash on the synthesized _read accessor for a non-Escapable type:

    error: cannot infer lifetime dependence on the '_read' accessor because 'self'
    is BitwiseCopyable, specify '@lifetime(borrow self)'

I don't know why the _read is synthesized in these cases, but apparently it's
always been that way.

Fixes: rdar://153773093 ([nonescapable] add a compiler feature to guard
~Escapable accessors when self is trivial)

(cherry picked from commit cc357f4f32)
2025-06-20 16:01:41 -07:00
Slava Pestov
de1d2905fd Sema: Relax diagnosis of implied marker protocol conformances with mismatched availability
This logic was introduced in https://github.com/swiftlang/swift/pull/75135.
The intent was to prevent an implied conformance from overriding an
existing unavailable one, for example in the case of Sendable. Let's
relax this check a bit to only diagnose if the mismatch is in the
unconditional availability, and not OS version.

Fixes rdar://142873265.
2025-06-17 14:43:03 -04:00
Gábor Horváth
7575b1fead [6.2][cxx-interop] Shared references are considered safe
Explanation: Shared references imported from C++ were not considered
safe. This is a widely used feature and this fix is blocking the users
from adopting strictly memory safe Swift.
Issue: rdar://151039766
Risk: Low, the fix only changes what declarations are considered safe.
Testing: Regression test added.
Original PR: #82203
Reviewer: @egorzhdan @fahadnayyar
2025-06-17 18:13:49 +01:00
Andrew Trick
b15d308053 LifetimeDependence type check: infer trivial _read accessor
This fixes a small oversight in the type checker's LifetimeDependence
inference. Allow inference on _read accessors even when 'self' is a trivial
type. This is needed because the compiler synthesizes a _read accessor even when
the user defines a getter (this is probably a mistake, but it's easire to just
fix inference at this point). There is no workaround because it defining both a
getter and '_read' is illegal!

    extension UnsafeMutableRawBufferPointer {
      var mutableBytes: MutableRawSpan {
        @_lifetime(borrow self)
        get {
          unsafe MutableRawSpan(_unsafeBytes: self)
        }
      }
    }

Fixes rdar://153346478 (Can't compile the
UnsafeMutableRawBufferPointer.mutableBytes property)

(cherry picked from commit 125a0862a9)
2025-06-16 10:50:57 -07:00
Slava Pestov
acb53d2050 Merge pull request #82132 from slavapestov/bind-extensions-macro-6.2
[6.2] Sema: Don't expand macros when binding extensions
2025-06-14 12:14:10 -04:00
Andrew Trick
a358403059 Merge pull request #82217 from atrick/62-lifedep-trivial-inout
[6.2] Update tests after disallowing @_lifetime(borrow) for inout
2025-06-13 19:35:06 -07:00
Slava Pestov
0466387609 AST: Add excludeMacroExpansions parameter to computeExtendedNominal() 2025-06-13 16:00:16 -04:00
John Hui
a2bd6cafd9 Merge pull request #82171 from j-hui/j-hui/6.2/jump-to-def-for-macro-expanded-clang-imports
🍒 [6.2] [SourceKit] Support location info for macro-expanded Clang imports
2025-06-13 04:10:37 -07:00
John Hui
c94955b571 [SourceKit] Support location info for macro-expanded Clang imports
Currently, when we jump-to-definition for decls that are macro-expanded
from Clang imported decls (e.g., safe overloads generated by
@_SwiftifyImport), setLocationInfo() emits a bongus location pointing to
a generated buffer, leading the IDE to try to jump to a file that does
not exist.

The root cause here is that setLocationInfo() calls getOriginalRange()
(earlier, getOriginalLocation()), which was not written to account for
such cases where a macro is generated from another generated buffer
whose kind is 'AttributeFromClang'.

This patch fixes setLocationInfo() with some refactoring:

-   getOriginalRange() is inlined into setLocationInfo(), so that the
    generated buffer-handling logic is localized to that function. This
    includes how it handles buffers generated for ReplacedFunctionBody.

-   getOriginalLocation() is used in a couple of other places that only
    care about macros expanded from the same buffer (so other generated
    buffers not not relevant). This "macro-chasing" logic is simplified
    and moved from ModuleDecl::getOriginalRange() to a free-standing
    function, getMacroUnexpandedRange() (there is no reason for it to be
    a method of ModuleDecl).

-   GeneratedSourceInfo now carries an extra ClangNode field, which is
    populated by getClangSwiftAttrSourceFile() when constructing
    a generated buffer for an 'AttributeFromClang'. This could probably
    be union'ed with one or more of the other fields in the future.

rdar://151020332
(cherry picked from commit 44aba1382d)
2025-06-12 18:24:04 -07:00
Andrew Trick
efa276a62c Disallow @_lifetime(borrow) for trivial 'inout' arguments
@_lifetime(borrow holder) // ERROR
    func test(holder: inout Holder) -> NE

Fixes rdar://153040843 ([nonescapable] disallow @_lifetime(borrow)
for trivial 'inout' arguments)

(cherry picked from commit a38925493b)
2025-06-12 16:03:55 -07:00
Andrew Trick
f0e9d98055 [NFC] LifetimeDependence: fix indentation
To avoid diff/merge confusion.

(cherry picked from commit 9dd88e277e)
2025-06-12 16:03:55 -07:00
Devin Coughlin
5c4066017a Merge pull request #82106 from swiftlang/gaborh/ambiguous-overloads-on-6.2
[6.2][cxx-interop] Support _LIBCPP_PREFERRED_OVERLOAD
2025-06-12 10:17:35 -07:00
Meghana Gupta
58b714b968 Introduce a new suppressible experimental feature to guard @_lifetime 2025-06-11 08:03:40 -07:00
Meghana Gupta
a9b831788d Update spelling for representing lifetime dependencies to @_lifetime 2025-06-11 08:03:39 -07:00
Gábor Horváth
2327cec99f [6.2][cxx-interop] Fix crash in ASTMangler triggered by UsingShadowDecls
Explanation: We did not handle this declaration kind. This PR makes sure we
mangle it the same way we do for the target declaration.
Issue: rdar://152841420
Risk: Low, the fix is small, localized, and straightforward.
Testing: Regression test added.
Original PR: #82144
Reviewer: @egorzhdan @hnrklssn @j-hui
2025-06-11 11:37:27 +01:00
Allan Shortlidge
f774d4a3b3 Merge pull request #82151 from tshortli/rhombicuboctahedron-6.2
[6.2] Upstream support for the Xcode 26 SDKs
2025-06-10 21:57:12 -07:00
Slava Pestov
4b3943a1fc Merge pull request #82131 from slavapestov/get-superclass-for-decl-6.2
[6.2] AST: More robust TypeBase::getSuperclassForDecl()
2025-06-10 18:38:43 -04:00
Allan Shortlidge
6882649397 AST: Canonicalize version numbers in @_originallyDefinedIn attributes. 2025-06-10 08:22:38 -07:00
Allan Shortlidge
d775fddf36 AST: Warn for non-existent platform versions in @available attributes. 2025-06-10 08:22:38 -07:00
Allan Shortlidge
003576c613 AST: Re-map macOS 16 aligned availability versions to 26.
- watchOS 12 -> 26
- visionOS 3 -> 26
- macos 16 -> 26
- iOS 19 -> 26
- tvOS 19 -> 26

The version numbers for `if #available(...)` queries are intentionally not
re-mapped.
2025-06-10 08:22:38 -07:00
Alex Hoppen
3780aba7df Merge pull request #82054 from ahoppen/6.2/dont-verify-mangle
[6.2][Indexing] Don't verify mangling of USRs
2025-06-10 13:58:38 +02:00
Pavel Yaskevich
3ed55703e1 Merge pull request #82036 from xedin/rdar-151911135-6.2
[6.2][Concurrency] Fix `SendableMetatype` conformance failures to behave l…
2025-06-09 21:26:55 -07:00
Slava Pestov
27a2396a2f AST: More robust TypeBase::getSuperclassForDecl()
This can return ErrorType if the AST is invalid.

A handful of callers handle the ErrorType result, but most don't,
blindly assuming the result is always a nominal type. This resulted
in a crash in at least one test case.

Lift the burden from callers by always returning a nominal type here.
2025-06-09 20:23:12 -04:00
Gábor Horváth
e700c6b8d4 [6.2][cxx-interop] Support _LIBCPP_PREFERRED_OVERLOAD
Explanation: Some functions are implemented both in libc and libc++.
Clang uses the enable_if attribute to resolve otherwise ambiguous
functions calls. This PR makes the name lookup aware of this attribute.
Issue: rdar://152192945
Risk: Low, only C/C++ APIs with enable_if attributes are affected.
Testing: Regression test added.
Original PR: #82019
Reviewer: @hnrklssn
2025-06-09 13:40:34 +01:00
Allan Shortlidge
f5bae411ca AST: Diagnose unrecognized platforms as errors with CustomAvailability enabled.
When the CustomAvailability experimental feature is enabled, make it an error
to specify an unrecognized availability domain name. Also, add these
diagnostics to a diagnostic group so that developers can control their behavior
when they are warnings.

Resolves rdar://152741624.
2025-06-06 22:44:12 -07:00
Slava Pestov
fa4c30ed6f Merge pull request #82051 from slavapestov/fix-rdar127120469-6.2
[6.2] ASTPrinter: Fix printing of let properties inside @objc @implementation extensions
2025-06-06 14:11:38 -04:00
Pavel Yaskevich
47925188ba [Concurrency] Fix SendableMetatype conformance failures to behave like Sendable ones
No warnings with minimal checking, warnings with `strict-concurrency=complete` and
if declaration is `@preconcurrency` until next major swift version.

Resolves: rdar://151911135
Resolves: https://github.com/swiftlang/swift/issues/81739
(cherry picked from commit e326cd00930ff042ba1595e7793af9aaf0208b97)
2025-06-06 08:51:05 -07:00
Alex Hoppen
558644f7fa [Indexing] Don't verify mangling of USRs
Verifying USR mangling adds ~30% overhead to indexing times. Since an incorrect USR mangling doesn't result in a correctness issue at the same level as a miscompile, save those 30% in non-assert builds.
2025-06-06 08:37:43 +02:00
Slava Pestov
2c53876c19 ASTPrinter: Fix printing of let properties inside @objc @implementation extensions
A `let` here is really just a `var` with a `{ get }`.

Fixes rdar://problem/127120469.
2025-06-06 00:25:02 -04:00
Allan Shortlidge
339ab824a8 AST: Fix iOS -> visionOS version remap for @backDeployed attrs.
The version remapping for `@backDeployed` regressed due to a bug introduced by
https://github.com/swiftlang/swift/pull/81922.

Also, fix some visionOS tests that have gotten out of date because we don't
seem to be running them in CI.

Resolves rdar://152542983.
2025-06-05 19:20:38 -07:00
Pavel Yaskevich
608a37ad04 Merge pull request #81997 from xedin/using-for-default-isolation-in-file-context-6.2
[6.2][AST/Sema] SE-0478: Implement using declaration under an experimental flag
2025-06-05 00:44:21 -07:00
Pavel Yaskevich
e5501d485a [AST] NFC: Capitalize UsingSpecifier::nonisolated for consistency
(cherry picked from commit 21ec5924f7)
2025-06-04 13:22:34 -07:00
Pavel Yaskevich
d3f8fd8fd7 [AST/Sema] Hide using declaration behind DefaultIsolationPerFile experimental feature
(cherry picked from commit c246a7a372)
2025-06-04 13:22:32 -07:00
Pavel Yaskevich
4f88004fc0 [AST] Don't print using declarations in swift interfaces
These declarations are effectively `fileprivate` at the moment
and should appear in swift interfaces.

(cherry picked from commit ad71e07cae)
2025-06-04 13:21:58 -07:00
Pavel Yaskevich
7d18588f93 [Concurrency] Add a request to retrieve default isolation of a file
The default isolation is computed based on `using` declaration
found in the file, if any.

(cherry picked from commit 36b77116bd)
2025-06-04 13:21:56 -07:00