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: dead c++ elimination #2504

Merged
merged 4 commits into from
Jun 9, 2023

Conversation

agoose77
Copy link
Collaborator

@agoose77 agoose77 commented Jun 6, 2023

Now that the C++ split has settled, I did another pass for any unused code and found the following. It's unfortunate that this comes after a C++ release, but we don't need to merge it soon.

The motivation for removing this code is that most of it is untested.

@codecov
Copy link

codecov bot commented Jun 6, 2023

Codecov Report

Merging #2504 (dd5a007) into main (5222b95) will decrease coverage by 0.01%.
The diff coverage is n/a.

Additional details and impacted files
Impacted Files Coverage Δ
src/awkward/_backends/backend.py 86.66% <ø> (-0.29%) ⬇️
src/awkward/_kernels.py 66.95% <ø> (-0.57%) ⬇️

@agoose77 agoose77 temporarily deployed to docs-preview June 7, 2023 00:01 — with GitHub Actions Inactive
@agoose77 agoose77 requested a review from jpivarski June 7, 2023 01:50
Comment on lines -98 to -109
inline struct Error
failure_pass_through(
const char* str,
int64_t identity,
int64_t attempt,
const char* filename) {
struct Error out;
out.str = str;
out.filename = filename;
out.identity = identity;
out.attempt = attempt;
out.pass_through = true;
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'm removing this because, seeing as none of our kernels use it, it's unlikely to be useful. I assume it's legacy from the C++ era?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that's right. It looks like we're letting pass_through be undefined now, which is a little nerve-wracking. If we're going to change the Error struct, we'll have to carefully check that nothing relies on its exact memory layout (in the Numba code). Meanwhile, if you want to set it to always false, just so that it's not undefined, that sounds safer.

Copy link
Collaborator

@ianna ianna left a comment

Choose a reason for hiding this comment

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

I'm all in favour of deleting code :-)

@jpivarski jpivarski added the pr-on-hold This PR is inactive due to a pending decision or other constraint label Jun 7, 2023
@jpivarski
Copy link
Member

On hold until after an awkward release, because it's blocking an uproot release.

@agoose77 agoose77 temporarily deployed to docs-preview June 9, 2023 09:35 — with GitHub Actions Inactive
@agoose77 agoose77 removed the pr-on-hold This PR is inactive due to a pending decision or other constraint label Jun 9, 2023
Copy link
Member

@jpivarski jpivarski 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 good to me!

Do you have a tool that identifies dead C++ code?

Comment on lines -98 to -109
inline struct Error
failure_pass_through(
const char* str,
int64_t identity,
int64_t attempt,
const char* filename) {
struct Error out;
out.str = str;
out.filename = filename;
out.identity = identity;
out.attempt = attempt;
out.pass_through = true;
Copy link
Member

Choose a reason for hiding this comment

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

Yes, that's right. It looks like we're letting pass_through be undefined now, which is a little nerve-wracking. If we're going to change the Error struct, we'll have to carefully check that nothing relies on its exact memory layout (in the Numba code). Meanwhile, if you want to set it to always false, just so that it's not undefined, that sounds safer.

Comment on lines 58 to 61
const char* filename;
int64_t identity;
int64_t attempt;
bool pass_through;
};
Copy link
Member

Choose a reason for hiding this comment

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

I spoke incorrectly: you are actually removing the pass_through field from the Error struct.

I looked through all the files in https://github.com/scikit-hep/awkward/tree/main/src/awkward/_connect/numba and I don't see anything that references the Error struct, so I guess all of that has been removed. (Earlier, some Numba code was calling these kernels directly; that was part of the design decision to make them purely extern "C". Calling external function pointers from Numba is slow—slower than would be expected of just not being able to optimize around it, for some reason—and so we gave that up. There are apparently no further traces of it. But if there were any, if Numba called kernels and expected this Error struct in return, it would have to make an assumption about its memory layout, and we wouldn't want those assumptions to get out of sync.)

Short story: it looks to me like it's okay to change the Error struct, so full speed ahead.

Comment on lines 267 to 270
("filename", c_char_p),
("id", c_int64),
("attempt", c_int64),
("pass_through", c_bool),
]
Copy link
Member

Choose a reason for hiding this comment

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

This is another thing that independently makes assumptions about the Error struct, but you've fixed it.

@agoose77
Copy link
Collaborator Author

agoose77 commented Jun 9, 2023

Do you have a tool that identifies dead C++ code?

Alas no, I erred in favour of the biological computer living upstairs ;)

@agoose77 agoose77 merged commit 60114c5 into main Jun 9, 2023
35 checks passed
@agoose77 agoose77 deleted the agoose77/refactor-dead-code-elimination branch June 9, 2023 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants