Skip to content

Conversation

localspook
Copy link
Contributor

Using a fold instead of template recursion.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Oct 19, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 19, 2025

@llvm/pr-subscribers-clang

Author: Victor Chernyakin (localspook)

Changes

Using a fold instead of template recursion.


Full diff: https://github.com/llvm/llvm-project/pull/164193.diff

1 Files Affected:

  • (modified) clang/include/clang/AST/IgnoreExpr.h (+1-11)
diff --git a/clang/include/clang/AST/IgnoreExpr.h b/clang/include/clang/AST/IgnoreExpr.h
index 917bada61fa6f..bf098f3f09068 100644
--- a/clang/include/clang/AST/IgnoreExpr.h
+++ b/clang/include/clang/AST/IgnoreExpr.h
@@ -17,16 +17,6 @@
 #include "clang/AST/ExprCXX.h"
 
 namespace clang {
-namespace detail {
-/// Given an expression E and functions Fn_1,...,Fn_n : Expr * -> Expr *,
-/// Return Fn_n(...(Fn_1(E)))
-inline Expr *IgnoreExprNodesImpl(Expr *E) { return E; }
-template <typename FnTy, typename... FnTys>
-Expr *IgnoreExprNodesImpl(Expr *E, FnTy &&Fn, FnTys &&... Fns) {
-  return IgnoreExprNodesImpl(std::forward<FnTy>(Fn)(E),
-                             std::forward<FnTys>(Fns)...);
-}
-} // namespace detail
 
 /// Given an expression E and functions Fn_1,...,Fn_n : Expr * -> Expr *,
 /// Recursively apply each of the functions to E until reaching a fixed point.
@@ -35,7 +25,7 @@ template <typename... FnTys> Expr *IgnoreExprNodes(Expr *E, FnTys &&... Fns) {
   Expr *LastE = nullptr;
   while (E != LastE) {
     LastE = E;
-    E = detail::IgnoreExprNodesImpl(E, std::forward<FnTys>(Fns)...);
+    ((E = std::forward<FnTys>(Fns)(E)), ...);
   }
   return E;
 }

Copy link
Contributor

@cor3ntin cor3ntin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we ever have more that 2 functions?
It might be simpler/faster to compile to just have

const Expr *IgnoreExprNodes(const Expr *E, const Expr*(*F)(const Expr*));
const Expr *IgnoreExprNodes(const Expr *E, const Expr*(*F1)(const Expr*),
                                                                                 const Expr*(*F2)(const Expr*)); 

@localspook
Copy link
Contributor Author

localspook commented Oct 20, 2025

We have this :D

return IgnoreExprNodes(
this, IgnoreImplicitSingleStep, IgnoreImplicitCastsExtraSingleStep,
IgnoreParensOnlySingleStep, IgnoreImplicitConstructorSingleStep,
IgnoreImplicitMemberCallSingleStep, IgnoreImplicitCallSingleStep);

@cor3ntin
Copy link
Contributor

We have this :D

return IgnoreExprNodes(
this, IgnoreImplicitSingleStep, IgnoreImplicitCastsExtraSingleStep,
IgnoreParensOnlySingleStep, IgnoreImplicitConstructorSingleStep,
IgnoreImplicitMemberCallSingleStep, IgnoreImplicitCallSingleStep);

We could use an array of functions for that (and apply the array in reverse)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants