Make compiler deterministic: use BTreeMap for property_analysis#11219
Merged
ogoffart merged 1 commit intoslint-ui:masterfrom Apr 2, 2026
Merged
Conversation
3 tasks
ogoffart
reviewed
Apr 1, 2026
Member
ogoffart
left a comment
There was a problem hiding this comment.
since visited is not iterated, i don't really understand where the non-determinism comes from.
Replace `HashMap<SmolStr, PropertyAnalysis>` with `BTreeMap` in `Element::property_analysis` to ensure deterministic iteration order. The HashMap was iterated in several passes (inlining, move_declarations, optimize_useless_rectangles, resolve_native_classes), and since HashMap uses Rust's default RandomState hasher, the iteration order varied between runs. This non-determinism propagated through the compiler, causing binding loop diagnostics to be emitted at different source positions across runs/platforms. Also updates namedreference.rs to use btree_map::Entry instead of hash_map::Entry, and move_declarations.rs to use BTreeMap for the local property_analysis collections.
b033bbf to
1ef8e9e
Compare
tilladam
added a commit
to tilladam/slint
that referenced
this pull request
Apr 10, 2026
Now that slint-ui#11219 (BTreeMap for property_analysis) is merged, the compiler's analysis order is deterministic. Restore the three syntax tests that were removed due to platform-dependent diagnostic positions: - binding_loop_issue_7849.slint (regression test for slint-ui#7849) - binding_loop_nested_repeater.slint - binding_loop_root_changed_callback.slint Also update loop descriptions in binding_loop_if_condition.slint and binding_loop_init_callback.slint to reflect the new deterministic traversal order which now includes the current property as the loop starting point.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
HashMap<SmolStr, PropertyAnalysis>withBTreeMapinElement::property_analysisto ensure deterministic iteration ordernamedreference.rsto usebtree_map::Entryinstead ofhash_map::Entrymove_declarations.rsto useBTreeMapfor local property analysis collectionsThe
HashMapwas iterated in several passes (inlining,move_declarations,optimize_useless_rectangles,resolve_native_classes). SinceHashMapuses Rust's defaultRandomStatehasher, iteration order varied between runs, which is a source of non-determinism in the compiler.This is a standalone improvement — a deterministic compiler is desirable regardless. It may or may not be sufficient to resolve the cross-platform diagnostic position differences seen in #10552; that would need to be validated by merging this and re-running CI on that branch.
Related: #11188
Test plan
cargo check -p slint-compilerpasses