Skip to content

Commit

Permalink
Sema: Re-arrange deck chairs again
Browse files Browse the repository at this point in the history
Another pre-emptive compiler_crasher regression fix.

I have an idea for consolidating some of these hacky circularity
checks in a nice way, but not now.
  • Loading branch information
slavapestov committed Jun 19, 2016
1 parent 9ddccad commit 0fc095c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
13 changes: 8 additions & 5 deletions lib/Sema/ITCDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,18 +244,15 @@ void IterativeTypeChecker::processInheritedProtocols(
if (anyDependencies)
return;

// FIXME: Hack to deal with recursion elsewhere.
if (protocol->isInheritedProtocolsValid())
return;

// Check for circular inheritance.
// FIXME: The diagnostics here should be improved... and this should probably
// be handled by the normal cycle detection.
bool diagnosedCircularity = false;
for (unsigned i = 0, n = allProtocols.size(); i != n; /*in loop*/) {
if (allProtocols[i] == protocol ||
allProtocols[i]->inheritsFrom(protocol)) {
if (!diagnosedCircularity) {
if (!diagnosedCircularity &&
!protocol->isInheritedProtocolsValid()) {
diagnose(protocol,
diag::circular_protocol_def, protocol->getName().str());
diagnosedCircularity = true;
Expand All @@ -269,6 +266,12 @@ void IterativeTypeChecker::processInheritedProtocols(
++i;
}

// FIXME: Hack to deal with recursion elsewhere.
// We recurse through DeclContext::getLocalProtocols() -- this should be
// redone to use the IterativeDeclChecker also.
if (protocol->isInheritedProtocolsValid())
return;

protocol->setInheritedProtocols(getASTContext().AllocateCopy(allProtocols));
}

Expand Down
24 changes: 15 additions & 9 deletions lib/Sema/TypeCheckProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1807,15 +1807,21 @@ static Substitution getArchetypeSubstitution(TypeChecker &tc,
SmallVector<ProtocolConformanceRef, 4> conformances;

bool isError = replacement->is<ErrorType>();
for (auto proto : archetype->getConformsTo()) {
ProtocolConformance *conformance = nullptr;
bool conforms = tc.conformsToProtocol(replacement, proto, dc, None,
&conformance);
assert((conforms || isError) &&
"Conformance should already have been verified");
(void)isError;
(void)conforms;
conformances.push_back(ProtocolConformanceRef(proto, conformance));
assert((archetype != nullptr || isError) &&
"Should have built archetypes already");

// FIXME: Turn the nullptr check into an assertion
if (archetype != nullptr) {
for (auto proto : archetype->getConformsTo()) {
ProtocolConformance *conformance = nullptr;
bool conforms = tc.conformsToProtocol(replacement, proto, dc, None,
&conformance);
assert((conforms || isError) &&
"Conformance should already have been verified");
(void)isError;
(void)conforms;
conformances.push_back(ProtocolConformanceRef(proto, conformance));
}
}

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

// RUN: not --crash %target-swift-frontend %s -parse
// RUN: not %target-swift-frontend %s -parse
func e{enum k:A}protocol A{associatedtype B:A
associatedtype n

0 comments on commit 0fc095c

Please sign in to comment.