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

non-parallel mode broken on master #214

Closed
RReverser opened this issue Apr 16, 2020 · 8 comments · Fixed by #216
Closed

non-parallel mode broken on master #214

RReverser opened this issue Apr 16, 2020 · 8 comments · Fixed by #216
Labels
I-Critical Issues that are breaking core functionality for a significant portion of users T-Bug Some piece of the software is not working as intended

Comments

@RReverser
Copy link
Contributor

Looks like 4ef9208 landed yesterday and removes the non-parallel mode added in #194.

These conditional compilation attributes and a separate synchronous code are important for environments like WebAssembly (which is what they were added for in the first place), where thread::spawn is not available and errors out at runtime.

After this change, it's invoked unconditionally again.

@shssoichiro
Copy link
Owner

Ah, I see. Unfortunately without this change it was failing to compile (i.e. it was already broken). Looks like I'll need to add a WASM target to the CI as well to catch issues like this.

@shssoichiro shssoichiro added I-Critical Issues that are breaking core functionality for a significant portion of users T-Bug Some piece of the software is not working as intended labels Apr 16, 2020
@RReverser
Copy link
Contributor Author

RReverser commented Apr 16, 2020

Hmm, do you know what exactly was broken?

It worked for me after the last PR (#208) and it even powers PNG compression on https://squoosh.app since 2 days ago as mentioned on #203. (Btw, I published a write up about this yesterday in case you're curious: https://rreverser.com/bringing-oxipng-to-squoosh/.)

Maybe something else changed in between within the last week?

@shssoichiro
Copy link
Owner

I haven't determined what caused this yet, but if I revert 4ef9208, I get these errors:

  cargo clippy --no-default-features
    Checking oxipng v2.3.0 (/home/soichiro/repos/oxipng)
warning: unused import: `std::thread`
  --> src/evaluate.rs:23:5
   |
23 | use std::thread;
   |     ^^^^^^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

error[E0507]: cannot move out of `self.eval_best_candidate.0`, as `self` is a captured variable in an `FnMut` closure
   --> src/evaluate.rs:154:31
    |
104 |     fn try_image_inner(&self, image: Arc<PngImage>, is_reduction: bool) {
    |                        ----- captured outer variable
...
154 |                         match self.eval_best_candidate {
    |                               ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider borrowing here: `&self.eval_best_candidate`
155 |                             Some(prev) if prev.cmp_key() < new.cmp_key() => {}
    |                                  ----
    |                                  |
    |                                  data moved here
    |                                  move occurs because `prev` has type `evaluate::Candidate`, which does not implement the `Copy` trait

error[E0594]: cannot assign to `self.eval_best_candidate` which is behind a `&` reference
   --> src/evaluate.rs:156:34
    |
156 | ...                   _ => self.eval_best_candidate = Some(new),
    |                            ^^^^^^^^^^^^^^^^^^^^^^^^ cannot assign

error: aborting due to 2 previous errors

I did attempt to resolve it by leaving the feature-dependent code in place and propagating &mut references up the chain, but that did not make the borrow checker very happy.

@RReverser
Copy link
Contributor Author

Ohh I see what's going on. I was wrong, I didn't actually update to #208 yet and that's the one that broke non-parallel mode. Let me revert 4ef9208 and try to fix this properly instead...

@RReverser
Copy link
Contributor Author

So the issue is that in #194 I've added RefCell to correctly handle internal mutability, but in #208 I've accidentally removed it and replaced with regular contents.

I just need to add that RefCell back. But yeah, having a CI run at least to build in --no-default-features mode would've been helpful to catch these easier in future.

@shssoichiro
Copy link
Owner

We do have that now, although it doesn't catch the lack of std::thread on WASM target. But unfortunately for a few weeks Travis had been broken and failing to report results. So it wasn't until a few days ago I migrated the project to Github Actions and we have a working CI again.

@RReverser
Copy link
Contributor Author

although it doesn't catch the lack of std::thread on WASM target

Yeah that one is trickier to catch. Rust includes the API regardless, but throws a runtime error, so the only way to catch it is by actually running tests (e.g. by compiling to wasm32-wasi and using Node.js- or wasmtime-based runner or something similar).

RReverser added a commit to RReverser/oxipng that referenced this issue Apr 16, 2020
It was accidentally removed as part of shssoichiro#208.
Fixes shssoichiro#214.
@RReverser
Copy link
Contributor Author

Done: #216

shssoichiro pushed a commit that referenced this issue Apr 16, 2020
It was accidentally removed as part of #208.
Fixes #214.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-Critical Issues that are breaking core functionality for a significant portion of users T-Bug Some piece of the software is not working as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants