This is an archive of the discontinued LLVM Phabricator instance.

[AsmParser] Improve error recovery again.
ClosedPublic

Authored by lattner on May 11 2022, 12:25 AM.

Details

Summary

Change the parsing logic to use StringRef instead of lower level
char* logic. Also, if emitting a diagnostic on the first token
in the file, we make sure to use that position instead of the
very start of the file.

Diff Detail

Event Timeline

lattner created this revision.May 11 2022, 12:25 AM
Herald added a project: Restricted Project. · View Herald Transcript
lattner requested review of this revision.May 11 2022, 12:25 AM
lattner accepted this revision.May 11 2022, 12:25 AM
This revision is now accepted and ready to land.May 11 2022, 12:25 AM
This revision was landed with ongoing or failed builds.May 11 2022, 12:25 AM
This revision was automatically updated to reflect the committed changes.
bzcheeseman added inline comments.May 11 2022, 8:35 AM
mlir/lib/Parser/Parser.cpp
202
StringRef eol = startOfBuffer.detectEOL();
if (!startOfBuffer.endswith(eol))

?

212
size_t newLineIndex = prefLine.find_last_of(eol); // eol variable from above

?

217

could you use rsplit on this? It'd just return a pair of stringrefs and then startOfBuffer is just the first (before the comment token).

LG with @bzcheeseman s comments addressed.

lattner added inline comments.May 11 2022, 12:51 PM
mlir/lib/Parser/Parser.cpp
202

detectEOL is... interesting, but massive overkill for what we're doing. I think the existing code is simple and good.

212

Likewise, it is fine to remove \n\r in any combination, and is simpler.

217

I investigated, but not really. rsplit is the wrong thing for lines that contain multiple //'s. We need split from the start of the line. I just tried startOfBuffer = startOfBuffer.split("//").first; but that is of course wrong, as is prevLine.split(...) without weird gymnastics. I think the existing code is a reasonable solution here.

Thanks for looking into it - if this is simpler than the other thing then by all means let's keep it simple!