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 more functions for ensuring nodes via MastForestBuilder #1404

Merged
merged 3 commits into from
Jul 20, 2024

Conversation

sergerad
Copy link
Contributor

@sergerad sergerad commented Jul 18, 2024

Closes #1355

Add methods toMastForestBuilder to facilitate ensuring nodes with fewer LOC

@sergerad sergerad changed the base branch from main to next July 18, 2024 08:31
@sergerad sergerad changed the title Serge test ensure block helper Add and ensure nodes from vec of operations Jul 18, 2024
@sergerad sergerad marked this pull request as ready for review July 18, 2024 08:35
@sergerad sergerad changed the title Add and ensure nodes from vec of operations Allow vector of operations to be passed into MAST Forest and Forest Builder fns Jul 18, 2024
@sergerad
Copy link
Contributor Author

Hey @plafer reviewers aren't assigned automatically and I can't request reviews. This one is ready for review.

@bobbinth bobbinth requested a review from plafer July 18, 2024 22:50
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 for tackling this one as well!

Overall, I think the solution works but we probably want to add convenience methods for other nodes too (e.g., for Join, and Split nodes). For these, I don't think we can use the Into approach (or at least I'm not sure how). So, we may end up needed MastForestBuilder::ensure_join(), MastForestBuilder::ensure_split() etc.

If we do the above, we might want to have a similar approach for basic blocks. Though, I agree, MastForestBuilder::ensure_basic_block() does not look as elegant as the current solution. Maybe, we can just say MastForestBuilder::ensure_block().

Separately, and not for this PR, I find the fact that we need to say "basic_block" in various places pretty cumbersome. Maybe we should just say "block" everywhere instead. @plafer and @bitwalker, curious what you think on this.

@bobbinth
Copy link
Contributor

Here is an example where instead of:

let nested = {
    let node = MastNode::new_split(r#true2, r#false2, expected_mast_forest_builder.forest());
    expected_mast_forest_builder.ensure_node(node)
};

We should be able to do something like:

let nested = expected_mast_forest_builder.ensure_split(r#true2, r#false2);

@sergerad sergerad changed the title Allow vector of operations to be passed into MAST Forest and Forest Builder fns Add more functions for ensuring nodes via MastForestBuilder Jul 19, 2024
@sergerad sergerad force-pushed the serge-test-ensure-block-helper branch from c53df25 to df767d8 Compare July 19, 2024 09:54
@sergerad sergerad requested a review from bobbinth July 19, 2024 09:59
@sergerad
Copy link
Contributor Author

@bobbinth I have made the suggested changes.

LMK if you prefer having separate functions as opposed to the Option<DecoratorList> for ensure_block().

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! I left one small comment inline. After it is addressed, we can merge.

LMK if you prefer having separate functions as opposed to the Option<DecoratorList> for ensure_block().

I think the way you have it now looks good - so, no need to change anything in this regard.

assembly/src/assembler/mast_forest_builder.rs Outdated Show resolved Hide resolved
@sergerad
Copy link
Contributor Author

Just wondering whether we want to do the same for MastForest::add_node() which is used similarly. E.G:

let dyn_node_id = {
        let node = MastNode::new_dyn();
        mast_forest.add_node(node).unwrap()
    }

@sergerad sergerad requested a review from bobbinth July 20, 2024 01:34
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.

All looks good! Thank you!

Just wondering whether we want to do the same for MastForest::add_node()

Yes - that would be great! But I'd do it in a separate PR.

@bobbinth bobbinth merged commit 64c7401 into 0xPolygonMiden:next Jul 20, 2024
9 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.

MastForest: Add convenience method for tests
2 participants