Skip to content

[lldb] Make SBProgress move-only #124843

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
Jan 28, 2025
Merged

Conversation

bulbazord
Copy link
Member

I wanted to clarify the semantics around SBProgress. Given the nature of Progress events, copying seems like the wrong idea. Making SBProgress move-only (like SBStream) seems like the better choice here.

I wanted to clarify the semantics around SBProgress.
Given the nature of Progress events, copying seems like the wrong idea.
Making SBProgress move-only (like SBStream) seems like the better choice
here.
@llvmbot
Copy link
Member

llvmbot commented Jan 28, 2025

@llvm/pr-subscribers-lldb

Author: Alex Langford (bulbazord)

Changes

I wanted to clarify the semantics around SBProgress. Given the nature of Progress events, copying seems like the wrong idea. Making SBProgress move-only (like SBStream) seems like the better choice here.


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

2 Files Affected:

  • (modified) lldb/include/lldb/API/SBProgress.h (+7)
  • (modified) lldb/source/API/SBProgress.cpp (+3)
diff --git a/lldb/include/lldb/API/SBProgress.h b/lldb/include/lldb/API/SBProgress.h
index d2eaf0a743cb3a..d574d1d2982b96 100644
--- a/lldb/include/lldb/API/SBProgress.h
+++ b/lldb/include/lldb/API/SBProgress.h
@@ -51,6 +51,10 @@ class LLDB_API SBProgress {
   SBProgress(const char *title, const char *details, uint64_t total_units,
              SBDebugger &debugger);
 
+#ifndef SWIG
+  SBProgress(SBProgress &&rhs);
+#endif
+
   ~SBProgress();
 
   void Increment(uint64_t amount, const char *description = nullptr);
@@ -59,6 +63,9 @@ class LLDB_API SBProgress {
   lldb_private::Progress &ref() const;
 
 private:
+  SBProgress(const SBProgress &rhs) = delete;
+  const SBProgress &operator=(const SBProgress &rhs) = delete;
+
   std::unique_ptr<lldb_private::Progress> m_opaque_up;
 }; // SBProgress
 } // namespace lldb
diff --git a/lldb/source/API/SBProgress.cpp b/lldb/source/API/SBProgress.cpp
index d6ed5f0d15fc94..e67e289a60eff4 100644
--- a/lldb/source/API/SBProgress.cpp
+++ b/lldb/source/API/SBProgress.cpp
@@ -32,6 +32,9 @@ SBProgress::SBProgress(const char *title, const char *details,
       lldb_private::Progress::Origin::eExternal);
 }
 
+SBProgress::SBProgress(SBProgress &&rhs)
+    : m_opaque_up(std::move(rhs.m_opaque_up)) {}
+
 SBProgress::~SBProgress() = default;
 
 void SBProgress::Increment(uint64_t amount, const char *description) {

Copy link
Contributor

@Jlalond Jlalond left a comment

Choose a reason for hiding this comment

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

LGTM, left you one comment @bulbazord that is mostly a question

@@ -59,6 +63,9 @@ class LLDB_API SBProgress {
lldb_private::Progress &ref() const;

private:
SBProgress(const SBProgress &rhs) = delete;
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh! I didn't originally do this because I thought we weren't adding deletes in the header.

Copy link
Member Author

Choose a reason for hiding this comment

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

SBStream does this to enforce no copying. :)

@@ -51,6 +51,10 @@ class LLDB_API SBProgress {
SBProgress(const char *title, const char *details, uint64_t total_units,
SBDebugger &debugger);

#ifndef SWIG
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the move operator for only Swig? Wouldn't this be useful if say DAP wanted to grab it's own progress object and then potentially move it?

Copy link
Member Author

@bulbazord bulbazord Jan 28, 2025

Choose a reason for hiding this comment

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

This is a preprocessor guard that prevents SWIG from processing the move constructor. SWIG generates the bindings by reading the API headers and doesn't handle move constructors well. SBStream does the same thing.

When the headers are installed for distribution, this header guard is removed with unifdef.

@bulbazord bulbazord merged commit 1f7eb6f into llvm:main Jan 28, 2025
7 of 8 checks passed
@bulbazord bulbazord deleted the sbprogress-move-only branch January 28, 2025 22:03
JDevlieghere pushed a commit to swiftlang/llvm-project that referenced this pull request Jan 29, 2025
I wanted to clarify the semantics around SBProgress. Given the nature of
Progress events, copying seems like the wrong idea. Making SBProgress
move-only (like SBStream) seems like the better choice here.

(cherry picked from commit 1f7eb6f)
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.

3 participants