Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Oh compilers are fun. Just recently I was reading through Rust's bug tracker, as one does, and learned that comparing function pointers is not deterministic. Compiling this code [0] in the Debug mode yields different results than in the Release mode. You can read the whole discussion about whether it's a LLVM bug, a Rustc bug, an undefined behavior, an intended behavior, a pretty serious bug, or nothing to worry about over at [1].

[0] https://play.rust-lang.org/?version=stable&mode=release&edit...

[1] https://github.com/rust-lang/rust/issues/54685



> comparing function pointers is not deterministic

The comparison is deterministic - the perhaps unexpected part is that two distinct but identical functions in the source code are folded into one in the binary.


That bug was actually a bit deeper; it merged the functions but would statically fold some comparisons to false while letting others persist to runtime (where they would evaluate to true) in the same build. You could do `x == y` twice and get different results, one of which was a lie.


God, that issue is a mess. Lots of people missing the forest (Rust and LLVM are breaking constant folding guarantees) for the trees (function pointer equality is weird).


It should be noted that function pointer comparison is defined to not be deterministic between different compiler option sets, it's at least for now possible but mostly useless.

Through there are bugs involved, too ;=)

(Due to const folding comparisons vs. doing them at runtime there was/is non-determinism in the same build between different call sites ... )


Just a heads up, you linked to the main Rust Playground page, not an actual gist.


Damn, you're right. I didn't notice because Playground remembers the last content you had in the editor... Anyway, the correct link is https://play.rust-lang.org/?gist=62d362e2bf72001bd3f3c4a3ed0...




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: