[Mlir-commits] [mlir] b474ca1 - [PDLL] Properly error out on returning results from native constraints
River Riddle
llvmlistbot at llvm.org
Sat Feb 26 11:26:43 PST 2022
Author: River Riddle
Date: 2022-02-26T11:08:51-08:00
New Revision: b474ca1d5a445cdfa924d794439013bea1599f92
URL: https://github.com/llvm/llvm-project/commit/b474ca1d5a445cdfa924d794439013bea1599f92
DIFF: https://github.com/llvm/llvm-project/commit/b474ca1d5a445cdfa924d794439013bea1599f92.diff
LOG: [PDLL] Properly error out on returning results from native constraints
PDL currently doesn't support result values from constraints, meaning we need
to error out until this is actually supported to avoid crashes.
Differential Revision: https://reviews.llvm.org/D119782
Added:
Modified:
mlir/lib/Tools/PDLL/Parser/Parser.cpp
mlir/test/mlir-pdll/Parser/constraint-failure.pdll
Removed:
################################################################################
diff --git a/mlir/lib/Tools/PDLL/Parser/Parser.cpp b/mlir/lib/Tools/PDLL/Parser/Parser.cpp
index e69e8ff7e1944..da7283799d951 100644
--- a/mlir/lib/Tools/PDLL/Parser/Parser.cpp
+++ b/mlir/lib/Tools/PDLL/Parser/Parser.cpp
@@ -955,6 +955,12 @@ FailureOr<T *> Parser::parseUserNativeConstraintOrRewriteDecl(
if (failed(parseToken(Token::semicolon,
"expected `;` after native declaration")))
return failure();
+ // TODO: PDL should be able to support constraint results in certain
+ // situations, we should revise this.
+ if (std::is_same<ast::UserConstraintDecl, T>::value && !results.empty()) {
+ return emitError(
+ "native Constraints currently do not support returning results");
+ }
return T::createNative(ctx, name, arguments, results, optCodeStr, resultType);
}
diff --git a/mlir/test/mlir-pdll/Parser/constraint-failure.pdll b/mlir/test/mlir-pdll/Parser/constraint-failure.pdll
index 8291913623943..18877b4bcc50e 100644
--- a/mlir/test/mlir-pdll/Parser/constraint-failure.pdll
+++ b/mlir/test/mlir-pdll/Parser/constraint-failure.pdll
@@ -116,22 +116,22 @@ Constraint Foo() -> {}
// -----
// CHECK: cannot create a single-element tuple with an element label
-Constraint Foo() -> result: Value;
+Constraint Foo() -> result: Value {}
// -----
// CHECK: cannot create a single-element tuple with an element label
-Constraint Foo() -> (result: Value);
+Constraint Foo() -> (result: Value) {}
// -----
// CHECK: expected identifier constraint
-Constraint Foo() -> ();
+Constraint Foo() -> () {}
// -----
// CHECK: expected `:` before result constraint
-Constraint Foo() -> (result{};
+Constraint Foo() -> (result {};
// -----
@@ -141,7 +141,7 @@ Constraint Foo() -> (Op{};
// -----
// CHECK: inline `Attr`, `Value`, and `ValueRange` type constraints are not permitted on arguments or results
-Constraint Foo() -> Value<type>){}
+Constraint Foo() -> Value<type>) {}
// -----
@@ -158,3 +158,8 @@ Pattern {
// CHECK: expected `;` after native declaration
Constraint Foo() [{}]
+
+// -----
+
+// CHECK: native Constraints currently do not support returning results
+Constraint Foo() -> Op;
More information about the Mlir-commits
mailing list