Skip to content

Commit 0c8cbf1

Browse files
[mlir] Revert to old fold logic in IR::Dialect::addTypes()
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 instance, 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]>
1 parent 14a027b commit 0c8cbf1

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

mlir/include/mlir/IR/Dialect.h

Lines changed: 5 additions & 1 deletion
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.

0 commit comments

Comments
 (0)