Skip to content

refactor: Add a new trait between AsmMachine and Box<AsmCoreMachine>#473

Merged
xxuejie merged 1 commit intonervosnetwork:developfrom
xxuejie:trait-to-reveal-asm-core-machine-develop
Mar 27, 2025
Merged

refactor: Add a new trait between AsmMachine and Box<AsmCoreMachine>#473
xxuejie merged 1 commit intonervosnetwork:developfrom
xxuejie:trait-to-reveal-asm-core-machine-develop

Conversation

@xxuejie
Copy link
Collaborator

@xxuejie xxuejie commented Mar 26, 2025

This is #472 cherry-picked to develop branch.

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 b64eda4 into nervosnetwork:develop Mar 27, 2025
16 checks passed
@xxuejie xxuejie deleted the trait-to-reveal-asm-core-machine-develop 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