-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
[Many pragma] Removing last remnants of pragma block at the top of pybind11.h #3168
Conversation
0e5f46c
to
084448a
Compare
@henryiii @Skylion007 Putting this PR back in Draft mode. I'll ping you when I'm done updating. |
084448a
to
cbbf839
Compare
Follow-on question to the discovery of https://stackoverflow.com/questions/9317473/forward-declaration-of-inline-functions: If it is true that forward declarations never need Isn't what we really want a compiler warning? Something like: I looked for |
@henryiii @Skylion007 The PR description is now significantly simpler. Could you please take a look? — I'm hoping for agreement to purge the 9 x 2 pragma blocks from this PR. |
We can see what @Skylion007 (or anyone else) says, but I'm in favor of the pragmas. Leaking warning suppression into user code is a clear regression, not an improvement. Having "secret" defines that force enable or disable things is ugly. And then there's still no way for a user to have attribute warnings enforced on their code as errors, since pybind11 is either hiding them or erroring on them. I think this is just an unavoidable issue caused by forcing ourselves to be header-only. I'm not so strongly in favor of the pragmas that I can't be convinced otherwise if others disagree, though. (And correct me if I'm misunderstanding the suggestion). I think, when we work on the pre-compilation step, this might become much simpler. All the "definition" files could be surrounded by this pragma as part of the standard setup/teardown for those files - after all, all NOINLINE functions will be pre-compilable and will not have a the no inline setting active when in pre-compile mode. |
My thinking is: The only "loss" going the route withOUT the pragmas is:
Side remark: potentially we can check the cuda version and modern versions may be fine. Contrast that with: developers have to permanently work with and around 9 x 2 pragma blocks, just so a few select platforms can activate a warning that they most likely get from also testing with other platforms anyway. Additionally: do we have performance or binary size measurements that would justify prioritizing
Net conclusion I'm arriving at (without having such data):
We will not leak warnings, it's only that a small fraction of pybind11 users will have to make the either-or choice above. @henryiii @Skylion007 could this sway your vote? |
79db0ef
to
b85972e
Compare
I converted this back to Draft for the minute. |
I decided it is best to split out PR #3179, get that out of the way first, then revisit the pragma vs either-or-for-a-few-platforms question. It will be much easier to see what the alternatives entail. |
b85972e
to
bec4e6d
Compare
Alternative PR #3186 was just merged. Discarding this PR. |
Follow-on to PR #3127, based on results obtained under PR #3125.
The suggested changelog entry will be in the final PR of this cleanup series.
Worksheet
This PR changes 9 files, removes 14 lines, adds 92 lines.
Most significant observation:
For all compilers except {CUDA, GCC7, GCC8, ICC}, a correct way to specify a forward declaration for a
noinline
function is:There are no warnings,
#pragma GCC diagnostic ignored "-Wattributes"
is NOT needed:https://github.com/pybind/pybind11/actions/runs/1091508338
See also: https://stackoverflow.com/questions/9317473/forward-declaration-of-inline-functions:
The stackoverflow page essentially suggests that the above is the one correct way to specify a forward declaration.
For {CUDA, GCC7, GCC8} our options are:
PYBIND11_NOINLINE_DISABLED
(see detail/common.h).pragma
s.Adding
pragma
around just the forward declarations is insufficient:FAILING https://github.com/pybind/pybind11/actions/runs/1091968458
The
pragma
s need to be added in 9 header files: (4 + 3) x 9 = 73 lines + 18 blank lines = 81 lines.The 9
pragma
s work: SUCCESS https://github.com/pybind/pybind11/actions/runs/1092076877In summary, we have a choice between cluttering our code with 9 x 2 small
pragma
blocks, or usingPYBIND11_NOINLINE_DISABLED
for the few troublesome platforms, while also providingPYBIND11_NOINLINE_FORCED
as an option. See the associated comment in detail/common.h.Note that the 9 x 2
pragmas
are a liability when refactoring. Depending on how code is moved, some may not be needed anymore (something that is likely to be overlooked), or they need to be copied to more files.For completeness:
The ICC
pragma
2196
cannot be removed:FAILING https://github.com/pybind/pybind11/actions/runs/1092275777
Pointing out a special case:
Converted from
inline
toPYBIND11_NOINLINE
for consistency:Note that this PR adds
inline
to thePYBIND11_NOINLINE
macro, which simplifies code elsewhere and removes the potential for inconsistencies (inconsequential, just not nice):inline
first:inline
second: