Commit Graph

45790 Commits

Author SHA1 Message Date
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
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
8514a4c297 Promote feature NonescapableAccessorOnTrivial to be non-experimental
This flag was not experimental for any good reason; it should always be
enabled. The flag only exists so we can introduce a new API:
UnsafeMutablePointer.mutableSpan. Supported compilers cannot handle the new API.

rdar://154247502 (Promote feature NonescapableAccessorOnTrivial to be
non-experimental)

(cherry picked from commit 3dc0e622bac5576bdb29ab343b46f6492dd4b9ff)
2025-06-24 18:53:27 -07: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
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
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
Meghana Gupta
3e359e4774 Support lifetime dependence inference on enum elements 2025-06-23 13:48:57 -07: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
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
Jamie
11525cabf8 [SILOptimizer]: slow OSSA lifetime canonicalization mitigation
OSSA lifetime canonicalization can take a very long time in certain
cases in which there are large basic blocks. to mitigate this, add logic
to skip walking the liveness boundary for extending liveness to dead
ends when there aren't any dead ends in the function.

Updates `DeadEndBlocks` with a new `isEmpty` method and cache to
determine if there are any dead-end blocks in a given function.

(cherry picked from commit 1f3f830fc7)
2025-06-22 18:08:06 -05: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
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
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
Mike Ash
1ce629e133 Merge pull request #82247 from mikeash/auth-code-function-begone-6.2
[6.2][Runtime] Remove redundant swift_auth_code_function, use existing swift_auth_code.
2025-06-16 11:23:44 -04: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
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
Mike Ash
fbda570183 [6.2][Runtime] Remove redundant swift_auth_code_function, use existing swift_auth_code.
rdar://153169049
(cherry picked from commit ec6a042831)
2025-06-13 18:50:37 -04: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
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
Hamish Knight
19bc18f064 Merge pull request #82152 from hamishknight/fix-nested-arenas-6.2 2025-06-13 08:01:57 +01: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
Meghana Gupta
1b34cbea4a Merge pull request #82146 from meg-gupta/cpunderscore
[6.2]  Update spelling for representing lifetime dependencies to @_lifetime
2025-06-12 05:25:46 -07:00
eeckstein
1848203b61 Merge pull request #82184 from eeckstein/fix-specializer-6.2
[6.2] GenericSpecializer: remove some kind of instructions if their operands become trivial after specialization
2025-06-12 06:56:08 +02:00
Konrad `ktoso` Malawski
85347b2020 Merge pull request #82180 from ktoso/pick-3aa28b4de9e4074e813cd3932f2aa52a6af415be 2025-06-12 13:48:34 +09:00
Erik Eckstein
0bdd827237 GenericSpecializer: remove some kind of instructions if their operands become trivial after specialization
Fixes a SIL verifier crash.

https://github.com/swiftlang/swift/issues/82093
rdar://152807200
2025-06-11 17:31:27 +02:00
Adrian Prantl
17095df87c Merge pull request #82109 from adrian-prantl/152743797-6.2
[RemoteInspection] Add a hook to process addresses before converting
2025-06-11 08:13:21 -07:00
Meghana Gupta
163d907e6d Downgrade use of @lifetime outside stdlib as a warning 2025-06-11 08:03:41 -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
Konrad 'ktoso' Malawski
b690384baf [Concurrency] Correct memory effect attributes of task_create
Without this, llvm would sometimes wrongly assume there's no indirect
accesses and the optimizations can lead to a runtime crash, by
optimizing away initializing options properly.

Resolves rdar://152548190
2025-06-11 22:05:17 +09: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
Steven Wu
15f9e0ecda Merge pull request #82069 from cachemeifyoucan/eng/PR-152441866-release
[6.2][CAS] Allow uncached job from CAS based dependency scanning
2025-06-10 11:24:44 -07:00
Pavel Yaskevich
27cd5eef15 Merge pull request #82114 from xedin/rdar-150689994-6.2
[6.2][Diagnostics] Correctly diagnose situations when immutable value is passed to `inout` parameter
2025-06-10 09:11:10 -07:00
Allan Shortlidge
aa1bce262c ModuleInterface: Canonicalize OS version numbers in loaded swiftinterfaces. 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
Hamish Knight
cc66fc886f [CS] Avoid solver-allocated inputs with typesSatisfyConstraint
Escaping solver-allocated types into a nested allocation arena is
problematic since we can e.g lazily compute the `ContextSubMap` for a
`NominalOrBoundGenericNominalType`, which is then destroyed when we
exit the nested arena. Ensure we don't pass any types with type
variables or placeholders to `typesSatisfyConstraint`.

rdar://152763265
2025-06-10 16:08:00 +01: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
Allan Shortlidge
7436be514a Merge pull request #82083 from tshortli/diagnose-unrecognized-availability-domains-as-errors-6.2
[6.2] AST: Diagnose unrecognized platforms as errors with `CustomAvailability` enabled
2025-06-09 18:16:02 -07:00
Pavel Yaskevich
1e463281b5 Merge pull request #82066 from xedin/rdar-152665294-6.2
[6.2][Demangle] Implement missing `Node::Kind::OutlinedInitializeWithTakeNoValueWitness`
2025-06-09 18:02:28 -07:00
Pavel Yaskevich
a9e5a8a07a [Diagnostics] Correctly diagnose situations when immutable value is passed to inout parameter
Currently the note is going to point to the "callee" but that is
incorrect when the failure is related to an argument of a call.

Detect this situation in `RValueTreatedAsLValueFailure::diagnoseAsNote`
and produce a correct note.

Resolves: rdar://150689994
(cherry picked from commit 6bbc101a98)
2025-06-09 09:39:12 -07:00
Adrian Prantl
957d042e1e [RemoteInspection] Add a hook to process addresses before converting
them to hex strings when creating anonymous context descriptors. This
aims to solve a problem when LLDB reads reflection metadata directly
from local binary files instead of downloading them from in-process
memory.

LLDB's MemoryReader implements this to convert the file address into
an in-process address, so mangled names created from instance metadata
can be matched with the field info data read from the local files.

rdar://152743797
(cherry picked from commit 540df142d7)
2025-06-09 08:16:04 -07: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
Allan Shortlidge
464c37a5bb AST: Add a warning group for @_implementationOnly deprecation diagnostics.
This allows developers to control the level of these diagnostics.

Resolves rdar://152735425.
2025-06-06 19:41:42 -07:00
Steven Wu
cc0af1d4f8 [CAS] Allow uncached job from CAS based dependency scanning
Create a path that swift-frontend can execute an uncached job from
modules built with CAS based explicit module build. The new flag
-import-module-from-cas will allow an uncached build to load module
from CAS, and combined with source file from real file system to build
the current module. This allows quick iterations that bypasses CAS,
without full dependency scanning every time in between.

rdar://152441866
2025-06-06 11:08:44 -07:00
Pavel Yaskevich
fd79a85981 [Demangle] Implement missing Node::Kind::OutlinedInitializeWithTakeNoValueWitness
Implements de/remangler support for `WOB` manglings.

(cherry picked from commit 8e49860349)
2025-06-06 10:05:56 -07: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
Pavel Yaskevich
2a3e2d0800 Merge pull request #82037 from xedin/rdar-146027395-6.2
[6.2][Concurrency] Downgrade errors to warnings when Sendable requirement is inferred from a preconcurrency protocol
2025-06-06 08:49:20 -07:00