-
Notifications
You must be signed in to change notification settings - Fork 160
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
Conversation
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).
There was a problem hiding this 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?
/// 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> |
There was a problem hiding this comment.
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!
There was a problem hiding this 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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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 byProcess
to interact with it in a more fine-grained fashion.It is still expected that most people will use the
execute
orexecute_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).