Skip to content

Commit

Permalink
fix(lib): generate same code on big-endian platforms (#431)
Browse files Browse the repository at this point in the history
* fix(lib): generate same code on big-endian platforms

* Update logos-codegen/src/graph/mod.rs

Co-authored-by: Jérome Eertmans <[email protected]>

---------

Co-authored-by: Jérome Eertmans <[email protected]>
  • Loading branch information
0x2a-42 and jeertmans authored Oct 17, 2024
1 parent 0f361d6 commit 3c81ceb
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion logos-codegen/src/graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<H: Hasher>(&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
Expand Down

0 comments on commit 3c81ceb

Please sign in to comment.