Skip to content

Commit

Permalink
[mlir] Revert to old fold logic in IR::Dialect::add{Types, Attributes…
Browse files Browse the repository at this point in the history
…}() (llvm#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]>
  • Loading branch information
andrey-golubev and nikita-kud authored Jan 29, 2024
1 parent 66347e5 commit e3a38a7
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions mlir/include/mlir/IR/Dialect.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,11 @@ class Dialect {
/// Register a set of type classes with this dialect.
template <typename... Args>
void addTypes() {
(addType<Args>(), ...);
// This initializer_list argument pack expansion is essentially equal to
// using a fold expression with a comma operator. Clang however, refuses
// to compile a fold expression with a depth of more than 256 by default.
// There seem to be no such limitations for initializer_list.
(void)std::initializer_list<int>{0, (addType<Args>(), 0)...};
}

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

/// Register an attribute instance with this dialect.
Expand Down

0 comments on commit e3a38a7

Please sign in to comment.