From ab3aec980d2e3cf55d01b6058392296c884f9a49 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Wed, 15 Jan 2020 10:27:35 -0500 Subject: [PATCH] TAMER: POC: Use FxHash to remove nondeterminism The default SipHash is a cryptographic hash and causes ordering to change between runs. --- tamer/src/ld/poc.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tamer/src/ld/poc.rs b/tamer/src/ld/poc.rs index a3f7bef8..df4fd676 100644 --- a/tamer/src/ld/poc.rs +++ b/tamer/src/ld/poc.rs @@ -23,10 +23,10 @@ use crate::ir::asg::IdentKind; use crate::ir::asg::{Asg, DefaultAsg, Object, ObjectRef, Source}; use crate::obj::xmlo::reader::{XmloError, XmloEvent, XmloReader}; use crate::sym::{DefaultInterner, Interner, Symbol}; +use fxhash::{FxHashMap, FxHashSet}; use petgraph::visit::DfsPostOrder; use quick_xml::events::{BytesEnd, BytesStart, BytesText, Event}; use quick_xml::Writer; -use std::collections::{HashMap, HashSet}; use std::convert::TryInto; use std::error::Error; use std::fs; @@ -36,8 +36,8 @@ type LinkerAsg<'i> = DefaultAsg<'i, global::ProgIdentSize>; type LinkerObjectRef = ObjectRef; pub fn main() -> Result<(), Box> { - let mut pkgs_seen = HashSet::::new(); - let mut fragments = HashMap::<&str, String>::new(); + let mut pkgs_seen: FxHashSet = Default::default(); + let mut fragments: FxHashMap<&str, String> = Default::default(); let mut depgraph = LinkerAsg::with_capacity(65536, 65536); let mut roots = Vec::new(); let interner = DefaultInterner::new(); @@ -91,8 +91,8 @@ pub fn main() -> Result<(), Box> { fn load_xmlo<'a, 'i, I: Interner<'i>>( path_str: &'a str, - pkgs_seen: &mut HashSet, - fragments: &mut HashMap<&'i str, String>, + pkgs_seen: &mut FxHashSet, + fragments: &mut FxHashMap<&'i str, String>, depgraph: &mut LinkerAsg<'i>, interner: &'i I, roots: &mut Vec, @@ -108,7 +108,7 @@ fn load_xmlo<'a, 'i, I: Interner<'i>>( //println!("processing {}", path_str); - let mut found = HashSet::<&str>::new(); + let mut found: FxHashSet<&str> = Default::default(); let file = fs::File::open(&path)?; let reader = BufReader::new(file); @@ -437,7 +437,7 @@ fn output_xmle<'a, 'i, I: Interner<'i>>( writer .write_event(Event::Start(BytesStart::borrowed_name(b"l:map-from")))?; - let mut map_froms = HashSet::<&str>::new(); + let mut map_froms: FxHashSet<&str> = Default::default(); for map_ident in &sorted.map { match map_ident {