diff --git a/logos-codegen/src/graph/mod.rs b/logos-codegen/src/graph/mod.rs index f82330f4..6d218e8c 100644 --- a/logos-codegen/src/graph/mod.rs +++ b/logos-codegen/src/graph/mod.rs @@ -58,9 +58,19 @@ pub trait Disambiguate { /// Id of a Node in the graph. `NodeId` can be referencing an empty /// slot that is going to be populated later in time. -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] pub struct NodeId(NonZeroU32); +impl Hash for NodeId { + fn hash(&self, state: &mut H) { + // Always use little-endian byte order for hashing to avoid + // different code generation on big-endian platforms due to + // iteration over a HashMap, + // see https://github.com/maciejhirsz/logos/issues/427. + state.write(&self.0.get().to_le_bytes()) + } +} + impl NodeId { fn get(self) -> usize { self.0.get() as usize