Composing labelled (`implements`) imports of one interface gives output wit-parser panics on

未关闭
#219 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

@sansmoraxz 已经在做这个了。

开始于 2026年10月8日。

  • #220 来自 @sansmoraxz —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
rust, wasm
领域
tooling

调研方向

The panic is in the wit-parser dependency (decoding.rs:797 asserts prev.is_none()), but the fix belongs in wac-graph's CompositionGraph::encode, which currently gives every labelled (implements "I") import one shared instance type. Build the issue's reproduction (a consumer importing the same interface that defines a type under primary and backup), then trace where encode interns and emits instance types, covering both the implicit-import path and explicit CompositionGraph::import nodes. Done is the repro's final wit_parser::decoding::decode(&composed) succeeding, with one instance type per labelled import as wit-component encodes it.

由索引模型根据 Issue 内容生成。

描述

When a composition has several (implements "I") imports of the same interface, CompositionGraph::encode gives them all one instance type:

(import "primary" (implements "test:test/logger") (instance (;0;) (type 0)))
(import "backup"  (implements "test:test/logger") (instance (;1;) (type 0)))

Several labels for one interface is the case labelled imports exist for (#200). This happens:

  • through implicit imports (an instantiated component's labelled imports left unsatisfied);
  • through explicit CompositionGraph::import nodes.

The output validates, and wasmtime runs it. But when the interface defines a type, wit-parser's decoder panics on it, and so does every tool built on that decoder:

  • wasm-tools component wit;
  • wit-bindgen;
  • jco. jco transpile aborts the same way (it uses wit-parser 0.259), so the composition can't be run in JavaScript.

The input component decodes fine: it's wit-component's shape, with one instance type per labelled import. Only wac's output has the shared type.

Reproduction

Cargo.toml:

[package]
name = "wac-implements-repro"
version = "0.1.0"
edition = "2024"

[dependencies]
wac-graph = "=0.12.0"
wit-parser = "=0.258.0"
wat = "1"

src/main.rs:

use wac_graph::{types::Package, CompositionGraph, EncodeOptions};

/// A component importing one interface, which defines a type, under two
/// labels: the shape wit-component produces (one instance type per import).
const CONSUMER: &str = r#"
(component
  (type (instance
    (type (enum "debug" "info"))
    (export "level" (type (eq 0)))
    (type (func (param "level" 1) (param "message" string)))
    (export "log" (func (type 2)))))
  (import "primary" (implements "test:test/logger") (instance (type 0)))
  (type (instance
    (type (enum "debug" "info"))
    (export "level" (type (eq 0)))
    (type (func (param "level" 1) (param "message" string)))
    (export "log" (func (type 2)))))
  (import "backup" (implements "test:test/logger") (instance (type 1)))
)
"#;

fn main() {
    let consumer = wat::parse_str(CONSUMER).unwrap();
    // The input decodes fine.
    wit_parser::decoding::decode(&consumer).expect("the consumer decodes");
    println!("consumer: decodes");

    let mut graph = CompositionGraph::new();
    let package = Package::from_bytes("test:consumer", None, consumer, graph.types_mut()).unwrap();
    let package = graph.register_package(package).unwrap();
    graph.instantiate(package);
    let composed = graph.encode(EncodeOptions::default()).unwrap();
    println!("composed: {} bytes, validated by wac", composed.len());

    // The composition does not: wit-parser panics.
    wit_parser::decoding::decode(&composed).expect("the composition decodes");
    println!("composition: decodes");
}

Output:

consumer: decodes
composed: 348 bytes, validated by wac

thread 'main' panicked at wit-parser-0.258.0/src/decoding.rs:797:29:
assertion failed: prev.is_none()

Expected

The composition decodes as the input does: each labelled import has its own instance type, as wit-component encodes it.

Related

  • bytecodealliance/wasm-tools#2506
主要语言
Rust
星标
207
派生
43
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

bytecodealliance/wac 的其他 Issue

查看 bytecodealliance/wac 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。