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

Disallow copy and move #4578

Merged
merged 6 commits into from
May 7, 2022
Merged

Conversation

ZHANGWENTAI
Copy link
Contributor

@ZHANGWENTAI ZHANGWENTAI commented Apr 2, 2022

What problem does this PR solve?

Issue Number: ref #4411

Problem Summary: use DISALLOW_COPY_AND_MOVE instead.

What is changed and how it works?

add DISALLOW_COPY, DISALLOW_MOVE, DISALLOWCOPY_AND_MOVE macro, and used in the files listed in #4411.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

None

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Apr 2, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • Lloyd-Pottiger
  • ywqzzy

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added the release-note-none Denotes a PR that doesn't merit a release note. label Apr 2, 2022
@CLAassistant
Copy link

CLAassistant commented Apr 2, 2022

CLA assistant check
All committers have signed the CLA.

@ti-chi-bot ti-chi-bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Apr 2, 2022
DISALLOW_COPY(ClassName); \
DISALLOW_MOVE(ClassName)

#define DISALLOW_COPY(ClassName) \
Copy link
Contributor

Choose a reason for hiding this comment

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

You can write the code in /dbms/src/Common/nocopyable.h

Copy link
Contributor Author

@ZHANGWENTAI ZHANGWENTAI Apr 7, 2022

Choose a reason for hiding this comment

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

I have done as you said. And I wonder if I need to replace the one line deletion of copy constructor or assign constructor like AggregateDescription(const AggregateDescription &) = delete; in /dbms/src/DataStreams/SummingSortedBlockInputStream.h, is it on purpose or I can replace it with DISALLOW_COPY(AggregateDescription) directly?

Copy link
Contributor

Choose a reason for hiding this comment

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

You can replace it directly. Maybe you can list some of the classes need to refactor in the issue and create some sub-issue, and you refactor 3 or 4 of them in one pr.

Copy link
Contributor

Choose a reason for hiding this comment

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

Like @ywqzzy said, the macro DISALLOW_COPY/DISALLOW_MOVE /DISALLOW_COPY_AND_MOVE should be defined in a common place like dbms/src/Common/noncopyable.h.

And I wonder whether we can define DISALLOW_COPY_AND_MOVE before DISALLOW_COPY/DISALLOW_MOVE ?

@fuzhe1989
Copy link
Contributor

@JaySon-Huang could you help to review this pr?

@ti-chi-bot ti-chi-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 13, 2022
@ywqzzy
Copy link
Contributor

ywqzzy commented Apr 14, 2022

/rebuild

1 similar comment
@ZHANGWENTAI
Copy link
Contributor Author

/rebuild

@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 18, 2022
@ZHANGWENTAI ZHANGWENTAI force-pushed the disallow_copy_and_move branch from deae845 to 6c60aff Compare April 21, 2022 03:32
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 21, 2022
@ZHANGWENTAI ZHANGWENTAI force-pushed the disallow_copy_and_move branch 2 times, most recently from 3ada1d7 to 09ad8b5 Compare April 21, 2022 04:44
@ywqzzy ywqzzy self-requested a review April 21, 2022 07:15
@ZHANGWENTAI
Copy link
Contributor Author

I found a mistake in dbms/src/Common/ExecutableTask.h, let me fix it and recommit.

@ZHANGWENTAI ZHANGWENTAI force-pushed the disallow_copy_and_move branch 3 times, most recently from f4c6f44 to 70e00ee Compare April 26, 2022 02:54
@ZHANGWENTAI
Copy link
Contributor Author

Can anyone review this pr? thx :)

@ywqzzy ywqzzy requested a review from JaySon-Huang April 28, 2022 12:53
@ywqzzy
Copy link
Contributor

ywqzzy commented Apr 28, 2022

/run-all-tests

@ywqzzy ywqzzy requested a review from Lloyd-Pottiger April 28, 2022 12:58
Copy link
Contributor

@ywqzzy ywqzzy left a comment

Choose a reason for hiding this comment

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

LGTM. Good Job!

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Apr 28, 2022
@sre-bot
Copy link
Collaborator

sre-bot commented Apr 28, 2022

Coverage for changed files

too many lines from llvm-cov, please refer to full report instead

Coverage summary

Functions  MissedFunctions  Executed  Lines   MissedLines  Cover
18053      10149            43.78%    200107  100945       49.55%

full coverage report (for internal network access only)

@ywqzzy ywqzzy self-requested a review April 28, 2022 15:37
Copy link
Contributor

@Lloyd-Pottiger Lloyd-Pottiger left a comment

Choose a reason for hiding this comment

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

Thanks for your good job! The two copy operations are independent. Declaring copy constructor does not prevent compiler to generate copy assignment and vice versa. And I found that there are some classes which only make copy constructor = delete but you also replace it with DISALLOW_COPY(className). In most cases, it is fine. However, could you please take a deep check to make sure it is all fine? And thanks for your great contribution again!

@@ -359,11 +360,8 @@ class PageDirectory
}

// No copying
PageDirectory(const PageDirectory &) = delete;
PageDirectory & operator=(const PageDirectory &) = delete;
// No moving
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe combine the two comments?

@Lloyd-Pottiger
Copy link
Contributor

And why do this? 😂

- std::string toString() const { return "Not Support"; }
+ std::string toString() const
+ {
+      return "Not Support";
+  }

honestly, I like the previous code style which makes code more compact with high readability. 😄

@ZHANGWENTAI ZHANGWENTAI force-pushed the disallow_copy_and_move branch from 10506f4 to 2929380 Compare May 5, 2022 06:07
@ZHANGWENTAI
Copy link
Contributor Author

Maybe the formatter automatically did the change.

we have enable AllowShortFunctionsOnASingleLine in .clang-format

I format the code in my local repo by python3 format-diff.py --diff_from git merge-base master HEAD``, but it still expend short functions. Is I doing it right?

Yes. AllowShortFunctionsOnASingleLine: Inline in clang-format means allow not force. Therefore, your style is legal for clang-format, so there is nothing changed 😂

hello! I have remained the format of short function and commit agian

@Lloyd-Pottiger
Copy link
Contributor

Maybe the formatter automatically did the change.

we have enable AllowShortFunctionsOnASingleLine in .clang-format

I format the code in my local repo by python3 format-diff.py --diff_from git merge-base master HEAD``, but it still expend short functions. Is I doing it right?

Yes. AllowShortFunctionsOnASingleLine: Inline in clang-format means allow not force. Therefore, your style is legal for clang-format, so there is nothing changed 😂

hello! I have remained the format of short function and commit agian

https://github.com/pingcap/tiflash/pull/4578/files#diff-e49f478fa33ca6648a69a7aba47d9485827d89793ef5784c080375ff2fce5cfb seems have not pushed?

@ZHANGWENTAI
Copy link
Contributor Author

ZHANGWENTAI commented May 6, 2022

Maybe the formatter automatically did the change.

we have enable AllowShortFunctionsOnASingleLine in .clang-format

I format the code in my local repo by python3 format-diff.py --diff_from git merge-base master HEAD``, but it still expend short functions. Is I doing it right?

Yes. AllowShortFunctionsOnASingleLine: Inline in clang-format means allow not force. Therefore, your style is legal for clang-format, so there is nothing changed 😂

hello! I have remained the format of short function and commit agian

https://github.com/pingcap/tiflash/pull/4578/files#diff-e49f478fa33ca6648a69a7aba47d9485827d89793ef5784c080375ff2fce5cfb seems have not pushed?

Actually I did 😂. The reason why I expand those functions still is to keep code style consistent in the file and some functions are not short enough. Expanding them is easier to read

@Lloyd-Pottiger
Copy link
Contributor

Maybe the formatter automatically did the change.

we have enable AllowShortFunctionsOnASingleLine in .clang-format

I format the code in my local repo by python3 format-diff.py --diff_from git merge-base master HEAD``, but it still expend short functions. Is I doing it right?

Yes. AllowShortFunctionsOnASingleLine: Inline in clang-format means allow not force. Therefore, your style is legal for clang-format, so there is nothing changed 😂

hello! I have remained the format of short function and commit agian

https://github.com/pingcap/tiflash/pull/4578/files#diff-e49f478fa33ca6648a69a7aba47d9485827d89793ef5784c080375ff2fce5cfb seems have not pushed?

Actually I did 😂. The reason why I expand those functions still is to keep code style consistent in the file and some functions are not short enough. Expanding them is easier to read

OK,cool

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels May 6, 2022
@Lloyd-Pottiger
Copy link
Contributor

@ywqzzy PTAL

@ywqzzy
Copy link
Contributor

ywqzzy commented May 6, 2022

/run-all-tests

@sre-bot
Copy link
Collaborator

sre-bot commented May 6, 2022

Coverage for changed files

too many lines from llvm-cov, please refer to full report instead

Coverage summary

Functions  MissedFunctions  Executed  Lines   MissedLines  Cover
18077      10153            43.83%    200562  101039       49.62%

full coverage report (for internal network access only)

@ywqzzy
Copy link
Contributor

ywqzzy commented May 7, 2022

/merge

@ti-chi-bot
Copy link
Member

@ywqzzy: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

You only need to trigger /merge once, and if the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

If you have any questions about the PR merge process, please refer to pr process.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: b1f5f25

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label May 7, 2022
@sre-bot
Copy link
Collaborator

sre-bot commented May 7, 2022

Coverage for changed files

too many lines from llvm-cov, please refer to full report instead

Coverage summary

Functions  MissedFunctions  Executed  Lines   MissedLines  Cover
18090      10150            43.89%    200902  100984       49.73%

full coverage report (for internal network access only)

@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 7, 2022
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 7, 2022
@ZHANGWENTAI
Copy link
Contributor Author

PTAL

@sre-bot
Copy link
Collaborator

sre-bot commented May 7, 2022

Coverage for changed files

too many lines from llvm-cov, please refer to full report instead

Coverage summary

Functions  MissedFunctions  Executed  Lines   MissedLines  Cover
18090      10151            43.89%    200906  101002       49.73%

full coverage report (for internal network access only)

@ti-chi-bot
Copy link
Member

@ZHANGWENTAI: Your PR was out of date, I have automatically updated it for you.

At the same time I will also trigger all tests for you:

/run-all-tests

If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@sre-bot
Copy link
Collaborator

sre-bot commented May 7, 2022

Coverage for changed files

too many lines from llvm-cov, please refer to full report instead

Coverage summary

Functions  MissedFunctions  Executed  Lines   MissedLines  Cover
18091      10150            43.89%    200958  100975       49.75%

full coverage report (for internal network access only)

@ti-chi-bot ti-chi-bot merged commit 7ffb943 into pingcap:master May 7, 2022
@ZHANGWENTAI ZHANGWENTAI deleted the disallow_copy_and_move branch May 7, 2022 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants