DouglasDwyer / wasm_component_layer

WebAssembly component model implementation for any backend.
68 stars 10 forks source link

Fix multilevel indirect references to `resource`, func panic when returning `None`, and Impl `UnaryComponentType` for `Result<(), ()>` #19

Closed Clunt closed 2 months ago

Clunt commented 2 months ago

When I try to implement WASIp2's wasi-filesystem, an error "Cannot instantiate resource as type" occursed by filesystem-error-code: func(err: borrow<error>) -> option<error-code>;. I found the reason is generate_types untreated Multilevel indirect references to resources. But, I can't sure to should chang id. Please review this code. thanks.

Simple WIT Example

package test:guest;

interface error {
    resource error {
        constructor();
    }
}

interface streams {
    use error.{error};

    resource streams-error {
        constructor();
    }
}

interface types {
    use streams.{error, streams-error};

    // Original wasip2 func define:
    // use streams.{error};
    // filesystem-error-code: func(err: borrow<error>) -> option<error-code>;
    borrow-error: func(err: borrow<error>); // Painc: Cannot instantiate resource as type.
    borrow-streams-error: func(error-inner: borrow<streams-error>); // Good!
}

interface run {
    start: func();
}

world guest {
    import types;

    export run;
}

Related Issue:https://github.com/DouglasDwyer/wasm_component_layer/issues/7, https://github.com/DouglasDwyer/wasm_component_layer/issues/17, https://github.com/DouglasDwyer/wasm_component_layer/issues/16 Related Commit: https://github.com/DouglasDwyer/wasm_component_layer/commit/30c202620c0b35cdfcaef829ea4e7b70ba4516dc

DouglasDwyer commented 2 months ago

Thank you for your contribution and your patience. I will make a new release shortly.