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

Omit asserts if condition can be proven statically #685

Merged
merged 1 commit into from
Jul 2, 2019
Merged

Conversation

dcodeIO
Copy link
Member

@dcodeIO dcodeIO commented Jun 21, 2019

As mentioned in #681 (comment), this PR makes assert try to prove an assertion statically, omitting generating any code if possible.

Shrinks some tests significantly as a side-product. Not 100% sure if it's sufficient this way, or whether a static_assert builtin would be a better choice.

@MaxGraey
Copy link
Member

May be better skip this optimization when using --debug or -O0?

@dcodeIO
Copy link
Member Author

dcodeIO commented Jun 21, 2019

Hmm, when I think about it, it's actually very similar to static branch elimination just that the branch here is an abort. It shouldn't generate any useful debug information if not hit anyway, except that there's an abort in the code that never executes referencing a (non-human-readable) string offset in memory. Hmm, hmm...

@dcodeIO
Copy link
Member Author

dcodeIO commented Jul 2, 2019

Going to merge this to get it out of the way, but let's all keep an eye open for potential downsides to this. If it doesn't work out well, it should be easy to reverse.

@dcodeIO dcodeIO merged commit d68c266 into master Jul 2, 2019
@dcodeIO dcodeIO deleted the static-assert branch September 20, 2019 09:08
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.

2 participants