Skip to content

[Sema] Avoid unnecessary copy on MultiLevelTemplateArgumentList. NFC #84459

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

Merged
merged 1 commit into from
Mar 8, 2024

Conversation

zyn0217
Copy link
Contributor

@zyn0217 zyn0217 commented Mar 8, 2024

We don't modify the MLTAL parameter in SetupConstraintScope, and it is better if we don't copy the 120-byte object each time we call the function.

We don't modify the MLTAL parameter in SetupConstraintScope, and it
is better if we don't copy the 120-byte object each time we call the
function.
@zyn0217 zyn0217 added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label Mar 8, 2024
@zyn0217 zyn0217 requested a review from erichkeane March 8, 2024 11:00
@zyn0217 zyn0217 requested a review from Endilll as a code owner March 8, 2024 11:00
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Mar 8, 2024
@llvmbot
Copy link
Member

llvmbot commented Mar 8, 2024

@llvm/pr-subscribers-clang

Author: Younan Zhang (zyn0217)

Changes

We don't modify the MLTAL parameter in SetupConstraintScope, and it is better if we don't copy the 120-byte object each time we call the function.


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

2 Files Affected:

  • (modified) clang/include/clang/Sema/Sema.h (+6-4)
  • (modified) clang/lib/Sema/SemaConcept.cpp (+2-1)
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 592c7871a4a55d..2cac7e6ca08fad 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -11607,12 +11607,14 @@ class Sema final {
       LocalInstantiationScope &Scope,
       const MultiLevelTemplateArgumentList &TemplateArgs);
 
-  /// used by SetupConstraintCheckingTemplateArgumentsAndScope to recursively(in
+  /// Used by SetupConstraintCheckingTemplateArgumentsAndScope to recursively(in
   /// the case of lambdas) set up the LocalInstantiationScope of the current
   /// function.
-  bool SetupConstraintScope(
-      FunctionDecl *FD, std::optional<ArrayRef<TemplateArgument>> TemplateArgs,
-      MultiLevelTemplateArgumentList MLTAL, LocalInstantiationScope &Scope);
+  bool
+  SetupConstraintScope(FunctionDecl *FD,
+                       std::optional<ArrayRef<TemplateArgument>> TemplateArgs,
+                       const MultiLevelTemplateArgumentList &MLTAL,
+                       LocalInstantiationScope &Scope);
 
   /// Used during constraint checking, sets up the constraint template argument
   /// lists, and calls SetupConstraintScope to set up the
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 2878e4d31ee8fe..a8e387e35fb4c9 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -586,7 +586,8 @@ bool Sema::addInstantiatedCapturesToScope(
 
 bool Sema::SetupConstraintScope(
     FunctionDecl *FD, std::optional<ArrayRef<TemplateArgument>> TemplateArgs,
-    MultiLevelTemplateArgumentList MLTAL, LocalInstantiationScope &Scope) {
+    const MultiLevelTemplateArgumentList &MLTAL,
+    LocalInstantiationScope &Scope) {
   if (FD->isTemplateInstantiation() && FD->getPrimaryTemplate()) {
     FunctionTemplateDecl *PrimaryTemplate = FD->getPrimaryTemplate();
     InstantiatingTemplate Inst(

@Endilll
Copy link
Contributor

Endilll commented Mar 8, 2024

Changes to Sema.h look good to me.

@zyn0217 zyn0217 merged commit 5d98d88 into llvm:main Mar 8, 2024
Copy link
Collaborator

@erichkeane erichkeane left a comment

Choose a reason for hiding this comment

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

Ah, this used to be a really small class, at one point it was an unsigned plus a handful of array-refs, so it made sense to pass by value. It seems to have grown a decent bit to the point that pass-by-const-ref now makes sense.

@zyn0217
Copy link
Contributor Author

zyn0217 commented Mar 8, 2024

Thanks. That explains now :)

@erichkeane
Copy link
Collaborator

Thanks. That explains now :)

No problem! Feel free to change a bunch of them, I'm sure we pass by copy quite a bit, I chased out many of them a while back, but I'm sure i didnt get them all.

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.

5 participants