Abort via report_fatal_error if dialect has been registered.

Fixes test in opt mode.

    Closes: tensorflow/mlir#17.

--

PiperOrigin-RevId: 243711043
This commit is contained in:
Jacques Pienaar 2019-04-15 16:32:00 -07:00 committed by Mehdi Amini
parent 6288503975
commit 5d783ab3bd
1 changed files with 8 additions and 5 deletions

View File

@ -703,11 +703,14 @@ void Dialect::registerDialect(MLIRContext *context) {
// Lock access to the context registry.
llvm::sys::SmartScopedWriter<true> registryLock(impl.contextMutex);
assert(llvm::none_of(impl.dialects,
[this](std::unique_ptr<Dialect> &dialect) {
return dialect->getNamespace() == getNamespace();
}) &&
"a dialect with the given namespace has already been registered");
// Abort if dialect with namespace has already been registered.
if (llvm::any_of(impl.dialects, [this](std::unique_ptr<Dialect> &dialect) {
return dialect->getNamespace() == getNamespace();
})) {
llvm::report_fatal_error("a dialect with namespace '" +
Twine(getNamespace()) +
"' has already been registered");
}
impl.dialects.push_back(std::unique_ptr<Dialect>(this));
}