LCNF repeats closure setup on every call to a returned function
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 44/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Ambito
- compilers
Direzione di ricerca
Start with the standalone Repro.lean example and run lean -Dtrace.Compiler.result=true -c Repro.c Repro.lean; inspect makeProbe and the specialized List.mapTR.loop in the trace. Compare the generated calls with the expected one-time setup, including the empty-map case. The issue says candidate patch #16908 reduces setup calls from three to one for three keys and keeps them at zero for an empty map.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Prerequisites
- Checked for an open duplicate.
- Reduced the issue to a standalone reproducer with no imports.
- Reproduced on the latest nightly,
nightly-2026-11-30.
Description
LCNF can move setup from a function that returns a closure into the closure's body. In this example, each probe recalculates the same index.
Context
#5908 reported the same pattern under the old compiler. The reproducer below shows it in the current LCNF pipeline.
Steps to Reproduce
-
Save this as
Repro.lean.@[noinline] def build (rows : List Nat) : Nat := rows.foldl (· + ·) 0 @[noinline] def makeProbe (rows : List Nat) : Nat → Nat := let index := build rows fun key => index + key def probeAll (rows keys : List Nat) : List Nat := let probe := makeProbe rows keys.map probe -
Run
lean -Dtrace.Compiler.result=true -c Repro.c Repro.lean. -
Inspect
makeProbeand the specializedList.mapTR.loopin the trace.
Expected behavior. The first probe calls build once. Later probes reuse the index. An empty map skips setup.
Actual behavior. makeProbe takes both rows and key in the generated code. The specialized loop calls makeProbe rows key for each key, so build folds over rows each time.
Versions
Lean 4.35.0, 4.36.0, 4.38.0-nightly-2026-11-30 (fd149e0), and master at 6079107. Tested on macOS 27.2 (Apple silicon).
Additional Information
Adding -Dtrace.Compiler.init=true shows the two-argument makeProbe in the initial LCNF. Removing @[noinline] from the factory also reproduces the issue.
The candidate patch in #16908 reduces the setup count from three to one for a three-key map and keeps it at zero for an empty map.
Impact
With n rows and m keys, the repeated folds make the setup work grow with n × m. Add a 👍 reaction if this affects your code.
- Lingua principale
- Lean
- Stelle
- 10.5k
- Fork
- 1.2k
- Merge medio
- 19h 36m
- PR unite (30g)
- 323
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di leanprover/lean4
-
P-medium
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
leanprover/lean4#16958 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
leanprover/lean4#16897 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
leanprover/lean4#16892 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 86/100
leanprover/lean4#16886 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
leanprover/lean4#16820 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di leanprover/lean4
Issue simili
-
chat compiler P1
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
HerringtonDarkholme/hd-lang#2793 ·
I maintainer di solito rispondono entro 1 giorno
-
area-dart-model gardening
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 87/100
I maintainer di solito rispondono entro 1 giorno
-
`shift(x, y)` with a uint256 shift amount >= 2**255 shifts in the wrong directionForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 3 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 71/100
facebookexperimental/semcode#195 ·
I maintainer di solito rispondono entro 2 giorni