Commit Graph

2171 Commits

Author SHA1 Message Date
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
Kavon Farvardin
58ad64d3f4 Reparenting: fix interface emission
The `@reparented` was missing and a typealias
was being synthesized unexpectedly, creating
an issue when typechecking the interface later.

There's no fundamental reason why typealiases
cannot be supported to say the same thing as
the same-type requirement, but I think the
same-type requirement is always needed to be
written on the extension, one way or another.

For now I've chosen to only go with an
explicitly-written same-type requirement.
2026-02-06 13:23:22 -08:00
Aidan Hall
e98a7a6bf8 Merge pull request #86842 from aidan-hall/just-func-type-lifetimes-try-print
LifetimeDependence: Support function types
2026-02-06 10:09:25 +00:00
Aidan Hall
a366c4765a [AST] Print function type LifetimeDependenceInfo using parameter labels
We fall back to indices when labels are not available, but labels are
preferable, because they readable, stable, and preferred by the lifetime
dependencies proposal.
2026-02-05 14:50:39 +00:00
Meghana Gupta
657fa172bc Fix ASTPrinting of borrow/mutate protocol requirements 2026-02-04 07:16:32 -08:00
Becca Royal-Gordon
fce99b3173 Merge pull request #86859 from beccadax/mod-squad-not-for-export 2026-01-29 09:02:50 -08:00
Xi Ge
4a44642fac Merge pull request #86717 from sepy97/fix_attributes_printer
ASTPrinter: skip printing incompatible attributes in swiftinterface
2026-01-28 21:10:47 -08:00
Sam Pyankov
1c2cb16a6a ASTPrinter: skip printing incompatible attributes in swiftinterface
Attributes that can not appear on declaration should not be printed in textual interface
rdar://164975727
2026-01-28 15:48:21 -08:00
Becca Royal-Gordon
f02b2f1532 Use export_as name in some private swiftinterfaces
Previously, if a declaration belonged to a module with an `export_as` attribute, Swift always used the exported module name in the public module interface and the real module name in the private module interface. However, this is only a rough approximation of the behavior we really want, which is to use the real name in module interfaces that might be imported by dependencies of the exported name.

Change this logic so that public interfaces always use the exported name, and private interfaces use the exported name *only* if a module with that name has been loaded. This should make it so that if you’re building the `export_as` module or anything that imports it, you use the exported name; otherwise you use the real name.

Fixes rdar://167874630.
2026-01-28 14:28:14 -08:00
Joe Groff
0f3ddfbcc8 Merge pull request #86545 from jckarter/builtin-borrow
`Builtin.Borrow` implementation
2026-01-26 07:32:31 -08:00
elsa
5e9f215f31 Merge pull request #86010 from elsakeirouz/rework-for-each-desugar
Rework ForEachStmt Desugaring
2026-01-24 13:55:51 +00:00
Erik Eckstein
47fc8cc789 add an option -print-no-uuids to suppress printing UUIDs in SIL output
To to make the output better diffable
2026-01-23 19:20:19 +01:00
Joe Groff
bc166d5a8c Add a Builtin.Borrow type.
This will represent the layout of a borrow of a value.
2026-01-23 07:46:50 -08:00
Elsa Keirouz
f7c21941b8 [AST] ForEachStmt: rename sequence getter/setter 2026-01-23 15:17:29 +00:00
Elsa Keirouz
d54a572f7f [Sema] desugar ForEachStmt at AST level 2026-01-23 15:17:29 +00:00
Elsa Keirouz
27cef65d56 [AST] Introduce opaque AST nodes 2026-01-23 15:17:28 +00:00
Meghana Gupta
a3adcf103a Update borrow and mutate accessors as opaque accessors 2026-01-20 11:43:59 -08:00
Tim Kientzle
adec1f6cbe Merge pull request #86277 from tbkka/tbkka-rdar149303951-try1
[SE-0474] Implement final `yielding borrow`/`yielding mutate` naming for coroutine accessors
2026-01-09 08:52:21 -08:00
Pavel Yaskevich
541b7afdb4 Merge pull request #86334 from xedin/rdar-167050741
[AST] ASTPrinter: Don't attempt to print `nonisolated(nonsending)` on…
2026-01-09 07:45:26 -08:00
Pavel Yaskevich
df109f857b [AST] ASTPrinter: Don't attempt to print nonisolated(nonsending) on non-function parameters
Don't look through sugar when checking whether to print
`nonisolated(nonsending)` in parameter positions, because
underlying types would already be marked appropriately
and parameters themselves doesn't require the modifier
transfer even when the sugar is stripped.

Resolves: rdar://167050741
2026-01-06 15:16:12 -08:00
Doug Gregor
3f00643d13 [Module interface printing] Print @c as @_cdecl for older compilers
Add a feature just for the purpose of suppressing it. Print the check
as `hasAttribute(c)` so this feature can be temporary.

Fixes rdar://167546897 .
2026-01-05 09:47:19 -08:00
Tim Kientzle
8eabeeb8ca [SE-0474] Read2/Modify2 => YieldingBorrow/YieldingMutate
This updates a large number of internal symbols, function names,
and types to match the final approved terminology.  Matching the
surface language terminology and the compiler internals should
make the code easier for people to understand into the future.
2026-01-03 16:05:12 -08:00
Becca Royal-Gordon
ef1470baed Don’t print module selectors in more cases
There were a number of cases where Swift would emit module selectors into module interface files that it was subsequently unable to parse because the compiler at least temporarily represented them as dependent member types. Modify the carve-out so that if *any* of a type’s parents are generic parameters or archetypes, we don’t print a module selector on it.

Fixes rdar://166180424.
2025-12-19 13:33:35 -08:00
Pavel Yaskevich
5b665a8426 [ASTPrinter] Print a fully resolved type for an outermost property wrapper in swift interfaces
The type of an outermost property wrapper should be printed together
with (inferred) generic arguments because otherwise if a any wrapper
in the chain has generic parameters that are not involved in
`wrappedValue:` argument it won't be impossible to infer them while
type-checking the interface file where it appears.

Resolves: rdar://122963120
2025-11-28 22:00:14 -08:00
Sam Pyankov
7c8766fac8 Merge pull request #85571 from sepy97/desugar-inherited-ParaProtoType
ModuleInterface: Avoid printing generic arguments of a ParameterizedProtocolType in inheritance clause
2025-11-20 18:29:52 -08:00
Sam Pyankov
480b64ef50 ModuleInterface: Avoid printing generic arguments of a ParameterizedProtocolType in inheritance clause
When emitting module interfaces, parameterized protocols in inheritance clauses were being printed with generic arguments (public struct T: Fancy<Float64>), causing errors with protocol conformance verification.
The fix strip ParameterizedProtocolType to its base protocol type when printing inherited types, producing the correct inheritance clause.

Resolves: rdar://161925627
2025-11-19 10:27:15 -08:00
Anthony Latsis
dd5ac838e5 AST: Properly disallow isa/cast/dyn_cast on Type
We currently disallow these by deleting them in the `swift` namespace.
This approach has several loopholes, all of which ultimately work
because we happen to define specializations of `simplify_type` for
`swift::Type`:
* `llvm::isa/cast/dyn_cast`. The deleted partial specializations will
  not be selected because they are not defined in the `llvm` namespace.
* The argument is a non-const `Type`. The deleted function templates
  will not be selected because they all accept a `const Type &`, and
  there is a better `Y &Val` partial specialization in LLVM.
* Other casting function templates such as `isa_and_nonull` and
  `cast_if_present` are not deleted.

Eliminate these loopholes by instead triggering a static assertion
failure with a helpful message upon instantiation of `CastInfo` for
`swift::Type`.
2025-11-14 19:02:41 +00:00
Slava Pestov
819738c83e AST: Rename mapTypeIntoContext() => mapTypeIntoEnvironment(), mapTypeOutOfContext() => mapTypeOutOfEnvironment() 2025-11-12 14:48:19 -05:00
Pavel Yaskevich
30b207ecf4 Merge pull request #85418 from xedin/rdar-164267736
[AST/Serialization] A few fixes for `nonisolated(nonsending)` handling
2025-11-12 09:34:49 -08:00
Anthony Latsis
bda6edb85c AST: Rename GenericContext::isGeneric to hasGenericParamList
`isGeneric` is a misleading name because this method checks for the
existence of a `GenericParamList`, which is not implied by genericity.
2025-11-11 15:55:16 +00:00
Pavel Yaskevich
c3ea3031b9 [AST] Fix printing of nonisolated(nonsending) in parameter type positions
Printing shouldn't rely on parameter declaration bit because it only
works in cases when there is an explicit `nonisolated(nonsending)`
modifier on the type.

Always print `nonisolated(nonsending)` before `sending`, `@escaping`
and other declaration attributes/modifiers to avoid parsing issues.

Resolves: rdar://164267736
2025-11-10 11:31:24 -08:00
Pavel Yaskevich
5f91e49c9c Merge pull request #85105 from xedin/rdar-140928937
[AST/Sema] Allow `Sendable` suppression on Objective-C class declarations
2025-11-07 15:09:35 -08:00
Pavel Yaskevich
3ce0f941e8 Merge pull request #85187 from xedin/rdar-161739470
[AST] NonisolatedNonsendingByDefault: Print `@concurrent` on `nonisol…
2025-11-04 06:28:02 -08:00
Pavel Yaskevich
9f7d31e118 [AST] NonisolatedNonsendingByDefault: Print @concurrent on nonisolated async function types
With the feature enabled any function type without an explicit `@concurrent`
is going to be inferred to be `nonisolated(nonsending)`. `@concurrent` should
always be printed for diagnostic and other purposes because the isolation
checking would consider them to be `nonisolated(nonsending)` otherwise, especially
important to code produced by fix-its.

Resolves: rdar://161739470
2025-11-03 09:13:02 -08:00
Becca Royal-Gordon
9454c0aaa4 Emit module selectors in swiftinterfaces
This support is currently opt-in and can be disabled by a blocklist.
2025-10-31 16:48:06 -07:00