Skip to content

Conversation

xxuejie
Copy link
Collaborator

@xxuejie xxuejie commented Mar 26, 2025

In current design, AsmMachine is a rigid type containing Box directly. This is required in a sense that assembly VM needs to know the inner data structures of AsmCoreMachine so as to function. However, It also puts a restriction on AsmMachine: while you can do the following in Rust VM:

DefaultMachine<Foo<DefaultCoreMachine<...>>

as long as Foo implements SupportMachine via a newtype pattern, this is not possible on AsmMachine. However there are certain cases we need wrappers on Box<AsmCoreMachine> to customize behaviors. This commit introduces a a new trait AsmCoreMachineRevealer between AsmMachine and AsmCoreMachine, it provides a mean for users of AsmMachine to customize its behavior, while also requires the presence of AsmCoreMachine, so assembly VM can still function.

If only Rust has generic specialization, we won't need to go through all those troubles...

In current design, AsmMachine is a rigid type containing
Box<AsmCoreMachine> directly. This is required in a sense that assembly
VM needs to know the inner data structures of AsmCoreMachine so as to
function. However, It also puts a restriction on AsmMachine: while you
can do the following in Rust VM:

```
DefaultMachine<Foo<DefaultCoreMachine<...>>
```

as long as Foo implements SupportMachine via a newtype pattern, this is
not possible on AsmMachine. However there are certain cases we need
wrappers on `Box<AsmCoreMachine>` to customize behaviors. This commit
introduces a a new trait `AsmCoreMachineRevealer` between AsmMachine and
AsmCoreMachine, it provides a mean for users of AsmMachine to customize
its behavior, while also requires the presence of AsmCoreMachine, so
assembly VM can still function.

If only Rust has generic specialization, we won't need to go through all
those troubles...
@xxuejie xxuejie merged commit 65fef7b into nervosnetwork:release-0.24 Mar 27, 2025
11 checks passed
@xxuejie xxuejie deleted the trait-to-reveal-asm-core-machine branch March 27, 2025 03:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants