lean4 icon indicating copy to clipboard operation
lean4 copied to clipboard

fix: accidental ownership with specialization

Open Kha opened this issue 1 year ago • 5 comments

The old compiler tried to avoid borrowing that could inhibit mutual TCO, but the implementation was wrong and in an unnecessary way:

  • ownVar is called but it can only mark variables of the current function, so the wrong variable was marked
  • there was no mutual recursion as the additional declaration came from specialization
  • the old compiler only supports TCO for self-calls anyway

Thus we restrict the borrow inhibition to self-calls. More extensive TCO could be considered in the new compiler.

Fixes #4240

Kha avatar May 24 '24 16:05 Kha

!bench

Kha avatar May 24 '24 16:05 Kha

Here are the benchmark results for commit e8981f68836d1fda671b6b3923c58662edd004e9. The entire run failed. Found no significant differences.

leanprover-bot avatar May 24 '24 16:05 leanprover-bot

!bench

Kha avatar May 24 '24 17:05 Kha

Mathlib CI status (docs):

Here are the benchmark results for commit d565cc5581221e1b6c00ef920c53f172f74517df. There were significant changes against commit b0c1112471a3f38859d9738184d21132b7d9cd0c:

  Benchmark   Metric          Change
  ==============================================
- parser      instructions     20.1% (13154.3 σ)
- parser      task-clock       26.7%    (11.8 σ)
- parser      wall-clock       26.7%    (11.8 σ)
- qsort       instructions      4.3%  (3149.6 σ)
+ stdlib      type checking    -2.9%   (-58.8 σ)

leanprover-bot avatar May 24 '24 17:05 leanprover-bot

We deemed the parser-specific slowdown (which effectively must be random chance given that the removed heuristic did not do what it intended to do) acceptable in exchange for a clear fix to the code and a modest overall stdlib boost.

Kha avatar Jun 07 '24 11:06 Kha