[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
This commit is contained in:
River Riddle 2022-02-14 13:39:06 -08:00
parent 9ad64a5c78
commit b474ca1d5a
2 changed files with 16 additions and 5 deletions

View File

@ -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);
}

View File

@ -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;