[clang] [Clang] Improve concept performance 1/N (PR #188421)

Matheus Izvekov via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 8 07:51:57 PDT 2026


================
@@ -1611,15 +1620,39 @@ namespace {
       }
       return Type;
     }
+
     // Override the default version to handle a rewrite-template-arg-pack case
-    // for building a deduction guide.
+    // for building a deduction guide, and to cache substitution results in
+    // concepts checking.
     bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
                                    TemplateArgumentLoc &Output,
                                    bool Uneval = false) {
       const TemplateArgument &Arg = Input.getArgument();
-      std::vector<TemplateArgument> TArgs;
+      if (auto *Cache = SemaRef.CurrentCachedTemplateArgs;
+          Cache && TemplateArgsHashValue) {
+        llvm::FoldingSetNodeID ID = *TemplateArgsHashValue;
+        ID.AddInteger(SemaRef.ArgPackSubstIndex.toInternalRepresentation());
+        Arg.Profile(ID, SemaRef.Context);
+        // FIXME: We should ideally only cache and restore TemplateArgument and
+        // rebuild the uncached TypeLoc separately in place. However this is
+        // nearly impossible given the current architecture of TreeTransform so
+        // that we have to lose TypeLoc fidelity in cases where TypeLocs are
----------------
mizvekov wrote:

I'd say that the transforms for `TemplateArgument` are inconsistent with the TreeTransform architecture, and that's why this is hard here.

All the other transforms leave the rebuilding of source locations to the caller side, which if TemplateArgument transform followed here, would make this fairly trivial.

https://github.com/llvm/llvm-project/pull/188421


More information about the cfe-commits mailing list