Skip to content

Commit 69099a8

Browse files
authored
Merge pull request #15527 from DougGregor/typealias-from-debugger
[AST] Skip verification of typealiases marked as "debugger aliases".
2 parents 41e7071 + 9aaa1f1 commit 69099a8

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,
@@ -2519,6 +2521,12 @@ class TypeAliasDecl : public GenericTypeDecl {
25192521
Bits.TypeAliasDecl.IsCompatibilityAlias = newValue;
25202522
}
25212523

2524+
/// Is this a special debugger variable?
2525+
bool isDebuggerAlias() const { return Bits.TypeAliasDecl.IsDebuggerAlias; }
2526+
void markAsDebuggerAlias(bool isDebuggerAlias) {
2527+
Bits.TypeAliasDecl.IsDebuggerAlias = isDebuggerAlias;
2528+
}
2529+
25222530
static bool classof(const Decl *D) {
25232531
return D->getKind() == DeclKind::TypeAlias;
25242532
}

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
@@ -2527,6 +2527,7 @@ TypeAliasDecl::TypeAliasDecl(SourceLoc TypeAliasLoc, SourceLoc EqualLoc,
25272527
: GenericTypeDecl(DeclKind::TypeAlias, DC, Name, NameLoc, {}, GenericParams),
25282528
TypeAliasLoc(TypeAliasLoc), EqualLoc(EqualLoc) {
25292529
Bits.TypeAliasDecl.IsCompatibilityAlias = false;
2530+
Bits.TypeAliasDecl.IsDebuggerAlias = false;
25302531
}
25312532

25322533
SourceRange TypeAliasDecl::getSourceRange() const {

0 commit comments

Comments
 (0)