# LLDB Negative Cache

**URL:** <https://forums.swift.org/t/lldb-negative-cache/77271>\
**Category:** LLDB\
**Created:** [January 17, 2025, 9:42pm UTC](https://forums.swift.org/t/lldb-negative-cache/77271 "2025-01-17T21:42:43Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![chiragramani](https://avatars.discourse-cdn.com/v4/letter/c/c89c15/32.png) [@chiragramani](https://forums.swift.org/u/chiragramani)\
**Post date:** [January 17, 2025, 9:42pm UTC](https://forums.swift.org/t/lldb-negative-cache/77271/1 "2025-01-17T21:42:43Z")

</div>

In Xcode, the LLDB variables view always beachballs for a bit when debugging a Swift file with type aliases referencing other typealiases.

Here’s the relevant source code:

```swift
open class SomeWorkflowStep<A, B> {}

public typealias SomeParameterType = Bool
public typealias SomeReferencingAliasV3 = SomeWorkflowStep<SomeParameterType, Bool>

class ReproV2 {
    let someReferencingAlias: SomeReferencingAliasV3?
    init(someReferencingAlias: SomeReferencingAliasV3? = nil) {
        self.someReferencingAlias = someReferencingAlias // breakpoint was added on this line.
    }
}

```

LLDB type logs show:

```swift
SwiftASTContextForModule("MyApplication")::SwiftDWARFImporterDelegate::lookupValue("SomeReferencingAliasV3")
TypeSystemSwiftTypeRef("MyApplication")::SwiftDWARFImporterForClangTypes::lookupValue("SomeReferencingAliasV3")
SwiftDWARFImporterDelegate::lookupValue() -- imported 0 types from debug info.
ReconstructTypeImpl("$s21MyApplicationMainLib22SomeReferencingAliasV3aSgD") -- not found
ReconstructTypeImpl("$s21MyApplicationMainLib22SomeReferencingAliasV3aSgD") -- found in the negative cache

```

Since its not able to find the type, it does a global lookup which takes significant time in our setup given ours is a heavy application.

```swift
Couldn't compute size of type $s21MyApplicationMainLib22SomeReferencingAliasV3aSgD using SwiftLanguageRuntime.
 SwiftASTContextForModule("MyApplication")::ReconstructTypeImpl("$s21MyApplicationMainLib22SomeReferencingAliasV3aSgD") -- found in the negative cache
 SwiftASTContextForModule("MyApplication")::GetBitSize() -- Input type is nullptr, bailing out.
 SwiftASTContextForModule("MyApplication")::ReconstructTypeImpl("$s21MyApplicationMainLib22SomeReferencingAliasV3aSgD") -- found in the negative cache
 SwiftASTContextForModule("MyApplication")::ReconstructTypeImpl("$s21MyApplicationMainLib22SomeReferencingAliasV3aSgD") -- found in the negative cache
 Couldn't compute size of type $s21MyApplicationMainLib22SomeReferencingAliasV3aSgD using SwiftLanguageRuntime.
 SwiftASTContextForModule("MyApplication")::ReconstructTypeImpl("$s21MyApplicationMainLib22SomeReferencingAliasV3aSgD") -- found in the negative cache
 SwiftASTContextForModule("MyApplication")::GetBitSize() -- Input type is nullptr, bailing out.
 SwiftASTContextForModule("MyApplication")::ReconstructTypeImpl("$s21MyApplicationMainLib22SomeReferencingAliasV3aSgD") -- found in the negative cache
 SwiftASTContextForModule("MyApplication")::ReconstructTypeImpl("$s21MyApplicationMainLib22SomeReferencingAliasV3aSgD") -- found in the negative cache
 Couldn't compute size of type $s21MyApplicationMainLib22SomeReferencingAliasV3aSgD using SwiftLanguageRuntime.
 SwiftASTContextForModule("MyApplication")::ReconstructTypeImpl("$s21MyApplicationMainLib22SomeReferencingAliasV3aSgD") -- found in the negative cache
 SwiftASTContextForModule("MyApplication")::GetBitSize() -- Input type is nullptr, bailing out.
 SwiftASTContextForModule("MyApplication")::ReconstructTypeImpl("$s21MyApplicationMainLib22SomeReferencingAliasV3aSgD") -- found in the negative cache
 SwiftASTContextForModule("MyApplication")::ReconstructTypeImpl("$s21MyApplicationMainLib22SomeReferencingAliasV3aSgD") -- found in the negative cache
 SwiftASTContextForModule("MyApplication")::ReconstructTypeImpl("$s21MyApplicationMainLib22SomeReferencingAliasV3aSgD") -- found in the negative cache
 SwiftASTContextForModule("MyApplication")::ReconstructTypeImpl("$s21MyApplicationMainLib22SomeReferencingAliasV3aSgD") -- found in the negative cache
 SwiftASTContextForModule("MyApplication")::ReconstructTypeImpl("$s21MyApplicationMainLib22SomeReferencingAliasV3aSgD") -- found in the negative cache
 SwiftASTContextForModule("MyApplication")::ReconstructTypeImpl("$s21MyApplicationMainLib22SomeReferencingAliasV3aSgD") -- found in the negative cache
 SwiftASTContextForModule("MyApplication")::ReconstructTypeImpl("$s21MyApplicationMainLib22SomeReferencingAliasV3aSgD") -- found in the negative cache
 SwiftASTContextForModule("MyApplication")::ReconstructTypeImpl("$s21MyApplicationMainLib22SomeReferencingAliasV3aSgD") -- found in the negative cache
 SwiftASTContextForModule("MyApplication")::ReconstructTypeImpl("$s21MyApplicationMainLib22SomeReferencingAliasV3aSgD") -- found in the negative cache
 SwiftASTContextForModule("MyApplication")::ReconstructTypeImpl("$s21MyApplicationMainLib22SomeReferencingAliasV3aSgD") -- found in the negative cache
 SwiftASTContextForModule("MyApplication")::ReconstructTypeImpl("$s21MyApplicationMainLib22SomeReferencingAliasV3aSgD") -- found in the negative cache
 SwiftASTContextForModule("MyApplication")::ReconstructTypeImpl("$s21MyApplicationMainLib22SomeReferencingAliasV3aSgD") -- found in the negative cache
 SwiftASTContextForModule("MyApplication")::ReconstructTypeImpl("$s21MyApplicationMainLib22SomeReferencingAliasV3aSgD") -- found in the negative cache
 SwiftASTContextForModule("MyApplication")::ReconstructTypeImpl("$s21MyApplicationMainLib22SomeReferencingAliasV3aSgD") -- found in the negative cache
 SwiftASTContextForModule("MyApplication")::ReconstructTypeImpl("$s21MyApplicationMainLib22SomeReferencingAliasV3aSgD") -- found in the negative cache
 SwiftASTContextForModule("MyApplication")::ReconstructTypeImpl("$s21MyApplicationMainLib22SomeReferencingAliasV3aSgD") -- found in the negative cache
 SwiftASTContextForModule("MyApplication")::ReconstructTypeImpl("$s21MyApplicationMainLib22SomeReferencingAliasV3aSgD") -- found in the negative cache
 TypeSystemSwiftTypeRefForExpressions::TypeSystemSwiftTypeRefForExpressions()
 returned project-wide scratch context
 returned project-wide scratch context
 returned project-wide scratch context
 dynamic type of instance_ptr 0x600000213620 is $s21MyApplicationMainLib7ReproV2CD
 [self 0x5cdf30e00] might have a dynamic type
 [self 0x5cdf30e00] has a new dynamic type MyApplicationMainLib.ReproV2
 returned project-wide scratch context
 dynamic type of instance_ptr 0x600000213620 is $s21MyApplicationMainLib7ReproV2CD
 dynamic type of instance_ptr 0x600000213620 is $s21MyApplicationMainLib7ReproV2CD
 dynamic type of instance_ptr 0x600000213620 is $s21MyApplicationMainLib7ReproV2CD
 dynamic type of instance_ptr 0x600000213620 is $s21MyApplicationMainLib7ReproV2CD
 dynamic type of instance_ptr 0x600000213620 is $s21MyApplicationMainLib7ReproV2CD
 dynamic type of instance_ptr 0x600000213620 is $s21MyApplicationMainLib7ReproV2CD
 returned project-wide scratch context
 returned project-wide scratch context
 SwiftASTContextForModule("MyApplication")::ReconstructTypeImpl("$s21MyApplicationMainLib22SomeReferencingAliasV3aSgD") -- found in the negative cache
 SwiftASTContextForModule("MyApplication")::ReconstructTypeImpl("$s21MyApplicationMainLib22SomeReferencingAliasV3aSgD") -- found in the negative cache
 SwiftASTContextForModule("MyApplication")::ReconstructTypeImpl("$s21MyApplicationMainLib22SomeReferencingAliasV3aSgD") -- found in the negative cache
 SwiftASTContextForModule("MyApplication")::ReconstructTypeImpl("$s21MyApplicationMainLib22SomeReferencingAliasV3aSgD") -- found in the negative cache
 SwiftASTContextForModule("MyApplication")::ReconstructTypeImpl("$s21MyApplicationMainLib22SomeReferencingAliasV3aSgD") -- found in the negative cache
 SwiftASTContextForModule("MyApplication")::ReconstructTypeImpl("$s21MyApplicationMainLib22SomeReferencingAliasV3aSgD") -- found in the negative cache
 SwiftASTContextForModule("MyApplication")::ReconstructTypeImpl("$s21MyApplicationMainLib22SomeReferencingAliasV3aSgD") -- found in the negative cache

```

1. `-ast-paths` are valid, and the module is found as per LLDB logs.
  - `SwiftASTContextForModule("MyApplication")::GetASTBuffersFromModule() -- Found 1189 AST file data entries in .../../MyApplication`

2. When I replace the typealias refereing other typealias with a Bool, or a struct, class - it all works fine and there are no negative cache issues reported in the lldb logs. The beachballing issue resolves, and the variables view loads seamlessly without any noticeable delays.
3. `swift-healthcheck` is all okay.
4. I believe this might be specific to our project, but if anyone has any insights or suggestions, that would be super helpful.

---

<div class="post-metadata">

**Author:** ![Adrian\_Prantl](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/adrian_prantl/32/1582_2.png) [@Adrian\_Prantl](https://forums.swift.org/u/Adrian_Prantl)\
**Post date:** [January 17, 2025, 11:22pm UTC](https://forums.swift.org/t/lldb-negative-cache/77271/2 "2025-01-17T23:22:53Z")

</div>

Is the code you posted representative of the actual problem?  
I recently added some missing functionality to support type aliases for associated types in [[lldb] Resolve typealias information for assiciated types via reflection by adrian-prantl · Pull Request #9768 · swiftlang/llvm-project · GitHub](https://github.com/swiftlang/llvm-project/pull/9768) but this seems to be a much simpler global type alias.

---

<div class="post-metadata">

**Author:** ![Adrian\_Prantl](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/adrian_prantl/32/1582_2.png) [@Adrian\_Prantl](https://forums.swift.org/u/Adrian_Prantl)\
**Post date:** [January 17, 2025, 11:30pm UTC](https://forums.swift.org/t/lldb-negative-cache/77271/3 "2025-01-17T23:30:23Z")

</div>

Looks like I can reproduce the type reconstruction failure from this alone! Thanks, I'll let you know when I found out more!

---

<div class="post-metadata">

**Author:** ![chiragramani](https://avatars.discourse-cdn.com/v4/letter/c/c89c15/32.png) [@chiragramani](https://forums.swift.org/u/chiragramani)\
**Post date:** [January 17, 2025, 11:36pm UTC](https://forums.swift.org/t/lldb-negative-cache/77271/4 "2025-01-17T23:36:07Z")

</div>

Thank you so much, @Adrian_Prantl!

---

<div class="post-metadata">

**Author:** ![Adrian\_Prantl](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/adrian_prantl/32/1582_2.png) [@Adrian\_Prantl](https://forums.swift.org/u/Adrian_Prantl)\
**Post date:** [January 24, 2025, 11:23pm UTC](https://forums.swift.org/t/lldb-negative-cache/77271/5 "2025-01-24T23:23:20Z")

</div>

I fixed 50% of the problem here: [[lldb] Recursively resolve type aliases when canonicalizing types by adrian-prantl · Pull Request #9883 · swiftlang/llvm-project · GitHub](https://github.com/swiftlang/llvm-project/pull/9883)  
The other bug is in the compiler, it doesn't emit debug info for the inner type alias since it's not directly used in a variable. In the LLDB test I worked around it with the `anchor` variable.

---

<div class="post-metadata">

**Author:** ![Adrian\_Prantl](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/adrian_prantl/32/1582_2.png) [@Adrian\_Prantl](https://forums.swift.org/u/Adrian_Prantl)\
**Post date:** [January 25, 2025, 1:07am UTC](https://forums.swift.org/t/lldb-negative-cache/77271/6 "2025-01-25T01:07:49Z")

</div>

Here's the compiler side: [[Debug info] Retain all type aliases in asttypes mode by adrian-prantl · Pull Request #78901 · swiftlang/swift · GitHub](https://github.com/swiftlang/swift/pull/78901)

---

<div class="post-metadata">

**Author:** ![chiragramani](https://avatars.discourse-cdn.com/v4/letter/c/c89c15/32.png) [@chiragramani](https://forums.swift.org/u/chiragramani)\
**Post date:** [February 3, 2025, 7:12pm UTC](https://forums.swift.org/t/lldb-negative-cache/77271/7 "2025-02-03T19:12:10Z")

</div>

Thank you @Adrian_Prantl 🙏🏼 This pattern is quite common in our monorepo, so these fixes will be very helpful to us.

---

<div class="post-metadata">

**Author:** ![chiragramani](https://avatars.discourse-cdn.com/v4/letter/c/c89c15/32.png) [@chiragramani](https://forums.swift.org/u/chiragramani)\
**Post date:** [March 6, 2025, 9:20pm UTC](https://forums.swift.org/t/lldb-negative-cache/77271/8 "2025-03-06T21:20:05Z")

</div>

@Adrian_Prantl  
Would it be possible to extract all types that make up a binary and query the Swift runtime (or other necessary components) to determine if they can be reconstructed, as required by LLDB to proactively avoid above negative cache issues? Are there existing tools or approaches that could facilitate this?

If this is feasible, we can then even explore adding it as a CI step when a developer creates a PR in-house - with an intent to provide an early detection mechanism for potential debugging regressions.

---

<div class="post-metadata">

**Author:** ![Adrian\_Prantl](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/adrian_prantl/32/1582_2.png) [@Adrian\_Prantl](https://forums.swift.org/u/Adrian_Prantl)\
**Post date:** [May 21, 2025, 6:49pm UTC](https://forums.swift.org/t/lldb-negative-cache/77271/9 "2025-05-21T18:49:33Z")

</div>

Not generally: To give a concrete counterexample, anything involving generics cannot be statically determined at compile time. For other types, while they may be constructible from just looking at a single module and its dependencies, they might not be directly reachable because there is no variable or function parameter of that type. Because the type graph is cyclic, enumerating all unique types is a non-trivial problem.
