Skip to content

[AST] Skip verification of typealiases marked as "debugger aliases". #15527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,11 @@ class alignas(1 << DeclAlignInBits) Decl {

SWIFT_INLINE_BITFIELD_EMPTY(GenericTypeDecl, TypeDecl);

SWIFT_INLINE_BITFIELD(TypeAliasDecl, GenericTypeDecl, 1,
SWIFT_INLINE_BITFIELD(TypeAliasDecl, GenericTypeDecl, 1+1,
/// Whether the typealias forwards perfectly to its underlying type.
IsCompatibilityAlias : 1
IsCompatibilityAlias : 1,
/// Whether this was a global typealias synthesized by the debugger.
IsDebuggerAlias : 1;
);

SWIFT_INLINE_BITFIELD(NominalTypeDecl, GenericTypeDecl, 1+1+1,
Expand Down Expand Up @@ -2513,6 +2515,12 @@ class TypeAliasDecl : public GenericTypeDecl {
Bits.TypeAliasDecl.IsCompatibilityAlias = newValue;
}

/// Is this a special debugger variable?
bool isDebuggerAlias() const { return Bits.TypeAliasDecl.IsDebuggerAlias; }
void markAsDebuggerAlias(bool isDebuggerAlias) {
Bits.TypeAliasDecl.IsDebuggerAlias = isDebuggerAlias;
}

static bool classof(const Decl *D) {
return D->getKind() == DeclKind::TypeAlias;
}
Expand Down
17 changes: 15 additions & 2 deletions lib/AST/ASTVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,20 @@ class Verifier : public ASTWalker {
bool shouldVerify(Pattern *S) { return true; }
bool shouldVerify(Decl *S) { return true; }

bool shouldVerify(TypeAliasDecl *typealias) {
// Don't verify type aliases formed by the debugger; they violate some
// AST invariants involving archetypes.
if (typealias->isDebuggerAlias()) return false;

// FIXME: Temporary hack to bridge the gap until LLDB starts setting
// the "debugger alias" flag.
if (typealias->getName().str().startswith("$") &&
typealias->getName().str().contains("lldb"))
return false;

return true;
}

// Default cases for whether we should verify a checked subtree.
bool shouldVerifyChecked(Expr *E) {
if (!E->getType()) {
Expand Down Expand Up @@ -582,8 +596,7 @@ class Verifier : public ASTWalker {
abort();
}

bool foundError = false &&
type->getCanonicalType().findIf([&](Type type) -> bool {
bool foundError = type->getCanonicalType().findIf([&](Type type) -> bool {
if (auto archetype = type->getAs<ArchetypeType>()) {
// Only visit each archetype once.
if (!visitedArchetypes.insert(archetype).second)
Expand Down
1 change: 1 addition & 0 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2513,6 +2513,7 @@ TypeAliasDecl::TypeAliasDecl(SourceLoc TypeAliasLoc, SourceLoc EqualLoc,
: GenericTypeDecl(DeclKind::TypeAlias, DC, Name, NameLoc, {}, GenericParams),
TypeAliasLoc(TypeAliasLoc), EqualLoc(EqualLoc) {
Bits.TypeAliasDecl.IsCompatibilityAlias = false;
Bits.TypeAliasDecl.IsDebuggerAlias = false;
}

SourceRange TypeAliasDecl::getSourceRange() const {
Expand Down