Same code compiles with default options but fails the IR check with compiler.small=16

Aperta
#16,975 2 commenti 1 reazione 0 assegnatari Vedi su GitHub

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
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Ambito
compilers

Direzione di ricerca

Start by reproducing the failure with the provided Program.lean and the -Dcompiler.small=16 option; compare it with the successful default run and with -Dcompiler.extract_closed=false. Then trace the compiler IR check error at makeShape through Lean's compiler and closed-term extraction paths. Done means the reproducer compiles with the higher threshold and the IR check accepts the resulting code.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug
Prerequisites
  • Check that your issue is not already filed:
    https://github.com/leanprover/lean4/issues
  • Reduce the issue to a minimal, self-contained, reproducible test case.
    Avoid dependencies to Mathlib or Batteries.
  • Test your test case against the latest nightly release, for example on
    https://live.lean-lang.org/#project=lean-nightly
    (You can also use the settings there to switch to “Lean nightly”)
  • When reporting a perceived soundness bug: Does it affect lake check --paranoid?
    If in doubt, please reach out on [email protected] for responsible disclosure.
Description

On both Lean v4.36.0 and v4.38.0-nightly-2026-12-04, the example below compiles with the default options. Changing only compiler.small from 1 to 16 makes compilation fail with unexpected IR type 'u8'.

Context

I encountered this while compiling the same Lean file with different inlining thresholds.

Steps to Reproduce
  1. Save the following as Program.lean.

    inductive Shape where
      | leaf : Bool → Bool → Bool → Shape
      | node : Array Bool → Bool → Array Nat → Shape → Shape
    
    def makeShape (n : Nat) : Shape :=
      if n == 100 then
        .node
          (((if true then ((true, n), true) else ((false, n), false)).1,
            if true then #[] else (let _ := n; #[])).2)
          ((id ((fun (_ : Nat) => (let _ := 7; #[] : Array Bool)) 31)).getD
            ((#[] : Array (Bool × Bool)).size + (#[] : Array Bool).size) ((let _ := false; false) == true))
          (match (let s := Shape.leaf false true true; s) with
           | .leaf b _ _ =>
             match Shape.leaf false b false with
             | .leaf .. | .node .. => #[]
           | .node _ _ xs _ => (fun (_ : Bool) => xs) false)
          (.node (let _ : Array Nat := #[]; #[].push false) (let b := false; b)
            (if false then #[] else #[].push 0)
            (.node (let _ := fun (_ : Bool × Nat) => (0 : Nat); #[])
              (if true then true && true else false) (let _ := #[(#[] : Array Nat).size]; #[])
              (.leaf (if false then !false else false)
                ((let _ : Array (Nat × Nat) := #[]; true), (31 : Nat)).1
                ((fun (_ : Bool × Nat) => false) (false, 255)))))
      else if n == 0 then
        .leaf
          ((#[] : Array Bool).setIfInBounds 2 true |>.getD 63
            (let _ := fun (_ : Bool × Nat) => (false, (#[] : Array Bool)).2; if true then true else !false))
          (match (let _ : Array Nat := #[]; Shape.leaf false false (!true)) with
           | .leaf _ b _ => b && (n == 15)
           | .node _ b _ _ => (#[] : Array Bool).getD (#[] : Array (Array Bool)).size b)
          false
      else
        .node
          ((match Shape.leaf true (!false) false with
            | .leaf .. | .node .. => #[] : Array Bool).setIfInBounds 7
              ((#[] : Array Bool).getD (#[] : Array Bool).size (!false)))
          (match Shape.leaf true false (let _ := false; false) with
           | .leaf .. => ((#[] : Array (Nat × Bool)).getD (#[] : Array (Bool × Bool)).size (15, true)).2
           | .node xs b _ _ => (let _ := b; (true, xs)).1)
          ((let _ := 0; if false then #[] else #[]), (if false then false else false)).1
          (.leaf true (let _ := ((0 : Nat), n); false) (false, (#[] : Array Nat)).1)
    
  2. Compile with the default options.

    lean +leanprover/lean4:v4.36.0 Program.lean
    
  3. Compile the same file with a higher inlining threshold.

    lean +leanprover/lean4:v4.36.0 -Dcompiler.small=16 Program.lean
    

Expected behavior: Both commands compile the file successfully.

Actual behavior: The default command exits with status 0. With compiler.small=16, Lean exits with status 1 and reports

Program.lean:5:4: error: failed to compile definition, compiler IR check failed at `makeShape`. Error: unexpected IR type 'u8'
Versions

Output of #eval Lean.versionString on Ubuntu 22.04.5 LTS (x86_64):

"4.36.0"
"4.38.0-nightly-2026-12-04"
Additional Information

On both versions, keeping compiler.small=16 and setting compiler.extract_closed=false makes the file compile successfully.

lean +leanprover/lean4:v4.36.0 -Dcompiler.small=16 -Dcompiler.extract_closed=false Program.lean
Impact

Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.

Lingua principale
Lean
Stelle
10.5k
Fork
1.2k
Merge medio
19h 36m
PR unite (30g)
323

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di leanprover/lean4

Tutte le issue di leanprover/lean4

Issue simili

Altre issue su Compilers

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.