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

parking_lot -> simple_mutex #219

Closed
wants to merge 1 commit into from
Closed

Conversation

MartinKavik
Copy link

@MartinKavik MartinKavik commented Dec 7, 2020

Resolves #218

This PR replaces the dependency parking_lot with simple_mutex to resolve runtime bugs caused by parking_lot's Mutex::lock in Wasm. See the linked issue for more info.

The fix has been manually tested through a Seed app that uses topo as an indirect dependency.


The PR has been marked as Draft because of two reasons:

  1. I can't compile it because of the error below. The error was already present in the main branch without my changes:
$ cargo build --all
   Compiling counter-moxie-dom-struct v0.1.0 (D:\repos\moxie\dom\examples\counter_struct)
error: expected an identifier
  --> dom\examples\counter_struct\src\lib.rs:37:1
   |
37 | moxie_dom::app_boot!(Counter);
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

How should I resolve it?

  1. It looks like the only thing that prevents to compile the project (at least topo) on the stable Rust is this line in Cargo.toml:
cargo-features = ["named-profiles"] # for coverage

Is there a simple way to remove this limitation?

Thank you!

@anp
Copy link
Owner

anp commented Dec 8, 2020

Thanks for the PR! I'm looking into the errors you ran into right now. Could you try making this change with std's locks instead of simple-mutex? That crate looks really cool but it looks like it's only used by one other crate right now and I don't feel qualified to assess the lock myself.

@anp
Copy link
Owner

anp commented Dec 8, 2020

How is your Rust toolchain installed? The repository is set up assuming you're using rustup which may not be correct.

@anp
Copy link
Owner

anp commented Dec 8, 2020

Re your question (2) I opened #221. There used to be a bunch more nightly deps and I think that might be the only one left!

Re (1), can you paste the output of rustc --version? That doesn't look like an issue I'd expect from the toolchain version but I'm not sure how to repro otherwise (I'm also on Windows).

@MartinKavik
Copy link
Author

Could you try making this change with std's locks instead of simple-mutex? That crate looks really cool but it looks like it's only used by one other crate right now and I don't feel qualified to assess the lock myself.

My first attempt was with std's Mutex but the problem was a different API - e.g. lock method:

fn lock(&self) -> LockResult<MutexGuard<'_, T>>  // std
fn lock(&self) -> MutexGuard<T>                  // simple-mutex
fn lock(&self) -> MutexGuard<'_, R, T>           // parking_lot

As the result, I had to write a lot of .unwrap()s or change the API to handle possible errors because of LockResult. Also I was fighting a lot with the compiler where the lock has been called inside macro definitions (if I remember it correctly.)
So I decided to use simple_mutex - replacement is much easier, should be faster than std and the author is pretty experienced.
However I can try to use std's Mutex again if you want, but I'll need to know if I should use unwrap or expect or change API.


How is your Rust toolchain installed?

I've installed Rust from the official *.exe installer. And I use classic rustup update. So it should be the most standard way.


Re (1), can you paste the output of rustc --version?

I've just tried the current one (rustc 1.50.0-nightly (1c389ffef 2020-11-24)) and the one set explicitly in Moxie's rust-toolchain (rustc 1.47.0-nightly (6c8927b0c 2020-07-26) and the error persists.

I'm not sure how to repro otherwise

I've done some more investigation and the reason why you can't reproduce it is Cargo.lock. I'm starting to hate dependency version resolving in Cargo.toml and I plan to remove Cargo.lock from my .gitignore's (it doesn't help with cargo install but that's another story.) I've also found the bug with parking_lot when I've deleted Cargo.lock and it broke the app for my client.

Ok, back to the problem. There is probably a bug or changed API in the latest paste crate 1.0.3. I can "fix" it by changing paste = "1.0.0" to paste = "=1.0.0" (or =1.0.2) in dom's Cargo.toml.

Let's look at the code in dom:

moxie/dom/src/lib.rs

Lines 76 to 88 in 74fb3e7

macro_rules! app_boot {
($app:ty) => {
moxie_dom::__paste! {
impl moxie_dom::Boot for $app {}
#[moxie_dom::__wasm_bindgen(js_name = [<boot $app>])]
#[doc(hidden)]
pub fn [<__js_boot_ $app:snake>] (root: moxie_dom::raw::sys::Node) {
<$app as moxie_dom::Boot>::boot(root);
}
}
};
}

I've tried to replace ($app:ty) with ($app:ident) and then some combinations like js_name = "[<boot $app>]") or js_name = "boot" $app but everything failed as a compilation error or even Rust compiler panic. What do you think? Should I create an issue in paste's repo? I guess it has been broken by this PR: dtolnay/paste#57

@anp
Copy link
Owner

anp commented Dec 29, 2020

Thank you again for this! I think for now it'll be easier to take the approach proposed in #225 so I'll give this a close.

What do you think? Should I create an issue in paste's repo? I guess it has been broken by this PR: dtolnay/paste#57

I'm not sure I follow where this error is coming from, if you're still hitting it can you open a separate issue? Would be happy to help figure it out.

@anp anp closed this Dec 29, 2020
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.

Error resolving module specifier “env”
2 participants