Stream: general

Topic: transitive imports validation failure


view this post on Zulip Evan Simmons (Sep 17 2024 at 16:37):

Hi bytecode alliance,
I'm having trouble composing two components where one world's interface is 'use'ing a dependent interface. The specific error is as follows.
Notes

> wasm-tools compose salutation.wasm -d types.wasm -o sal_ty.wasm
error: failed to validate output component `sal_ty.wasm`

Caused by:
    0: instance not valid to be used as export (at offset 0x10a56)

salutation/types.wit

package hotswap:salutation@0.1.0;

interface user-interface {
    type tag = u64;
    enum gender {
        male,
        female,
        other
    }

    record user {
        name: string,
        id: u64,
        tenant-tags: list<tag>,
        gender: gender,
    }
    record time {
        seconds: u64,
        nanos: u64,
    }

    age-in-weeks: func(u: user, now: time) -> u32;
}
world types {
    export user-interface;
}

salutation/salutation.wit

package hotswap:salutation@0.1.0;

interface salutation {
    use user-interface.{user};

    variant formal-honorific {
        sir,
        maam,
        sir-maam,
        custom(string)
    }
    get-formal-honorific: func(u: user) -> formal-honorific;
    greet: func(u: user) -> string;
}

world app {
    export salutation;
}

Thanks for your help!

Repository for design and specification of the Component Model - WebAssembly/component-model

view this post on Zulip Alex Crichton (Sep 17 2024 at 17:50):

Can you provide more steps of how to reproduce? As-is I'm not sure what the various components in play are here. It's also worth mentioning that wac should generally be used instead of wasm-tools compose nowadays. I know you say it's the same error message, but figured I'd reiterate anyway

view this post on Zulip Evan Simmons (Sep 17 2024 at 22:38):

Hi Alex, thanks so much for your suggestion. I've created a repo for repro (lol) here: https://github.com/estk/hotswap-example

Contribute to estk/hotswap-example development by creating an account on GitHub.

view this post on Zulip Evan Simmons (Sep 17 2024 at 22:42):

After having the same issue with wac, i enabled logging and backtracing:

...
 DEBUG wac_graph::encoding     > popping type scope
 DEBUG wac_graph::encoding     > instance type encoded to type index 17
 DEBUG wac_graph::graph        > import `wasi:filesystem/preopens@0.2.0` encoded to instance index 9
 DEBUG wac_graph::graph        > interface `wasi:filesystem/preopens@0.2.0` is available for aliasing as instance index 9
 DEBUG wac_graph::graph        > instantiating package `plug:types` with arguments: [("wasi:cli/environment@0.2.0", Instance, 0), ("wasi:cli/exit@0.2.0", Instance, 1), ("wasi:io/error@0.2.0", Instance, 2), ("wasi:io/streams@0.2.0", Instance, 3), ("wasi:cli/stdin@0.2.0", Instance, 4), ("wasi:cli/stdout@0.2.0", Instance, 5), ("wasi:cli/stderr@0.2.0", Instance, 6), ("wasi:clocks/wall-clock@0.2.0", Instance, 7), ("wasi:filesystem/types@0.2.0", Instance, 8), ("wasi:filesystem/preopens@0.2.0", Instance, 9)]
 DEBUG wac_graph::graph        > instantiation of package `plug:types` encoded to instance index 10
 DEBUG wac_graph::graph        > encoding alias for instance export `hotswap:salutation/user-interface@0.1.0` of instance index 10
 DEBUG wac_graph::graph        > alias of export `hotswap:salutation/user-interface@0.1.0` encoded to instance index 11
 DEBUG wac_graph::graph        > instantiating package `socket` with arguments: [("hotswap:salutation/user-interface@0.1.0", Instance, 11), ("wasi:cli/environment@0.2.0", Instance, 0), ("wasi:cli/exit@0.2.0", Instance, 1), ("wasi:io/error@0.2.0", Instance, 2), ("wasi:io/streams@0.2.0", Instance, 3), ("wasi:cli/stdin@0.2.0", Instance, 4), ("wasi:cli/stdout@0.2.0", Instance, 5), ("wasi:cli/stderr@0.2.0", Instance, 6), ("wasi:clocks/wall-clock@0.2.0", Instance, 7), ("wasi:filesystem/types@0.2.0", Instance, 8), ("wasi:filesystem/preopens@0.2.0", Instance, 9)]
 DEBUG wac_graph::graph        > instantiation of package `socket` encoded to instance index 12
 DEBUG wac_graph::graph        > encoding alias for instance export `hotswap:salutation/salutation@0.1.0` of instance index 12
 DEBUG wac_graph::graph        > alias of export `hotswap:salutation/salutation@0.1.0` encoded to instance index 13
error: encoding produced a component that failed validation

Caused by:
    instance not valid to be used as export (at offset 0x36d3bf)

Stack backtrace:
   0: std::backtrace_rs::backtrace::libunwind::trace
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1: std::backtrace_rs::backtrace::trace_unsynchronized
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2: std::backtrace::Backtrace::create
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/backtrace.rs:331:13
   3: anyhow::error::<impl core::convert::From<E> for anyhow::Error>::from
   4: <core::result::Result<T,F> as core::ops::try_trait::FromResidual<core::result::Result<core::convert::Infallible,E>>>::from_residual
   5: wac_cli::commands::plug::PlugCommand::exec::{{closure}}
   6: wac::main::{{closure}}
...

view this post on Zulip Alex Crichton (Sep 18 2024 at 15:07):

thanks! I'll try to take a look at this in the near future. If you'd like as well in the meantime I think it'd be reasonable to file an issue too

view this post on Zulip Evan Simmons (Sep 18 2024 at 23:47):

Cool, ya i think this might be the same issue: https://github.com/bytecodealliance/wasm-tools/issues/1798

Component has been built successfully but failed the invalidation. This repo https://github.com/sammyne/wasm-component-broken-compose is made to reproduce the problem. Requirement Rust 1.80.1 (3762...

view this post on Zulip Alex Crichton (Sep 20 2024 at 18:53):

A bit delayed getting to this but I left a comment on the issue there about what's going wrong, let me know if the workaround of "move the types around" doesn't work for you though

view this post on Zulip Evan Simmons (Sep 20 2024 at 19:51):

That was a super helpful explanation. I just tried the suggestion, and it seems the consequences of moving the type up is that the top level component then needs to implement that interface.

view this post on Zulip Evan Simmons (Sep 20 2024 at 19:52):

My use case is roughly, team A owns the raw data and type definitions, team B, C, ... imports those and uses them in their business logic. Maybe there is some other way to accomplish this?

view this post on Zulip Evan Simmons (Sep 20 2024 at 19:55):

Ive created an issue in the wac repo here: https://github.com/bytecodealliance/wac/issues/141

Repro https://github.com/estk/hotswap-example The error wac plug --plug types.wasm salutation.wasm -o tysal.wasm error: encoding produced a component that failed validation Caused by: instance not ...

view this post on Zulip Alex Crichton (Sep 20 2024 at 20:07):

Another possibility is to split interface salutation into interface salutation and interface salutation-types, and I think that should work?

view this post on Zulip Evan Simmons (Sep 20 2024 at 20:11):

standby let me try that

view this post on Zulip Evan Simmons (Sep 20 2024 at 20:20):

i pushed the changes to my main branch, one sec and ill try to fix the compile err

view this post on Zulip Evan Simmons (Sep 20 2024 at 20:28):

ok, its typechecking now, but same error

view this post on Zulip Evan Simmons (Sep 20 2024 at 20:28):

types.rs

interface user-types {
    type tag = u64;
    enum gender {
        male,
        female,
        other
    }

    record user {
        name: string,
        id: u64,
        tenant-tags: list<tag>,
        gender: gender,
    }
    record time {
        seconds: u64,
        nanos: u64,
    }
}

interface user {
    use user-types.{user, time};
    age-in-weeks: func(u: user, now: time) -> u32;
}
world types {
    export user;
    export user-types;
}

view this post on Zulip Evan Simmons (Sep 20 2024 at 20:29):

salutation.rs

interface salutation-types {
    variant formal-honorific {
        sir,
        maam,
        sir-maam,
        custom(string)
    }
}
interface salutation {
    use user-types.{user, time};
    use salutation-types.{formal-honorific};

    get-formal-honorific: func(u: user) -> formal-honorific;
    greet: func(u: user) -> string;
}

world app {
    import user;
    import user-types;
    export salutation-types;
    export salutation;
}

view this post on Zulip Alex Crichton (Sep 20 2024 at 20:43):

if you remove export salutation-types does it work?

view this post on Zulip Alex Crichton (Sep 20 2024 at 20:43):

(maybe export user-types too?)

view this post on Zulip Evan Simmons (Sep 20 2024 at 20:49):

standby

view this post on Zulip Evan Simmons (Sep 20 2024 at 20:50):

world app {
    import user;
    export salutation;
}
cargo component build -p types
cargo component build -p salutation
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.02s
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.00s

wac plug --plug types.wasm salutation.wasm -o tysal.wasm
error: encoding produced a component that failed validation

Caused by:
    instance not valid to be used as export (at offset 0x36dcea)

view this post on Zulip Evan Simmons (Sep 20 2024 at 20:51):

(same deal with user-types still imported)

view this post on Zulip Alex Crichton (Sep 20 2024 at 21:02):

hm so locally if I take the WITs you just mentioned above and delete export user-types;, import user-types;, and export salutation-types; I can get a composition to work locally

view this post on Zulip Alex Crichton (Sep 20 2024 at 21:03):

did you update world types { ... } as well to not have the export user-types?

view this post on Zulip Alex Crichton (Sep 20 2024 at 21:03):

(and to be clear this is all still a bug in wac/wasm-compose, in the meantime I'm curious if a workaround is possible)

view this post on Zulip Evan Simmons (Sep 20 2024 at 23:37):

Sorry for the delay, was in mtgs. Ok, so yes with those changes it does work!

view this post on Zulip Evan Simmons (Sep 20 2024 at 23:39):

I've pushed a commit to the main branch with those fixes. Super interesting that that worked.


Last updated: Nov 22 2024 at 17:03 UTC