From b12c88d0a8decf1927548c546ed9b6880917b1d5 Mon Sep 17 00:00:00 2001 From: "Golubev, Andrey" Date: Fri, 26 Jan 2024 11:44:23 +0000 Subject: [PATCH] [mlir] Revert to old fold logic in IR::Dialect::add{Types, Attributes}() 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(), ...); Partially reverts 26d811b3ecd2fa1ca3d9b41e17fb42b8c7ad03d6. Co-authored-by: Nikita Kudriavtsev --- mlir/include/mlir/IR/Dialect.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mlir/include/mlir/IR/Dialect.h b/mlir/include/mlir/IR/Dialect.h index 45f29f37dd3b9..50f6f6de5c289 100644 --- a/mlir/include/mlir/IR/Dialect.h +++ b/mlir/include/mlir/IR/Dialect.h @@ -281,7 +281,11 @@ class Dialect { /// Register a set of type classes with this dialect. template void addTypes() { - (addType(), ...); + // 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{0, (addType(), 0)...}; } /// Register a type instance with this dialect. @@ -292,7 +296,11 @@ class Dialect { /// Register a set of attribute classes with this dialect. template void addAttributes() { - (addAttribute(), ...); + // 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{0, (addAttribute(), 0)...}; } /// Register an attribute instance with this dialect.