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

Aperta
#765 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 4 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
30/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
wasm
Ambito
compilers

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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!

Lingua principale
WebAssembly
Stelle
1.4k
Fork
134
Merge medio
3g 19h
PR unite (30g)
8

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di WebAssembly/component-model

Tutte le issue di WebAssembly/component-model

Issue simili

Altre issue su Compilers

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.