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

add full api to engine #50

Merged
merged 1 commit into from
Nov 27, 2023
Merged

Conversation

eric-therond
Copy link
Contributor

following #36
to move the rest of the user-API from interpreter to engine

Copy link
Collaborator

@anakrish anakrish left a comment

Choose a reason for hiding this comment

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

Overall, looks good to me.

src/engine.rs Outdated
}

impl Engine {
pub fn new() -> Self {
Self {
pub fn new() -> Result<Self> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

In future we can change this so that all our new functions return T instead of Result; new functions are expected to always succeed.

src/engine.rs Outdated
}

pub fn add_data(&mut self, data: Value) -> Result<()> {
self.data.merge(data)
self.prepared = false;
self.interpreter.get_data().merge(data)
Copy link
Collaborator

Choose a reason for hiding this comment

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

get_data_mut() reads better.

src/engine.rs Outdated
// Analyze the modules and determine how statements must be scheduled.
let analyzer = Analyzer::new();
let schedule = analyzer.analyze(&self.modules)?;
pub fn prepare_for_eval(&mut self, enable_tracing: bool) -> Result<()> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this function need to be public?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think not, previously it was necessary for the end-user to explicitly calls this function and now it's done automatically behind the hood when calling eval_* functions of the engine. I don't see a valid reason for the end-user to call it.

@@ -86,16 +86,15 @@ struct LoopExpr {
}

impl Interpreter {
pub fn new(modules: &[Ref<Module>]) -> Result<Interpreter> {
pub fn new() -> Result<Interpreter> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

In future we can change this so that Interpreter is returned instead of Result

pub fn set_modules(&mut self, modules: &[Ref<Module>]) {
self.modules = modules.to_vec();
}

pub fn get_modules(&mut self) -> &mut Vec<Ref<Module>> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

get_modules_mut is a better name since a mutable reference is returned.

self.init_data = init_data;
}

pub fn get_init_data(&mut self) -> &mut Value {
Copy link
Collaborator

Choose a reason for hiding this comment

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

get_init_data_mut is a better name since a mutable reference is returned.

Alternatively we could have a merge_init_data(&mut self, v : Value) that performs a merge of init data. That way we don't need to return mutable references.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apparently I don't use get_init_data anylonger, I forgot to delete it.
There is a set_init_data(&mut self, v : Value) that does what you expect?

Copy link
Collaborator

@anakrish anakrish left a comment

Choose a reason for hiding this comment

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

LGTM.

Note: Changing input would also require re-preparation.

@eric-therond
Copy link
Contributor Author

Can you explain why? I don't see anything in the prepare_for_eval function that depends on the input.

Signed-off-by: eric-therond <eric.therond.fr@gmail.com>
@anakrish
Copy link
Collaborator

Can you explain why? I don't see anything in the prepare_for_eval function that depends on the input.

I'm thinking a rule that depends on input values like below would need to be reevaluated when input changes

package test
a = input.a

@anakrish
Copy link
Collaborator

Can you explain why? I don't see anything in the prepare_for_eval function that depends on the input.

I'm thinking a rule that depends on input values like below would need to be reevaluated when input changes

package test
a = input.a

Reading the code, currently we don't depend on input in prepare_for_eval. I had a different re-evaluation scheme in mind when I made the earlier remark.

Copy link
Collaborator

@anakrish anakrish left a comment

Choose a reason for hiding this comment

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

LGTM

@anakrish anakrish merged commit ef36d9b into microsoft:main Nov 27, 2023
2 checks passed
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