Skip to content

Mark definitions in a noncomputable section that fail to compile with noncomputable attribute #9021

Open

Description

@zwarich

Currently, definitions in a noncomputable section that fail to compile do not get marked with noncomputable. The current check for noncomputable in the toMono pass checks for the attribute, but there is a second check in the IR phase for definitions without any IR. This still catches most issues, but it is possible for the use of a noncomputable definition to be erroneously optimized away between these two checks.

Activity

  1. self-assigned this
    on Jun 27, 2025
  2. added
    bug
    on Jun 27, 2025
  3. zwarich commented on Jul 11, 2025

    @zwarich
    ContributorAuthor

    The basic idea of this fix is simple:

    diff --git a/src/Lean/CoreM.lean b/src/Lean/CoreM.lean
    index a89aeeadd6..880a90873f 100644
    --- a/src/Lean/CoreM.lean
    +++ b/src/Lean/CoreM.lean
    @@ -9,6 +9,7 @@ import Lean.Util.Trace
     import Lean.Log
     import Lean.ResolveName
     import Lean.Elab.InfoTree.Types
    +import Lean.Compiler.NoncomputableAttr
     import Lean.MonadEnv
     import Lean.Elab.Exception
     import Lean.Language.Basic
    @@ -714,6 +715,9 @@ where doCompile := do
           state.restore
           if logErrors then
             throw e
    +      else
    +        for decl in decls do
    +          modifyEnv (addNoncomputable · decl)
    
     def compileDecl (decl : Declaration) (logErrors := true) : CoreM Unit := do
       compileDecls (Compiler.getDeclNamesForCodeGen decl) logErrors
    

    However, it has two problems:

    • Setting an attribute in this async context doesn't work right. I'll have to sort this out with Sebastian, as some of the code wrapping the compiler is related to the way that the old compiler used the kernel environment.
    • if I force non-async elaboration, then there are new noncomputable failures in Mathlib. A number of these are fixed by fix: mark irrelevant params as erased in mono type signatures #9226, which we want for other reasons, but it has a bizarre memory usage regression that needs to be investigated.
  4. added
    P-medium
    on Jul 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P-mediumbug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions