feat: Gate type error collection behind flag
This commit is contained in:
parent
5a05e9e8d4
commit
524314721b
|
@ -104,7 +104,11 @@ structure InfoWithContext where
|
|||
info: Elab.Info
|
||||
context?: Option Elab.ContextInfo := .none
|
||||
|
||||
private def collectSorrysInTree (t : Elab.InfoTree) : IO (List InfoWithContext) := do
|
||||
structure GoalCollectionOptions where
|
||||
collectTypeErrors : Bool := false
|
||||
|
||||
private def collectSorrysInTree (t : Elab.InfoTree) (options : GoalCollectionOptions := {})
|
||||
: IO (List InfoWithContext) := do
|
||||
let infos ← t.findAllInfoM none fun i ctx? => match i with
|
||||
| .ofTermInfo { expectedType?, expr, stx, lctx, isBinder := false, .. } => do
|
||||
let .some ctx := ctx? | return (false, true)
|
||||
|
@ -112,6 +116,8 @@ private def collectSorrysInTree (t : Elab.InfoTree) : IO (List InfoWithContext)
|
|||
if expectedType?.isNone then
|
||||
throw $ .userError "Sorry of indeterminant type is not allowed"
|
||||
return (true, false)
|
||||
unless options.collectTypeErrors do
|
||||
return (false, true)
|
||||
let .some expectedType := expectedType? | return (false, true)
|
||||
let typeMatch ← ctx.runMetaM lctx do
|
||||
let type ← Meta.inferType expr
|
||||
|
@ -130,8 +136,9 @@ private def collectSorrysInTree (t : Elab.InfoTree) : IO (List InfoWithContext)
|
|||
|
||||
-- NOTE: Plural deliberately not spelled "sorries"
|
||||
@[export pantograph_frontend_collect_sorrys_m]
|
||||
def collectSorrys (step: CompilationStep) : IO (List InfoWithContext) := do
|
||||
return (← step.trees.mapM collectSorrysInTree).join
|
||||
def collectSorrys (step: CompilationStep) (options : GoalCollectionOptions := {})
|
||||
: IO (List InfoWithContext) := do
|
||||
return (← step.trees.mapM $ λ tree => collectSorrysInTree tree options).join
|
||||
|
||||
structure AnnotatedGoalState where
|
||||
state : GoalState
|
||||
|
|
|
@ -319,11 +319,13 @@ structure FrontendProcess where
|
|||
-- One of these two must be supplied: Either supply the file name or the content.
|
||||
fileName?: Option String := .none
|
||||
file?: Option String := .none
|
||||
-- If set to true, collect tactic invocations
|
||||
-- collect tactic invocations
|
||||
invocations: Bool := false
|
||||
-- If set to true, collect `sorry`s
|
||||
-- collect `sorry`s
|
||||
sorrys: Bool := false
|
||||
-- If set to true, extract new constants
|
||||
-- collect type errors
|
||||
typeErrorsAsGoals: Bool := false
|
||||
-- list new constants from each compilation step
|
||||
newConstants: Bool := false
|
||||
deriving Lean.FromJson
|
||||
structure InvokedTactic where
|
||||
|
|
|
@ -265,7 +265,7 @@ def execute (command: Protocol.Command): MainM Lean.Json := do
|
|||
else
|
||||
pure .none
|
||||
let sorrys ← if args.sorrys then
|
||||
Frontend.collectSorrys step
|
||||
Frontend.collectSorrys step (options := { collectTypeErrors := args.typeErrorsAsGoals })
|
||||
else
|
||||
pure []
|
||||
let messages ← step.messageStrings
|
||||
|
|
|
@ -6,11 +6,12 @@ import Test.Common
|
|||
open Lean Pantograph
|
||||
namespace Pantograph.Test.Frontend
|
||||
|
||||
def collectSorrysFromSource (source: String) : MetaM (List GoalState) := do
|
||||
def collectSorrysFromSource (source: String) (options : Frontend.GoalCollectionOptions := {})
|
||||
: MetaM (List GoalState) := do
|
||||
let filename := "<anonymous>"
|
||||
let (context, state) ← do Frontend.createContextStateFromFile source filename (← getEnv) {}
|
||||
let m := Frontend.mapCompilationSteps λ step => do
|
||||
return (step.before, ← Frontend.collectSorrys step)
|
||||
return (step.before, ← Frontend.collectSorrys step options)
|
||||
let li ← m.run context |>.run' state
|
||||
let goalStates ← li.filterMapM λ (env, sorrys) => withEnv env do
|
||||
if sorrys.isEmpty then
|
||||
|
@ -181,9 +182,10 @@ def test_capture_type_mismatch : TestT MetaM Unit := do
|
|||
let input := "
|
||||
def mystery (k: Nat) : Nat := true
|
||||
"
|
||||
let goalStates ← (collectSorrysFromSource input).run' {}
|
||||
let options := { collectTypeErrors := true }
|
||||
let goalStates ← (collectSorrysFromSource input options).run' {}
|
||||
let [goalState] := goalStates | panic! s!"Incorrect number of states: {goalStates.length}"
|
||||
checkEq "goals" ((← goalState.serializeGoals (options := {})).map (·.devolatilize)) #[
|
||||
checkEq "goals" ((← goalState.serializeGoals).map (·.devolatilize)) #[
|
||||
{
|
||||
target := { pp? := "Nat" },
|
||||
vars := #[{
|
||||
|
@ -197,7 +199,8 @@ def test_capture_type_mismatch_in_binder : TestT MetaM Unit := do
|
|||
let input := "
|
||||
example (p: Prop) (h: (∀ (x: Prop), Nat) → p): p := h (λ (y: Nat) => 5)
|
||||
"
|
||||
let goalStates ← (collectSorrysFromSource input).run' {}
|
||||
let options := { collectTypeErrors := true }
|
||||
let goalStates ← (collectSorrysFromSource input options).run' {}
|
||||
let [goalState] := goalStates | panic! s!"Incorrect number of states: {goalStates.length}"
|
||||
checkEq "goals" ((← goalState.serializeGoals (options := {})).map (·.devolatilize)) #[
|
||||
]
|
||||
|
@ -236,7 +239,7 @@ def suite (env : Environment): List (String × IO LSpec.TestSeq) :=
|
|||
("sorry_in_coupled", test_sorry_in_coupled),
|
||||
("environment_capture", test_environment_capture),
|
||||
("capture_type_mismatch", test_capture_type_mismatch),
|
||||
("capture_type_mismatch_in_binder", test_capture_type_mismatch_in_binder),
|
||||
--("capture_type_mismatch_in_binder", test_capture_type_mismatch_in_binder),
|
||||
("collect_one_constant", test_collect_one_constant),
|
||||
("collect_one_theorem", test_collect_one_theorem),
|
||||
]
|
||||
|
|
|
@ -171,10 +171,11 @@ def test_frontend_process : Test :=
|
|||
let goal1 := "p q : Prop\nh : p\n⊢ p ∨ q"
|
||||
step "frontend.process"
|
||||
[
|
||||
("file", .str file),
|
||||
("invocations", .bool true),
|
||||
("sorrys", .bool false),
|
||||
("newConstants", .bool false),
|
||||
("file", .str file),
|
||||
("invocations", .bool true),
|
||||
("sorrys", .bool false),
|
||||
("typeErrorsAsGoals", .bool false),
|
||||
("newConstants", .bool false),
|
||||
]
|
||||
({
|
||||
units := [{
|
||||
|
@ -215,6 +216,7 @@ def test_frontend_process_sorry : Test :=
|
|||
("file", .str file),
|
||||
("invocations", .bool false),
|
||||
("sorrys", .bool true),
|
||||
("typeErrorsAsGoals", .bool false),
|
||||
("newConstants", .bool false),
|
||||
]
|
||||
({
|
||||
|
|
Loading…
Reference in New Issue