Skip to content

Stop building with assertions by default even in release builds. Fixes #3058 #3065

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

kripken
Copy link
Member

@kripken kripken commented Aug 20, 2020

As mentioned in #3058 this made sense in the early days when bugs were
everywhere, but we probably don't need all our users doing this all the time.

Some numbers: Testing on two benchmarks, this makes us about 5% faster,
and builds are 8% smaller.

This adds CI run for a debug build, which has assertions enabled, so we
don't lose coverage here. (We will lose coverage in the emscripten CI
though which will use a release build.) Looks like that build is ~6 minutes
vs ~5 minutes for the opt build (faster compilation, but slower to run the
tests).

@sbc100
Copy link
Member

sbc100 commented Aug 20, 2020

Hmm.. I guess in that past we were using asserts for normal error reporting in some cases?

I'm curious, how we build out upstream llvm? Do we use release+assert like chromium does for its clang?

@kripken
Copy link
Member Author

kripken commented Aug 20, 2020

Hmm.. I guess in that past we were using asserts for normal error reporting in some cases?

Yes, I had to fix one such place in wasm-shell.

how we build out upstream llvm?

Looks like just a Release build, no asserts:

https://github.com/WebAssembly/waterfall/blob/bf095321091328f1be1c1f250c26700f4cfaa6cb/src/build.py#L789

@dschuff
Copy link
Member

dschuff commented Aug 20, 2020

As long as we've removed places where we have asserts for conditions that can arise from user inputs (as opposed to things that should "never happen" i.e. if it fails there's a bug), then this seems OK to me. (IMO we should also never call abort in those situations either, which I think we used to. But that's a separate issue from asserts since abort won't be compiled away).

We actually build LLVM as "Release+Asserts" (https://github.com/WebAssembly/waterfall/blob/bf095321091328f1be1c1f250c26700f4cfaa6cb/src/build.py#L903) which keeps asserts (and llvm_unreachable) but is otherwise like a release build.
Regarding that, I like having it as the default for all of our regular CI tests (we do get assertion failures sometimes), but I would be OK with shipping a non-asserts build in emsdk (it is somewhat faster). At some point I had hoped to revisit our release process such that we could use Release+Asserts builds for all of our pre-and post-commit tests, but then kick off a more highly-optimized build just for tagged releases. We could even go one better and have that build be LTO or PGO.

assert(valid);
if (!valid) {
std::cerr << "Invalid module!\n";
abort();
Copy link
Member

Choose a reason for hiding this comment

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

Actually I guess I just said we shouldn't use abort for this purpose. The reason is that it's treated by the system more like a crash (e.g. you get a core file on Linux, and the exit status is different). Did we have a Fatal class somewhere for this purpose at one point?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah yes, good point. Looks like this file is old and didn't use it, and I was copying the other behavior, but I fixed them all now.

@kripken
Copy link
Member Author

kripken commented Aug 21, 2020

(Ah, I just looked at LLVM's CMAKE_BUILD_TYPE and saw it was Release, I didn't realize you can set assertions with a separate flag, so I was wrong before.)

@kripken
Copy link
Member Author

kripken commented Sep 22, 2020

ping on this - what do people think?

@sbc100
Copy link
Member

sbc100 commented Sep 22, 2020

So we would loose both assertions and the --debug mechanism?

I don't think an 8% win on size of binaryen makes much difference to emsdk users. As for the 5% win on speed do you think that would knock 5% of the wasm-opt and finalize times for large builds? If so then i might be worth it. I'm actaully quite surprised about that 5%... I guess we do a lot of asserting?

@aheejin
Copy link
Member

aheejin commented Sep 22, 2020

I generally agree with #3065 (comment) that as long as we keep testing the release build with assertions enabled, the build we ship to users can be (or is even better be) highly optimized. But you are the person who got and fixed larger number of bug reports than anyone else here, so you would know the best how much the bug reports with assertions enabled helped. If you think it was OK without assertions it should be fine on that point too.

@tlively
Copy link
Member

tlively commented Sep 22, 2020

I would prefer if we had an easy way to do a ReleaseWithAsserts build, since that's what I would want to do most local development with. I have no problem shipping release binaries without asserts, though.

@kripken
Copy link
Member Author

kripken commented Sep 22, 2020

Thanks for the feedback. Well, it sounds like we are unsure what to do here. Maybe the safe thing is to eventually do @dschuff 's idea from earlier, to get the builders capable of building both Release and Release+Asserts, then to use the former for final releases to users and the latter for our test runs? I'll switch this PR to a draft.

@tlively I think a Release+Asserts build is as easy as cmake -DBYN_ENABLE_ASSERTIONS=OFF?

@kripken kripken marked this pull request as draft September 22, 2020 17:08
@tlively
Copy link
Member

tlively commented Sep 22, 2020

The sense I got from the feedback was that you should go for it, not that we were unsure, but maybe I'm reading the sentiment incorrectly.

@sbc100
Copy link
Member

sbc100 commented Sep 22, 2020

Yeah. I don't feel strongly about this at this point.

@kripken
Copy link
Member Author

kripken commented Sep 22, 2020

Yeah, sorry, I didn't mean to imply people were opposed. But I'm also not 100% sure this is the right move. So I think the safe approach is probably better, and to wait for builder work for that.

Base automatically changed from master to main January 19, 2021 21:59
// We have an option to build with assertions disabled
// BYN_ASSERTIONS_ENABLED=OFF, but we currently don't recommend using and we
// don't test with it.
#error "binaryen is currently designed to be built with assertions enabled."
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should just remove these errors independently of this PR, and then once we have separate CI and Release builds as we've been discussing, then we can run with assertions on CI and without on our release builds.

Copy link
Member Author

Choose a reason for hiding this comment

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

sgtm. @sbc100 you added those specific ones - any concerns? if not i can open a PR.

Copy link
Member

Choose a reason for hiding this comment

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

I can't remember exactly why a I added this. Perhaps we were depending on assert or something like them for normal error reporting. I'm not sure if that is still true. I guess now.

Copy link
Member

Choose a reason for hiding this comment

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

I assumed it was because we were at one point depending on asserts for error reporting. But we aren't doing that anymore.

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.

5 participants