ia0 / data-encoding

Efficient and customizable data-encoding functions in Rust
https://data-encoding.rs/
MIT License
176 stars 23 forks source link

Use BTreeMap for deterministic proc macro #109

Closed capickett closed 3 months ago

capickett commented 3 months ago

At Meta, we use buck to build our rust code. However, in order to be efficient with caching, buck requires that compilations are deterministic. Using HashMap by default results in non-deterministic output as the iteration order changes between invocations.

BTreeMap here is the quickest zero-new-dependency approach. Other options might be:

  1. https://crates.io/crates/rustc-hash use FxHashMap which is deterministic
  2. https://docs.rs/indexmap/latest/indexmap/ use IndexMap which maintains insertion order
capickett commented 3 months ago

I pre-emptively opened this by accident.

ia0 commented 3 months ago

Thanks for the PR! In theory the proc-macro behavior should be deterministic. Otherwise it's a bug. The only non-deterministic aspect I can see is the error message for unexpected keys, where the unexpected keys are listed in a non-deterministic order. This can be fixed if it is an issue.