Fix TableGen emitter: hasValue() has been renamed has_value()
authorMehdi Amini <joker.eph@gmail.com>
Fri, 2 Jun 2023 03:54:32 +0000 (20:54 -0700)
committerMehdi Amini <joker.eph@gmail.com>
Fri, 2 Jun 2023 04:36:34 +0000 (21:36 -0700)
This codepath isn't exercised in-tree right now unfortunately, this only
happens when a dialect does not use the default entry points for types
parsing AND is extensible: both of these aren't the default settings and
the combination of them isn't common.

Fix #63058

mlir/test/mlir-tblgen/attr-or-type-format.td
mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp

index 9017a63..230fa90 100644 (file)
@@ -1,5 +1,6 @@
-// RUN: mlir-tblgen -gen-attrdef-defs -I %S/../../include %s | FileCheck %s --check-prefix=ATTR
-// RUN: mlir-tblgen -gen-typedef-defs -I %S/../../include %s | FileCheck %s --check-prefix=TYPE
+// RUN: sed 's/DEFAULT_TYPE_PARSER/0/' %s | mlir-tblgen -gen-attrdef-defs -I %S/../../include | FileCheck %s --check-prefix=ATTR
+// RUN: sed 's/DEFAULT_TYPE_PARSER/0/' %s | mlir-tblgen -gen-typedef-defs -I %S/../../include | FileCheck %s --check-prefix=TYPE
+// RUN: sed 's/DEFAULT_TYPE_PARSER/1/' %s | mlir-tblgen -gen-typedef-defs -I %S/../../include | FileCheck %s --check-prefix=TYPE --check-prefix=DEFAULT_TYPE_PARSER
 
 include "mlir/IR/AttrTypeBase.td"
 include "mlir/IR/EnumAttr.td"
@@ -9,7 +10,8 @@ include "mlir/IR/OpBase.td"
 def Test_Dialect : Dialect {
   let name = "TestDialect";
   let cppNamespace = "::test";
-  let useDefaultTypePrinterParser = 0;
+  let useDefaultTypePrinterParser = DEFAULT_TYPE_PARSER;
+  let isExtensible = 1;
 }
 
 class TestAttr<string name> : AttrDef<Test_Dialect, name>;
@@ -642,3 +644,9 @@ def TypeN : TestType<"TestP"> {
   let mnemonic = "type_n";
   let assemblyFormat = "`<` (`?`) : (struct($a, $b)^)? `>`";
 }
+
+// DEFAULT_TYPE_PARSER: TestDialect::parseType(::mlir::DialectAsmParser &parser)
+// DEFAULT_TYPE_PARSER: auto parseResult = parseOptionalDynamicType(mnemonic, parser, genType);
+// DEFAULT_TYPE_PARSER: if (parseResult.has_value()) {
+// DEFAULT_TYPE_PARSER:   if (::mlir::succeeded(parseResult.getValue()))
+// DEFAULT_TYPE_PARSER:     return genType;
\ No newline at end of file
index 0928512..a23975f 100644 (file)
@@ -734,7 +734,7 @@ void {0}::printType(::mlir::Type type,
 static const char *const dialectDynamicTypeParserDispatch = R"(
   {
     auto parseResult = parseOptionalDynamicType(mnemonic, parser, genType);
-    if (parseResult.hasValue()) {
+    if (parseResult.has_value()) {
       if (::mlir::succeeded(parseResult.getValue()))
         return genType;
       return Type();