Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

liftTermElabM uses a non-default meta context #3499

Open
digama0 opened this issue Feb 26, 2024 · 0 comments
Open

liftTermElabM uses a non-default meta context #3499

digama0 opened this issue Feb 26, 2024 · 0 comments
Labels
bug Something isn't working P-low We are not planning to work on this issue

Comments

@digama0
Copy link
Collaborator

digama0 commented Feb 26, 2024

In leanprover-community/batteries#671, there was an issue in the simpNF linter which was reduced to the setting of foApprox from the MetaM state. The problem is that not all methods for lifting a MetaM into IO to run it set the config in the same way:

import Lean.Meta.Tactic.Simp.Main
import Std.Tactic.OpenPrivate
import Std.Tactic.RunCmd

def MyPred (_ : Nat → Nat) : Prop := True
@[simp] theorem bad1 (f : Unit → Nat → Nat) : MyPred (f ()) = True := sorry

open Lean Elab Meta Tactic Term 

def test : MetaM Unit := withReducible do
  let (t, _) ← Elab.Term.TermElabM.run do
    Elab.Term.elabTerm (← `(fun f : Unit → Nat → Nat => MyPred (f ()))) none
  let ctx := { ← Simp.Context.mkDefault with config.decide := false }
  lambdaLetTelescope t fun _ lhs => do
    let ({ expr := lhs', .. }, _) ← simp lhs ctx
    if lhs == lhs' then throwError "did not simplify"

run_cmd Command.runTermElabM fun _ => test                             -- ok
run_cmd Command.liftTermElabM test                                     -- ok
run_elab test                                                          -- ok
run_meta test                                                          -- ok
#eval show TermElabM _ from test                                       -- ok
#eval show MetaM _ from test                                           -- fail
#eval show CoreM _ from MetaM.run' test {} {}                          -- fail
#eval show CoreM _ from MetaM.run' test { config.foApprox := true } {} -- ok
open private mkMetaContext from Lean.Elab.Command in
#eval show CoreM _ from MetaM.run' test mkMetaContext {}               -- ok

The fact that the default MetaM context constructed by {} is not the same as the MetaM context used by liftTermElabM (and transitively, most regular metaprogramming code) is error-prone since it means that you get different results depending on whether you use MetaM.run' or liftTermElabM, resulting in the above-demonstrated inconsistency. My recommendation is to have the current mkMetaContext be the default (i.e. make {} do the same thing as mkMetaContext).

cc: @leodemoura

@digama0 digama0 added the bug Something isn't working label Feb 26, 2024
@digama0 digama0 changed the title runTermElabM uses a non-default meta context liftTermElabM uses a non-default meta context Feb 26, 2024
@leanprover-bot leanprover-bot added the P-low We are not planning to work on this issue label Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P-low We are not planning to work on this issue
Projects
None yet
Development

No branches or pull requests

2 participants