Coder Social home page Coder Social logo

Comments (10)

rylev avatar rylev commented on June 23, 2024

Without seeing the exact code that's being compiled, it's difficult to say for sure. The error you're seeing is caused by trying to read or skip string data from a WebAssembly module that exceeds the maximum allowed size for a string (100,000 bytes).

If you run wasm-tools validate $PATH_TO_COMPONENT do you see the error again?

from cargo-component.

toadslop avatar toadslop commented on June 23, 2024

Hi Ryan, thanks for the idea. I ran the command that you mentioned, but nothing was output to the console at all. I assume that means that the checks were successful?

For some additional context, I'm writing a parser using a parser combinator library called chumsky. I believe that the problem starts happening when the parser types reach a certain depth of recursion, though I haven't been able to verify that yet.

from cargo-component.

toadslop avatar toadslop commented on June 23, 2024

For additional context, I only run into errors when using cargo-component. If I compile to windows-msvc or directly to wasm32-wasi, I don't see any errors.

For more context, I found that when I run wasm-tools compose to compose my wasm components using the files that were output by the step that raised the error that I mentioned above, I get this error message:

error: failed to parse component `C:\Users\bnhei\source\silex\target/wasm32-wasi/debug/silex-parser.wasm`

Caused by:
    0: the file is not a WebAssembly component

It does seem that something was happening after the file was compiled that failed.

from cargo-component.

toadslop avatar toadslop commented on June 23, 2024

wasm-chumsky-type-info.txt

I dug into the .wasm file and found that the type information generated for the Chumsky parser is massive -- 19.3 megabytes on its own (see attached file), well over the limit that you mentioned above. Judging from what you mentioned, I would guess that the type information is stored as a string, and thus goes over the maximum possible size for a string?

from cargo-component.

rylev avatar rylev commented on June 23, 2024

The error about the binary not being a component makes sense. It seems that cargo-component was successfully able to produce a WebAssembly module, but then when it tried to convert that module into a component, that step failed leaving you with just a plain module.

The type info does seem like a very likely culprit. The short term work around is to strip that info from the binary (perhaps using wasm-tools strip) and then making the module a component using wasm-tools component new. What the actual fix for cargo-component is, I'm less sure of. Seems like this error case might need to be handled more elegantly.

from cargo-component.

toadslop avatar toadslop commented on June 23, 2024

Thanks for the suggestions. I tried using wasm-tools strip and it did significantly reduce the file size, but when I ran wasm-tools component new I received the same error message as before: error: string size out of bounds (at offset 0x3c4ff4). When I opened the binary to check its content, I did find that the massive Chumsky parser type was still included. I tried again with the --all option and got the following error:

error: failed to encode a component from module

Caused by:
    0: failed to decode world from module
    1: module was not valid
    2: module requires an import interface named `wasi_snapshot_preview1`

I guess in this case, it stripped too much. Next I'll --delete option and see if I can't target just that specific section.

from cargo-component.

toadslop avatar toadslop commented on June 23, 2024

By the way, this issue a limitation of cargo-component, right? Is this something that I might expect to see a fix for in the near future, or is it niche enough that I should plan or relying on a workaround, or just to avoid using libraries that generate such large type definitions?

from cargo-component.

toadslop avatar toadslop commented on June 23, 2024

To add one more update, it does seem that the offending part of the .wasm file was debug info -- when I tried building the project in release mode, I didn't encounter any error. This suggests that an easy fix would be to make cargo-component detect and skip debug info.

from cargo-component.

peterhuene avatar peterhuene commented on June 23, 2024

Hi @toadslop.

By the way, this issue a limitation of cargo-component, right?

No, this is an intentional limitation in wasmparser, the underlying library that various component model tools use to parse WebAssembly modules and components; it's a hard limitation that cargo-component cannot work around.

This suggests that an easy fix would be to make cargo-component detect and skip debug info.

wasmparser does not process debug information sections and cargo-component does not either, so I suspect the offending wasm string is actually contained the name custom section, which is processed by both wit-component (the library used to componentize the output from rustc) and cargo-component as part of appending producer metadata to the output.

Given that cargo-component provides error context when adding a producers section and that context is not present in the observed error message, my first guess would be it's failing from wit-component's attempt to add its producers section.

I think the proper fix here is to add a strip option in Cargo.toml for cargo-component to strip the custom sections of the core module prior to componentization; similarly, but a separate issue, an optimize option should be added for cargo-component for it to pass the module through wasm-opt.

from cargo-component.

peterhuene avatar peterhuene commented on June 23, 2024

I haven't tried, but the suppression of the name section might correlate to one of the profile options in Cargo.toml.

A possible work around might be adding the following to your Cargo.toml:

[profile.dev]
debug = false

or

[profile.dev]
strip = "symbols"

Obviously that will impact your ability to see useful stack traces for traps originating from the component (or otherwise being able to debug it).

from cargo-component.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.