Skip to content

Commit 0680e84

Browse files
andrey-golubevnikita-kud
authored andcommitted
[mlir] Revert to old fold logic in IR::Dialect::add{Types, Attributes}() (#79582)
Fold expressions on Clang are limited to 256 elements. This causes compilation errors in cases when the amount of elements added exceeds this limit. Side-step the issue by restoring the original trick that would use the std::initializer_list. For the record, in our downstream Clang 16 gives: mlir/include/mlir/IR/Dialect.h:269:23: fatal error: instantiating fold expression with 688 arguments exceeded expression nesting limit of 256 (addType<Args>(), ...); Partially reverts 26d811b. Co-authored-by: Nikita Kudriavtsev <[email protected]> (cherry picked from commit e3a38a7)
1 parent bdaf16d commit 0680e84

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

mlir/include/mlir/IR/Dialect.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,11 @@ class Dialect {
281281
/// Register a set of type classes with this dialect.
282282
template <typename... Args>
283283
void addTypes() {
284-
(addType<Args>(), ...);
284+
// This initializer_list argument pack expansion is essentially equal to
285+
// using a fold expression with a comma operator. Clang however, refuses
286+
// to compile a fold expression with a depth of more than 256 by default.
287+
// There seem to be no such limitations for initializer_list.
288+
(void)std::initializer_list<int>{0, (addType<Args>(), 0)...};
285289
}
286290

287291
/// Register a type instance with this dialect.
@@ -292,7 +296,11 @@ class Dialect {
292296
/// Register a set of attribute classes with this dialect.
293297
template <typename... Args>
294298
void addAttributes() {
295-
(addAttribute<Args>(), ...);
299+
// This initializer_list argument pack expansion is essentially equal to
300+
// using a fold expression with a comma operator. Clang however, refuses
301+
// to compile a fold expression with a depth of more than 256 by default.
302+
// There seem to be no such limitations for initializer_list.
303+
(void)std::initializer_list<int>{0, (addAttribute<Args>(), 0)...};
296304
}
297305

298306
/// Register an attribute instance with this dialect.

0 commit comments

Comments
 (0)