diff --git a/mlir/include/mlir/IR/DialectImplementation.h b/mlir/include/mlir/IR/DialectImplementation.h --- a/mlir/include/mlir/IR/DialectImplementation.h +++ b/mlir/include/mlir/IR/DialectImplementation.h @@ -140,12 +140,18 @@ } }; +namespace detail { +template +using has_push_back_t = decltype(std::declval().push_back( + std::declval())); +} // namespace detail + /// Parse any container that supports back insertion as a list. template -struct FieldParser< - ContainerT, std::enable_if_t::value, - ContainerT>> { +struct FieldParser::value, + ContainerT>> { using ElementT = typename ContainerT::value_type; static FailureOr parse(AsmParser &parser) { ContainerT elements; @@ -153,7 +159,7 @@ auto element = FieldParser::parse(parser); if (failed(element)) return failure(); - elements.push_back(*element); + elements.push_back(std::move(*element)); return success(); }; if (parser.parseCommaSeparatedList(elementParser)) diff --git a/mlir/test/lib/Dialect/Test/TestAttrDefs.td b/mlir/test/lib/Dialect/Test/TestAttrDefs.td --- a/mlir/test/lib/Dialect/Test/TestAttrDefs.td +++ b/mlir/test/lib/Dialect/Test/TestAttrDefs.td @@ -173,6 +173,11 @@ let printer = "::printIntArray($_printer, $_self)"; } + +def TestParamVector : ArrayRefParameter<"int", ""> { + let cppStorageType = "std::vector"; +} + def TestParamUnsigned : AttrParameter<"uint64_t", ""> {} def TestAttrWithFormat : Test_Attr<"TestAttrWithFormat"> { @@ -183,6 +188,7 @@ "::mlir::IntegerAttr":$three, TestParamFour:$four, TestParamUnsigned:$five, + TestParamVector:$six, // Array of another attribute. ArrayRefParameter< "AttrWithTypeBuilderAttr", // The parameter C++ type. @@ -192,7 +198,7 @@ let mnemonic = "attr_with_format"; let assemblyFormat = [{ - `<` $one `:` struct($two, $four) `:` $three `:` $five `,` + `<` $one `:` struct($two, $four) `:` $three `:` $five `:` `[` $six `]` `,` `[` `` $arrayOfAttrWithTypeBuilderAttr `]` `>` }]; let genVerifyDecl = 1; diff --git a/mlir/test/lib/Dialect/Test/TestAttributes.cpp b/mlir/test/lib/Dialect/Test/TestAttributes.cpp --- a/mlir/test/lib/Dialect/Test/TestAttributes.cpp +++ b/mlir/test/lib/Dialect/Test/TestAttributes.cpp @@ -98,11 +98,10 @@ return success(); } -LogicalResult -TestAttrWithFormatAttr::verify(function_ref emitError, - int64_t one, std::string two, IntegerAttr three, - ArrayRef four, uint64_t five, - ArrayRef arrayOfAttrs) { +LogicalResult TestAttrWithFormatAttr::verify( + function_ref emitError, int64_t one, std::string two, + IntegerAttr three, ArrayRef four, uint64_t five, ArrayRef six, + ArrayRef arrayOfAttrs) { if (four.size() != static_cast(one)) return emitError() << "expected 'one' to equal 'four.size()'"; return success(); diff --git a/mlir/test/mlir-tblgen/attr-or-type-format-roundtrip.mlir b/mlir/test/mlir-tblgen/attr-or-type-format-roundtrip.mlir --- a/mlir/test/mlir-tblgen/attr-or-type-format-roundtrip.mlir +++ b/mlir/test/mlir-tblgen/attr-or-type-format-roundtrip.mlir @@ -5,10 +5,10 @@ // CHECK: !test.type_with_format<2147, three = "hi", two = "hi"> func.func private @test_roundtrip_parameter_parsers(!test.type_with_format<111, three = #test, two = "foo">) -> !test.type_with_format<2147, two = "hi", three = "hi"> attributes { - // CHECK: #test.attr_with_format<3 : two = "hello", four = [1, 2, 3] : 42 : i64 : 0, [ 10 : i16] - attr0 = #test.attr_with_format<3 : two = "hello", four = [1, 2, 3] : 42 : i64 : 0, [10 : i16]>, - // CHECK: #test.attr_with_format<5 : two = "a_string", four = [4, 5, 6, 7, 8] : 8 : i8 : 255, [ 10 : i16]>, - attr1 = #test.attr_with_format<5 : two = "a_string", four = [4, 5, 6, 7, 8] : 8 : i8 : 255, [10 : i16]>, + // CHECK: #test.attr_with_format<3 : two = "hello", four = [1, 2, 3] : 42 : i64 : 0 : [4, 5, 6], [ 10 : i16] + attr0 = #test.attr_with_format<3 : two = "hello", four = [1, 2, 3] : 42 : i64 : 0 : [4, 5, 6], [10 : i16]>, + // CHECK: #test.attr_with_format<5 : two = "a_string", four = [4, 5, 6, 7, 8] : 8 : i8 : 255 : [9, 10, 11], [ 10 : i16]>, + attr1 = #test.attr_with_format<5 : two = "a_string", four = [4, 5, 6, 7, 8] : 8 : i8 : 255 : [9, 10, 11], [10 : i16]>, // CHECK: #test attr2 = #test, // CHECK: #test.attr_params<42, 24> diff --git a/mlir/test/mlir-tblgen/attr-or-type-format.mlir b/mlir/test/mlir-tblgen/attr-or-type-format.mlir --- a/mlir/test/mlir-tblgen/attr-or-type-format.mlir +++ b/mlir/test/mlir-tblgen/attr-or-type-format.mlir @@ -123,7 +123,7 @@ func.func private @test_verifier_fails() -> () attributes { // expected-error@+1 {{expected 'one' to equal 'four.size()'}} - attr = #test.attr_with_format<42 : two = "hello", four = [1, 2, 3] : 42 : i64 : 0, [10 : i16]> + attr = #test.attr_with_format<42 : two = "hello", four = [1, 2, 3] : 42 : i64 : 0 : [4, 5, 6], [10 : i16]> } // -----