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

Require C++17 for Halide. #5282

Merged
merged 83 commits into from
Jun 8, 2021
Merged

Require C++17 for Halide. #5282

merged 83 commits into from
Jun 8, 2021

Conversation

steven-johnson
Copy link
Contributor

@steven-johnson steven-johnson commented Sep 18, 2020

As of Halide 13, we require C++17 to build or use Halide. (We previously claimed to require C++11, although Make builds typically ended up using C++14 due to llvm-config --cxxflags specifying it.)

Fixes #4216

@steven-johnson
Copy link
Contributor Author

The Linux failures appear to be a latent, pre-existing bug that compiler changes have revealed. Stay tuned...

…0 committer Steven Johnson <[email protected]> 1600973808 -0700

Require C++17 for Halide.

(We previously required C++11, although Make builds typically ended up using C++14 due to `llvm-config --cxxflags` specifying it.)
@steven-johnson steven-johnson marked this pull request as ready for review September 24, 2020 19:17
@steven-johnson
Copy link
Contributor Author

No rush to land this (we probably want to wait until after the release/11.x branch is created) but marking 'ready for review' so that people can review/comment at their leisure.

@steven-johnson steven-johnson requested review from abadams and jrk and removed request for jrk and abadams September 24, 2020 19:18
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS NO)

# MSVC won't set __cplusplus correctly unless this flag is also set
Copy link
Member

Choose a reason for hiding this comment

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

Is there no way to hide this idiocy from our users?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We reported this to the CMake folks and they insisted they couldn't change it without a 'policy' flag to enable it, because existing (broken) code might rely on this (insanely broken) behavior, so they aren't gonna change it anytime soon.

The alternative that most people seem to end up using is to combine sniffing of __cplusplus with sniffing of _MSC_LANG, which would work I guess, but is just so f***ing wrong that I didn't want to do it, just on principle. Maybe that's a more pragmatic approach than requiring the build files to insert extra things to work around bad decisions by both MSVC and CMake.

Copy link
Member

Choose a reason for hiding this comment

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

Can we move the setting onto our side of the fence somehow, instead of in the user CMakeLists?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, yes and no.

We currently don't need to check __cplusplus at all (there's a reality check in Codegen_LLVM.cpp but it is just as a backstop).

If we only used C++17 features internal to libHalide, then we wouldn't need this.

If we eventually use a C++17 feature in headers exposed to user code (e.g. in templates), though, then we'd definitely have this problem (ie the user code's build system would have to set this flag).

I guess the better answer is to bite the bullet and accept that checks of that sort will have to check both __cplusplus and _MSC_LANG for the foreseeable future, which is just a sorry state of affairs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(fix pushed)

@alexreinking alexreinking added this to the v12.0.0 milestone Oct 16, 2020
For some reason, these are only getting flagged under C++17 builds, but they are legit (minor) issues we want to fix.
v2.4.3 can generate a lot of compiler warnings under C++17; v2.5 fixes there.

Note 1: I am unsure about the issues with keeping in sync with Ubuntu 20.04; tagging @alexreinking for comments

Note 2: the current version of PyBind11 is actually v2.6, but it has many more changes and upgrading looks nontrivial; deliberately holding off on that upgrade for now.
@steven-johnson
Copy link
Contributor Author

So now that Halide 12 is done, are we ready to land this? Are there any major downstream stakeholders that have any objections?

README.md Outdated
Comment on lines 19 to 21
(Note that *using* Halide requires C++11 or later, but *building* Halide
requires C++17.)

Copy link
Member

Choose a reason for hiding this comment

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

This needs to be fixed now that we decided to go C++17 wholesale.

src/Generator.h Outdated Show resolved Hide resolved
src/Generator.h Outdated
Comment on lines 3482 to 3494
inline void build_inputs(std::vector<std::vector<StubInput>> &inputs, int idx) {
internal_assert(idx == (int)inputs.size());
}

template<typename Last>
inline void build_inputs(std::vector<std::vector<StubInput>> &inputs, int idx, const Last &last) {
inputs[idx] = build_input(idx, last);
}

template<typename First, typename Second, typename... Rest>
inline void build_inputs(std::vector<std::vector<StubInput>> &inputs, int idx, const First &first, const Second &second, const Rest &...rest) {
build_inputs<First>(inputs, idx, first);
build_inputs<Second, Rest...>(inputs, idx + 1, second, rest...);
Copy link
Member

Choose a reason for hiding this comment

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

Since we're going full C++17, this can be reverted, right?

@steven-johnson
Copy link
Contributor Author

All green (again). Are we ready to land this?

@@ -136,6 +136,7 @@ int main(int argc, char **argv) {

Copy link
Member

Choose a reason for hiding this comment

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

This file doesn't seem related?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

...huh, weird, will revert

@abadams
Copy link
Member

abadams commented Jun 7, 2021

No objections here.

README_cmake.md Outdated
@@ -558,7 +558,7 @@ immediately after setting the minimum version.

The next three variables set the project-wide C++ standard. The first,
[`CMAKE_CXX_STANDARD`][cmake_cxx_standard], simply sets the standard version.
Halide requires at least C++11. The second,
Halide requires at least c++17. The second,
Copy link
Member

Choose a reason for hiding this comment

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

@steven-johnson - can you fix this one little thing before merging? No need to wait on buildbots for this, obviously.

@abadams
Copy link
Member

abadams commented Jun 8, 2021

We have discussed this quite a lot at dev meetings, so I think it's good to just land at this point without waiting for explicit approvals from everyone. It can always be rolled back if someone has a serious complaint.

@steven-johnson steven-johnson merged commit cdac77b into master Jun 8, 2021
@steven-johnson steven-johnson deleted the srj/c++17 branch June 8, 2021 17:05
@alexreinking alexreinking removed the release_notes For changes that may warrant a note in README for official releases. label Apr 6, 2022
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.

When should we consider moving Halide to C++17?
5 participants