Commit Graph

798 Commits

Author SHA1 Message Date
Kavon Farvardin 19119ad88a introduce @_preInverseGenerics(except:)
@_preInverseGenerics(except: <inverses>) is an extension of the existing
@_preInverseGenerics attribute that provides selective control over which
inverse requirements are mangled into a declaration's symbol name.

While the bare @_preInverseGenerics strips all inverse constraints
(~Copyable and ~Escapable) from mangling, the 'except:' form allows specific
inverses to be retained. This is needed when a type like Span already had
~Copyable mangled into its ABI-stable symbols and now needs to retroactively
adopt ~Escapable without changing those existing symbols. You can now express
that with `@_preInverseGenerics(except: ~Copyable)` to strip-out every inverse
except ~Copyable to preserve the pre-existing ~Copyable-containing symbols.

It requires the new experimental feature `PreInverseGenericsExcept`.

rdar://176395527
2026-05-14 18:27:00 -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
Pavel Yaskevich b7aa9f09e8 [ASTMangler] SILFunctionType: Remove the flag that disables nonisolated(nonsending) mangling 2026-04-13 14:19:04 -07:00
Pavel Yaskevich aa59c1aaf3 [Mangling/SIL] Mangling support for nonisolated(nonsending) isolation in SIL function types 2026-04-10 09:35:30 -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
Slava Pestov e7a94ee205 AST: Remove TypeBase::hasDependentMember()
I need to free up a bit.
2026-03-21 08:48:47 -04:00
Mike Ash 3dce226714 Merge pull request #87052 from mikeash/checked-objc-async-completion-name-collision-fix
[Concurrency] Emit a distinct mangling for checked ObjC async completion handlers.
2026-02-11 10:40:53 -05: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
Mike Ash 2abf087e71 [Concurrency] Emit a distinct mangling for checked ObjC async completion handlers.
This avoids coalescing checked and unchecked handlers with the same types, which results in runtime crashes as they are not compatible.

We have a separate mangling for predefined handlers, TZ, which is unused. Repurpose this for checked handlers. Unchecked handlers keep their existing mangling with Tz.

rdar://152263818
2026-02-06 17:45:43 -05:00
Joe Groff 0f3ddfbcc8 Merge pull request #86545 from jckarter/builtin-borrow
`Builtin.Borrow` implementation
2026-01-26 07:32:31 -08: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 27cef65d56 [AST] Introduce opaque AST nodes 2026-01-23 15:17:28 +00:00
Pavel Yaskevich 6487b433c0 [ASTMangler] Restore stripConcurrency behavior for @preconcurrency declarations
This is a follow-up to https://github.com/swiftlang/swift/pull/86557

When mangling a `@preconcurrency` declaration, `dropGlobalActor`
is set to `true`, and the original condition behind that used to
remove isolation from function types regardless of whether the
function type was actually global-actor isolated or not. We need
to maintain this behavior for mangling or risk breaking ABI for
the existing declarations that had isolation like `@isolated(any)`.
2026-01-17 18:28:07 -08:00
Slava Pestov f8f48d173c ASTMangler: Fix incorrect mangling of retroactive conformances to marker protocols
We turn off the AllowMarkerProtocols mangler flag when
mangling the types that are passed into the runtime demangler.

The logic in appendAnyProtocolConformance() was wrong when
this flag was set; we would early exit from this function,
but then appendRetroactiveConformances() would still call
appendListSeparator(). The would result in an invalid mangled
string which could not be parsed by the demangler.

In particular, this meant that the recent changes to generalize
Equatable to allow non-Copyable and non-Escapable conformers
could introduce runtime crashes, because a mangled string for
a retroactive conformance to Equatable could be incorrect.

The fix is to handle AllowMarkerProtocols further up in
forEachConditionalConformance().

Note that this change should not directly change ABI, because
AllowMarkerProtocols is on for symbol names.

When AllowMarkerProtocols is on, we still always mangle
conformances to Copyable and Escapable in this code path.

This means that even with this change, mangling a symbol name
that contains a retroactive conformance to Equatable can output
a different string than in Swift 6.3, which means we have an ABI
break. That problem requires a separate fix.

- Fixes rdar://problem/168023786.
2026-01-15 22:11:30 -05: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
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
Slava Pestov 4282bb1746 ASTMangler: Use ASTContext stored in the mangler instance instead of fishing it out of random places 2026-01-02 15:15:15 -05:00
Slava Pestov cf438f076e ASTMangler: Upgrade a couple of assert() to ASSERT() 2026-01-02 15:15:15 -05:00
Slava Pestov 2934386efd ASTMangler: Fix mangling of sugared (nested) ProtocolCompositionTypes
Canonical ProtocolCompositionTypes never nest; we flatten the structure
when computing a canonical type.

However, in DWARF mangling, we might encounter ProtocolCompositionTypes
that contain other ProtocolCompositionTypes, via TypeAliasType sugar.

Make sure to visit this nested structure instead of just ignoring it.

- Fixes https://github.com/swiftlang/swift/issues/86207.
2026-01-02 15:15:15 -05:00
Slava Pestov 819738c83e AST: Rename mapTypeIntoContext() => mapTypeIntoEnvironment(), mapTypeOutOfContext() => mapTypeOutOfEnvironment() 2025-11-12 14:48:19 -05: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
Doug Gregor 0ac8a83051 Use correct IR name for AutoDiff mangling 2025-10-29 19:35:57 -07:00
Hamish Knight 169096c233 [AST] Rename mangleDeclAsUSR -> mangleDeclWithPrefix
This is used by other things that don't necessarily want an IDE
USR.
2025-10-23 09:11:17 +01:00
Hamish Knight a1e1656ed5 [AST] Remove respectOriginallyDefinedIn parameter from mangleAnyDecl
This was always set to `true` except for USR mangling, where we already
have it set to `false` for IDE USRs. The other clients were:

- AutoDiff, which is just using the resulting string as a dictionary
key, so don't seem to have any preference.
- The ClangImporter, which always overrides `@_originallyDefinedIn`
anyway.
2025-10-23 09:11:17 +01:00
Hamish Knight b607ec7a2f [AST] Introduce ASTMangler::forUSR
Rather than setting the USR-specific bits for each USR entrypoint
into the mangler just expose a convenience constructor for USR
generation that sets them.
2025-10-23 09:11:17 +01:00
Hamish Knight 401eafa9f1 [AST] NFC: Move getABIDecl onto ASTMangler 2025-10-23 09:11:17 +01:00
Meghana Gupta 06eb315612 Update mangling for borrow and mutate accessors 2025-10-20 09:05:36 -07:00
Michael Gottesman 2fa3908e94 [concurrency] Add a new type Builtin.ImplicitActor.
This is currently not wired up to anything. I am going to wire it up in
subsequent commits.

The reason why we are introducing this new Builtin type is to represent that we
are going to start stealing bits from the protocol witness table pointer of the
Optional<any Actor> that this type is bitwise compatible with. The type will
ensure that this value is only used in places where we know that it will be
properly masked out giving us certainty that this value will not be used in any
manner without it first being bit cleared and transformed back to Optional<any
Actor>.
2025-10-16 10:51:13 -07:00
Hamish Knight 364eba482d [AST] Use CustomAttr's DeclContext for ResolveMacroRequest
Remove the DeclContext parameter from ResolveMacroRequest, we can now
retrieve the DeclContext either from the CustomAttr or macro expansion
expr/decl directly.
2025-10-16 11:21:54 +01:00
Erik Eckstein ea6e3c9b4d ASTMangler: make sure to mangle canonical replacement types of substitution maps
When mangling types, it's expected that the type is canonical. Except if mangling for debug info.
Fixes a crash.
2025-10-06 09:47:41 +02:00
Hamish Knight 954b08cae5 [AST] Remove UnresolvedType
We have now removed all uses of this type.
2025-10-03 09:50:42 +01:00
Meghana Gupta c764244df0 Merge pull request #84180 from meg-gupta/borrowandmutatepr
Add preliminary support for borrow accessors
2025-09-15 10:01:15 -07:00
Egor Zhdan 5dc2817913 Merge pull request #83874 from egorzhdan/egorzhdan/redecl-context-assertion
[cxx-interop] Fix an assertion for `extern "C"` blocks
2025-09-09 23:11:39 +01:00
Meghana Gupta 1cff471c57 Introduce ResultConvention::Guaranteed and ResultConvention::GuaranteedAddress
ResultConvention::Guaranteed will be used by borrow accessors when the storage type can be returned by value.

ResultConvention::GuaranteedAddress will be used by mutate accessors and borrow accessors when the storage type
cannot be returned by value.
2025-09-09 14:45:40 -07:00
Meghana Gupta 28c4595735 Add mangling support for borrow/mutate accessors 2025-09-09 14:30:34 -07:00
Ahmed Elrefaey 1bc96857a8 Merge pull request #82464 from a7medev/feat/full-documentation-in-code-completion
[IDE] Add full documentation to code completion result
2025-09-04 10:06:21 +01:00
Janat Baig 798c0f51a4 Merge branch 'main' into temp-branch 2025-08-23 11:11:04 -04:00
Egor Zhdan 2409e33928 [cxx-interop] Fix an assertion for extern "C" blocks
rdar://158896622 / resolves https://github.com/swiftlang/swift/issues/83861
2025-08-22 17:51:38 +01:00
Pavel Yaskevich 53ef38e31b [AST] NFC: Rename function type isolation NonisolatedCaller to NonisolatedNonsending
This reduces the number of ways we refer to caller isolated async
functions and matches the name to the attribute spelling.
2025-08-05 17:22:10 -07:00
JanBaig 0dbbc8ece0 [SIL] SILDeclRef Mangling Added 2025-07-31 22:18:00 -04:00
Anthony Latsis fec049e5e4 Address llvm::PointerUnion::{is,get} deprecations
These were deprecated in
https://github.com/llvm/llvm-project/pull/122623.
2025-07-29 18:37:48 +01:00
Anthony Latsis 2920ea84d1 Address llvm::(Mutable)ArrayRef ctor deprecations
See:
- https://github.com/llvm/llvm-project/pull/146113
- https://github.com/llvm/llvm-project/pull/146011
2025-07-21 12:36:53 +01:00
QuietMisdreavus 1948907eb3 use RespectOriginallyDefinedIn when mangling extension contexts (#82348)
Resolves rdar://152598492

Consider the following Swift, adapted from a real-world framework:

```swift
@available(macOS 10.8, *)
@_originallyDefinedIn(module: "another", macOS 11.0)
public struct SimpleStruct {}

@available(macOS 12.0, iOS 13.0, *)
public extension SimpleStruct {
    struct InnerStruct {}
}
```

In this scenario, `SimpleStruct` was originally in a module called
`another`, but was migrated to this module around the time of macOS
11.0. Since then, the module was ported to iOS and gained a nested type
`SimpleStruct.InnerStruct`. When mangling USRs for this nested type, the
result differs depending on whether we're targeting macOS or iOS.
They're mostly the same, but the macOS build yields a USR with an `AAE`
infix, designating that the `InnerStruct` was defined in an extension
from a module with the name of the base module. On iOS, this infix does
not exist.

The reason this is happening is because of the implementation of
`getAlternateModuleName` checking the availability spec in the
`@_originallyDefinedIn` attribute against the currently active target.
If the target matches the spec, then the alternate module name is
reported, otherwise the real module name is. Since the iOS build reports
the real module name, the mangling code doesn't bother including the
extension-context infix, instead just opting to include the parent
type's name and moving on.

This PR routes around this issue by passing the
`RespectOriginallyDefinedIn` variable to the
`ExtensionDecl::isInSameDefiningModule` method, and using that to skip
the alternate module name entirely. It also sets
`RespectOriginallyDefinedIn` to `false` in more places when mangling
USRs, but i'm not 100% confident that it was all necessary. The goal was
to make USRs more consistent across platforms, regardless of the
surrounding context.
2025-06-30 12:57:12 -06:00
Slava Pestov 9033198674 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-27 10:56:12 -04:00
Gabor Horvath 059051cf69 [cxx-interop] Fix crash in ASTMangler triggered by UsingShadowDecls
We did not handle this declaration kind. This PR introduces makes sure
we mangle it the same way we do for the target declaration.

Fixes #82108.
2025-06-10 15:50:54 +01:00
Alex Hoppen ff483fe092 Merge pull request #81941 from ahoppen/dont-verify-mangle
[Indexing] Don't verify mangling of USRs
2025-06-06 08:36:28 +02:00
Alex Hoppen 563f971c1e [Indexing] Don't verify mangling of USRs
Verifying USR mangling adds ~30% overhead to indexing times. Since an incorrect USR mangling doesn't result in a correctness issue at the same level as a miscompile, save those 30% in non-assert builds.
2025-06-04 20:45:33 +02:00
Pavel Yaskevich aabfebec03 [AST] Add new declaration - using
Initially this declaration is going to be used to determine
per-file default actor isolation i.e. `using @MainActor` and
`using nonisolated` but it could be extended to support other
file-global settings in the future.
2025-05-30 00:39:06 -07:00
Hamish Knight edca7c85ad Adopt ABORT throughout the compiler
Convert a bunch of places where we're dumping to stderr and calling
`abort` over to using `ABORT` such that the message gets printed to
the pretty stack trace. This ensures it gets picked up by
CrashReporter.
2025-05-19 20:55:01 +01:00
Alejandro Alonso 9e24563bb7 Merge pull request #81365 from Azoy/my-existentials
[AST & Runtime] Correctly mangle extended existentials with inverse requirements
2025-05-12 13:21:07 -07:00