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

Ouverte
#765 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 4 jours

Personne n'a encore pris cette issue.

Évaluation

Difficulté
5/5
Temps estimé
Plus d'une semaine
Accessibilité débutants
30/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
Active
Stack technique
wasm
Domaine
compilers

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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!

Langage dominant
WebAssembly
Étoiles
1.4k
Forks
134
Merge moyen
3 j 19 h
PR mergées (30 j)
8

Préparer son environnement

Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de WebAssembly/component-model

Toutes les issues de WebAssembly/component-model

Issues similaires

Plus d'issues Compilers

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.