Skip to content

refactor: Build dense MAST forests through finalization - #3326

Merged
huitseeker merged 5 commits into
issue-3067-rationalize-digestsfrom
issue-3325-mastforest-builder
Jul 3, 2026
Merged

refactor: Build dense MAST forests through finalization#3326
huitseeker merged 5 commits into
issue-3067-rationalize-digestsfrom
issue-3325-mastforest-builder

Conversation

@huitseeker

@huitseeker huitseeker commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

Closes #3325. On top of #3311.

Dense MastForest values now leave normal construction in canonical node order. Builders may still append while they are building, but they must call finalization before returning a MastForest.

This PR adds DenseMastForestBuilder for dense construction. finish() and finish_with_id_map() call MastForest::from_parts_with_id_map(), which orders MastForest.nodes as external nodes, then basic blocks, then internal nodes. External nodes are sorted by digest. Children stay before parents. The returned ID map uses the final node IDs.

MastForestMerger now builds through that builder and remaps root maps after finalization. The assembly MastForestBuilder finalizer now applies the final ID map before it builds source and debug metadata.

The old append API is no longer available in normal builds. add_to_forest() and make_root() are limited to tests and arbitrary.

Serialization now expects the in-memory order to be valid. It no longer rebuilds a canonical forest before writing. The dependency commitment reads the external node prefix directly.

Public examples now use DenseMastForestBuilder, so docs do not point callers back to the append API.

@huitseeker
huitseeker requested a review from bobbinth July 3, 2026 15:47
@huitseeker
huitseeker marked this pull request as ready for review July 3, 2026 15:49
@huitseeker
huitseeker force-pushed the issue-3325-mastforest-builder branch from d2f65ee to 12e18d3 Compare July 3, 2026 20:08
@huitseeker
huitseeker merged commit 88aef51 into issue-3067-rationalize-digests Jul 3, 2026
18 checks passed
@huitseeker
huitseeker deleted the issue-3325-mastforest-builder branch July 3, 2026 20:49
@huitseeker
huitseeker restored the issue-3325-mastforest-builder branch July 3, 2026 20:49
@huitseeker

huitseeker commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator Author

I meant to merge #3308 instead, wrong tab 🤦, reverted, reopend as #3329, and hopefully updated all references to point there.

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.

1 participant