xref: /llvm-project/mlir/test/mlir-pdll/Parser/expr-failure.pdll (revision 780a20984b6af067eed5870eb7c00ea076b6072a)
1// RUN: not mlir-pdll %s -I %S -I %S/../../../include -split-input-file 2>&1 | FileCheck %s
2
3//===----------------------------------------------------------------------===//
4// Reference Expr
5//===----------------------------------------------------------------------===//
6
7Pattern {
8  // CHECK: expected identifier constraint
9  let foo = Foo: ;
10}
11
12// -----
13
14Pattern {
15  // CHECK: undefined reference to `bar`
16  let foo = bar;
17}
18
19// -----
20
21Pattern FooPattern {
22  erase _: Op;
23}
24
25Pattern {
26  // CHECK: invalid reference to `FooPattern`
27  let foo = FooPattern;
28}
29
30// -----
31
32Pattern {
33  // CHECK: expected `:` after `_` variable
34  let foo = _;
35}
36
37// -----
38
39Pattern {
40  // CHECK: expected identifier constraint
41  let foo = _: ;
42}
43
44// -----
45
46//===----------------------------------------------------------------------===//
47// Call Expr
48//===----------------------------------------------------------------------===//
49
50Constraint foo(value: Value);
51
52Pattern {
53  // CHECK: expected `)` after argument list
54  foo(_: Value{};
55}
56
57// -----
58
59Pattern {
60  // CHECK: expected a reference to a callable `Constraint` or `Rewrite`, but got: `Op`
61  let foo: Op;
62  foo();
63}
64
65// -----
66
67Constraint Foo();
68
69Pattern {
70  // CHECK: invalid number of arguments for constraint call; expected 0, but got 1
71  Foo(_: Value);
72}
73
74// -----
75
76Constraint Foo(arg: Value);
77
78Pattern {
79  // CHECK: unable to convert expression of type `Attr` to the expected type of `Value`
80  Foo(attr<"i32">);
81}
82
83// -----
84
85//===----------------------------------------------------------------------===//
86// Member Access Expr
87//===----------------------------------------------------------------------===//
88
89Pattern {
90  // CHECK: expected identifier or numeric member name
91  let root: Op;
92  erase root.<>;
93}
94
95// -----
96
97Pattern {
98  // CHECK: invalid member access `unknown_result` on expression of type `Op`
99  let root: Op;
100  erase root.unknown_result;
101}
102
103// -----
104
105Pattern {
106  let tuple = (result1 = value: Value, result2 = value);
107
108  // CHECK: invalid member access `unknown_result` on expression of type `Tuple<result1: Value, result2: Value>`
109  let tuple2 = (tuple.result1, tuple.unknown_result);
110
111  erase op<>;
112}
113
114// -----
115
116Pattern {
117  let tuple = (result1 = value: Value, result2 = value);
118
119  // CHECK: invalid member access `2` on expression of type `Tuple<result1: Value, result2: Value>`
120  let tuple2 = (tuple.0, tuple.2);
121
122  erase op<>;
123}
124
125// -----
126
127//===----------------------------------------------------------------------===//
128// Range Expr
129//===----------------------------------------------------------------------===//
130
131Pattern {
132  // CHECK: unable to convert expression of type `Tuple<>` to the expected type of `ValueRange`
133  // CHECK: Tuple to Range conversion is currently only allowed within a rewrite context
134  erase op<>(());
135}
136
137// -----
138
139Pattern {
140  // CHECK: unable to convert expression of type `Tuple<Value, Type>` to the expected type of `ValueRange`
141  replace op<>(arg: Value) -> (type: Type) with op<test.op>((arg, type));
142}
143
144// -----
145
146//===----------------------------------------------------------------------===//
147// Tuple Expr
148//===----------------------------------------------------------------------===//
149
150Pattern {
151  // CHECK: expected `)` after tuple element list
152  let tuple = (value: Value, value;
153}
154
155// -----
156
157Pattern {
158  // CHECK: unable to build a tuple with `Tuple<Value, Value>` element
159  let tuple = (_: Value, _: Value);
160  let var = (tuple);
161  erase op<>;
162}
163
164// -----
165
166Constraint Foo();
167
168Pattern {
169  // CHECK: unable to build a tuple with `Constraint` element
170  let tuple = (Foo);
171  erase op<>;
172}
173
174// -----
175
176Constraint Foo(op: Op) {}
177
178Pattern {
179  // CHECK: unable to negate non native constraints
180  let root = op<>;
181  not Foo(root);
182}
183
184// -----
185
186Rewrite Foo();
187
188Pattern {
189  // CHECK: unable to build a tuple with `Rewrite` element
190  let tuple = (Foo);
191  erase op<>;
192}
193
194// -----
195
196Rewrite Foo(op: Op);
197
198Pattern {
199  // CHECK: unable to negate a Rewrite
200  let root = op<>;
201  rewrite root with {
202     not Foo(root);
203  }
204}
205
206// -----
207
208Pattern {
209  // CHECK: expected native constraint
210  not attr<"0 : i1">
211  erase _;
212}
213
214// -----
215
216Pattern {
217  let tuple = (attr<"3 : i34">);
218  // CHECK: expected `(` after function name
219  not tuple.0;
220  erase _;
221}
222
223// -----
224
225Pattern {
226  // CHECK: expected expression
227  let tuple = (10 = _: Value);
228  erase op<>;
229}
230
231// -----
232
233Pattern {
234  // CHECK: duplicate tuple element label `field`
235  // CHECK: see previous label use here
236  let tuple = (field = _: Value, field = _: Value);
237  erase op<>;
238}
239
240// -----
241
242//===----------------------------------------------------------------------===//
243// `attr` Expr
244//===----------------------------------------------------------------------===//
245
246Pattern {
247  // CHECK: expected string literal containing MLIR attribute
248  let foo = attr<foo>;
249}
250
251// -----
252
253Pattern {
254  // CHECK: expected `>` after attribute literal
255  let foo = attr<""<>;
256}
257
258// -----
259
260//===----------------------------------------------------------------------===//
261// `op` Expr
262//===----------------------------------------------------------------------===//
263
264Pattern {
265  // CHECK: expected `)` after operation operand list
266  let value: Value;
267  let foo = op<func.func>(value<;
268}
269
270// -----
271
272Pattern {
273  // CHECK: unable to convert expression of type `Attr` to the expected type of `ValueRange`
274  let attr: Attr;
275  let foo = op<func.func>(attr);
276}
277
278// -----
279
280Pattern {
281  // CHECK: expected `Value` or `ValueRange` convertible expression, but got `Type`
282  let foo = op<>(_: Type, _: TypeRange);
283}
284
285// -----
286
287Pattern {
288  // CHECK: expected identifier or string attribute name
289  let foo = op<> { 10;
290}
291
292// -----
293
294Pattern {
295  // CHECK: expected `Attr` expression, but got `Value`
296  let foo = op<> { foo = _: Value };
297}
298
299// -----
300
301Pattern {
302  // CHECK: expected `}` after operation attribute list
303  let foo = op<> { "foo" {;
304}
305
306// -----
307
308Pattern {
309  // CHECK: expected `(` before operation result type list
310  let foo = op<> -> );
311}
312
313// -----
314
315Pattern {
316  // CHECK: unable to convert expression of type `ValueRange` to the expected type of `TypeRange`
317  let foo = op<> -> (_: ValueRange);
318}
319
320// -----
321
322Pattern {
323  // CHECK: expected `Type` or `TypeRange` convertible expression, but got `Value`
324  let foo = op<> -> (_: Value, _: ValueRange);
325}
326
327// -----
328
329Pattern {
330  // CHECK: expected `)` after operation result type list
331  let value: TypeRange;
332  let foo = op<> -> (value<;
333}
334
335// -----
336
337#include "include/ops.td"
338
339Pattern {
340  // CHECK: invalid number of operand groups for `test.all_empty`; expected 0, but got 2
341  // CHECK: see the definition of `test.all_empty` here
342  let foo = op<test.all_empty>(operand1: Value, operand2: Value);
343}
344
345// -----
346
347#include "include/ops.td"
348
349Pattern {
350  // CHECK: invalid number of result groups for `test.all_empty`; expected 0, but got 2
351  // CHECK: see the definition of `test.all_empty` here
352  let foo = op<test.all_empty> -> (result1: Type, result2: Type);
353}
354
355// -----
356
357Pattern {
358  // CHECK: warning: operation result types are marked to be inferred, but
359  // CHECK-SAME: `test.unknown_inferred_result_op` is unknown.
360  // CHECK-SAME: Ensure that `test.unknown_inferred_result_op` supports zero
361  // CHECK-SAME: results or implements `InferTypeOpInterface`.
362  // CHECK-SAME: Include the ODS definition of this operation to remove this
363  // CHECK-SAME: warning.
364  rewrite _: Op with {
365    op<test.unknown_inferred_result_op>;
366  };
367}
368
369// -----
370
371#include "include/ops.td"
372
373Pattern {
374  // CHECK: warning: operation result types are marked to be inferred, but
375  // CHECK-SAME: `test.multiple_single_result` does not provide an implementation
376  // CHECK-SAME: of `InferTypeOpInterface`. Ensure that `test.multiple_single_result`
377  // CHECK-SAME: attaches `InferTypeOpInterface` at runtime, or add support
378  // CHECK-SAME: to the ODS definition to remove this warning.
379  // CHECK: see the definition of `test.multiple_single_result` here
380  rewrite _: Op with {
381    op<test.multiple_single_result>;
382  };
383}
384
385// -----
386
387//===----------------------------------------------------------------------===//
388// `type` Expr
389//===----------------------------------------------------------------------===//
390
391Pattern {
392  // CHECK: expected string literal containing MLIR type
393  let foo = type<foo;
394}
395
396// -----
397
398Pattern {
399  // CHECK: expected `>` after type literal
400  let foo = type<"";
401}
402