Skip to content

Commit da092e8

Browse files
authored
Fix bytecode roundtrip of unregistered ops (#82932)
When roundtripping to bytecode an unregistered operation name that does not contain any '.' separator, the bytecode writer will emit an op encoding without a proper opName. In this case, the string just becomes a possibly unknown dialect name. At parsing, this dialect name is used as a proper operation name. However, when the unregistered operation name coincidentally matches that of a dialect, the parser would fail. That means we can't roundtrip an unregistered op with a name that matches one of the registered dialect names. For example, ``` "index"() : () -> () ``` can be emitted but cannot be parsed, because its name is coincidentally the same as that of the Index dialect. The patch removes such inconsistency. This patch specifically fixes the bytecode roundtrip of `mlir/test/IR/parser.mlir`.
1 parent 085f9b0 commit da092e8

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

mlir/lib/Bytecode/Reader/BytecodeReader.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,22 +1854,18 @@ BytecodeReader::Impl::parseOpName(EncodingReader &reader,
18541854
// Check to see if this operation name has already been resolved. If we
18551855
// haven't, load the dialect and build the operation name.
18561856
if (!opName->opName) {
1857-
// Load the dialect and its version.
1858-
DialectReader dialectReader(attrTypeReader, stringReader, resourceReader,
1859-
dialectsMap, reader, version);
1860-
if (failed(opName->dialect->load(dialectReader, getContext())))
1861-
return failure();
18621857
// If the opName is empty, this is because we use to accept names such as
18631858
// `foo` without any `.` separator. We shouldn't tolerate this in textual
18641859
// format anymore but for now we'll be backward compatible. This can only
18651860
// happen with unregistered dialects.
18661861
if (opName->name.empty()) {
1867-
if (opName->dialect->getLoadedDialect())
1868-
return emitError(fileLoc) << "has an empty opname for dialect '"
1869-
<< opName->dialect->name << "'\n";
1870-
18711862
opName->opName.emplace(opName->dialect->name, getContext());
18721863
} else {
1864+
// Load the dialect and its version.
1865+
DialectReader dialectReader(attrTypeReader, stringReader, resourceReader,
1866+
dialectsMap, reader, version);
1867+
if (failed(opName->dialect->load(dialectReader, getContext())))
1868+
return failure();
18731869
opName->opName.emplace((opName->dialect->name + "." + opName->name).str(),
18741870
getContext());
18751871
}

0 commit comments

Comments
 (0)