Inferred value for implicit argument leads to suboptimal IR #4157
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
Consider the following code
The generated IR looks like this:
This is suboptimal: we always build
x_4
which is the same asx_1
anyway, even though it is only needed in theelse
branch of theif
. Later stages of the IR pipeline optimize the constructor call away, so we are left withbut this is still bad because we don't get to reuse the memory cell of
x_1
in thetrue
branch of theif
in the function. The reason seems to be connected to the fact that we infer(a, b).fst
as the implicit argument tog
. If the linelet b' := g ha
is changed tolet b' := g (a := a) ha
, then we get the expected IRContext
This is a minimization of an issue I observed while working on the hash map, see my comment there.
Steps to Reproduce
Expected behavior: Quality of the generated IR should not depend on whether we used
(a, b).1
ora
for the implicit argument, given that the IR clearly shows that in both cases we just passa
tog
.Actual behavior: Suboptimal IR in case
(a, b).1
is used as the implicit argument.Versions
4.9.0-nightly-2024-05-11
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: