0xMiden / 0xMiden/compiler

Add high-level types in Miden SDK on a case-by-case basis

Aberta
#479 1 comentário 0 reações 0 responsáveis Ver no GitHub
Linguagem predominante
Rust
Estrelas
115
Forks
84
Merge médio
1d 8h
PRs com merge (30d)
15

Descrição

Following up on the https://github.com/0xMiden/compiler/pull/436#issuecomment-2774579198

The original idea was to have two sets of types.

Low-level type in `miden-base-sys` crate:

```rust
struct CoreAsset {
inner: Word
}

```

And a high-level in `miden-base` crate:

```rust
enum Asset {
Fungible(FungibleAsset)
NonFungible(NonFungibleAsset)
}

struct FungibleAsset {
faucet_id: AccountId,
amount: u64,
}

struct NonFungibleAsset(Word);
```

For every type that we want to use in the component API, we need to define it in the WIT format, which limits us to the [WIT type system](https://github.com/WebAssembly/component-model/blob/main/design/mvp/WIT.md#wit-types). Although we are remapping the WIT types to our custom Rust type, it should have the same shape as the WIT type since the lifting/lowering of the types are not customizable (yet).

This makes me wonder if we would be better off with just the low-level types and exposing all the functionality of high-level types via the low-level type's methods. We can still define additional "helper" types in Rust land without mentioning them in WIT, as long as they are not used in the component API.

Pros:

1. No need to convert to/from low-level types (`Word`) when calling MASM code (stdlib, tx kernel);
2. Cheaper passing through the component API due to simpler lifting/lowering;
3. Only one set of types;

Cons:

1. Some overhead when accessing the fields in the inner `Word`;
2. Field access only via getters/setters;

If we choose to go with only the low-level types, then we need to rename `CoreAsset` to `Asset`.

Guia de contribuição

Abrir o guia de contribuição

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.