[Optimization] Equivalent functions are not merged because their panic information differs. #80021
Labels
I-heavy
Issue: Problems and improvements with respect to binary size of generated code.
I was playing around in the compiler explorer with APIs using
AsRef<T>
to provide more ergonomic interfaces.My example used
AsRef<[u8]>
to allow an API to use string literals, byte arrays, byte strings, etc.I wanted to know if there was an elegant way to avoid monomorphization overhead for large functions that only differ by a
AsRef::as_ref
call at the very top, or if the compiler could do this for me in optmized builds.My tests can be found here:
https://godbolt.org/z/5MzKMT
However, far more interestingly, I saw that
asref_inner
andasref_direct
were not merged by the compiler in an optimized build, despite being 100% the same code.The only difference is that they have different source location info for a potential panic.
Perhaps this is a contrived case, since fully equivalent functions are probably rare in real code,
however I still thought it was worth bringing up.
Perhaps the functions could be merged if the panic information was smuggled through a register or the stack at the call site instead?
The text was updated successfully, but these errors were encountered: