Skip to content
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

refactor: Fix deprecated errors when using shared_ptr::unique() #11318

Conversation

czentgr
Copy link
Collaborator

@czentgr czentgr commented Oct 22, 2024

After the macOS CommandLineTools SDK15 (with Clang16), the new shared_ptr.h now issues the deprecated warnings for C++17 when using the shared_ptr::unique function. This function is removed for C++20.

The solution is to replace the function with the actual implementation using use_count.

Example error:

/Users/czentgr/gitspace/velox/velox/vector/BaseVector.cpp:604:14: error: 'unique' is deprecated [-Werror,-Wdeprecated-declarations]
  if (result.unique() && !isUnknownType) {
             ^
/Library/Developer/CommandLineTools/SDKs/MacOSX15.0.sdk/usr/include/c++/v1/__memory/shared_ptr.h:730:3: note: 'unique' has been explicitly marked deprecated here
  _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_HIDE_FROM_ABI bool unique() const _NOEXCEPT { return use_count() == 1; }
  ^
/Library/Developer/CommandLineTools/SDKs/MacOSX15.0.sdk/usr/include/c++/v1/__config:1022:41: note: expanded from macro '_LIBCPP_DEPRECATED_IN_CXX17'
#    define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED

Resolves: #11342

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 22, 2024
Copy link

netlify bot commented Oct 22, 2024

Deploy Preview for meta-velox canceled.

Name Link
🔨 Latest commit c52ceb4
🔍 Latest deploy log https://app.netlify.com/sites/meta-velox/deploys/672a8c819f15120008163bde

@czentgr czentgr force-pushed the fix_shared_ptr_unique_dependency branch from b0b166b to 27fbeec Compare October 22, 2024 16:41
@@ -63,7 +63,7 @@ void prepareResult(
result->encoding() == VectorEncoding::Simple::ARRAY) ||
(type->kind() == TypeKind::MAP &&
result->encoding() == VectorEncoding::Simple::MAP)) &&
result.unique())) {
result.use_count() == 1)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I am wondering whether we should even rely on use_count as its unreliable , see for e.g : https://stackoverflow.com/a/77286276 .

Copy link
Collaborator Author

@czentgr czentgr Oct 24, 2024

Choose a reason for hiding this comment

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

Correct, it is unreliable. This change is a 1-1 replacement for now. Using unique was already unreliable and I guess that is why it is being removed. It will need some change eventually.

Copy link
Contributor

Choose a reason for hiding this comment

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

Understood , I will create another issue to remove the use of shared_ptr::use_count == 1 from the code base as its unreliable and not meant for use across threads.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ahh, was about to create this issue :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@czentgr czentgr requested a review from majetideepak October 24, 2024 22:08
@czentgr czentgr marked this pull request as ready for review October 24, 2024 22:08
@czentgr
Copy link
Collaborator Author

czentgr commented Oct 24, 2024

@majetideepak FYI.

@@ -99,7 +99,7 @@ void setConstantField(
const VectorPtr& constant,
vector_size_t size,
VectorPtr& field) {
if (field && field->isConstantEncoding() && field.unique() &&
if (field && field->isConstantEncoding() && field.use_count() == 0 &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be field.use_count() == 1? lets add () (field.use_count() == 1)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We don't seem to use () around boolean expressions like these within if statements. So I didn't add it. I just added it when using macros where the argument is expanded to avoid any potential issues.

@@ -112,7 +112,7 @@ void setNullField(
VectorPtr& field,
const TypePtr& type,
memory::MemoryPool* pool) {
if (field && field->isConstantEncoding() && field.unique() &&
if (field && field->isConstantEncoding() && field.use_count() == 0 &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

(field.use_count() == 1)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I only use the quotes when they are expression arguments into macros that could not be replaced e.g. with ASSERT_EQ.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, it is == 1. mistake when fixing a merge conflict.

@@ -673,7 +673,7 @@ void RowVector::resize(vector_size_t newSize, bool setNotNull) {
// to skip uniqueness check since effectively we are just changing
// the length.
if (newSize > oldSize) {
VELOX_CHECK(child.unique(), "Resizing shared child vector");
VELOX_CHECK(child.use_count() == 1, "Resizing shared child vector");
Copy link
Collaborator

Choose a reason for hiding this comment

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

use VELOX_CHECK_EQ

@czentgr czentgr force-pushed the fix_shared_ptr_unique_dependency branch from 83eb2af to ee3f458 Compare October 29, 2024 18:18
@majetideepak majetideepak added the ready-to-merge PR that have been reviewed and are ready for merging. PRs with this tag notify the Velox Meta oncall label Oct 29, 2024
@facebook-github-bot
Copy link
Contributor

@mbasmanova has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@mbasmanova
Copy link
Contributor

@czentgr Would you rebase to resolve merge conflicts?

After the macOS CommandLineTools SDK15  (with Clang16), the new shared_ptr.h now issues the
deprecated warnings  for C++17 when using the shared_ptr::unique function. This function is removed for C++20.

The solution is to replace the function with the actual implementation using use_count.
@czentgr czentgr force-pushed the fix_shared_ptr_unique_dependency branch from ee3f458 to c52ceb4 Compare November 5, 2024 21:22
@czentgr czentgr changed the title Fix deprecated errors when using shared_ptr::unique() refactor: Fix deprecated errors when using shared_ptr::unique() Nov 5, 2024
@czentgr
Copy link
Collaborator Author

czentgr commented Nov 5, 2024

@mbasmanova I've completed the rebase and resolved the conflict.

@facebook-github-bot
Copy link
Contributor

@mbasmanova has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@mbasmanova merged this pull request in ef4614d.

Copy link

Conbench analyzed the 1 benchmark run on commit ef4614d0.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged ready-to-merge PR that have been reviewed and are ready for merging. PRs with this tag notify the Velox Meta oncall
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using macOS Clang16: error: 'unique' is deprecated
5 participants