This is an archive of the discontinued LLVM Phabricator instance.

[mlir][bytecode] Fix dialect version parsing.
ClosedPublic

Authored by jpienaar on May 10 2023, 4:03 AM.

Details

Summary

We were querying the wrong EncReader along some paths that resulted in
failures depending on if one encountered an Attribute from an unloaded
dialect before encountering an operation from that dialect.

Also fix error where we were able to emit "custom" form for an attribute
without custom form in TestDialect.

Diff Detail

Event Timeline

jpienaar created this revision.May 10 2023, 4:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 10 2023, 4:03 AM
jpienaar requested review of this revision.May 10 2023, 4:03 AM
mehdi_amini added inline comments.May 10 2023, 4:23 PM
mlir/lib/Bytecode/Reader/BytecodeReader.cpp
1391

I am puzzled, versionBuffer wasn't used at all, how did it ever worked?

mfrancio added inline comments.May 10 2023, 4:31 PM
mlir/lib/Bytecode/Reader/BytecodeReader.cpp
1391

It is used in parseOpName, before loading the dialect reader:

// Load the dialect and its version.
EncodingReader versionReader(opName->dialect->versionBuffer, fileLoc);
mehdi_amini added inline comments.May 10 2023, 4:46 PM
mlir/lib/Bytecode/Reader/BytecodeReader.cpp
1391

OK so we should remove it from there now that it is here right ?

jpienaar updated this revision to Diff 521221.May 11 2023, 12:56 AM

Remove unused encReader created

This was created but never used as it would be replaced in call.

mlir/lib/Bytecode/Reader/BytecodeReader.cpp
1391

Yes, that's why this only happened when attribute got materialized first. And yes removed.

jpienaar updated this revision to Diff 521222.May 11 2023, 1:04 AM

Op was being printed as dialect, change to dialect.op form.

mehdi_amini accepted this revision.May 11 2023, 1:22 AM
mehdi_amini added inline comments.
mlir/lib/Bytecode/Reader/BytecodeReader.cpp
840

I'm fine with introducing this method, but it seems like if this is the pattern to create a new DialectReader for a specific encoding buffer, we should be consistent and use it everywhere we're doing it.

That is there are a couple of other places like:

// Initialize the resource reader with the resource sections.
DialectReader dialectReader(attrTypeReader, stringReader, resourceReader,
                            reader);
1390

Instead of `withE

This revision is now accepted and ready to land.May 11 2023, 1:22 AM

(I think your other comment got cut off)

mlir/lib/Bytecode/Reader/BytecodeReader.cpp
840

We don't have a DialectReader to start with there. This is effectively "take DialectReader where everything else remains the same but with different EncodingReader" (e.g., clone with new encoding reader). I don't see this pattern used elsewhere here.

mehdi_amini added inline comments.May 11 2023, 1:41 AM
mlir/lib/Bytecode/Reader/BytecodeReader.cpp
840

Ah I missed that the other case didn't have a DialectReader at hand!

This revision was automatically updated to reflect the committed changes.