[rust-dev] optimizing away const/pure function calls?
pcwalton at mozilla.com
Fri Jun 20 11:09:15 PDT 2014
On 6/20/14 11:02 AM, Josh Haberman wrote:
> Is there any reasonable scenario under which the compiler could decide
> to allocate stack space to cache that lookup, so that the code above
> would be optimized to only perform one lookup?
LLVM will do this if it can see the definition of `contains_key` (which
it will, if it's generic) and can tell that it's pure. We don't have any
way at the moment to force LLVM to decide that a function is pure if it
can't work it out for itself, though.
More information about the Rust-dev