Skip to content

Commit 9aaa1f1

Browse files
committed
[AST] Skip verification of typealiases marked as "debugger aliases".
LLDB creates global typealiases that have archetypes in them, which violates AST invariants and trips up the AST verifier. Introduce a specific bit that LLDB can set to indicate that a given typealias is such an alias. We'll skip AST verification for such typealiases. As a way to stage in this change without requiring synchronization across the Swift and LLDB repos, also match typealiases with the names $.*lldb in the AST verifier and skip verification. Once LLDB is setting the bit appropriately, we'll remove this hack.
1 parent e0d423a commit 9aaa1f1

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

include/swift/AST/Decl.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,11 @@ class alignas(1 << DeclAlignInBits) Decl {
426426

427427
SWIFT_INLINE_BITFIELD_EMPTY(GenericTypeDecl, TypeDecl);
428428

429-
SWIFT_INLINE_BITFIELD(TypeAliasDecl, GenericTypeDecl, 1,
429+
SWIFT_INLINE_BITFIELD(TypeAliasDecl, GenericTypeDecl, 1+1,
430430
/// Whether the typealias forwards perfectly to its underlying type.
431-
IsCompatibilityAlias : 1
431+
IsCompatibilityAlias : 1,
432+
/// Whether this was a global typealias synthesized by the debugger.
433+
IsDebuggerAlias : 1;
432434
);
433435

434436
SWIFT_INLINE_BITFIELD(NominalTypeDecl, GenericTypeDecl, 1+1+1,
@@ -2513,6 +2515,12 @@ class TypeAliasDecl : public GenericTypeDecl {
25132515
Bits.TypeAliasDecl.IsCompatibilityAlias = newValue;
25142516
}
25152517

2518+
/// Is this a special debugger variable?
2519+
bool isDebuggerAlias() const { return Bits.TypeAliasDecl.IsDebuggerAlias; }
2520+
void markAsDebuggerAlias(bool isDebuggerAlias) {
2521+
Bits.TypeAliasDecl.IsDebuggerAlias = isDebuggerAlias;
2522+
}
2523+
25162524
static bool classof(const Decl *D) {
25172525
return D->getKind() == DeclKind::TypeAlias;
25182526
}

lib/AST/ASTVerifier.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,20 @@ class Verifier : public ASTWalker {
445445
bool shouldVerify(Pattern *S) { return true; }
446446
bool shouldVerify(Decl *S) { return true; }
447447

448+
bool shouldVerify(TypeAliasDecl *typealias) {
449+
// Don't verify type aliases formed by the debugger; they violate some
450+
// AST invariants involving archetypes.
451+
if (typealias->isDebuggerAlias()) return false;
452+
453+
// FIXME: Temporary hack to bridge the gap until LLDB starts setting
454+
// the "debugger alias" flag.
455+
if (typealias->getName().str().startswith("$") &&
456+
typealias->getName().str().contains("lldb"))
457+
return false;
458+
459+
return true;
460+
}
461+
448462
// Default cases for whether we should verify a checked subtree.
449463
bool shouldVerifyChecked(Expr *E) {
450464
if (!E->getType()) {
@@ -582,8 +596,7 @@ class Verifier : public ASTWalker {
582596
abort();
583597
}
584598

585-
bool foundError = false &&
586-
type->getCanonicalType().findIf([&](Type type) -> bool {
599+
bool foundError = type->getCanonicalType().findIf([&](Type type) -> bool {
587600
if (auto archetype = type->getAs<ArchetypeType>()) {
588601
// Only visit each archetype once.
589602
if (!visitedArchetypes.insert(archetype).second)

lib/AST/Decl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2513,6 +2513,7 @@ TypeAliasDecl::TypeAliasDecl(SourceLoc TypeAliasLoc, SourceLoc EqualLoc,
25132513
: GenericTypeDecl(DeclKind::TypeAlias, DC, Name, NameLoc, {}, GenericParams),
25142514
TypeAliasLoc(TypeAliasLoc), EqualLoc(EqualLoc) {
25152515
Bits.TypeAliasDecl.IsCompatibilityAlias = false;
2516+
Bits.TypeAliasDecl.IsDebuggerAlias = false;
25162517
}
25172518

25182519
SourceRange TypeAliasDecl::getSourceRange() const {

0 commit comments

Comments
 (0)