Commit Graph

45907 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
Joe Groff
009ce4b82a Add an "addressable for dependencies" flag to value witness flags.
This may be useful for type layout of borrow fields in the future, should we
decide that addressable-for-dependencies borrows should always be represented
by a pointer. rdar://153650278
2025-06-18 12:47:36 -07:00
Adrian Prantl
0d5cc180fb [Reflection] Add lightweight error handling to ReflectionContext
Reflection metadata lookup failures are notoriously difficult to debug
because there is no error handling in TypeLowering outside of
compile-time #ifdef'd fprintf(stderr) calls. The nicest thing to do
would be to adopt llvm::Expected<> but TypeLowering is also included
in the standard library, which only has access to a tiny subset of the
LLVM Support library. This patch adds a place to store a pointer to
the first encountered error, which can then be converted to an
llvm::Error at the API level.

(cherry picked from commit 868c9912aa)
2025-06-18 10:10:23 -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