Skip to content

[AST] Block recursion through ProtocolDecl::getInheritedProtocols(). #17278

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 2 commits into from
Jun 16, 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
7 changes: 5 additions & 2 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ class alignas(1 << DeclAlignInBits) Decl {
HasValidatedLayout : 1
);

SWIFT_INLINE_BITFIELD_FULL(ProtocolDecl, NominalTypeDecl, 1+1+1+1+1+1+1+2+8+16,
SWIFT_INLINE_BITFIELD_FULL(ProtocolDecl, NominalTypeDecl, 1+1+1+1+1+1+1+2+8+16+1,
/// Whether the \c RequiresClass bit is valid.
RequiresClassValid : 1,

Expand Down Expand Up @@ -520,7 +520,10 @@ class alignas(1 << DeclAlignInBits) Decl {
KnownProtocol : 8, // '8' for speed. This only needs 6.

/// The number of requirements in the requirement signature.
NumRequirementsInSignature : 16
NumRequirementsInSignature : 16,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this, and other changes, are indented with tabs instead of spaces, like the rest of the file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yikes, good catch. My editor has gone nuts.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I'll clean them up shortly; for now, I need to unblock CI)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whitespace cleaned up in #17277, thank you!


/// Whether we are currently computing inherited protocols.
ComputingInheritedProtocols : 1
);

SWIFT_INLINE_BITFIELD(ClassDecl, NominalTypeDecl, 1+2+1+2+1+3+1+1,
Expand Down
6 changes: 6 additions & 0 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3170,6 +3170,7 @@ ProtocolDecl::ProtocolDecl(DeclContext *DC, SourceLoc ProtocolLoc,
Bits.ProtocolDecl.NumRequirementsInSignature = 0;
Bits.ProtocolDecl.HasMissingRequirements = false;
Bits.ProtocolDecl.KnownProtocol = 0;
Bits.ProtocolDecl.ComputingInheritedProtocols = false;
}

llvm::TinyPtrVector<ProtocolDecl *>
Expand All @@ -3180,6 +3181,10 @@ ProtocolDecl::getInheritedProtocols() const {
// We shouldn't need this, but it shows up in recursive invocations.
if (!isRequirementSignatureComputed()) {
SmallPtrSet<ProtocolDecl *, 4> known;
if (Bits.ProtocolDecl.ComputingInheritedProtocols) return result;

auto *self = const_cast<ProtocolDecl *>(this);
self->Bits.ProtocolDecl.ComputingInheritedProtocols = true;
for (unsigned index : indices(getInherited())) {
if (auto type = getInheritedType(index)) {
// Only protocols can appear in the inheritance clause
Expand All @@ -3195,6 +3200,7 @@ ProtocolDecl::getInheritedProtocols() const {
}
}
}
self->Bits.ProtocolDecl.ComputingInheritedProtocols = false;
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors

// RUN: not --crash %target-swift-frontend %s -emit-ir
// RUN: not %target-swift-frontend %s -emit-ir
protocol b:Self.a&(Int
protocol b{}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors

// RUN: not --crash %target-swift-frontend %s -emit-ir
// RUN: not %target-swift-frontend %s -emit-ir
protocol A:Self.a&( A
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors

// RUN: not --crash %target-swift-frontend %s -emit-ir
// RUN: not %target-swift-frontend %s -emit-ir
protocol A:RangeReplaceableCollection&(t:A{extension{}a e:class a{}class a
{{}lass a=_{case.a<a =nil??as?=
:a<a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors

// RUN: not --crash %target-swift-frontend %s -emit-ir
// RUN: not %target-swift-frontend %s -emit-ir
protocol A:a
& {}typealias a:A