Skip to content

refactor: Build dense MAST forests through finalization - #3329

Closed
huitseeker wants to merge 5 commits into
issue-3067-rationalize-digestsfrom
issue-3325-mastforest-builder
Closed

refactor: Build dense MAST forests through finalization#3329
huitseeker wants to merge 5 commits into
issue-3067-rationalize-digestsfrom
issue-3325-mastforest-builder

Conversation

@huitseeker

Copy link
Copy Markdown
Collaborator

Closes #3325. On top of #3311. Re-do of #3326 after misclick

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 20:51
@huitseeker
huitseeker force-pushed the issue-3325-mastforest-builder branch from 627c273 to 258f711 Compare July 3, 2026 20:52
@huitseeker huitseeker linked an issue Jul 3, 2026 that may be closed by this pull request
@huitseeker huitseeker added this to the v0.25.0 milestone Jul 3, 2026
@huitseeker
huitseeker force-pushed the issue-3067-rationalize-digests branch from 1454efa to f2ee07d Compare July 3, 2026 21:12
@huitseeker
huitseeker force-pushed the issue-3325-mastforest-builder branch from 258f711 to 24b37d7 Compare July 3, 2026 21:12
@huitseeker
huitseeker force-pushed the issue-3067-rationalize-digests branch from f2ee07d to 74beb7b Compare July 3, 2026 23:54
@huitseeker
huitseeker force-pushed the issue-3325-mastforest-builder branch from 24b37d7 to 62af2ce Compare July 3, 2026 23:54
@huitseeker

Copy link
Copy Markdown
Collaborator Author

Closing this in favor of #3334.

@huitseeker huitseeker closed this Jul 6, 2026
@huitseeker
huitseeker deleted the issue-3325-mastforest-builder branch July 21, 2026 14:09
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.

Make dense MastForest construction produce canonical node order

1 participant