knurling-rs / defmt

Efficient, deferred formatting for logging on embedded systems
https://defmt.ferrous-systems.com/
Apache License 2.0
829 stars 76 forks source link

Don't rely on `Span`'s debug representation #344

Open jonas-schievink opened 3 years ago

jonas-schievink commented 3 years ago

defmt needs to generate symbol names that are unique per macro invocation, even when the macro arguments are identical. We don't want to generate a random number to keep builds reproducible, so what we do currently is:

// We want a deterministic, but unique-per-macro-invocation identifier. For that we
// hash the call site `Span`'s debug representation, which contains a counter that
// should disambiguate macro invocations within a crate.
let s = format!("{:?}", Span::call_site());
let mut hasher = DefaultHasher::new();
s.hash(&mut hasher);
hasher.finish()

This relies on the debug representation of Span, which is probably not the best idea.

Until access to line and column of the span is possible in stable Rust (cc https://github.com/rust-lang/rust/issues/54725), we don't really have a good way of fixing this.

madsmtm commented 2 years ago

I've opened an internals thread for discussing a solution to this.