Disallow `[method]...` naming unless the resource was defined in the same context

未關閉
#765 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 4 天內回覆

還沒有人認領這個 Issue。

評估

難度
5/5
預估耗時
一週以上
新手友好度
30/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
wasm
領域
compilers

研究方向

Start with the two component examples in this issue and the linked wasm-tools issue #2731; then locate the wasmparser validation and tests that accept these patterns. The rule for when methods may be attached is unresolved, so done means defining that rule and updating validation and tests without breaking the existing wit-component pattern unintentionally.

由索引模型根據 Issue 內容生成。

描述

Currently wasmparser accepts this component:

  (component
    (import "a" (instance $a
      (export "r" (type (sub resource)))
    ))
    (alias export $a "r" (type $r))
    (import "b" (instance
      (export "r" (type $x (eq $r)))
      (export "[method]r.f" (func (param "self" (borrow $x))))
    ))
  )

But arguably this is a bad idea. This isn't representable in WIT at all and there aren't any actual users of this AFAIK, so I think it would be best to disallow this. In essence only the resource definition should be able to attach methods, because otherwise you could have different instances define the same method and it'd be ambiguous of what to call.

More problematically, however, wasmparser also accepts this:

(component
  (type (component
    (import "a" (type $a (sub resource)))
    (export "r" (type $x (eq $a)))
    (export "[method]r.f" (func (param "self" (borrow $x))))
  ))
)

and this is how wit-component works for any component which exports a resource in an interface. This means that this pattern is widely used meaning that the rule of "must be on the definition" would break a lot of components today.

Ideally wit-component would generate a component that looks like htis:

(component
  (type (component
    (import "a" (type $a (sub resource)))
    (export "r" (type $x (eq $a)) (type (sub resource))) ;; note the type ascription here
    (export "[method]r.f" (func (param "self" (borrow $x))))
  ))
)

but wasmparser does not yet implement that today (https://github.com/bytecodealliance/wasm-tools/issues/2731)

I'm also a bit stuck on what "must be next to the definition" means. For example a resource could be declared, then exported, and then methods must be on the type introduced by the export. In that sense some aliases work, but some don't. Hence, the issue here!

主要語言
WebAssembly
星號
1.4k
分支
134
平均合併
3 天 19 小時
30 天內合併 PR
8

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

WebAssembly/component-model 的其他 Issue

查看 WebAssembly/component-model 的全部 Issue

相似的 Issue

更多 Compilers Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。