@[inline]
annotation is ignored when specializing function with fixed type class argument
#4191
Open
3 tasks done
Labels
bug
Something isn't working
depends on new code generator
We are currently working on a new compiler (code generator) for Lean. This issue/PR is blocked by it
P-medium
We may work on this issue if we find the time
Prerequisites
Please put an X between the brackets as you perform the following steps:
https://github.com/leanprover/lean4/issues
Avoid dependencies to Mathlib or Batteries.
https://live.lean-lang.org/#project=lean-nightly
(You can also use the settings there to switch to “Lean nightly”)
Description
The following clumsy benchmark tests two variants of a pair of functions
reinsertAux
andexpand_go
(named after the hash map operations they are inspired by). The difference is that the first version passes a function intoreinsertAux
as a type class, while the second version passes in the function directly.It is important for performance that
reinsertAux
is inlined intoexpand_go
, because only after the inlining it is possible to see that the memory from the input ofexpand_go
can be reused in the constructor application inreinsertAux
. Inspecting the IR, we indeed see that the IR for bothexpand₁_go
andexpand₂_go
gets this right. In fact, the IR for these two functions returned bytrace.compiler.ir.reset_reuse
is exactly identical. It looks like this:However, this IR isn't actually used due to specialization. The specialized IR is visible at the two
runBenchmark
functions. Inspecting thereset_reuse
IR this time, we getfor the first version and
for the second version. Here we see that in the first version
reinsertAux
was not inlined, and so there is noreset
/reuse
pair for the memory cells of the lists, and this is clearly measurable when we run the code: on my machine, I getContext
During benchmarking I noticed that
insert
performance for the Lean hash map is about 10% better than for the Batteries hash map. This issue is the result of analyzing that observation. The Lean hash map looks like the second version, while the Batteries hash map looks like the first version.Steps to Reproduce
Expected behavior: Both versions should respect the
@[inline]
attribute onreinsertAux
during specialization.Actual behavior: Passing in the function via a type class leads to the
@[inline]
attribute being ignored.Versions
4.9.0-nightly-2024-05-16
Linux markus-z16 6.8.9-300.fc40.x86_64 #1 SMP PREEMPT_DYNAMIC Thu May 2 18:59:06 UTC 2024 x86_64 GNU/Linux
Additional Information
[Additional information, configuration or data that might be necessary to reproduce the issue]
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.
The text was updated successfully, but these errors were encountered: