Skip to content

Commit

Permalink
compiler: Use BTreeMap at a few more place to help with determinism o…
Browse files Browse the repository at this point in the history
…f the output

CC #7642
  • Loading branch information
ogoffart committed Feb 15, 2025
1 parent ba893b9 commit b2e7b0e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions internal/compiler/llr/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::layout::Orientation;
use core::num::NonZeroUsize;
use itertools::Either;
use smol_str::SmolStr;
use std::collections::HashMap;
use std::collections::BTreeMap;
use std::rc::Rc;

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -139,7 +139,7 @@ pub enum Expression {
},
Struct {
ty: Rc<crate::langtype::Struct>,
values: HashMap<SmolStr, Expression>,
values: BTreeMap<SmolStr, Expression>,
},

EasingCurve(crate::expression_tree::EasingCurve),
Expand Down
4 changes: 2 additions & 2 deletions internal/compiler/llr/lower_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ pub fn get_layout_info(
},
)
})
.collect::<HashMap<_, _>>();
.collect::<BTreeMap<_, _>>();

for (nr, s) in constraints.for_each_restrictions(orientation) {
values.insert(
Expand Down Expand Up @@ -1031,7 +1031,7 @@ pub fn make_struct(
it: impl IntoIterator<Item = (&'static str, Type, llr_Expression)>,
) -> llr_Expression {
let mut fields = BTreeMap::<SmolStr, Type>::new();
let mut values = HashMap::<SmolStr, llr_Expression>::new();
let mut values = BTreeMap::<SmolStr, llr_Expression>::new();
for (name, ty, expr) in it {
fields.insert(SmolStr::new(name), ty);
values.insert(SmolStr::new(name), expr);
Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/llr/lower_to_item_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ fn lower_geometry(
ctx: &ExpressionLoweringCtx<'_>,
) -> super::Expression {
let mut fields = BTreeMap::default();
let mut values = HashMap::with_capacity(4);
let mut values = BTreeMap::default();
for (f, v) in [("x", &geom.x), ("y", &geom.y), ("width", &geom.width), ("height", &geom.height)]
{
fields.insert(f.into(), Type::LogicalLength);
Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/object_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub struct Document {
/// Map of resources that should be embedded in the generated code, indexed by their absolute path on
/// disk on the build system
pub embedded_file_resources:
RefCell<HashMap<SmolStr, crate::embedded_resources::EmbeddedResources>>,
RefCell<BTreeMap<SmolStr, crate::embedded_resources::EmbeddedResources>>,

/// The list of used extra types used recursively.
pub used_types: RefCell<UsedSubTypes>,
Expand Down
10 changes: 5 additions & 5 deletions internal/compiler/passes/embed_images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::EmbedResourcesKind;
use image::GenericImageView;
use smol_str::SmolStr;
use std::cell::RefCell;
use std::collections::HashMap;
use std::collections::{BTreeMap, HashMap};
use std::future::Future;
use std::pin::Pin;
use std::rc::Rc;
Expand Down Expand Up @@ -83,7 +83,7 @@ fn collect_image_urls_from_expression(
fn embed_images_from_expression(
e: &mut Expression,
urls: &HashMap<SmolStr, Option<SmolStr>>,
global_embedded_resources: &RefCell<HashMap<SmolStr, EmbeddedResources>>,
global_embedded_resources: &RefCell<BTreeMap<SmolStr, EmbeddedResources>>,
embed_files: EmbedResourcesKind,
scale_factor: f64,
diag: &mut BuildDiagnostics,
Expand Down Expand Up @@ -126,7 +126,7 @@ fn embed_images_from_expression(
}

fn embed_image(
global_embedded_resources: &RefCell<HashMap<SmolStr, EmbeddedResources>>,
global_embedded_resources: &RefCell<BTreeMap<SmolStr, EmbeddedResources>>,
embed_files: EmbedResourcesKind,
path: &str,
_scale_factor: f64,
Expand All @@ -136,8 +136,8 @@ fn embed_image(
let mut resources = global_embedded_resources.borrow_mut();
let maybe_id = resources.len();
let e = match resources.entry(path.into()) {
std::collections::hash_map::Entry::Occupied(e) => e.into_mut(),
std::collections::hash_map::Entry::Vacant(e) => {
std::collections::btree_map::Entry::Occupied(e) => e.into_mut(),
std::collections::btree_map::Entry::Vacant(e) => {
// Check that the file exists, so that later we can unwrap safely in the generators, etc.
if embed_files == EmbedResourcesKind::ListAllResources {
// Really do nothing with the image!
Expand Down

0 comments on commit b2e7b0e

Please sign in to comment.