Commit Graph

103252 Commits

Author SHA1 Message Date
Sima Nerush
a0b0a0704d [Concurrency] Make sure to still infer global actor if the conformance kind is explicit.
(cherry picked from commit 7e42a19187)
2025-06-17 15:29:18 -07:00
Sima Nerush
0ed6c1cf41 [Concurrency] Look for explicit 'nonisolated' when getting isolation from protocol conformances.
(cherry picked from commit 4fca62a771)
2025-06-17 15:29:18 -07:00
Hamish Knight
f95eb6bf48 [Sema] Tighten up function call check in resolveKeyPathExpr
Check for `CallExpr` instead of `ApplyExpr`, we don't support
arbitrary postfix operators in key paths.
2025-06-17 23:07:55 +01: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
d242750ac9 Merge pull request #82269 from atrick/62-infer-implicit-read
[6.2] LifetimeDependence type check: infer trivial _read accessor
2025-06-17 09:55:05 -07:00
Hamish Knight
61e0326b7f [Sema] Add null check in createMemberwiseInitParameter
The property wrapper initializer info may be null if e.g we had a
request cycle, just use the property's interface type in that case.

rdar://82899428
2025-06-17 17:31:24 +01:00
nate-chandler
7bb7326fd2 Merge pull request #82282 from nate-chandler/cherrypick/release/6.2/rdar151726387
6.2: [IRGen] Fix FixedArray of fixedSize 1 element addressing
2025-06-17 08:41:28 -07:00
Joe Groff
f765d28999 SILGen: Handle struct fields and addressors as addressable storage.
When accessing stored properties out of an addressable variable or parameter
binding, the stored property's address inside the addressable storage of the
aggregate is itself addressable. Also, if a computed property is implemented
using an addressor, treat that as a sign that the returned address should be
used as addressable storage as well. rdar://152280207
2025-06-17 07:58:59 -07:00
Nate Chandler
2cf7ef5fdc [IRGen] Fix FixedArray of fixedSize 1 elt addring.
When a `FixedArray`'s fixed size is 1, it looks like `[1 x %Ty]`. Given
an array's address, performing an operation on each element's address
entail's indexing into the array to each element's index to produce an
element's address for each index.  That is true even when the array
consists of a single element.  In that case, produce an address for that
single element by indexing to index 0 into each passed-in array.

rdar://151726387
2025-06-16 20:34:22 -07:00
Pavel Yaskevich
cd83345651 [Concurrency] NonisolatedNonsendingByDefault: Don't attempt to migrate $ prefixed declarations
These are special declarations that are synthesized by the compiler
or a macro and warnings about them are non-actionable.

(cherry picked from commit 17976c7775)
2025-06-16 13:44:02 -07:00
Pavel Yaskevich
93c955c4f9 [Concurrency] NonisolatedNonsendingByDefault: Don't attempt to migrate swift-testing test cases
The execution of these functions is controlled by the testing
framework and it's okay if their behavior changes when the feature
flag is enabled.

Resolves: rdar://152687527
(cherry picked from commit f2f5d234dc)
2025-06-16 13:44:02 -07: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
Hamish Knight
c1db12a0d4 Merge pull request #82239 from hamishknight/cod-cycle-6.2
[6.2] [Sema] Scale back CodingKeys hack in `TypeChecker::lookupUnqualifiedType`
2025-06-14 12:54:54 +01:00
Meghana Gupta
2bbc1c393c Merge pull request #82224 from meg-gupta/fixinlinercrashcp
[6.2] Fix an inliner crash when inlining begin_apply with scoped lifetime dependence
2025-06-13 23:06:36 -07: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
Dario Rexin
533e215f6f [IRGen] Emit null check before swift_conformsToProtocol for nullable metatypes
rdar://149882902

swift_conformsToProtocol does not properly handle nullptr values, which can currently be passed if the source type is an optional metatype. This change adds emission of a null check before calling the runtime function in these cases.
2025-06-13 17:00:49 -07:00
Meghana Gupta
d5b82a3b7c [6.2] Fix an inliner crash when inlining begin_apply with scoped lifetime dependence 2025-06-13 14:18:29 -07:00
Alastair Houghton
7fe3948c15 Merge pull request #82232 from al45tair/eng/PR-148168098-6.2
[IRGen] Don't use GOTPCREL relocations for x86 ELF.
2025-06-13 21:40:41 +01:00
Slava Pestov
a10cc92bf7 Sema: Try to bind extensions without expanding macros
Macro expansion can call typeCheckExpr(), which performs qualified
lookups. So if we expand macros while binding extensions, these
qualified lookups can fail because they cannot find members of
extensions that have not been bound yet.

To fix this, try binding extensions without performing macro
expansion first. If any extensions remain at the end, we fall back
to the old behavior, and try to bind them again, this time
performing macro expansion.

Fixes rdar://149798059.
2025-06-13 16:00:16 -04:00
Slava Pestov
0466387609 AST: Add excludeMacroExpansions parameter to computeExtendedNominal() 2025-06-13 16:00:16 -04:00
Slava Pestov
15f968f269 AST: Call setExtendedNominal() instead of cacheOutput(ExtendedNominalRequest...) 2025-06-13 16:00:16 -04:00
Hamish Knight
9ba1da9a51 [Sema] Scale back CodingKeys hack in TypeChecker::lookupUnqualifiedType
I previously added this hack to match the logic in
`TypeChecker::lookupUnqualified`, but it turns out that can introduce
request cycles for cases where `CodingKeys` is used in a generic
requirement for one of `Codable`'s potential value witnesses. Scale
back the hack such that it's only done when we get an initial empty
lookup result, ensuring we maintain source compatibility. Both these
lookup hacks should go away once we properly handle CodingKeys 
synthesis.

rdar://153096639
2025-06-13 19:56:02 +01:00
Pavel Yaskevich
c17d370158 Merge pull request #82219 from xedin/rdar-152687353-6.2
[6.2][Concurrency] NonisolatedNonsendingByDefault: Migration applies only to the current module declarations
2025-06-13 09:14:47 -07: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
Alastair Houghton
20df87c940 [IRGen] Don't use GOTPCREL relocations for x86 ELF.
Unforunately, x86 ELF linkers like to optimize GOTPCREL relocations by
replacing `mov` instructions that go via the GOT with `lea` instructions
that do not.

That would be fine, but they aren't very selective and will happily
perform this transformation in non-code sections if they think that
the bytes before a relocation look like a `mov` instruction.

This corrupts our metadata.

rdar://148168098
2025-06-13 10:25:56 +01:00
Hamish Knight
19bc18f064 Merge pull request #82152 from hamishknight/fix-nested-arenas-6.2 2025-06-13 08:01:57 +01:00
Gábor Horváth
9bf1d288f6 Merge pull request #82105 from swiftlang/gaborh/disable-non-aliased-instantiations-on-6.2
[6.2][cxx-interop] Only swiftify template instantiations behind typealiases
2025-06-13 04:21:55 +01:00
Devin Coughlin
1507bcd421 Merge pull request #82193 from hnrklssn/skip-bounds-safety-types2-6.2
Cherry-pick [ClangImporter] Look through bounds attributes for template matching #82076
2025-06-12 18:36:27 -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
Pavel Yaskevich
fe2db95851 Merge pull request #82209 from xedin/rdar-143581268-6.2
[6.2][TypeChecker] Remove `@_inheritActorContext` effect from synchronous types
2025-06-12 17:27:00 -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
Michael Gottesman
479dcd05de Merge pull request #82196 from gottesmm/release/6.2-151955519
[6.2] Change send-never-sendable of isolated partial applies to use SIL level info instead of AST info.
2025-06-12 13:09:52 -07:00
Michael Gottesman
eb8ef3fb09 Merge pull request #82082 from gottesmm/release/6.2-152596823
[6.2][silgen] Teach SILGen how to emit a forced dynamic member ref given nonisolated(nonsending) casts.
2025-06-12 13:08:06 -07:00
Gábor Horváth
4590d5551b [6.2][cxx-interop] Only swiftify template instantiations behind type aliases
Explanation: C++ template instantiations that are not behind type
aliases don't have corresponding Swift names that are both syntactically
and semantically valid types. This PR prevents generating swiftified
overloads for those types.
Issue: rdar://151422108
Risk: Low, we swiftify functions less often.
Testing: Regression test added.
Original PR: #81973
Reviewer: @hnrklssn
2025-06-12 19:05:36 +01:00
Gábor Horváth
5d243730b4 Merge pull request #82061 from swiftlang/gaborh/swiftify-initializers-on-6.2
[6.2][cxx-interop] Support Swiftifying C++ constructors
2025-06-12 19:01:26 +01:00
Pavel Yaskevich
c0984d2bf5 [Concurrency] NonisolatedNonsendingByDefault/NFC: Move 'same module' check higher
This is a follow-up to https://github.com/swiftlang/swift/pull/82173
which moves the check higher to make it an early exist.

(cherry picked from commit f0502c2257)
2025-06-12 10:42:32 -07:00
Pavel Yaskevich
20e086cdc7 [Concurrency] NonisolatedNonsendingByDefault: Migration applies only to the current module declarations
Prevent migration from handling declarations that come from a
module different from the current one, this is primarily a
problem for swiftinterfaces that can get rebuilt when the module
is imported by a model that has migration mode enabled.

Resolves: rdar://152687353
(cherry picked from commit bcd6caaea4)
2025-06-12 10:19:46 -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
Devin Coughlin
dd2f521d86 Merge pull request #82104 from swiftlang/gaborh/swiftify-private-on-6.2
[6.2][cxx-interop] Avoid swiftifying private and protected methods
2025-06-12 10:08:29 -07:00
Pavel Yaskevich
36f376f50c [TypeChecker] Remove @_inheritActorContext effect from synchronous types
The compiler would previously accept use of `@_inheritActorContext`
on a parameter with a synchronous function type which wasn't marked
as `@isolated(any)`. That is incorrect because in such cases the
attribute has no effect and furthermore would prevent Sendable
and isolation checking.

Uses like that are currently diagnosed by the type-checker but we
need to go one step further and remove the effect in such case to
prevent invalid uses.

Resolves: rdar://143581268
(cherry picked from commit dbe19b6d5f)
2025-06-12 08:54:12 -07:00
Michael Gottesman
d6891a7395 Change send-never-sendable of isolated partial applies to use SIL level info instead of AST info.
The reason I am doing this is that we have gotten reports about certain test
cases where we are emitting errors about self being captured in isolated
closures where the sourceloc is invalid. The reason why this happened is that
the decl returned by getIsolationCrossing did not have a SourceLoc since self
was being used implicitly.

In this commit I fix that issue by using SIL level information instead of AST
level information. This guarantees that we get an appropriate SourceLoc. As an
additional benefit, this fixed some extant errors where due to some sort of bug
in the AST, we were saying that a value was nonisolated when it was actor
isolated in some of the error msgs.

rdar://151955519
(cherry picked from commit f31236931b)
2025-06-11 14:02:01 -07:00
Henrik G. Olsson
96f0ab2068 Merge pull request #82076 from hnrklssn/skip-bounds-safety-types2
When instantiating templated functions with pointers to the templated type, the ClangImporter does not strip type sugar. This strips type sugar for bounds attributes, to make sure that they import the same regardless of whether they are parsed or not.

rdar://151041990
(cherry picked from commit 00afb8ba81)
2025-06-11 21:46:09 +02:00
susmonteiro
862efcf3a0 [cxx-interop] Support for printing C++ foreign references
Adds support for printing a C++ foreign reference in Swift.

Also skips metadata of private fields in C++ records imported as Swift classes, following up on #81035

(cherry-picked from 848fad0021)
2025-06-11 17:13:01 +01: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
Henrik G. Olsson
6e6a57b0e6 Merge pull request #82145 from hnrklssn/swiftify-sizedby-6.2
Cherry-pick "[Swiftify] Support __sized_by on byte-sized pointee types" to release/6.2
2025-06-11 08:04:50 +02:00