Skip to content

Commit a57a418

Browse files
committed
RequirementMachine: Make getTypeForSymbolRange() more robust when asserts are off
1 parent 048a64d commit a57a418

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

lib/AST/RequirementMachine/InterfaceType.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,16 @@ getTypeForSymbolRange(const Symbol *begin, const Symbol *end, Type root,
261261
// Return a sugared GenericTypeParamType if we're given an array of
262262
// sugared types to substitute.
263263
unsigned index = GenericParamKey(genericParam).findIndexIn(genericParams);
264+
265+
if (index == genericParams.size()) {
266+
llvm::errs() << "Invalid generic parameter: " << genericParam << "\n";
267+
llvm::errs() << "Valid generic parameters are";
268+
for (auto *otherParam : genericParams)
269+
llvm::errs() << " " << Type(otherParam);
270+
llvm::errs() << "\n";
271+
abort();
272+
}
273+
264274
result = genericParams[index];
265275
return;
266276
}
@@ -344,7 +354,14 @@ getTypeForSymbolRange(const Symbol *begin, const Symbol *end, Type root,
344354
assert(prefix.size() > 0);
345355

346356
auto *props = map.lookUpProperties(prefix.rbegin(), prefix.rend());
347-
assert(props != nullptr);
357+
if (props == nullptr) {
358+
llvm::errs() << "Cannot build interface type for term "
359+
<< MutableTerm(begin, end) << "\n";
360+
llvm::errs() << "Prefix does not conform to any protocols: "
361+
<< prefix << "\n\n";
362+
map.dump(llvm::errs());
363+
abort();
364+
}
348365

349366
// Assert that the associated type's protocol appears among the set
350367
// of protocols that the prefix conforms to.
@@ -356,6 +373,18 @@ getTypeForSymbolRange(const Symbol *begin, const Symbol *end, Type root,
356373
#endif
357374

358375
assocType = props->getAssociatedType(symbol.getName());
376+
if (assocType == nullptr) {
377+
llvm::errs() << "Cannot build interface type for term "
378+
<< MutableTerm(begin, end) << "\n";
379+
llvm::errs() << "Prefix term does not not have a nested type named "
380+
<< symbol.getName() << ": "
381+
<< prefix << "\n";
382+
llvm::errs() << "Property map entry: ";
383+
props->dump(llvm::errs());
384+
llvm::errs() << "\n\n";
385+
map.dump(llvm::errs());
386+
abort();
387+
}
359388
}
360389

361390
result = DependentMemberType::get(result, assocType);

0 commit comments

Comments
 (0)