-
Notifications
You must be signed in to change notification settings - Fork 12k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[mlir] Revert to old fold logic in IR::Dialect::add{Types, Attributes}() #79582
Conversation
@llvm/pr-subscribers-mlir-core @llvm/pr-subscribers-mlir Author: Andrei Golubev (andrey-golubev) ChangesFold 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 Partially reverts 26d811b. Full diff: https://github.com/llvm/llvm-project/pull/79582.diff 1 Files Affected:
diff --git a/mlir/include/mlir/IR/Dialect.h b/mlir/include/mlir/IR/Dialect.h
index 45f29f37dd3b97c..9fe1e1c89b228cb 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 <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.
|
75f52c8
to
0c8cbf1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@zero9178 I guess you had similar experience with this in addOperations(). CC @joker-eph btw, given this problem is likely to stay with us for a while, should I also change addAttributes() / addInterfaces()? Chances are, someone would hit it eventually ... |
Personally I think it'd make sense to change it for |
Quite. My gut feeling tells the same. Guessing if addAttributes is called by TableGen so does the addInterfaces? But given that interfaces, well, abstract away common functionality, the amount of them should be an order smaller. |
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]>
0c8cbf1
to
b12c88d
Compare
Restored old code for addAttributes() as well (force-pushed) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still LGTM
LG, but what's the tradeoff? Is this code less efficient somehow in any way? |
Not that I know of. I guess it got replaced with fold expressions since this is what such cases should really be (and they weren't fold expressions since it was pre-C++17). Unfortunately, turns out there are (strange) limitations for fold expressions (perhaps someone used a fixed-size array in Clang to parse these so now one gets the error mentioned in the commit msg by default). Thinking about it, the "restored" version might be slower to compile: there's a type lookup ( |
ping. can one of you press the merge button? |
…}() (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]> (cherry picked from commit e3a38a7)
…}() (#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)
…}() (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]> (cherry picked from commit e3a38a7)
…}() (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]> (cherry picked from commit e3a38a7)
…}() (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]> (cherry picked from commit e3a38a7)
…}() (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]> (cherry picked from commit e3a38a7)
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 26d811b.