Commit Graph

2205 Commits

Author SHA1 Message Date
Allan Shortlidge b559ff94e2 ModuleInterface: Indicate @_spi designated inits are missing in public interfaces.
When an open class has `@_spi` designated initializers, derived classes in
clients building against its public .swiftinterface cannot safely inherit the
public convenience initializers. Print `@_hasMissingDesignatedInitializers` to
indicate this.

A similar bug for classes with designated initializers that have package access
level exists that should be fixed in a follow up. Currently, package clients
will lose access to inherited convenience inits when building from a package
.swiftinterface.

Resolves rdar://152167110
2026-06-08 21:18:28 -07:00
Tony Allevato bd216eb75a Merge pull request #89125 from allevato/raw-identifier-decl-names
Handle raw identifiers correctly in renamed APIs.
2026-06-06 19:22:43 -04:00
John Hui 889e989924 Merge pull request #87060 from j-hui/no-samespace-lookup 2026-06-05 15:27:59 -07:00
Slava Pestov 0fbe0faef0 AST: Remove unused method 2026-06-04 13:36:20 -04:00
Slava Pestov d23f58a689 AST: Escape member names when printing a DependentMemberType
We need to ensure the right form of printName() is called, so that
associated types named "Type", "Protocol", and so on, can be
properly escaped. Otherwise, we can print something like "Self.Type"
which is interpreted as a metatype.

Fixes rdar://177052246.
2026-06-04 13:36:20 -04:00
John Hui 1c2a1ff71b [cxx-interop] Refactor member lookup and enumeration logic
We were still using ClangDirectLookup in just two places outside of
ClangImporter, both to enumerate members of C++ namespaces. (Doing so
was probably wrong after dbce64ec481493efdb38fc0fb1fbf51df981b7f5 since
ClangDirectLookup no longer handled inline namespaces.)

This patch introduces a new function, forEachCXXNamespaceMember, which
consolidates the logic from those call sites and migrates it to
ClangLookup.cpp.

Apart from those call sites, ClangDirectLookup is only used in one
other place: ClangRecordMemberLookup. This patch also gets rid of
ClangDirectLookup as a request, and converts it to a helper function
designated for record member lookups. It also cleans up much of the
implementation details, including an unintentional re-implementation of
getNonTransparentDeclContext(), thereby fixing two instances of #54905.

Note that commit causes a crash when looking up nested unscoped enum
members with ObjC interop (see ClangImporter/enum-anon{,-sized}.swift).
This is fixed in the subsequent commit, which deals specifically with
nested enum lookup.

rdar://170858363
2026-06-03 14:17:36 -07:00
John Hui a4d15c5cc3 Merge pull request #89313 from j-hui/swift-synthesize-interface-plusplus
[swift-synthesize-interface] Improve C++ interop support
2026-05-27 19:03:55 -07:00
John Hui ee703b27bc [swift-synthesize-interface] Print synthesized decls
swift-synthesize-interface doesn't print implicit decls to avoid
polluting its output, but that also suppresses user-facing *synthesized*
decls.

This patch introduces an option, AlwaysPrintSynthesized, which ensures
synthesized decls are printed, and enables it for
swift-synthesize-interface.
2026-05-22 15:30:33 -07:00
Kavon Farvardin 2bdaa53b5d Convert PreInverseGenericsExcept to a SUPPRESSIBLE_EXPERIMENTAL_FEATURE
The suppression can help us avoid a typechecking condfail,
though the mangled names of any symbols will be wrong as we simply
omit the attribute in this simplistic suppression strategy.

related to rdar://176395527
2026-05-20 17:35:12 -07:00
Tony Allevato 0924981eab Handle raw identifiers correctly in renamed APIs.
This change adds support for raw identifiers when renaming APIs in
Swift. This includes APIs defined in Swift (using the
`@availability(..., renamed: ...)` attribute), as well as C/Objective-C
(using either the `swift_name` attribute or APINotes). All of these take
decl names as strings, and so the parsing for these requires that any
decl name components (the base name or the argument labels) must have
surrounding backticks in order to be treated correctly as a raw
identifier.

Getting this working required some refactoring of `ParsedDeclName`
since it previously assumed that it could just split around delimiters
like `.`, `(`, and `:`. That's no longer guaranteed to work, so I've
introduced backtick-aware split helpers to deal with this. Likewise,
`ParsedDeclName` now keeps track of special decl base names (like
`init` and `subscript`) to ensure that they're handled properly and
not incorrectly escaped under the new logic.
2026-05-17 21:03:18 -04:00
Patryk Stefanski 9e057e5c14 [cxx-interop] Guard Span-referencing declarations in Cxx module interface behind version check
When a newer toolchain (Swift >=6.2) is used with an older SDK whose
stdlib predates Swift 6.2, the Cxx module interface references
`Swift.Span` and `Swift.MutableSpan` which don't exist in the older
stdlib, causing build failures.

Guard individual declarations in the Cxx overlay that reference
`Span`/`MutableSpan` behind `#if canImport(Swift, _version: 6.2)`. The
guard wraps (rather than replaces) existing feature-based guards like
`$LifetimeDependence`, so both compiler capability and stdlib
availability are checked.

rdar://176312542
2026-05-14 15:41:07 -07:00
Xi Ge 08776427a1 [AST] Introduce HiddenType for mangled-name placeholders
HiddenType is a new TypeBase subclass that carries a mangled name
without leaking the actual type definition. It serves as a type-slot
placeholder for stored-property types that have been elided from a
serialized binary module, so that the client side can either

(1) resolve this mangled name to the real type if the client has access to the owning module, or

(2) use the mangled name as a key to query abstract layout information also serialized in the binary module.

As an example — a library with a hidden field of a bridging-imported type:

```
    // Utility.h (internal bridging header)
    //   typedef struct { int value; } Wrapper;

    public struct S {
      private var w: Wrapper
      public var weight: Double
    }

  In the serialized module, the client's view reconstructs as:

    public struct S {
      private var w: @_hidden("$sSo7Wrappera")
      public var weight: Double
    }
```
2026-05-12 17:13:14 -07:00
Aidan Hall d966ce12ef Merge pull request #88768 from aidan-hall/lifedep-refactored-print
Unified lifetime printing for Swift, SIL and AST dumps
2026-05-08 22:24:00 +01:00
Aidan Hall b134e3f9d9 Lifetimes: Include in AST type dumps 2026-05-06 11:02:51 +01:00
Aidan Hall d01dcfe628 Lifetimes: Refactor SIL & Swift lifetime printing into a unified implementation 2026-05-06 11:02:48 +01:00
Artem Chikin 00001b93e4 [Source Warning Control] Exclude @diagnose from textual module interfaces
The @diagnose attribute only affects local diagnostic behavior within a declaration's body and has no API or ABI impact. It should not appear in .swiftinterface files, and should not cause declarations to be wrapped in #if $SourceWarningControl feature guards.
2026-04-29 10:39:29 +01:00
Konrad Malawski a6617f8801 rename isNonisolatedNonsendingCaller -> isNonisolatedNonsending 2026-04-28 09:21:46 -07:00
Konrad Malawski 2b8026dd94 rename isNonIsolatedCaller -> isNonisolatedNonsendingCaller 2026-04-28 09:21:46 -07:00
Konrad Malawski 4e4769de49 Rename stale CallerIsolated to NonisolatedNonsending 2026-04-28 09:21:23 -07:00
Aidan Hall fb2aa63295 Merge pull request #87217 from aidan-hall/lifedep-infer-closure-dependence
LifetimeDependence closure context dependence
2026-04-27 16:23:04 +01:00
Aidan Hall 9003e146dc LifetimeDependenceInfo: Print all lifetimes outside SwiftInterface
This is necessary for diagnostics
2026-04-24 16:14:25 +01:00
Aidan Hall d779a13f2d LifetimeDependence: Closure capture dependencies 2026-04-24 16:14:21 +01:00
Pavel Yaskevich ae0c69face Merge pull request #88179 from broken-circle/feature/tuple-diagnostic
[Diagnostics] Coalesce large homogeneous tuples in diagnostics
2026-04-22 22:01:13 -07:00
Pavel Yaskevich 5b6a29fd8a [Frontend] Use @caller_isolated to represent nonisolated(nonsending) isolation of SIL function type
`nonisolated(nonsending)` is a modifier and it's really hard to
work with in SIL because most of the things are represented as
attributes there.
2026-04-13 14:18:53 -07:00
Pavel Yaskevich c6cd4f42e9 [SIL] SILFunctionType: Add support for nonisolated(nonsending) isolation
Similarly to `@isolated(any)` it's sometimes necessary to check
whether a call is to a `nonisolated(nonsending)` function value
i.e. for hop elimination pass and without this isolation support
it has to go trying to figure out the isolation from a callee
which is not possible if it doesn't refer to a `SILFunction *`.
2026-04-10 09:35:30 -07:00
broken-circle 784edd1ac1 [Diagnostics] Use isEqual() for homogeneous tuple detection
Compare element types with `isEqual()` instead of pointer equality so
canonical types are compared, and to account for sugar (like parentheses).
2026-04-08 17:29:54 -07:00
broken-circle ebc82848a6 Change compact tuple diagnostic message
Use a diagnostic message that cannot be mistaken for actual syntax.
2026-04-01 08:31:40 -07:00
broken-circle 0d42e6d62e [Diagnostics] Coalesce large homogeneous tuples in diagnostics
Homogeneous unlabeled tuples with many elements produce unwieldy type
names in diagnostics (e.g. C fixed-size arrays). Print them in compact
`(N of T)` form when there are 5+ elements, mirroring the style used
in `TypePrinter.visitInlineArrayType()` and SE-0483.

Add `PrintOptions.PrintHomogeneousTuplesCompactly`, enabled only in
diagnostic print paths. Type equality uses pointer comparison to avoid
coalescing differently-sugared types.
2026-03-29 16:34:12 -07:00
Slava Pestov 3c2720b8bc AST: Introduce JoinType and MeetType singletons
These will be used internally by the type checker to represent bindings
that are the joins and meets of types involving type variables. They
will not appear anywhere outside of the bindings code---so you won't
see them in expressions, or matchTypes(), etc.
2026-03-21 08:48:47 -04:00
susmonteiro e66793fcee [cxx-interop] Gate CxxBorrowingSequence behind Swift version check 2026-03-16 17:04:31 +00:00
Rintaro Ishizaki f8911bc257 [ASTPrinter] Disambiguation marker for simple-stored var accessor block
Previously, the `@_accessorBlock` disambiguation attribute was only
emitted for observed variables. But We need `@_accessorBlock`
disambiguation marker for simple stored properties with non-public
setters in `@frozen` types too.

rdar://171819084
2026-03-05 14:14:41 -08:00
Sam Pyankov 87421450a5 Merge pull request #87434 from sepy97/transitive_import_check
ASTPrinter: Filter inherited constructors from restricted modules
2026-02-25 20:50:23 -08:00
Sam Pyankov 2aeaf2cd89 ASTPrinter: Filter inherited constructors from restricted modules
Skip printing inherited constructors defined in modules that are not
publicly imported.
This prevents interface verification errors where types are used but
their modules aren't in the import list.

rdar://168101765
2026-02-25 11:36:32 -08:00
Artem Chikin b6e9e5c7ba [Literal Expressions] Introduce expression-based generic arguments
Introduce new syntax for parsing arbitrary integer literal expressions for generic value arguments:
```swift
InlineArray<(<Expr>), T>
[(<Expr>) of T]
```
Which, for now, will co-exist alongside the current syntax of simple integer literals.

Replace `IntegerTypeRepr` with `GenericArgumentExprTypeRepr`, a new `TypeRepr` node that wraps arbitrary expressions in generic argument positions (e.g., `InlineArray<(1 + 3), Int>`). The node tracks resolution state, distinguishing whether the expression resolved to a type or an integer value.

Key changes:
- Parse parenthesized generic arguments as expressions
- Recover and distinguish types from integer expressions in `resolveGenericArgumentExprTypeRepr`.
- When the `LiteralExpressions` feature is enabled, type-check and constant-fold expressions to integer values
- Extract `PreCheckTarget` into a public header to expose `simplifyTypeExpr` for use during type resolution

Resolves rdar://168005391
2026-02-24 14:10:39 +00:00
Aidan Hall 229eccb899 Merge pull request #87183 from aidan-hall/lifedep-borrow-print
LifetimeDependence: Fix mutable borrow printing
2026-02-16 10:12:35 +00:00
Becca Royal-Gordon 3dc9fba08e Merge pull request #87128 from beccadax/mod-squad-dissociated
[ModuleInterface] Fix associated type selectors more
2026-02-12 23:04:55 -08:00
Aidan Hall a8c5a0cc92 LifetimeDependence: Fix mutable borrow printing
Use the '&' specifier for inout scoped dependence sources, since this is the
only kind of borrowed dependence they can have.
2026-02-12 17:29:56 +00:00
Andrew Trick 0867ca8ec4 Merge pull request #87101 from atrick/lifedep-inout-immortal
Support @_lifetime(immortal) to suppress inout default dependency
2026-02-12 09:09:31 -08:00
Pavel Yaskevich 88c0b0adcb Merge pull request #87096 from xedin/rdar-166159992
[ASTPrinter] Print `Sendable` conformance for package types in swift …
2026-02-11 12:20:03 -08:00
Andrew Trick b7e2186f7d Support @_lifetime(immortal) to suppress inout default dependency
Non-Escapable 'inout' arguments have a default self-dependency, regardless of
any other annotations.  For example:

    @_lifetime(dest: copy source)
    /* DEFAULT: @_lifetime(dest: copy dest, copy source) */
    func foo<T: ~Escapable>(dest: inout T, source: T)

An immortal lifetime specifier now suppresses that default. For example:

    @_lifetime(dest: immortal, copy source)
    /* DEFAULT: @_lifetime(dest: copy source) */
    func foo<T: ~Escapable>(dest: inout T, source: T)

This is necessary because there is otherwise no other way to suppress the
default lifetime.

Fixes rdar://170016708 ([nonescapable] Support @_lifetime(immortal) to suppress
the usual inout default self-dependency)
2026-02-11 05:55:26 -08:00
Becca Royal-Gordon b0bd6c711c Merge pull request #86905 from beccadax/mod-squad-not-for-export-2 2026-02-11 02:28:08 -08:00
Becca Royal-Gordon 31ef4d00e0 [ModuleInterface] Fix associated type selectors more
Qualification has discovered a complicated test case where the module interface printer incorrectly adds module selectors to nested types that don’t support them. Tweak module interface printing to omit the module selector in more situations.

Fixes rdar://169720990.
2026-02-10 16:43:21 -08:00
Becca Royal-Gordon cbad1d8a18 Tweak export_as behavior with submodules
In #86859, I modified the way `export_as` names are used in private module interfaces so that the `export_as` name is used when that module has been imported. This turns out to be slightly too aggressive in a specific scenario where a submodule of the export_as module imports a submodule of the real module—the compiler ends up using the export name even though the resulting lookup won’t actually work.

Modify the logic for deciding whether to use an exported module name so that it not only checks whether the export_as module has been loaded, but also whether the specific module or submodule the declaration belongs to is (possibly transitively) imported by that module.

Fixes rdar://167874630 (harder).
2026-02-10 15:49:47 -08:00
Artem Chikin f53ccd656d Merge pull request #86934 from artemcm/LiteralExpressionEnumRawValues
[Literal Expressions] Add support for literal expressions in enum raw values
2026-02-10 22:28:59 +00:00
Kavon Farvardin d49ebd5a58 Merge pull request #87066 from kavon/supp-assoc-interfaces
SuppressedAssociatedTypesWithDefaults: swiftinterface and mangling support
2026-02-10 03:04:16 -08:00
Artem Chikin 1e5ba5fca8 [Literal Expressions] Add support for literal expressions in enum raw values
Modify relevant portions of the type-checker and parser to allow, when the 'LiteralExpressions' experimental feature is enabled, for arbitrary integer-typed expressions in enum raw value specifiers. These expressions will be type-checked and constant-folded into an integer literal expression, keeping the current interface of 'EnumElementDecl' consistent for clients.

Previously, 'EnumRawValuesRequest' had two different "modes" which were discerned based on typechecking stage (structural | interface), where the former had the request compute all raw values, both user-specified literal expressions and computing increment-derived values as well; the latter would also type-check the user-specified expressions and compute their types.
- With the need to have enum case raw values support arbitrary integer expressions, the request ('EnumRawValuesRequest') has been refactored and simplified to *always* both compute all case raw values and perform type-checking of user-specified raw value expressions. This is done in order to allow the AST-based constant-folding infrastructure ('ConstantFoldExpression' request) to run on the expressions. Constant folding is invoked during the evaluation of 'EnumRawValuesRequest' on all user-specified raw value expressions, in order to be able to compute subsequent increment values and ensure the expressions are foldable. If they are not, i.e. if constant folding fails, a relevant diagnostic will be emitted.
- 'EnumElementDecl' continues to store the raw value expression, which is no longer a 'LiteralExpr' but rather an 'Expr'; however, the getter ('getRawValueExpr') continues to return a 'LiteralExpr' by invoking the constant-folding request on the stored value, which is guaranteed to return a cached result from a prior invocation in 'EnumRawValuesRequest', assuming it succeeded.
- Furthermore, the 'structural' request kind was previously not cached, whereas now because the request must always do the complete type-checking work, it is always cached.

Resolves rdar://168005520
2026-02-10 09:43:07 +00:00
Kavon Farvardin b2e698ec41 SuppAssocDefaults: update getRequirementsWithInverses
Given that we implicitly expanded Copyable & Escapable
conformance requirements for suppressed primary associated
types, we now need this function to do the opposite;
filtering Copyable & Escapable requirements on such primary
associated types and adding inverses if those requirements
are missing.

This function plays a crucial role in emitting the interface
files accurately for functions and types, in addition to
how we mangle generic signatures into function symbols.

The mangling for generic signatures under the -WithDefaults version of
suppressed associated types goes like this:

- primary associated type T.A has an inverse `Rj` or `RJ` mangled
  into the generic signature if it lacks the conformance, or
  nothing is mangled into it.

- non-primary associated type T.B has either a `T.B: Copyable`
  requirement mangled into it, or nothing is mangled into it.

For the legacy SuppressedAssociatedTypes feature, where there's no
defaults, it uses the "non-primary assocated type" mangling strategy
for all generic signatures.
2026-02-09 16:10:00 -08:00
Pavel Yaskevich 824c6dc926 [ASTPrinter] Print Sendable conformance for package types in swift interfaces
If printing is for a package interface, let's add derived/implied `Sendable`
conformance to avoid having to infer it while type-checking the interface
file later. Such inference is not always possible, because i.e. a package
declaration can have private storage that won't be printed in a package
interface file and attempting inference would produce an invalid result.

Resolves: rdar://166159992
2026-02-09 14:38:12 -08:00
John Hui 9dc1174994 [cxx-interop] [NFC] Stabilize interface order of Clang record members
We may visit and thus import these members in an unpredictable order.
To avoid future churn for module interface test cases, sort the printed
module interface output according to some rough heuristics.
2026-02-07 10:54:12 -08:00
Kavon Farvardin 3021f32c9b Merge pull request #87048 from kavon/retro-refinement-3
Reparenting: second batch of fixes
2026-02-06 19:04:04 -08:00