This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Refactor: Extract Class CheckRunner on check_clang_tidy.py
ClosedPublic

Authored by LegalizeAdulthood on Jan 4 2019, 5:09 PM.

Details

Summary

Break up the huge function by extracting a class, storing intermediate
state as class members and breaking up the big function into a group
of class methods all at the same level of abstraction.

Diff Detail

Event Timeline

Extract Function try_run

Eugene.Zelenko set the repository for this revision to rCTE Clang Tools Extra.Jan 4 2019, 5:54 PM
Eugene.Zelenko added a project: Restricted Project.
JonasToth added inline comments.
test/clang-tidy/check_clang_tidy.py
112

Its better to use .format() instead of % syntax

148–227

If would prefer keeping the if check_notes outside of the function call and remove that one argument. Same for the other check_... functions

I really want to get these reviewed quickly. Otherwise, I will run out of available time to complete them and get them submitted.

I really want to get these reviewed quickly. Otherwise, I will run out of available time to complete them and get them submitted.

I will give my best to be available this weekend but the review takes time until the patch is in an acceptable state, same for the other revision.
This process is required to keep good quality and catch bugs, even subtile ones early. Breaking code is the worst of all options.

test/clang-tidy/check_clang_tidy.py
103

Such a long list of returned values make me wonder if it would be worth creating a NamedTuple / class to hold them.
This may make the call site more readable too.

141

These three check_* function all use the same 'FileCheck', '-....'] pattern. Maybe it's worth syndicating that to a try_run_filecheck(input_file0, input_file1, *extra_args)` function.

178

This is the verbose call site I was pointing to above.

To avoid passing lots of state to/from extracted functions, extract a class instead and use member variables for most of the state

LegalizeAdulthood retitled this revision from [clang-tidy] Refactor: Compose Method on check_clang_tidy.py to [clang-tidy] Refactor: Extract Class CheckRunner on check_clang_tidy.py.Mar 15 2019, 12:35 AM

From my side its LGTM, but I would let @serge-sans-paille accept, as he is probably more familiar with python then I am.

LegalizeAdulthood marked 9 inline comments as done.Mar 20 2019, 10:59 AM
LegalizeAdulthood added inline comments.
test/clang-tidy/check_clang_tidy.py
112

That can be done in a later commit; it is not the point of this review.

141

That can be done in a later commit; it is not the point of this review.

148–227

It's the wrong level of abstraction for the if check to be inside run()

178

Addressed by Extract Class instead of Extract Function

Sorry for the long delay, this LGTM

This revision is now accepted and ready to land.Aug 19 2019, 6:33 AM
LegalizeAdulthood marked 4 inline comments as done.
LegalizeAdulthood edited the summary of this revision. (Show Details)
LegalizeAdulthood set the repository for this revision to rG LLVM Github Monorepo.

Rebase on top of tree

This was accepted before in August, 2019, but the script changed in the meantime. I've repeated the Extract Class on top-of-tree,
so presumably this is still acceptable. However, I don't know how commit access has changed. (I don't think I have it anymore.)

If there are no new comments by the end of the week, I'm going to accept this revision and commit it.

aaron.ballman resigned from this revision.Jan 4 2022, 2:06 PM

Resigning only because I don't think I have strong enough Python skills to give a quality review. I didn't spot anything that concerned me specific to this patch though.