-
Notifications
You must be signed in to change notification settings - Fork 373
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
Fix: Local Includes with "" in Lin. Solvers MLMG #1485
Conversation
This fixes AMReX-local includes inside `LinearSolvers/MLMG/` to use `include "AMReX_<...>.H"` instead of `<...>`. Using quotes is important here for isolation, since compilers will otherwise look on the system first, will then potentially find an (outdated or incompatible) installation of AMReX, will mix it in and cause sometimes really hard to debug compile (or even runtime) issues, since text inclusion is a copy-paste operation. Free after the LLVM project's include guidelines and the "Include-What-You-Use Project": - Use `""` for AMReX-local includes - Order: AMReX `<>`, other third party includes `<>`, - std libraries last (so one catches missing includes early)
We probably should reorder the headers. But I don't think we should change from |
The issue was that we specifically did want versions of the headers in the local build directory to override the "true" Source/ copy, since that's a code pattern we use in Castro -- provide a header file with an empty definition of a function and then allow the user to copy the header and override it in their problem setup, to implement something like a problem-specific physics source term. |
Thanks! |
I don't use it on files from AMReX. I would be fine if AMReX didn't implement that code pattern, and I do not really see a use for it within AMReX. |
The problem should hopefully only arise with sub-directories, but I cannot vouch for each all compilers and IIRC it's not uniformly defined. (GCC: docs; Clang: docs) sudo -s
echo "#error ohoh" > /usr/include/header.H
echo "#pragma once" > header.H
cat <<EOF >> main.cpp
#include <header.H>
int main()
{
return 0;
}
EOF
g++ main.cpp
# error
g++ -I$PWD main.cpp
# ok
g++ -isystem $PWD main.cpp
# ok I just had recently such an issue again with AppleClang on macOS: openPMD/openPMD-api#640 Adding the local "" headers would definitely be more robust in new environments, I would say. Also with respect to alternative build systems and package management that might manipulate and symlink include paths around. For example, a downstream dependency might have |
One could argue it makes the code more robust if the user has headers named "AMReX_*.H" and it's put in the local build directory. But we consider |
What I am trying to say is I cannot imagine a realistic case where |
Distinct prefix in all files and explicit flat structure makes it robust, agreed. We can certainly wait if something manifests at some point, too - and only change the include order so long. |
Sounds good. |
No probs, includes in #1496. |
## Summary Include own headers before stdlib headers to catch missing includes early. This avoid problems with less common compilers and environments. Carved out of #1485 ## Additional background ## Checklist The proposed changes: - [ ] fix a bug or incorrect behavior in AMReX - [ ] add new capabilities to AMReX - [ ] changes answers in the test suite to more than roundoff level - [ ] are likely to significantly affect the results of downstream AMReX users - [ ] are described in the proposed changes to the AMReX documentation, if appropriate
Summary
This fixes AMReX-local includes inside
LinearSolvers/MLMG/
to useinclude "AMReX_<...>.H"
instead of<...>
. Using quotes is important here for isolation, since compilers will otherwise look on the system first, will then potentially find an (outdated or incompatible) installation of AMReX, will mix it in and cause sometimes really hard to debug compile (or even runtime) issues, since text inclusion is a copy-paste operation.Additional background
Free after the LLVM project's include guidelines and the "Include-What-You-Use Project":
""
for AMReX-local includes""
<>
, e.g. MPI, OpenMP, etc.<>
(so one catches missing includes early)Checklist
The proposed changes: