Commit Graph

1204 Commits

Author SHA1 Message Date
Anthony Latsis dd9f44ada3 IRGenDebugInfo: Adjust to "[llvm][DebugInfo][NFC] Remove DITypeRefArray in favour of DITypeArray (#177066)"
See https://github.com/llvm/llvm-project/pull/177066.
2026-05-31 00:56:13 +01:00
Xi Ge 241e803a24 Merge pull request #89438 from nkcsgexi/ir-hidden-type 2026-05-28 08:17:25 -07:00
Xi Ge fe7fdce8ee IRGen: lower hidden C-type layout to TrivialHiddenTypeInfo
When a struct has stored properties from an internal bridging header,
add @_hasHiddenStoredProperties to force address-only on both library
and client sides, and resolve layout via the defining module's
HiddenTypeLayouts table in IRGen.

Making these structs loadable is challenging because library and client
must agree on the register-passing scheme (which registers carry which
fields), and that scheme depends on the full type structure that the
client cannot see. Address-only sidesteps this by passing everything
indirectly.

Tests: hidden-type-irgen.swift verifies the Client's IR has correct
alloca sizes/alignments and outlined copy witnesses without referencing
hidden C symbols. hidden-type-runtime.swift builds a dylib + executable
and verifies values round-trip correctly across the boundary at runtime.
2026-05-27 22:28:27 -07:00
Emil Pedersen c4bcd4e9e7 [DebugInfo] Remove unused DebugInfoCanonicalizer pass (NFC)
This pass was replaced with MovedAsyncVarDebugInfoPropagator 4 years
ago, and is now dead code.
2026-05-26 14:59:17 +01:00
Max Desiatov 2a65d590ba IRGenDebugInfo: work around LifetimeDependenceInfo handling (#89266)
`ASTDemangler` drops LifetimeDependenceInfo (see `ASTDemangler.cpp`'s "Handle LifetimeDependenceInfo here" TODO); until that TODO is closed, types containing function types with lifetime dependencies cannot round-trip.

Resolves https://github.com/swiftlang/swift/issues/89257

rdar://177437498
2026-05-20 13:23:35 -07:00
Emil Pedersen 947b9f2ffa [DebugInfo] Remove unused SILDIExpr operators
Since salvageDebugInfo now uses debug reconstruction basic blocks,
the plus, minus, and constant SILDebugInfoExpression operators were
left unused. This commit removes them, and updates some of their tests
to use debug basic blocks.

Assisted-by: Claude
2026-05-18 18:07:09 +01:00
Xi Ge 4f60cc6e6e Merge pull request #89057 from nkcsgexi/hidden-type 2026-05-13 06:38:57 -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
Emil Pedersen f5bfa8396d [IRGen] [DebugInfo] Replace IndirectionKind in DebugInfo handling with op_deref
Instead of using a single DirectValue/IndirectValue enum with duplicate values
for coro context, indirect values are now represented with an extra op_deref
throughout.

This makes the code simpler: Coro context is now a boolean throughout, and
the intent behind indirection is clearer. It also cleanly supports multiple
layers of indirection: if two consecutive paths set the indirection kind to
IndirectValue, it would only insert one DW_OP_deref instead of two.

This fixes the move_function_dbginfo.swift test file with the deref behaviour
(rdar://176552243). All changed test cases have been tested manually in LLDB
to make sure it is the correct behaviour.

Assisted-by: Claude
2026-05-12 16:17:44 +01:00
Leonard Grey ffe398fe96 Merge pull request #88419 from speednoisemovement/inner_struct_name
[IRGenDebugInfo][CodeView] Name inner type member in bound generic sized containers
2026-04-21 08:53:34 -04:00
Leonard Grey 7a191e54a7 [IRGenDebugInfo][CodeView] Name inner type member in bound generic sized containers
As a workaround for issues with uniquing, bound generics are emitted as a nested structure:
- A sized outer structure with no name or identifier
- A sizeless inner structure with the mangled name as the name and no identifier.

The actual mechanism of connection for the inner and outer structures is
that the outer structure has a single unnamed member whose type is the
inner structure.

However, LLVM CodeView emission treats unnamed members as anonymous
structs and tries to inline their members into the parent. But since the
inner struct has no members, the effect is that it gets dropped.

This change names the inner struct with the mangled type name. This will
have the effect of preserving the inner struct in CodeView output, and
allow us to use a variation of the DWARF logic at
https://github.com/swiftlang/llvm-project/blob/cd1235e59b87c84144802ab85592ee75a615f231/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserSwift.cpp#L166
to recognize and handle this pattern.

More details and discussion at https://github.com/swiftlang/swift/issues/87093
2026-04-10 16:01:42 -04:00
Augusto Noronha 69925b6a25 [DebugInfo] Emit DW_TAG_inheritance for protocol composition members
Protocol compositions like `P1 & P2` are now emitted with
DW_TAG_inheritance entries referencing each constituent protocol.
2026-04-01 15:14:13 -07:00
Augusto Noronha eb420df888 [lldb] Encode marker annotation for protocols in debug info.
Marker protocols are a compile time concept only, and emit no metadata.
RemoteInspection does not know how to handle existentials with these
types.

This patch emits debug info for marker protocols, so LLDB can handle
them properly before querying RemoteInspection for type information.

rdar://172847891
2026-03-25 14:18:32 -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
Raphael Isemann 345bda9157 Merge pull request #87569 from Teemperor/StorageType 2026-03-20 19:46:47 +00:00
Raphael Isemann b772384527 [DebugInfo] No longer assign non-fixed-size types the size of a pointer
`CompletedDebugTypeInfo::getFromTypeInfo` currently uses the storage type as
the preferred source of size information.
For address-only types (and any other type that has no fixed size at compile
time), the storage type is always changed to a pointer.

This currently causes that some non-fixed-size types (e.g., generics)
are assigned the size of a pointer as their actual size in the generated
debug information.

For example:

```
protocol P {
associatedtype S
}

func foo<B: P>(_ b: B) {
let x: (aaa: Int, bbb: B.S?) = (aaa: 0, bbb: nil)
_ = x
let y: (Fx: Int, Fy: Int) = (Fx: 0, Fy: 0)
_ = y
}
```

results in the following DWARF output where the first struct
is given size 8 (= the size of a pointer).

```
0x000000d4:   DW_TAG_structure_type
                DW_AT_name	("$sSi3aaa_1S4main1PPQzSg3bbbtD")
                DW_AT_linkage_name	("$sSi3aaa_1S4main1PPQzSg3bbbtD")
                DW_AT_byte_size	(0x08)
                DW_AT_APPLE_runtime_class	(DW_LANG_Swift)

0x000000f3:   DW_TAG_structure_type
                DW_AT_name	("$sSi2Fx_Si2FytD")
                DW_AT_linkage_name	("$sSi2Fx_Si2FytD")
                DW_AT_byte_size	(0x10)
                DW_AT_APPLE_runtime_class	(DW_LANG_Swift)
```

This change modifies `CompletedDebugTypeInfo::getFromTypeInfo` to ignore the
storage size for types that do not have fixed size. Generics now have no
specified size or 0 in DWARF. FixedArray<A, B> without substituted type/size
is now also emitted using the dedicated FixedArray code.
2026-03-13 13:42:05 +00:00
Steven Wu 083029a112 [DebugInfo][Caching] Using CASID for bridging header PCH
Fix the debug info emitted for bridging header PCH when compilation
caching is used. This includes:
* Bridging header should have the correct dwo_name that uses CASID
* The search_path for PCH should be the cache key that can load the PCH
  just like other modules.
2026-03-12 17:16:16 -07:00
Adrian Prantl 8ef2d49796 Merge pull request #87296 from cachemeifyoucan/eng/PR-169110002
[Caching] Support -debug-module-path type of debug info
2026-03-06 18:05:36 -08:00
Steven Wu c496931403 [Caching] Support -debug-module-path type of debug info
Add flag `-debug-module-cache-key` and flag `-debug-module-self-key` to
support embedded swift module output in the debug info via CASID.

rdar://169110002
2026-02-27 09:42:05 -08:00
Augusto Noronha 9a42678cd0 [DebugInfo] Emit DW_TAG_reference_type for indirect enum cases in DWARF
Wrap indirect enum case payload types in DW_TAG_reference_type to indicate
that the case stores a pointer to a heap-allocated box rather than the
payload directly.

rdar://170687015
2026-02-23 15:53:16 -08:00
Augusto Noronha 24d1ee02f4 [DebugInfo] Emit inheritance info for generic classes with -gdwarf-types
rdar://170020164
2026-02-11 10:10:34 -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
Hiroshi Yamauchi 6f60adf009 Use a separate DIRefMap cache for existential typealiases (#86368)
After https://github.com/swiftlang/swift/pull/85655, DI types for
existential typealiases and their inner protocol types are created,
which may encounter conflicts in the DIRefMap cache and assert failures
because they can have identical mangled names. This change fixes this
issue by using a separate cache for existential typealiases to avoid
such conflicts.

Issue https://github.com/swiftlang/swift/issues/86313
2026-01-14 13:50: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
Tim Kientzle 56635157fa Switch IRGen debug info to standard terminology 2026-01-04 08:56:53 -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
Steven Wu 36e1f62119 [DebugInfo] CAS built swift TU should have CASID as dwo_name for PCM
When using compilation caching, make sure the debug info emitted in the
swift TU references PCM files via CASID instead of file path. This
allows dsymutil and lldb to load clang modules correctly from CAS,
instead of relying on file system to load the file.

rdar://167054494
2025-12-22 16:53:49 -08:00
Felipe de Azevedo Piovezan 0cff9c7b95 [IRGenDebugInfo] Replace llvm.dbg.coroframe_entry with dbg.declare_value
We had introduced coroframe_entry downstream while the upstream proposal
was discussed. It has since been merged upstream, so this commit changes
the code to use the upstream intrisic, avoiding a binary incompatibility
in the IR w.r.t. upstream.
2025-12-02 17:09:17 +00:00
Adrian Prantl 45547be3f8 [Debug Info] Represent type alias existantials in debug info
Previously debug info made not difference between an existential type and a
protocol type. This caused us to loose typealiases such as

typealias Alias = ProtocolType

in the debug info.

rdar://161134092
2025-11-21 15:17:47 -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
Steven Wu 4e0484201d Merge pull request #83621 from cachemeifyoucan/eng/PR-gmodule-with-cas-id-update
Update swift compiler after clang gmodule CAS build update
2025-11-07 10:03:44 -08:00
Slava Pestov 46b41a3ae4 Merge pull request #85288 from slavapestov/narrow-cxx-roundtrip-carveout
IRGen: Only skip round-trip demangler check for types that involve C++ types
2025-11-03 20:17:10 -05:00
Slava Pestov d4869193c8 IRGen: Only skip round-trip demangler check for types that involve C++ types
Previously this was disabled entirely if C++ interop was
enabled, which is too broad.
2025-11-03 13:59:06 -05:00
Steven Wu ee09790748 Update swift compiler after clang gmodule CAS build update
Fix swift compiler build and test to work with new clang gmodule build
with CAS, which encodes references to clang PCMs as CASIDs.
2025-10-28 11:35:44 -07:00
Adrian Prantl cb4efa0839 Add a -debug-module-path frontend option
This new option allows the Driver to pass the path to a compilation
job's own binary swiftmodule artifact to the frontend. The compiler
then stores this path in the debug info, to allow clients like LLDB to
unambiguously know which binary Swift module belongs to which compile
unit.

rdar://163302154
2025-10-23 17:10:50 -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
Slava Pestov b720735879 IRGen: Don't ask for stored properties of resilient types in debug info emission 2025-10-15 13:44:42 -04:00
Tim Kientzle 41f680cb93 Merge pull request #84826 from tbkka/tbkka-revert-revert-floatingpointdescription
Re-land new Floating-poing `debugDescription`
2025-10-12 20:19:12 -07:00
Tim Kientzle 4c0b58096e Make _InlineArray subject to the same optimizations as InlineArray 2025-10-10 14:06:14 -07:00
Adrian Prantl b8f2d33ded [DebugInfo] Use the human-readable name as name of FwdDecls of unused structs
rdar://162080220
2025-10-06 17:54:57 -07:00
Adrian Prantl 305f0edb20 [DebugInfo] Properly nest types declared in extensions in the debug info
rdar://161923580
2025-10-03 16:12:24 -07:00
Hamish Knight 954b08cae5 [AST] Remove UnresolvedType
We have now removed all uses of this type.
2025-10-03 09:50:42 +01:00
swift-ci 0d2c4ca9be Merge remote-tracking branch 'origin/main' into rebranch 2025-09-15 10:29:21 -07:00
Meghana Gupta 9fe489ce22 Introduce borrow and mutate as new accessor kinds
And handle them in various covered switches
2025-09-09 14:30:26 -07:00
Shubham Sandeep Rastogi 3eb40fc19c Emit llvm.dbg.coroframe_entry instead of llvm.dbg.declare for async code.
For swift async debug info, we create llvm.dbg.declare that contain
locations which may not be a pointer or int. This is fine, because the
CoroSplitter pass fixes up those llvm.dbg.declares later.

However, with a recent change to the LLVM Verifier, there is a check
that asserts if there is a llvm.dbg.declare with a location other than
a pointer or an int.

To workaround the problem, we created a new llvm.dbg.coroframe_entry
intrinsic that doesn't have the same restriction as llvm.dbg.declare.

This patch ensures that in async code, we now emit the new
llvm.dbg.coroframe_entry intrinsic, instead of llvm.dbg.declare
intrinsic

rdar://157299589

rdar://157509307
2025-08-23 20:13:18 -07:00
Shubham Sandeep Rastogi 35ed2080ba Revert "Temporarily disable debug info generation for async functions"
This reverts commit 8d763321c1.
2025-08-22 15:31:47 -07:00
Ben Barham 8d763321c1 Temporarily disable debug info generation for async functions
Temporary workaround for a compiler crash in rebranch:
```
location of #dbg_declare must be a pointer or int
```
2025-08-13 15:36:02 -07:00
Anthony Latsis 1de3e14252 Revert "DebugInfo: Bring back accidentally dropped DIFlagArtificial flag"
This reverts commit 5a456c5c3f.
2025-07-31 11:43:26 +01:00
Anthony Latsis 5a456c5c3f DebugInfo: Bring back accidentally dropped DIFlagArtificial flag
Patches up https://github.com/swiftlang/swift/pull/83283.
2025-07-30 23:28:53 +01:00