Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lib): generate same code on big-endian platforms #431

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading