From fee62e21861aa80d5da2b450a86c33ed879399b7 Mon Sep 17 00:00:00 2001 From: Eric Schweitz Date: Wed, 28 Aug 2019 13:55:11 -0700 Subject: [PATCH] Tweak to the pretty type parser to recognize that `->` is a special token. Tweak to the pretty type parser to recognize that `->` is a special token that shouldn't be split into two characters. This change allows dialect types to wrap function types as in `!my.ptr_type<(i32) -> i32>`. Closes #105 COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/105 from schweitzpgi:parse-arrow 8b2d768053f419daae5a1a864121a44c4319acbe PiperOrigin-RevId: 265986240 --- third_party/mlir/lib/IR/AsmPrinter.cpp | 7 +++++++ third_party/mlir/lib/Parser/Parser.cpp | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/third_party/mlir/lib/IR/AsmPrinter.cpp b/third_party/mlir/lib/IR/AsmPrinter.cpp index 9da922cd621..06c5eac8643 100644 --- a/third_party/mlir/lib/IR/AsmPrinter.cpp +++ b/third_party/mlir/lib/IR/AsmPrinter.cpp @@ -544,6 +544,13 @@ static bool isDialectSymbolSimpleEnoughForPrettyForm(StringRef symName) { case '{': nestedPunctuation.push_back(c); continue; + case '-': + // Treat `->` as a special token. + if (!symName.empty() && symName.front() == '>') { + symName = symName.drop_front(); + continue; + } + break; // Reject types with mismatched brackets. case '>': if (nestedPunctuation.pop_back_val() != '<') diff --git a/third_party/mlir/lib/Parser/Parser.cpp b/third_party/mlir/lib/Parser/Parser.cpp index c377ccdd6af..dde24e4cdb4 100644 --- a/third_party/mlir/lib/Parser/Parser.cpp +++ b/third_party/mlir/lib/Parser/Parser.cpp @@ -379,6 +379,12 @@ ParseResult Parser::parsePrettyDialectSymbolName(StringRef &prettyName) { nestedPunctuation.push_back(c); continue; + case '-': + // The sequence `->` is treated as special token. + if (*curPtr == '>') + ++curPtr; + continue; + case '>': if (nestedPunctuation.pop_back_val() != '<') return emitError("unbalanced '>' character in pretty dialect name");