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

Rename halide_assert -> halide_abort_if_false #6382

Merged
merged 11 commits into from
Nov 8, 2021
Merged

Conversation

steven-johnson
Copy link
Contributor

A crashing bug got mistakenly inserted because a new contributor (reasonably) assumed that the halide_assert() macro in our runtime code was like a C assert() (i.e., something that would vanish in optimized builds).

This is not the case; it is a check that happens in all build modes and always triggers an abort() if it fires. We should remove any ambiguity about it, so this proposes to rename it to somethingmore like the Google/Abseil-style CHECK() macro, to make it stand out more.

(We may want to do a followup to verify that all of the uses really are unrecoverable errors that aren't better handled by returning an error.)

A crashing bug got mistakenly inserted because a new contributor (reasonably) assumed that the `halide_assert()` macro in our runtime code was like a C `assert()` (i.e., something that would vanish in optimized builds).

This is not the case; it is a check that happens in all build modes and always triggers an `abort()` if it fires. We should remove any ambiguity about it, so this proposes to rename it to somethingmore like the Google/Abseil-style CHECK() macro, to make it stand out more.

(We may want to do a followup to verify that all of the uses really are unrecoverable errors that aren't better handled by returning an error.)
@steven-johnson steven-johnson changed the title Rename halide_assert -> HALIDDE_CHECK Rename halide_assert -> HALIDE_CHECK Nov 3, 2021
@steven-johnson
Copy link
Contributor Author

Failures unrelated (see #6386)

@steven-johnson steven-johnson changed the title Rename halide_assert -> HALIDE_CHECK Rename halide_assert -> halide_abort_if_false Nov 3, 2021
@dsharletg
Copy link
Contributor

Should the original use that caused this problem be an abort even in debug mode? I think maybe it was just wrong to assert at all. In which case, the problem isn't that assert is active in non-debug builds at all.

In general I think the only reason to disable asserts in non-debug builds isn't because we should tolerate assert failures there, but we just don't want the performance hit due to assert overhead.

So, I question whether this PR and related PRs are needed at all?

@abadams
Copy link
Member

abadams commented Nov 3, 2021

The name is still misleading though, because it evokes "assert", so even if no usage changes +1 to the rename.

@steven-johnson
Copy link
Contributor Author

In general I think the only reason to disable asserts in non-debug builds isn't because we should tolerate assert failures there, but we just don't want the performance hit due to assert overhead.

I think it's both. An assertion failure / abort() in our runtime should be the absolutely last resort, and only for errors that are truly unrecoverable. The vast majority of existing halide_assert() usage looks to be more of the assert() usage variety (ie, documenting an invariant that doesn't even need checking at runtime unless in a special build for debugging).

@@ -1159,21 +1159,30 @@ void CodeGen_LLVM::optimize_module() {
#endif
pb.registerOptimizerLastEPCallback(
[](ModulePassManager &mpm, OptimizationLevel level) {
#if LLVM_VERSION >= 140
Copy link
Member

Choose a reason for hiding this comment

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

Not sure what's going on in this file?

@abadams
Copy link
Member

abadams commented Nov 8, 2021

Oh you merged in a fix for trunk llvm branch. Got it.

@steven-johnson steven-johnson merged commit d6f1345 into master Nov 8, 2021
@steven-johnson steven-johnson deleted the srj/halide_assert branch November 8, 2021 23:13
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.

3 participants