`self` mutability in the account methods in the script
- Langage dominant
- Rust
- Étoiles
- 115
- Forks
- 84
- Merge moyen
- 1 j 8 h
- PR mergées (30 j)
- 15
Description
### Problem
We don't have the information regarding the mutability of `self` in the account methods in the script.
### Context
All the account components with bindings generated as free functions in the modules are gathered under the `Account` as struct methods.
### Why `self` mutability info missing?
TLDR; The bindings are generated from the WIT interface which has no notion of `self` (it's just a bunch of functions) and therefore its mutability.
Let's take the `basic-wallet` example.
From the user's code with proper `&mut self` at https://github.com/0xMiden/compiler/blob/adfb610b8b4c1747ece077a6128855348efacafb/examples/basic-wallet/src/lib.rs?plain=1#L14-L38
The `#[component]` macro generates the WIT interface:
```wit
// This file is auto-generated by the `#[component]` macro.
// Do not edit this file manually.
package miden:basic-wallet@0.1.0;
use miden:base/core-types@1.0.0;
interface basic-wallet {
use core-types.{asset, note-idx};
receive-asset: func(asset: asset);
move-asset-to-note: func(asset: asset, note-idx: note-idx);
}
world basic-wallet-world {
export basic-wallet;
}
```
From which the `wit-bindgen::generate!` macro generates bindings (free functions in a module):
```rust
pub mod bindings {
pub mod miden {
pub mod basic_wallet {
pub mod basic_wallet {
pub fn receive_asset(asset: ::miden::Asset) -> () {
...
}
pub fn move_asset_to_note(asset: ::miden::Asset, note_idx: ::miden::NoteIdx) -> () {
...
}
}
}
}
```
Then, we generate methods for the `Account` from the functions above.
There is no notion of `self` in the WIT and therefore in the generated bindings.
### Solutions
Explore the Wasm CM resources to represent an account component. See an intro to resources at https://component-model.bytecodealliance.org/language-support/using-wit-resources/rust.html
The resource has `self` in the generated Rust bindings and has `borrow` as well as `write` and `read` attributes in the WIT for the resource methods.
AFAIR, the Wasm CM resource uses `call_indirect` in the compiled code so it might be the time for us to implement it.
Guide de contribution
Ouvrir le guide de contribution
Piste de recherche
Le problème concerne l'ajout d'informations de mutabilité pour `self` dans les méthodes de compte générées à partir d'interfaces WIT. Commencez par examiner la macro `#[component]` dans le compilateur, la génération WIT et la sortie de `wit-bindgen::generate!`. Recherchez des ressources sur le Wasm Component Model et ses attributs `borrow`, `write` et `read`. L'exemple `basic-wallet` dans examples/basic-wallet/src/lib.rs montre le code utilisateur actuel. La mise en œuvre nécessitera probablement des modifications de la macro et de la logique de génération des bindings, et pourrait nécessiter un support pour `call_indirect`.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- rust, wasm
- Domaine
- backend-api-design, compilers
- Type d'issue
- Fonctionnalité
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100