Commit Graph

21693 Commits

Author SHA1 Message Date
Andrew Trick
5a866009f9 Merge pull request #82472 from atrick/explicit-init
Disable surprising lifetime inference of implicit initializers
2025-06-27 04:19:05 -07:00
Anthony Latsis
1f89bb6a94 Merge pull request #82452 from swiftlang/jepa2
Sema: Fix the insertion location for conformances attributes
2025-06-26 21:38:41 +01:00
Andrew Trick
7abe2222f9 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)
2025-06-26 12:47:01 -07:00
Hamish Knight
46f5e417fd Merge pull request #82481 from hamishknight/tic-tac-toe
[SourceKit] Print backticks if needed in `printDisplayName`
2025-06-26 12:29:27 +01:00
Andrew Trick
87f2510a27 Diagnostic note for invalid @_lifetime annotations on inout params
Users commonly try to write a lifetime dependency on an 'inout' parameters as:

    @_lifetime(a: &a)
    func f_inout_useless(a: inout MutableRawSpan) {}

This is useless. Guide them toward what they really wanted:

    @_lifetime(a: copy a)

Fixes rdar://151618856 (@lifetime(..) gives inconsistent error messages)
2025-06-25 16:34:43 -07:00
Andrew Trick
05fa82b7a7 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) {}
2025-06-25 16:34:43 -07:00
Andrew Trick
df0b81c88d 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.
2025-06-25 16:34:42 -07:00
Andrew Trick
465d6a82e7 Fix LifetimeDependence diagnostic formatting
Remove incorrectly nested single quotes from the suggested fix.
2025-06-25 15:24:12 -07:00
Argyrios Kyrtzidis
d385e8c87a Merge pull request #81792 from sina-mahdavi/sina-mahdavi/fix-llvm-prefix-mapping-calls
fix calls to llvm prefix mapping functions to use space-separated opt…
2025-06-25 13:19:21 -07:00
Artem Chikin
705b1a667f Merge pull request #82429 from artemcm/ScannerInvalidBinaryModuleRefactor
[Dependency Scanning] Refactor the scanner to simplify layering
2025-06-25 09:03:18 -07:00
Hamish Knight
55ef1bcaf0 [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 15:15:17 +01:00
Sina Mahdavi
7090b7e145 fix calls to llvm prefix mapping functions to use space-separated option format 2025-06-24 13:32:55 -07:00
eeckstein
830a842b7b Merge pull request #82455 from eeckstein/adress-of-borrow-feature
Guard InlineArray addressors with feature flag
2025-06-24 20:58:18 +02:00
Slava Pestov
be6669b3ec Merge pull request #82446 from slavapestov/fix-rdar152509409
AST: Tweak ConformanceLookupTable::compareConformances() some more
2025-06-24 11:47:21 -04:00
Erik Eckstein
0dbc63a00b Guard InlineArray addressors with feature flag
To be able to parse a recent Swift.swiftinterface file with a 6.2 compiler.
This is a follow-up fix for https://github.com/swiftlang/swift/pull/81441

rdar://154118968
2025-06-24 16:02:54 +02:00
Anthony Latsis
ad8c52237c Sema: Fix the insertion location for conformances attributes 2025-06-24 14:49:03 +01:00
Meghana Gupta
86bdca5bf4 Merge pull request #82354 from meg-gupta/lifetimeenum
Add lifetime dependencies on function types representing ~Escapable enum elements with ~Escapable payloads
2025-06-23 22:07:38 -07:00
Slava Pestov
8d30df5327 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:54:18 -04:00
Meghana Gupta
0eb32f6943 Fixes after merge conflict 2025-06-23 16:52:18 -07:00
Evan Wilde
7f3fdb322d Merge pull request #82355 from etcwilde/ewilde/fbsd-cxx-interop-runtime
FreeBSD: Link C++ runtimes when Cxx interop is enabled
2025-06-23 14:21:02 -07:00
Meghana Gupta
2a2deea77b Avoid circular reference errors by adding an early bailout for imported enums 2025-06-23 13:42:55 -07:00
Meghana Gupta
db24b6f758 Support lifetime dependence inference on enum elements 2025-06-23 13:42:53 -07:00
Meghana Gupta
ccda38b513 [NFC] Prepare LifetimeDependenceInfo to hold EnumElementDecl* 2025-06-23 13:42:48 -07:00
Artem Chikin
39c096c388 [Dependency Scanning] Refactor 'ModuleDependenciesCache' to not hold a reference to the global 'SwiftDependencyScanningService'
While this made sense in the distant past where the scanning service provided backing storage for the dependency cache, it no longer does so and now makes for awkard layering where clients get at the service via the cache. Now the cache is a simple data structure while all the clients that need access to the scanning service will get it explicitly.
2025-06-23 13:39:43 -07:00
Artem Chikin
68883a1014 [Dependency Scanning] Refactor Swift Scanner loader to be standalone
- 'SwiftModuleScanner' will now be owned directly by the 'ModuleDependencyScanningWorker' and will contain all the necessary custom logic, instead of being instantiated by the module interface loader for each query
- Moves ownership over module output path and sdk module output path directly into the scanning worker, instead of the cache
2025-06-23 13:39:36 -07:00
Egor Zhdan
e232273886 Merge pull request #82413 from swiftlang/egorzhdan/namespace-printer-null-crash
[cxx-interop] Fix printing of namespaces declared in bridging headers
2025-06-23 21:07:36 +01:00
Egor Zhdan
cc9c51deea [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
2025-06-23 16:25:48 +01:00
Andrew Trick
855b3e4446 [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')
2025-06-22 23:27:09 -07:00
Andrew Trick
374026f344 Merge pull request #82380 from atrick/nonescapable-accessor-on-trivial
Add Feature: NonescapableAccessorOnTrivial
2025-06-21 09:24:12 -07:00
Andrew Trick
cc357f4f32 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)
2025-06-20 15:59:13 -07:00
Anthony Latsis
1ceeb7089b Merge pull request #82338 from AnthonyLatsis/jepa
ASTBridging: Bridge more enums directly
2025-06-20 23:13:50 +01:00
Anthony Latsis
dd78cd6dbe ASTBridging: Bridge swift::PlatformKind directly 2025-06-20 16:46:03 +01:00
Anthony Latsis
de46b95e7e ASTBridging: Bridge swift::GenericTypeParamKind directly 2025-06-20 16:46:03 +01:00
Anthony Latsis
dcbf2781c5 ASTBridging: Bridge swift::RequirementReprKind directly 2025-06-20 16:46:03 +01:00
Anthony Latsis
69a27e1735 ASTBridging: Bridge swift::LayoutConstraintKind directly 2025-06-20 16:46:03 +01:00
Anthony Latsis
b347aedeb0 ASTBridging: Encapsulate some operations on BridgedLayoutConstraint
NB: Switching from factory methods to initializers as well crashes on
Windows.
2025-06-20 16:44:49 +01:00
Hamish Knight
3c8a8a860a Merge pull request #82292 from hamishknight/bigger-hammer
[AST] Replace type variables and placeholders in original ErrorTypes
2025-06-20 10:59:24 +01:00
Anthony Latsis
30a8b59c6e ASTBridging: Bridge swift::TypeAttrKind directly 2025-06-19 18:11:40 +01:00
Anthony Latsis
8501c8776e ASTBridging: Bridge swift::ExternKind directly 2025-06-19 18:11:40 +01:00
Anthony Latsis
0b0ebfc9fb ASTBridging: Bridge swift::ExposureKind directly 2025-06-19 18:11:40 +01:00
Anthony Latsis
b2b79f3ad7 ASTBridging: Bridge swift::InlineKind directly 2025-06-19 18:11:40 +01:00
Anthony Latsis
6527be558a ASTBridging: Bridge swift::NonIsolatedModifier directly 2025-06-19 18:11:40 +01:00
Anthony Latsis
29ef3e300f ASTBridging: Bridge swift::InheritActorContextModifier directly 2025-06-19 18:11:40 +01:00
Anthony Latsis
68bb4b33f9 ASTBridging: Bridge swift::EffectsKind directly 2025-06-19 18:11:40 +01:00
Anthony Latsis
12de029d97 ASTBridging: Bridge swift::AccessLevel directly 2025-06-19 18:11:40 +01:00
Anthony Latsis
cf09773d66 ASTBridging: Bridge swift::Associativity directly 2025-06-19 18:11:40 +01:00
Anthony Latsis
38360fe625 ASTBridging: Bridge swift::DeclAttrKind directly 2025-06-19 18:11:39 +01:00
Anthony Latsis
722bc0f086 ASTBridging: Bridge swift::DiagID directly 2025-06-19 12:29:27 +01:00
John McCall
a2ded3606e Merge pull request #82327 from rjmccall/non-recursive-print-options
Introduce non-recursive print options and use them to handle IUO printing more elegantly
2025-06-19 18:40:03 +09:00
John Hui
a0d3ad7bd0 Merge pull request #82006 from j-hui/jump-to-def-for-macro-expanded-clang-imports
[SourceKit] Support location info for macro-expanded Clang imports
2025-06-19 02:01:40 -07:00