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

cannot find type MmapSerializationSink in crate measureme #4132

Closed
ctaggart opened this issue Apr 20, 2020 · 8 comments
Closed

cannot find type MmapSerializationSink in crate measureme #4132

ctaggart opened this issue Apr 20, 2020 · 8 comments
Labels
blocked Blocked on rustc, an RFC, etc.

Comments

@ctaggart
Copy link
Contributor

I updated dependencies without the Cargo.lock committed and how I can't build with rustc stable or nightly with any of these versions:

# rustfmt-nightly = "*"
# rustfmt-nightly = "=1.4.11"
# rustfmt_lib = "=2.0.0-rc.1"
rustfmt_lib = { git = "https://github.com/rust-lang/rustfmt" }

I keep getting this error:

error[E0412]: cannot find type `MmapSerializationSink` in crate `measureme`
   --> /Users/cameron/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/rustc-ap-rustc_data_structures-654.0.0/profiling.rs:103:37
    |
103 | type SerializationSink = measureme::MmapSerializationSink;
    |                                     ^^^^^^^^^^^^^^^^^^^^^ help: a trait with a similar name exists: `SerializationSink`
    | 
   ::: /Users/cameron/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/measureme-0.7.1/src/serialization.rs:14:1
    |
14  | pub trait SerializationSink: Sized + Send + Sync + 'static {
    | ---------------------------------------------------------- similarly named trait `SerializationSink` defined here

error[E0425]: cannot find function `get_resident` in this scope
   --> /Users/cameron/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/rustc-ap-rustc_data_structures-654.0.0/profiling.rs:585:28
    |
585 |     let mem_string = match get_resident() {
    |                            ^^^^^^^^^^^^ not found in this scope

error: aborting due to 2 previous errors
@calebcartwright
Copy link
Member

calebcartwright commented Apr 20, 2020

Hi @ctaggart - Could you provide more context?

Are you trying to build something that is using rustfmt as a lib? What's the version of rust you're using?

rustfmt has the rustc-ap-* crates in its dependency tree, both on the master branch in this repo as well as the most recent 1.4.14 release. However, all the dependencies within the rustfmt tree, including rustc-ap-rustc_data_structures, are compiling successfully on the latest nightly (as well as the previous several nightlies that I have locally)

$ rustc -Vv
rustc 1.44.0-nightly (dbf8b6bf1 2020-04-19)
binary: rustc
commit-hash: dbf8b6bf116c7bece2987ff4bd2792f008a6ee77
commit-date: 2020-04-19
host: x86_64-unknown-linux-gnu
release: 1.44.0-nightly
LLVM version: 9.0

@ctaggart
Copy link
Contributor Author

ctaggart commented Apr 20, 2020

Hi @calebcartwright, thanks for the quick reply. I reproduced the issue here:
https://github.com/ctaggart/rustfmt_4132

It gets that error only when I target wasm:
cargo build --target wasm32-unknown-unknown

I'm wanting to embed formatting in a wasm app. The code I had from months ago was based on how RLS was using rustfmt.

https://github.com/ctaggart/rustfmt_4132/blob/master/src/lib.rs

use rustfmt_nightly::{Config, Edition, EmitMode, Input, Session, Verbosity};

fn format(source: String) -> String {
    // https://github.com/rust-lang/rls/blob/master/rls/src/actions/format.rs
    let mut config = Config::default();
    config.set().edition(Edition::Edition2018);
    config.set().emit_mode(EmitMode::Stdout);
    config.set().skip_children(true);
    config.set().verbose(Verbosity::Quiet);
    let mut buf = Vec::<u8>::new();
    {
        let mut session = Session::new(config, Some(&mut buf));
        session.format(Input::Text(source)).unwrap();
    }
    String::from_utf8(buf).unwrap()
}

If there is a better way to do this with the new rustfmt_lib with less dependencies, I'd love to know.

@ctaggart
Copy link
Contributor Author

I opened up rust-lang/rust#71369 with a possible fix. I'd still really like to know how to do the above with the new rustfmt_lib.

@calebcartwright
Copy link
Member

Out of curiosity, could you tell us a little more about your case and what you're planning on using the rustfmt lib for/what kind of formatting capabilities your app will provide? There's not many consumers of the rustfmt lib (RLS is the only one I know of that uses it to provide formatting in editors/IDEs) so it'd be helpful to know another use case anyways.

If there is a better way to do this with the new rustfmt_lib with less dependencies, I'd love to know.

rustfmt is always (or at least for the very extended forseeable future) going to require nightly to compile and have dependencies on the rustc internals because it needs parsing support for all the latest and greatest syntax as quickly as possible.

These internal APIs are inherently dynamic, and honestly not really intended for outside consumers. They regularly contain breaking changes which starts an upgrade dance involving rustfmt, racer, and rls (all of which have to be updated in coordination when new versions of those rustc internals are needed in any one of those projects).

Adding the rustfmt lib into your project's dependency tree will likely subject your project to some of these same challenges. I'm not saying you shouldn't do so, just wanted you to be aware 😄

@topecongiro
Copy link
Contributor

@ctaggart Thank you for the report! We can test whether the PR fixes this issue by updating rustc-ap-* crates to the version which includes the fix. These crates get published automatically every week, so we may need to wait an additional week or so after the PR gets merged.

@topecongiro topecongiro added the blocked Blocked on rustc, an RFC, etc. label Apr 21, 2020
@ctaggart
Copy link
Contributor Author

My use case is to generate and format code from a wasm. The code generation is working, but I need it formatted and that is where rustfmt comes in. I'm okay with nightly. Thanks for the update on the timeline. Hopefully this is the only blocker and not just the first one.

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Apr 22, 2020
…ic-morse

allow wasm32 compilation of librustc_data_structures/profiling.rs

I'm trying to use rustfmt from a wasm app. I ran into this compilation problem rust-lang/rustfmt#4132 and after investigating, it looked like just adjusting a few cfg's. I based it on how measureme added support in rust-lang/measureme#43.

My testing on my macbook was just that librustc_data_structures builds now with both:
- cargo build
- cargo build --target wasm32-unknown-unknown
@calebcartwright
Copy link
Member

Looks like the upstream PR was merged so those changes will be available in the next rustc-ap-* release (Tuesday)

@ctaggart
Copy link
Contributor Author

ctaggart commented May 8, 2020

This particular issue was fixed by updating to rustc 646 in #4157. I got rustfmt_lib working from wasm with a couple more fixes that will probably be rustc 658. See rust-lang/rust#72017 .

@ctaggart ctaggart closed this as completed May 8, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue May 8, 2020
Work around ICEs during cross-compilation for target, ast, & attr

This applies the fix for rust-lang#72003 to work around rust-lang#56935 to three more libraries. With these additional fixes, I'm able to use rustfmt_lib from wasm (rust-lang/rustfmt#4132 (comment)), which was my goal.

To get it working locally and to test, I copied the `.cargo/registry/src` and applied the fix and replaced the reference in my project:
``` toml
[replace]
"rustc-ap-rustc_span:656.0.0" = { path = "../rustc-ap-rustc_span" }
"rustc-ap-rustc_target:656.0.0" = { path = "../rustc-ap-rustc_target" }
"rustc-ap-rustc_ast:656.0.0" = { path = "../rustc-ap-rustc_ast" }
"rustc-ap-rustc_attr:656.0.0" = { path = "../rustc-ap-rustc_attr" }
```
@ctaggart ctaggart mentioned this issue May 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked Blocked on rustc, an RFC, etc.
Projects
None yet
Development

No branches or pull requests

3 participants