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

Add CompilerConfig opt to disable IR verification in debug mode #1332

Merged
merged 3 commits into from
Mar 25, 2020

Conversation

MarkMcCaskey
Copy link
Contributor

@MarkMcCaskey MarkMcCaskey commented Mar 24, 2020

Resolves #1330

Review

  • Add a short description of the the change to the CHANGELOG.md file

@MarkMcCaskey MarkMcCaskey added 📦 lib-compiler-cranelift About wasmer-compiler-cranelift 📦 lib-deprecated About the deprecated crates labels Mar 24, 2020
@MarkMcCaskey MarkMcCaskey force-pushed the feature/disable-ir-verification branch from 7d59fb4 to 403e14b Compare March 24, 2020 21:52
@nlewycky nlewycky changed the title Add CompilerConifg opt to disable IR verification in debug mode Add CompilerConfig opt to disable IR verification in debug mode Mar 24, 2020
enable_verifier = !config.disable_debug_mode_verification;
} else {
// Set defaults if no config found.
enable_verifier = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

How about enable_verifier = cfg!(test) || cfg!(debug_assertions)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would require duplicating that boolean expression because it needs to be checked on the other case too! I considered it but decided against it

/// (for example in 'debug' builds). Enabling this flag will make compilation faster at the
/// cost of not detecting bugs in the compiler. The verification steps that this flag
/// disables are disabled by default in 'release' builds.
pub disable_debug_mode_verification: bool,
Copy link
Contributor

@nlewycky nlewycky Mar 24, 2020

Choose a reason for hiding this comment

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

Is there anything stopping us from turning verification on in a release build? Say, for users who are prepared to spend extra compile-time for extra assurance? If we can do that, could we make this control the setting unilaterally, and also remove the negative?

Copy link
Member

@syrusakbary syrusakbary Mar 24, 2020

Choose a reason for hiding this comment

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

Yup, agreed with Nick. Since debug verification is probably always false, we can do something like:

Suggested change
pub disable_debug_mode_verification: bool,
pub enable_ir_verification: bool,

(note: this can work for both Cranelift and LLVM, since they both have IR verifiers).

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd like to rename it to something like "extra_safety_checks" or "backend_internal_verification" or something along those lines. There's nothing special about clif/llvm here, singlepass could have its own safety checks too, and it doesn't have an IR.

Copy link
Member

Choose a reason for hiding this comment

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

What about enable_internal_verification or enable_verification (I kind of like keeping backend out, since this might be a setting on the backend config itself?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's phrased in the negative because we derive(Default) which means it defaults to false haha. I can make a manual implementation of Default though

enable_verifier = cfg!(test) || cfg!(debug_assertions);
}

if enable_verifier {
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional.
builder.set("enable_verifier", if enable_verifier { "true" } else { "false" }).unwrap();

impl Default for CompilerConfig {
fn default() -> Self {
Self {
symbol_map: Default::default(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't you use ..Default::default() for these?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would infinite loop I believe! My understanding of what ..Default::default() does is that it calls default on the type you're constructing and then overrides the fields you specified. Because we're defining default, I don't believe we can use that syntax here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, just verified this:

warning: function cannot return without recursing
   --> lib/runtime-core/src/backend.rs:159:5
    |
159 |     fn default() -> Self {
    |     ^^^^^^^^^^^^^^^^^^^^ cannot return without recursing
...
178 |             ..Default::default()
    |               ------------------ recursive call site
    |
    = note: `#[warn(unconditional_recursion)]` on by default
    = help: a `loop` may express intention better if this is on purpose

@MarkMcCaskey
Copy link
Contributor Author

bors r+

bors bot added a commit that referenced this pull request Mar 24, 2020
1332: Add `CompilerConfig` opt to disable IR verification in debug mode r=MarkMcCaskey a=MarkMcCaskey

Resolves #1330 

# Review

- [x] Add a short description of the the change to the CHANGELOG.md file


Co-authored-by: Mark McCaskey <mark@wasmer.io>
@bors
Copy link
Contributor

bors bot commented Mar 25, 2020

Timed out

@MarkMcCaskey
Copy link
Contributor Author

bors retry

@bors
Copy link
Contributor

bors bot commented Mar 25, 2020

Build succeeded

@bors bors bot merged commit 4e53f9e into master Mar 25, 2020
@bors bors bot deleted the feature/disable-ir-verification branch March 25, 2020 01:47
webmaster128 added a commit to CosmWasm/cosmwasm that referenced this pull request Mar 25, 2020
We'll need this to test the patch
wasmerio/wasmer#1332
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 lib-compiler-cranelift About wasmer-compiler-cranelift 📦 lib-deprecated About the deprecated crates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow disabling cranelift verifier explicitely
3 participants