Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(processor): expose the process api #1395

Merged
merged 1 commit into from
Jul 15, 2024
Merged

Conversation

bitwalker
Copy link
Contributor

While doing some testing in the compiler where I wanted to set up some VM state and then execute a program on that state, I realized that there is no currently public API that allows one to access the state of the process to do so, short of using the internals feature flag of the crate.

Rather than requiring the use of that flag, this commit instead makes public the [Process] struct, but with all of its fields private unless the internals flag is enabled. This makes it possible to use the public APIs of the various traits implemented by Process to interact with it in a more fine-grained fashion.

It is still expected that most people will use the execute or execute_iter APIs, but this makes it possible to take control over that yourself when necessary/useful. I should also note that we were making the [Process] struct visible for ourselves under #[cfg(test)], so it is clearly useful in certain cases (namely testing).

While doing some testing in the compiler where I wanted to set up some
VM state and then execute a program on that state, I realized that there
is no currently public API that allows one to access the state of the
process to do so, short of using the `internals` feature flag of the
crate.

Rather than requiring the use of that flag, this commit instead makes
public the [Process] struct, but with all of its fields private unless
the `internals` flag is enabled. This makes it possible to use the
public APIs of the various traits implemented by `Process` to interact
with it in a more fine-grained fashion.

It is still expected that most people will use the `execute` or
`execute_iter` APIs, but this makes it possible to take control over
that yourself when necessary/useful. I should also note that we were
making the [Process] struct visible for ourselves under `#[cfg(test)]`,
so it is clearly useful in certain cases (namely testing).
@bitwalker bitwalker added enhancement New feature or request processor Related to Miden VM processor labels Jul 15, 2024
@bitwalker bitwalker self-assigned this Jul 15, 2024
Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thank you!

The initial intent was that if people want to interact with the Process struct directly, it is most likely for testing purposes and they would enable this via the internals feature. But I don't see any harm in exposing the process struct the way you have in this PR.

As an aside, we should probably rename internals feature into testing. @Fumuran - could you open issue/PR for this?

Comment on lines +165 to +175
/// A [Process] is the underlying execution engine for a Miden [Program].
///
/// Typically, you do not need to worry about, or use [Process] directly, instead you should prefer
/// to use either [execute] or [execute_iter], which also handle setting up the process state,
/// inputs, as well as compute the [ExecutionTrace] for the program.
///
/// However, for situations in which you want finer-grained control over those steps, you will need
/// to construct an instance of [Process] using [Process::new], invoke [Process::execute], and then
/// get the execution trace using [ExecutionTrace::new] using the outputs produced by execution.
#[cfg(not(any(test, feature = "internals")))]
struct Process<H>
pub struct Process<H>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for writing these docs!

Copy link
Contributor

@Fumuran Fumuran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you!

Copy link
Contributor

@plafer plafer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bitwalker bitwalker merged commit 322538e into next Jul 15, 2024
15 checks passed
@bitwalker bitwalker deleted the bitwalker/pub-vm-process branch July 15, 2024 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request processor Related to Miden VM processor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants