Skip to content

[ADT] Skip destroying trivially destructible values in DenseMap #106934

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kazutakahirata
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Sep 2, 2024

@llvm/pr-subscribers-llvm-adt

Author: Kazu Hirata (kazutakahirata)

Changes

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

1 Files Affected:

  • (modified) llvm/include/llvm/ADT/DenseMap.h (+5)
diff --git a/llvm/include/llvm/ADT/DenseMap.h b/llvm/include/llvm/ADT/DenseMap.h
index f71cd5b4771b75..68f3f1defc2bd0 100644
--- a/llvm/include/llvm/ADT/DenseMap.h
+++ b/llvm/include/llvm/ADT/DenseMap.h
@@ -392,6 +392,11 @@ class DenseMapBase : public DebugEpochBase {
   DenseMapBase() = default;
 
   void destroyAll() {
+    // Don't bother destroying trivially destructible stuff.
+    if constexpr (std::is_trivially_destructible_v<KeyT> &&
+                  std::is_trivially_destructible_v<ValueT>)
+      return;
+
     if (getNumBuckets() == 0) // Nothing to do.
       return;
 

Copy link
Member

@kuhar kuhar left a comment

Choose a reason for hiding this comment

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

This looks fine in isolation, but I wonder if we do have a test that makes sure that non-trivial destructors get run?

@kazutakahirata
Copy link
Contributor Author

This looks fine in isolation, but I wonder if we do have a test that makes sure that non-trivial destructors get run?

Let me come up with some tests. Thanks!

Copy link
Member

@MaskRay MaskRay left a comment

Choose a reason for hiding this comment

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

Test?

@dwblaikie
Copy link
Collaborator

Test?

Not sure this is testable? If they're trivially destructible, it wouldn't be possible to observe the difference between destroying them and not destroying them, right?

@kuhar
Copy link
Member

kuhar commented Dec 9, 2024

Test?

Not sure this is testable? If they're trivially destructible, it wouldn't be possible to observe the difference between destroying them and not destroying them, right?

We could have the test for the non-trivially destructible case to make sure we don't unintentionally skip destructors. If we already do, it would be good to point out in the PR description.

@dwblaikie
Copy link
Collaborator

Test?

Not sure this is testable? If they're trivially destructible, it wouldn't be possible to observe the difference between destroying them and not destroying them, right?

We could have the test for the non-trivially destructible case to make sure we don't unintentionally skip destructors. If we already do, it would be good to point out in the PR description.

Sure, that'd be nice - good call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants