Closed PhilippGackstatter closed 3 weeks ago
I would like to test the implementation with some more complex "real-world" input, but this is difficult in
miden-core
without anAssembler
. I don't want to move those test intomiden-assembly
though as that separates the implementation and the tests crate-wise.
I actually think it may be fine to have some tests for merging forests in the miden-assembly
crate. It would simplify things a bit and there is not too much downside.
I updated the implementation to use the desired merging behavior for external nodes with decorators present. The refactor to support this turned out to be fairly complex but I think it's alright now. I still need to add documentation in many places, handle some errors and probably some other small things, but conceptually I think it is in a reviewable state now again.
I implemented the refactoring now, but there are still some things left to clean up for sure. I added an assertion to most tests now that assert that the "child id < parent id" property holds, so that's nice :tada:. If you have feedback on the approach now, I'd be happy to hear it and the other nits I will address tomorrow.
Also, sorry for the huge code changes, hopefully that was the last one.
After adding a test that used the MastForest
from the Miden StdLib I encountered a small bug in the iterator logic, but that is fixed now. The PR is now ready for a full review again.
Describe your changes
Closes #1529
Implements
MastForest
merging.The implementation is explained in comments and it's hopefully sufficient to understand the PR, which is why I'm not adding the details here again. If any explanation is insufficient I'm happy to expand on it!
Couple of notes and ideas:
MastForestDfsIter
could be 1) made public and 2) could be made more general to allow for in-order, pre-order as well as post-order iteration ofMastForest
s. Let me know if any of these are desirable. For now it seems best to keep them private.MastForestMerger
is also kept private because the useful functionality can be exposed through the methods added onMastForest
directly and there is no benefit in terms of functionality by making it public.EqHash
intomiden-core
.miden-core
so that it can be used inmiden-assembly
byMastForestBuilder
where it originally lived. MovingMastForestBuilder
into core doesn't seem fitting since it is used only for assembly and specially made for that. Overall it's not bad to haveEqHash
public in core.MastNodeFingerprint
and perhaps introducepub type DecoratorFingerprint = Blake3Digest<32>
for decorators. I think the "fingerprint" nicely describes that this type can be used to compare mast nodes although I'm of course open to other suggestions.miden-core
without anAssembler
. I don't want to move those test intomiden-assembly
though as that separates the implementation and the tests crate-wise. Even with an assembler, it would still be somewhat challenging to come up with the expected merged forest to assert against without basically handwriting it. Although I suppose asserting a couple of properties might be sufficient instead of the entire forest, so it would still be an improvement. One possibility I see to add test in miden-core would be to generate snapshots inmiden-assembly
, for example, and add them as plaintext serializedMastForest
s to miden-core. Snapshot testing could be done with something likeinsta
or without, I suppose. This would require adding#[cfg_attr(test, derive(Serialize, Deserialize))]
toMastForest
and all its descendants which is fine I guess. I'm happy to receive some general input on the testing story for this task though.Checklist before requesting a review
next
according to naming convention.