Skip to content

Commit ae1598d

Browse files
committed
RequirementMachine: Better validation in RequirementMachine::getReducedShapeTerm()
1 parent 4a49419 commit ae1598d

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

lib/AST/RequirementMachine/GenericSignatureQueries.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -721,20 +721,27 @@ MutableTerm
721721
RequirementMachine::getReducedShapeTerm(Type type) const {
722722
assert(type->isParameterPack());
723723

724-
auto rootType = type->getRootGenericParam();
725-
auto term = Context.getMutableTermForType(rootType->getCanonicalType(),
724+
auto term = Context.getMutableTermForType(type->getCanonicalType(),
726725
/*proto=*/nullptr);
727726

728-
// Append the 'shape' symbol to the term.
727+
// From a type term T, form the shape term `T.[shape]`.
729728
term.add(Symbol::forShape(Context));
730729

730+
// Compute the reduced shape term `T'.[shape]`.
731731
System.simplify(term);
732732
verify(term);
733733

734-
// Remove the 'shape' symbol from the term.
735-
assert(term.back().getKind() == Symbol::Kind::Shape);
736-
MutableTerm reducedTerm(term.begin(), term.end() - 1);
734+
// Get the term T', which is the reduced shape of T.
735+
if (term.size() != 2 ||
736+
term[0].getKind() != Symbol::Kind::GenericParam ||
737+
term[1].getKind() != Symbol::Kind::Shape) {
738+
llvm::errs() << "Invalid reduced shape\n";
739+
llvm::errs() << "Type: " << type << "\n";
740+
llvm::errs() << "Term: " << term << "\n";
741+
abort();
742+
}
737743

744+
MutableTerm reducedTerm(term.begin(), term.end() - 1);
738745
return reducedTerm;
739746
}
740747

0 commit comments

Comments
 (0)