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

document overflow-checks #675

Open
ibaryshnikov opened this issue Jul 11, 2019 · 8 comments
Open

document overflow-checks #675

ibaryshnikov opened this issue Jul 11, 2019 · 8 comments
Labels
help wanted Extra attention is needed PR welcome

Comments

@ibaryshnikov
Copy link
Member

ibaryshnikov commented Jul 11, 2019

Consider the following code:

#[wasm_bindgen]
pub fn add(a: u8, b: u8) -> u8 {
    a + b
}

The build command is

wasm-pack build --target web

Initialization js is

import init, { add } from './pkg/overflow_check.js';

window.addEventListener('load', async () => {
    await init();

    const result = add(200, 200);
    console.log(`result`, result);
});

Expected result (from JS perspective) is either 400 or error
Actual result is 144
Possible fix is to enable overflow checks in Cargo.toml

[profile.release]
overflow-checks = true

The problem here is that it's a default build, which produces a wrong result silently.

Making debug builds by default was already discussed in #437
I'd like to bring this topic again and collect some feedback here

Environment details:

wasm-pack 0.8.1
wasm-bindgen 0.2.47
rustc 1.36.0
@fitzgen
Copy link
Member

fitzgen commented Jul 11, 2019

I don't think that we want to change whether overflow checks are enabled or not for a given profile by default. If building with the debug profile, we should use the debug profile's defaults for overflow checks, and same thing for release profile. Changing that behavor is veering off too much from standard configurations for my taste.

I don't know if either @alexcrichton or @ashleygwilliams feel that this point changes the calculus of whether the default profile should be release or debug, though. I don't have strong opinions.

@alexcrichton
Copy link
Contributor

I agree that we shouldn't change the default [profile] section by default as it's relatively unidiomatic in Rust. I'm personally still slightly in favor of debug-by-default, but nowadays it would be a big change for wasm-pack so it may no longer be on the table.

@ibaryshnikov
Copy link
Member Author

I'd like to clarify that I don't suggest to change the default [profile]. My point is that I as a user can add to my own Cargo.toml for every project

[profile.release]
overflow-checks = true

@alexcrichton
Copy link
Contributor

Ah good point! I'm personally always down for documentation updates which mention things like that

@ibaryshnikov
Copy link
Member Author

What was the reason to make --release build as default?

@alexcrichton
Copy link
Contributor

IIRC it was because many users coming from JS may not know about a debug/optimized distinction and if rust/wasm is evaluated with the results of wasm-pack build we'd want that to be "best in class". I may be misremembering though

@Pauan
Copy link
Contributor

Pauan commented Jul 15, 2019

@alexcrichton Yeah, I vaguely remember something about users complaining about file size/performance (which are quite bad in debug mode).

@ashleygwilliams ashleygwilliams changed the title Integers overflow in default build document overflow-checks Jul 16, 2019
@ashleygwilliams ashleygwilliams added help wanted Extra attention is needed PR welcome labels Jul 16, 2019
@ibaryshnikov
Copy link
Member Author

Well, I wanted to gather some feedback and to propose either changind defaults to --dev, or making this flag required (without defaults). My bet is that people who complained about code performance before would start to complain about compiling times later. I think that once people start building big web applications in rust, they will start switching to debug build. And now, before 1.0, it would be easier to make a breaking change.

It doesn't deny the need in a good documentation for everything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed PR welcome
Projects
None yet
Development

No branches or pull requests

5 participants