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

Đang mở
#765 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 4 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
30/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
wasm
Lĩnh vực
compilers

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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!

Ngôn ngữ chính
WebAssembly
Star
1.4k
Fork
134
Merge trung bình
3 ngày 19 giờ
Pull request đã merge (30 ngày)
8

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của WebAssembly/component-model

Tất cả issue của WebAssembly/component-model

Issue tương tự

Thêm issue về Compilers

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.