Compare commits
34 Commits
env/inspec
...
dev
Author | SHA1 | Date |
---|---|---|
Leni Aniva | 59935e386b | |
Leni Aniva | 62363cb943 | |
Leni Aniva | 9d445783c2 | |
Leni Aniva | c1f63af019 | |
Leni Aniva | b8b46c4a9c | |
Leni Aniva | 60e78b322e | |
Leni Aniva | 06fdf7e678 | |
Leni Aniva | 5e61282660 | |
Leni Aniva | 9d2a999a4f | |
Leni Aniva | db24650aec | |
Leni Aniva | 6a9ba4bb15 | |
Leni Aniva | ebde7c9eed | |
Leni Aniva | ef4e5ecbf8 | |
Leni Aniva | a374af3a5f | |
Leni Aniva | 9eec14503a | |
Leni Aniva | 814f36eb63 | |
Leni Aniva | aa066b8634 | |
Leni Aniva | 072d351f04 | |
Leni Aniva | cb46b47a60 | |
Leni Aniva | 5ce6123de7 | |
Leni Aniva | f891960362 | |
Leni Aniva | 6302b747b8 | |
Leni Aniva | 07e737eb81 | |
Leni Aniva | 56f40462ae | |
Leni Aniva | 524314721b | |
Leni Aniva | 5a05e9e8d4 | |
Leni Aniva | 48b924fae2 | |
Leni Aniva | b42d917aa7 | |
Leni Aniva | 53bad1c4c9 | |
Leni Aniva | 7a3b89cc0e | |
Leni Aniva | c0090dec97 | |
Leni Aniva | 13e01b9e62 | |
Leni Aniva | fb3d36584f | |
Leni Aniva | 13dd11e995 |
|
@ -264,25 +264,24 @@ def serializeName (name: Name) (sanitize: Bool := true): String :=
|
||||||
if n.contains Lean.idBeginEscape then s!"{quote}{n}{quote}" else n
|
if n.contains Lean.idBeginEscape then s!"{quote}{n}{quote}" else n
|
||||||
|
|
||||||
/-- serialize a sort level. Expression is optimized to be compact e.g. `(+ u 2)` -/
|
/-- serialize a sort level. Expression is optimized to be compact e.g. `(+ u 2)` -/
|
||||||
partial def serializeSortLevel (level: Level) (sanitize: Bool): String :=
|
partial def serializeSortLevel (level: Level) : String :=
|
||||||
let k := level.getOffset
|
let k := level.getOffset
|
||||||
let u := level.getLevelOffset
|
let u := level.getLevelOffset
|
||||||
let u_str := match u with
|
let u_str := match u with
|
||||||
| .zero => "0"
|
| .zero => "0"
|
||||||
| .succ _ => panic! "getLevelOffset should not return .succ"
|
| .succ _ => panic! "getLevelOffset should not return .succ"
|
||||||
| .max v w =>
|
| .max v w =>
|
||||||
let v := serializeSortLevel v sanitize
|
let v := serializeSortLevel v
|
||||||
let w := serializeSortLevel w sanitize
|
let w := serializeSortLevel w
|
||||||
s!"(:max {v} {w})"
|
s!"(:max {v} {w})"
|
||||||
| .imax v w =>
|
| .imax v w =>
|
||||||
let v := serializeSortLevel v sanitize
|
let v := serializeSortLevel v
|
||||||
let w := serializeSortLevel w sanitize
|
let w := serializeSortLevel w
|
||||||
s!"(:imax {v} {w})"
|
s!"(:imax {v} {w})"
|
||||||
| .param name =>
|
| .param name =>
|
||||||
let name := serializeName name sanitize
|
|
||||||
s!"{name}"
|
s!"{name}"
|
||||||
| .mvar id =>
|
| .mvar id =>
|
||||||
let name := serializeName id.name sanitize
|
let name := id.name
|
||||||
s!"(:mv {name})"
|
s!"(:mv {name})"
|
||||||
match k, u with
|
match k, u with
|
||||||
| 0, _ => u_str
|
| 0, _ => u_str
|
||||||
|
@ -295,7 +294,7 @@ partial def serializeSortLevel (level: Level) (sanitize: Bool): String :=
|
||||||
|
|
||||||
A `_` symbol in the AST indicates automatic deductions not present in the original expression.
|
A `_` symbol in the AST indicates automatic deductions not present in the original expression.
|
||||||
-/
|
-/
|
||||||
partial def serializeExpressionSexp (expr: Expr) (sanitize: Bool := true): MetaM String := do
|
partial def serializeExpressionSexp (expr: Expr) : MetaM String := do
|
||||||
self expr
|
self expr
|
||||||
where
|
where
|
||||||
delayedMVarToSexp (e: Expr): MetaM (Option String) := do
|
delayedMVarToSexp (e: Expr): MetaM (Option String) := do
|
||||||
|
@ -334,9 +333,10 @@ partial def serializeExpressionSexp (expr: Expr) (sanitize: Bool := true): MetaM
|
||||||
let name := mvarId.name
|
let name := mvarId.name
|
||||||
pure s!"(:{pref} {name})"
|
pure s!"(:{pref} {name})"
|
||||||
| .sort level =>
|
| .sort level =>
|
||||||
let level := serializeSortLevel level sanitize
|
let level := serializeSortLevel level
|
||||||
pure s!"(:sort {level})"
|
pure s!"(:sort {level})"
|
||||||
| .const declName _ =>
|
| .const declName _ =>
|
||||||
|
let declName := serializeName declName (sanitize := false)
|
||||||
-- The universe level of the const expression is elided since it should be
|
-- The universe level of the const expression is elided since it should be
|
||||||
-- inferrable from surrounding expression
|
-- inferrable from surrounding expression
|
||||||
pure s!"(:c {declName})"
|
pure s!"(:c {declName})"
|
||||||
|
@ -369,7 +369,7 @@ partial def serializeExpressionSexp (expr: Expr) (sanitize: Bool := true): MetaM
|
||||||
-- is wrapped in a :lit sexp.
|
-- is wrapped in a :lit sexp.
|
||||||
let v' := match v with
|
let v' := match v with
|
||||||
| .natVal val => toString val
|
| .natVal val => toString val
|
||||||
| .strVal val => s!"\"{val}\""
|
| .strVal val => IR.EmitC.quoteString val
|
||||||
pure s!"(:lit {v'})"
|
pure s!"(:lit {v'})"
|
||||||
| .mdata _ inner =>
|
| .mdata _ inner =>
|
||||||
-- NOTE: Equivalent to expr itself, but mdata influences the prettyprinter
|
-- NOTE: Equivalent to expr itself, but mdata influences the prettyprinter
|
||||||
|
@ -384,9 +384,9 @@ partial def serializeExpressionSexp (expr: Expr) (sanitize: Bool := true): MetaM
|
||||||
-- Elides all unhygenic names
|
-- Elides all unhygenic names
|
||||||
binderInfoSexp : Lean.BinderInfo → String
|
binderInfoSexp : Lean.BinderInfo → String
|
||||||
| .default => ""
|
| .default => ""
|
||||||
| .implicit => " :implicit"
|
| .implicit => " :i"
|
||||||
| .strictImplicit => " :strictImplicit"
|
| .strictImplicit => " :si"
|
||||||
| .instImplicit => " :instImplicit"
|
| .instImplicit => " :ii"
|
||||||
|
|
||||||
def serializeExpression (options: @&Protocol.Options) (e: Expr): MetaM Protocol.Expression := do
|
def serializeExpression (options: @&Protocol.Options) (e: Expr): MetaM Protocol.Expression := do
|
||||||
let pp?: Option String ← match options.printExprPretty with
|
let pp?: Option String ← match options.printExprPretty with
|
||||||
|
@ -532,7 +532,7 @@ protected def GoalState.diag (goalState: GoalState) (parent?: Option GoalState :
|
||||||
then instantiateAll decl.type
|
then instantiateAll decl.type
|
||||||
else pure $ decl.type
|
else pure $ decl.type
|
||||||
let type_sexp ← if options.printSexp then
|
let type_sexp ← if options.printSexp then
|
||||||
let sexp ← serializeExpressionSexp type (sanitize := false)
|
let sexp ← serializeExpressionSexp type
|
||||||
pure <| " " ++ sexp
|
pure <| " " ++ sexp
|
||||||
else
|
else
|
||||||
pure ""
|
pure ""
|
||||||
|
|
|
@ -67,7 +67,7 @@ def processOneCommand: FrontendM (CompilationStep × Bool) := do
|
||||||
let s := (← get).commandState
|
let s := (← get).commandState
|
||||||
let before := s.env
|
let before := s.env
|
||||||
let done ← Elab.Frontend.processCommand
|
let done ← Elab.Frontend.processCommand
|
||||||
let stx := (← get).commands.back
|
let stx := (← get).commands.back!
|
||||||
let src := (← read).inputCtx.input.toSubstring.extract (← get).cmdPos (← get).parserState.pos
|
let src := (← read).inputCtx.input.toSubstring.extract (← get).cmdPos (← get).parserState.pos
|
||||||
let s' := (← get).commandState
|
let s' := (← get).commandState
|
||||||
let after := s'.env
|
let after := s'.env
|
||||||
|
|
|
@ -80,10 +80,10 @@ def collectTactics (t : Elab.InfoTree) : List TacticInvocation :=
|
||||||
|
|
||||||
@[export pantograph_frontend_collect_tactics_from_compilation_step_m]
|
@[export pantograph_frontend_collect_tactics_from_compilation_step_m]
|
||||||
def collectTacticsFromCompilationStep (step : CompilationStep) : IO (List Protocol.InvokedTactic) := do
|
def collectTacticsFromCompilationStep (step : CompilationStep) : IO (List Protocol.InvokedTactic) := do
|
||||||
let tacticInfoTrees := step.trees.bind λ tree => tree.filter λ
|
let tacticInfoTrees := step.trees.flatMap λ tree => tree.filter λ
|
||||||
| info@(.ofTacticInfo _) => info.isOriginal
|
| info@(.ofTacticInfo _) => info.isOriginal
|
||||||
| _ => false
|
| _ => false
|
||||||
let tactics := tacticInfoTrees.bind collectTactics
|
let tactics := tacticInfoTrees.flatMap collectTactics
|
||||||
tactics.mapM λ invocation => do
|
tactics.mapM λ invocation => do
|
||||||
let goalBefore := (Format.joinSep (← invocation.goalState) "\n").pretty
|
let goalBefore := (Format.joinSep (← invocation.goalState) "\n").pretty
|
||||||
let goalAfter := (Format.joinSep (← invocation.goalStateAfter) "\n").pretty
|
let goalAfter := (Format.joinSep (← invocation.goalStateAfter) "\n").pretty
|
||||||
|
@ -104,14 +104,20 @@ structure InfoWithContext where
|
||||||
info: Elab.Info
|
info: Elab.Info
|
||||||
context?: Option Elab.ContextInfo := .none
|
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
|
let infos ← t.findAllInfoM none fun i ctx? => match i with
|
||||||
| .ofTermInfo { expectedType?, expr, stx, lctx, .. } => do
|
| .ofTermInfo { expectedType?, expr, stx, lctx, isBinder := false, .. } => do
|
||||||
let .some ctx := ctx? | return (false, true)
|
let .some ctx := ctx? | return (false, true)
|
||||||
if expr.isSorry ∧ stx.isOfKind `Lean.Parser.Term.sorry then
|
if expr.isSorry ∧ stx.isOfKind `Lean.Parser.Term.sorry then
|
||||||
if expectedType?.isNone then
|
if expectedType?.isNone then
|
||||||
throw $ .userError "Sorry of indeterminant type is not allowed"
|
throw $ .userError "Sorry of indeterminant type is not allowed"
|
||||||
return (true, false)
|
return (true, false)
|
||||||
|
unless options.collectTypeErrors do
|
||||||
|
return (false, true)
|
||||||
let .some expectedType := expectedType? | return (false, true)
|
let .some expectedType := expectedType? | return (false, true)
|
||||||
let typeMatch ← ctx.runMetaM lctx do
|
let typeMatch ← ctx.runMetaM lctx do
|
||||||
let type ← Meta.inferType expr
|
let type ← Meta.inferType expr
|
||||||
|
@ -130,8 +136,9 @@ private def collectSorrysInTree (t : Elab.InfoTree) : IO (List InfoWithContext)
|
||||||
|
|
||||||
-- NOTE: Plural deliberately not spelled "sorries"
|
-- NOTE: Plural deliberately not spelled "sorries"
|
||||||
@[export pantograph_frontend_collect_sorrys_m]
|
@[export pantograph_frontend_collect_sorrys_m]
|
||||||
def collectSorrys (step: CompilationStep) : IO (List InfoWithContext) := do
|
def collectSorrys (step: CompilationStep) (options : GoalCollectionOptions := {})
|
||||||
return (← step.trees.mapM collectSorrysInTree).join
|
: IO (List InfoWithContext) := do
|
||||||
|
return (← step.trees.mapM $ λ tree => collectSorrysInTree tree options).flatten
|
||||||
|
|
||||||
structure AnnotatedGoalState where
|
structure AnnotatedGoalState where
|
||||||
state : GoalState
|
state : GoalState
|
||||||
|
@ -149,13 +156,18 @@ def sorrysToGoalState (sorrys : List InfoWithContext) : MetaM AnnotatedGoalState
|
||||||
match i.info with
|
match i.info with
|
||||||
| .ofTermInfo termInfo => do
|
| .ofTermInfo termInfo => do
|
||||||
let mvarId ← MetaTranslate.translateMVarFromTermInfo termInfo i.context?
|
let mvarId ← MetaTranslate.translateMVarFromTermInfo termInfo i.context?
|
||||||
|
if (← mvarId.getType).hasSorry then
|
||||||
|
throwError s!"Coupling is not allowed in drafting"
|
||||||
return [(mvarId, stxByteRange termInfo.stx)]
|
return [(mvarId, stxByteRange termInfo.stx)]
|
||||||
| .ofTacticInfo tacticInfo => do
|
| .ofTacticInfo tacticInfo => do
|
||||||
let mvarIds ← MetaTranslate.translateMVarFromTacticInfoBefore tacticInfo i.context?
|
let mvarIds ← MetaTranslate.translateMVarFromTacticInfoBefore tacticInfo i.context?
|
||||||
|
for mvarId in mvarIds do
|
||||||
|
if (← mvarId.getType).hasSorry then
|
||||||
|
throwError s!"Coupling is not allowed in drafting"
|
||||||
let range := stxByteRange tacticInfo.stx
|
let range := stxByteRange tacticInfo.stx
|
||||||
return mvarIds.map (·, range)
|
return mvarIds.map (·, range)
|
||||||
| _ => panic! "Invalid info"
|
| _ => panic! "Invalid info"
|
||||||
let annotatedGoals := List.join (← goalsM.run {} |>.run' {})
|
let annotatedGoals := List.flatten (← goalsM.run {} |>.run' {})
|
||||||
let goals := annotatedGoals.map Prod.fst
|
let goals := annotatedGoals.map Prod.fst
|
||||||
let srcBoundaries := annotatedGoals.map Prod.snd
|
let srcBoundaries := annotatedGoals.map Prod.snd
|
||||||
let root := match goals with
|
let root := match goals with
|
||||||
|
|
|
@ -26,6 +26,8 @@ protected def Info.stx? : Info → Option Syntax
|
||||||
| .ofFVarAliasInfo _ => none
|
| .ofFVarAliasInfo _ => none
|
||||||
| .ofFieldRedeclInfo info => info.stx
|
| .ofFieldRedeclInfo info => info.stx
|
||||||
| .ofOmissionInfo info => info.stx
|
| .ofOmissionInfo info => info.stx
|
||||||
|
| .ofChoiceInfo info => info.stx
|
||||||
|
| .ofPartialTermInfo info => info.stx
|
||||||
/-- Is the `Syntax` for this `Lean.Elab.Info` original, or synthetic? -/
|
/-- Is the `Syntax` for this `Lean.Elab.Info` original, or synthetic? -/
|
||||||
protected def Info.isOriginal (i : Info) : Bool :=
|
protected def Info.isOriginal (i : Info) : Bool :=
|
||||||
match i.stx? with
|
match i.stx? with
|
||||||
|
@ -87,9 +89,9 @@ partial def InfoTree.filter (p : Info → Bool) (m : MVarId → Bool := fun _ =>
|
||||||
| .context ctx tree => tree.filter p m |>.map (.context ctx)
|
| .context ctx tree => tree.filter p m |>.map (.context ctx)
|
||||||
| .node info children =>
|
| .node info children =>
|
||||||
if p info then
|
if p info then
|
||||||
[.node info (children.toList.map (filter p m)).join.toPArray']
|
[.node info (children.toList.map (filter p m)).flatten.toPArray']
|
||||||
else
|
else
|
||||||
(children.toList.map (filter p m)).join
|
(children.toList.map (filter p m)).flatten
|
||||||
| .hole mvar => if m mvar then [.hole mvar] else []
|
| .hole mvar => if m mvar then [.hole mvar] else []
|
||||||
|
|
||||||
/-- Analogue of `Lean.Elab.InfoTree.findInfo?`, but that returns a list of all results. -/
|
/-- Analogue of `Lean.Elab.InfoTree.findInfo?`, but that returns a list of all results. -/
|
||||||
|
@ -103,7 +105,7 @@ partial def InfoTree.findAllInfo
|
||||||
| .context inner t => findAllInfo t (inner.mergeIntoOuter? context?) haltOnMatch pred
|
| .context inner t => findAllInfo t (inner.mergeIntoOuter? context?) haltOnMatch pred
|
||||||
| .node i children =>
|
| .node i children =>
|
||||||
let head := if pred i then [(i, context?, children)] else []
|
let head := if pred i then [(i, context?, children)] else []
|
||||||
let tail := if haltOnMatch ∧ !head.isEmpty then [] else children.toList.bind (fun t => findAllInfo t context? haltOnMatch pred)
|
let tail := if haltOnMatch ∧ !head.isEmpty then [] else children.toList.flatMap (fun t => findAllInfo t context? haltOnMatch pred)
|
||||||
head ++ tail
|
head ++ tail
|
||||||
| _ => []
|
| _ => []
|
||||||
|
|
||||||
|
@ -119,7 +121,7 @@ partial def InfoTree.findAllInfoM [Monad m]
|
||||||
let (flagCollect, flagRecurse) ← pred i context?
|
let (flagCollect, flagRecurse) ← pred i context?
|
||||||
let head := if flagCollect then [(i, context?, children)] else []
|
let head := if flagCollect then [(i, context?, children)] else []
|
||||||
let tail := if ¬ flagRecurse then pure [] else children.toList.mapM (fun t => t.findAllInfoM context? pred)
|
let tail := if ¬ flagRecurse then pure [] else children.toList.mapM (fun t => t.findAllInfoM context? pred)
|
||||||
return head ++ (← tail).join
|
return head ++ (← tail).flatten
|
||||||
| _ => return []
|
| _ => return []
|
||||||
|
|
||||||
@[export pantograph_infotree_to_string_m]
|
@[export pantograph_infotree_to_string_m]
|
||||||
|
@ -141,6 +143,8 @@ partial def InfoTree.toString (t : InfoTree) (ctx?: Option Elab.ContextInfo := .
|
||||||
| .ofFVarAliasInfo _ => pure "[fvar]"
|
| .ofFVarAliasInfo _ => pure "[fvar]"
|
||||||
| .ofFieldRedeclInfo _ => pure "[field_redecl]"
|
| .ofFieldRedeclInfo _ => pure "[field_redecl]"
|
||||||
| .ofOmissionInfo _ => pure "[omission]"
|
| .ofOmissionInfo _ => pure "[omission]"
|
||||||
|
| .ofChoiceInfo _ => pure "[choice]"
|
||||||
|
| .ofPartialTermInfo _ => pure "[partial_term]"
|
||||||
let children := "\n".intercalate (← children.toList.mapM λ t' => do pure $ indent $ ← t'.toString ctx)
|
let children := "\n".intercalate (← children.toList.mapM λ t' => do pure $ indent $ ← t'.toString ctx)
|
||||||
return s!"{node}\n{children}"
|
return s!"{node}\n{children}"
|
||||||
else throw <| IO.userError "No `ContextInfo` available."
|
else throw <| IO.userError "No `ContextInfo` available."
|
||||||
|
|
|
@ -68,7 +68,8 @@ private partial def translateExpr (srcExpr: Expr) : MetaTranslateM Expr := do
|
||||||
match e with
|
match e with
|
||||||
| .fvar fvarId =>
|
| .fvar fvarId =>
|
||||||
let .some fvarId' := state.fvarMap[fvarId]? | panic! s!"FVar id not registered: {fvarId.name}"
|
let .some fvarId' := state.fvarMap[fvarId]? | panic! s!"FVar id not registered: {fvarId.name}"
|
||||||
assert! (← getLCtx).contains fvarId'
|
-- Delegating this to `Meta.check` later
|
||||||
|
--assert! (← getLCtx).contains fvarId'
|
||||||
return .done $ .fvar fvarId'
|
return .done $ .fvar fvarId'
|
||||||
| .mvar mvarId => do
|
| .mvar mvarId => do
|
||||||
-- Must not be assigned
|
-- Must not be assigned
|
||||||
|
|
|
@ -183,7 +183,8 @@ private def collectAllErroredMVars (src : MVarId) : Elab.TermElabM (List MVarId)
|
||||||
-- to one of these seed mvars, it means an error has occurred when a tactic
|
-- to one of these seed mvars, it means an error has occurred when a tactic
|
||||||
-- was executing on `src`. `evalTactic`, will not capture these mvars, so we
|
-- was executing on `src`. `evalTactic`, will not capture these mvars, so we
|
||||||
-- need to manually find them and save them into the goal list.
|
-- need to manually find them and save them into the goal list.
|
||||||
let descendants ← Meta.getMVars $ ← instantiateMVars (.mvar src)
|
|
||||||
|
let descendants ← Meta.getMVars (.mvar src)
|
||||||
--let _ ← Elab.Term.logUnassignedUsingErrorInfos descendants
|
--let _ ← Elab.Term.logUnassignedUsingErrorInfos descendants
|
||||||
let mut alreadyVisited : MVarIdSet := {}
|
let mut alreadyVisited : MVarIdSet := {}
|
||||||
let mut result : MVarIdSet := {}
|
let mut result : MVarIdSet := {}
|
||||||
|
@ -237,25 +238,34 @@ inductive TacticResult where
|
||||||
-- The given action cannot be executed in the state
|
-- The given action cannot be executed in the state
|
||||||
| invalidAction (message: String)
|
| invalidAction (message: String)
|
||||||
|
|
||||||
|
private def dumpMessageLog (prevMessageLength : Nat) : CoreM (Array String) := do
|
||||||
|
let newMessages ← (← Core.getMessageLog).toList.drop prevMessageLength
|
||||||
|
|>.filterMapM λ m => do
|
||||||
|
if m.severity == .error then
|
||||||
|
return .some $ ← m.toString
|
||||||
|
else
|
||||||
|
return .none
|
||||||
|
Core.resetMessageLog
|
||||||
|
return newMessages.toArray
|
||||||
|
|
||||||
/-- Executes a `TacticM` monad on this `GoalState`, collecting the errors as necessary -/
|
/-- Executes a `TacticM` monad on this `GoalState`, collecting the errors as necessary -/
|
||||||
protected def GoalState.tryTacticM (state: GoalState) (goal: MVarId) (tacticM: Elab.Tactic.TacticM Unit) (guardMVarErrors : Bool := false):
|
protected def GoalState.tryTacticM
|
||||||
Elab.TermElabM TacticResult := do
|
(state: GoalState) (goal: MVarId) (tacticM: Elab.Tactic.TacticM Unit)
|
||||||
|
(guardMVarErrors : Bool := false)
|
||||||
|
: Elab.TermElabM TacticResult := do
|
||||||
|
let prevMessageLength := state.coreState.messages.toList.length
|
||||||
try
|
try
|
||||||
let nextState ← state.step goal tacticM guardMVarErrors
|
let nextState ← state.step goal tacticM guardMVarErrors
|
||||||
|
|
||||||
-- Check if error messages have been generated in the core.
|
-- Check if error messages have been generated in the core.
|
||||||
let newMessages ← (← Core.getMessageLog).toList.drop state.coreState.messages.toList.length
|
let newMessages ← dumpMessageLog prevMessageLength
|
||||||
|>.filterMapM λ m => do
|
|
||||||
if m.severity == .error then
|
|
||||||
return .some $ ← m.toString
|
|
||||||
else
|
|
||||||
return .none
|
|
||||||
Core.resetMessageLog
|
|
||||||
if ¬ newMessages.isEmpty then
|
if ¬ newMessages.isEmpty then
|
||||||
return .failure newMessages.toArray
|
return .failure newMessages
|
||||||
return .success nextState
|
return .success nextState
|
||||||
catch exception =>
|
catch exception =>
|
||||||
return .failure #[← exception.toMessageData.toString]
|
match exception with
|
||||||
|
| .internal _ => return .failure $ ← dumpMessageLog prevMessageLength
|
||||||
|
| _ => return .failure #[← exception.toMessageData.toString]
|
||||||
|
|
||||||
/-- Execute a string tactic on given state. Restores TermElabM -/
|
/-- Execute a string tactic on given state. Restores TermElabM -/
|
||||||
@[export pantograph_goal_state_try_tactic_m]
|
@[export pantograph_goal_state_try_tactic_m]
|
||||||
|
|
|
@ -207,6 +207,14 @@ protected def GoalState.tryNoConfuse (state: GoalState) (goal: MVarId) (eq: Stri
|
||||||
| .ok syn => pure syn
|
| .ok syn => pure syn
|
||||||
| .error error => return .parseError error
|
| .error error => return .parseError error
|
||||||
state.tryTacticM goal (tacticM := Tactic.evalNoConfuse eq)
|
state.tryTacticM goal (tacticM := Tactic.evalNoConfuse eq)
|
||||||
|
@[export pantograph_goal_try_draft_m]
|
||||||
|
protected def GoalState.tryDraft (state: GoalState) (goal: MVarId) (expr: String): CoreM TacticResult := do
|
||||||
|
let expr ← match (← parseTermM expr) with
|
||||||
|
| .ok syn => pure syn
|
||||||
|
| .error error => return .parseError error
|
||||||
|
runTermElabM do
|
||||||
|
state.restoreElabM
|
||||||
|
state.tryTacticM goal (Tactic.evalDraft expr)
|
||||||
@[export pantograph_goal_let_m]
|
@[export pantograph_goal_let_m]
|
||||||
def goalLet (state: GoalState) (goal: MVarId) (binderName: String) (type: String): CoreM TacticResult :=
|
def goalLet (state: GoalState) (goal: MVarId) (binderName: String) (type: String): CoreM TacticResult :=
|
||||||
runTermElabM <| state.tryLet goal binderName type
|
runTermElabM <| state.tryLet goal binderName type
|
||||||
|
|
|
@ -237,6 +237,7 @@ structure GoalTactic where
|
||||||
calc?: Option String := .none
|
calc?: Option String := .none
|
||||||
-- true to enter `conv`, `false` to exit. In case of exit the `goalId` is ignored.
|
-- true to enter `conv`, `false` to exit. In case of exit the `goalId` is ignored.
|
||||||
conv?: Option Bool := .none
|
conv?: Option Bool := .none
|
||||||
|
draft?: Option String := .none
|
||||||
|
|
||||||
-- In case of the `have` tactic, the new free variable name is provided here
|
-- In case of the `have` tactic, the new free variable name is provided here
|
||||||
binderName?: Option String := .none
|
binderName?: Option String := .none
|
||||||
|
@ -327,11 +328,13 @@ structure FrontendProcess where
|
||||||
-- One of these two must be supplied: Either supply the file name or the content.
|
-- One of these two must be supplied: Either supply the file name or the content.
|
||||||
fileName?: Option String := .none
|
fileName?: Option String := .none
|
||||||
file?: Option String := .none
|
file?: Option String := .none
|
||||||
-- If set to true, collect tactic invocations
|
-- collect tactic invocations
|
||||||
invocations: Bool := false
|
invocations: Bool := false
|
||||||
-- If set to true, collect `sorry`s
|
-- collect `sorry`s
|
||||||
sorrys: Bool := false
|
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
|
newConstants: Bool := false
|
||||||
deriving Lean.FromJson
|
deriving Lean.FromJson
|
||||||
structure InvokedTactic where
|
structure InvokedTactic where
|
||||||
|
|
|
@ -27,5 +27,38 @@ def evalAssign : Elab.Tactic.Tactic := fun stx => Elab.Tactic.withMainContext do
|
||||||
goal.assign expr
|
goal.assign expr
|
||||||
Elab.Tactic.replaceMainGoal nextGoals
|
Elab.Tactic.replaceMainGoal nextGoals
|
||||||
|
|
||||||
|
def sorryToHole (src : Expr) : StateRefT (List MVarId) MetaM Expr := do
|
||||||
|
Meta.transform src λ
|
||||||
|
| .app (.app (.const ``sorryAx ..) type) .. => do
|
||||||
|
let type ← instantiateMVars type
|
||||||
|
if type.hasSorry then
|
||||||
|
throwError s!"Coupling is not allowed in draft tactic: {← Meta.ppExpr type}"
|
||||||
|
let mvar ← Meta.mkFreshExprSyntheticOpaqueMVar type
|
||||||
|
modify (mvar.mvarId! :: .)
|
||||||
|
pure $ .done mvar
|
||||||
|
| _ => pure .continue
|
||||||
|
|
||||||
|
-- Given a complete (no holes) expression, extract the sorry's from it and convert them into goals.
|
||||||
|
def draft (goal : MVarId) (expr : Expr) : MetaM (List MVarId) := do
|
||||||
|
goal.checkNotAssigned `Pantograph.Tactic.draft
|
||||||
|
let exprType ← Meta.inferType expr
|
||||||
|
let goalType ← goal.getType
|
||||||
|
unless ← Meta.isDefEq goalType exprType do
|
||||||
|
throwError s!"{← Meta.ppExpr expr} : {← Meta.ppExpr exprType} ≠ {← Meta.ppExpr goalType}"
|
||||||
|
|
||||||
|
let (expr', holes) ← sorryToHole expr |>.run []
|
||||||
|
goal.assign expr'
|
||||||
|
return holes.reverse
|
||||||
|
|
||||||
|
def evalDraft : Elab.Tactic.Tactic := fun stx ↦ Elab.Tactic.withMainContext do
|
||||||
|
let target ← Elab.Tactic.getMainTarget
|
||||||
|
let goal ← Elab.Tactic.getMainGoal
|
||||||
|
let (expr, holeGoals) ← Elab.Tactic.elabTermWithHoles stx
|
||||||
|
(expectedType? := .some target)
|
||||||
|
(tagSuffix := .anonymous)
|
||||||
|
(allowNaturalHoles := true)
|
||||||
|
let draftGoals ← draft goal expr
|
||||||
|
Elab.Tactic.replaceMainGoal $ holeGoals ++ draftGoals
|
||||||
|
|
||||||
|
|
||||||
end Pantograph.Tactic
|
end Pantograph.Tactic
|
||||||
|
|
|
@ -40,7 +40,7 @@ def «have» (mvarId: MVarId) (binderName: Name) (type: Expr): MetaM BranchResul
|
||||||
let fvarId ← mkFreshFVarId
|
let fvarId ← mkFreshFVarId
|
||||||
let lctxUpstream := lctx.mkLocalDecl fvarId binderName type
|
let lctxUpstream := lctx.mkLocalDecl fvarId binderName type
|
||||||
let mvarUpstream ←
|
let mvarUpstream ←
|
||||||
withTheReader Meta.Context (fun ctx => { ctx with lctx := lctxUpstream }) do
|
Meta.withLCtx lctxUpstream #[] do
|
||||||
Meta.withNewLocalInstances #[.fvar fvarId] 0 do
|
Meta.withNewLocalInstances #[.fvar fvarId] 0 do
|
||||||
let mvarUpstream ← mkUpstreamMVar mvarId
|
let mvarUpstream ← mkUpstreamMVar mvarId
|
||||||
--let expr: Expr := .app (.lam binderName type mvarBranch .default) mvarUpstream
|
--let expr: Expr := .app (.lam binderName type mvarBranch .default) mvarUpstream
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
namespace Pantograph
|
namespace Pantograph
|
||||||
|
|
||||||
@[export pantograph_version]
|
@[export pantograph_version]
|
||||||
def version := "0.2.23"
|
def version := "0.2.25"
|
||||||
|
|
||||||
end Pantograph
|
end Pantograph
|
||||||
|
|
23
Repl.lean
23
Repl.lean
|
@ -145,24 +145,27 @@ def execute (command: Protocol.Command): MainM Lean.Json := do
|
||||||
let .some goal := goalState.goals.get? args.goalId |
|
let .some goal := goalState.goals.get? args.goalId |
|
||||||
return .error $ errorIndex s!"Invalid goal index {args.goalId}"
|
return .error $ errorIndex s!"Invalid goal index {args.goalId}"
|
||||||
let nextGoalState?: Except _ TacticResult ← runTermElabInMainM do
|
let nextGoalState?: Except _ TacticResult ← runTermElabInMainM do
|
||||||
match args.tactic?, args.expr?, args.have?, args.let?, args.calc?, args.conv? with
|
-- NOTE: Should probably use a macro to handle this...
|
||||||
| .some tactic, .none, .none, .none, .none, .none => do
|
match args.tactic?, args.expr?, args.have?, args.let?, args.calc?, args.conv?, args.draft? with
|
||||||
|
| .some tactic, .none, .none, .none, .none, .none, .none => do
|
||||||
pure <| Except.ok <| ← goalState.tryTactic goal tactic
|
pure <| Except.ok <| ← goalState.tryTactic goal tactic
|
||||||
| .none, .some expr, .none, .none, .none, .none => do
|
| .none, .some expr, .none, .none, .none, .none, .none => do
|
||||||
pure <| Except.ok <| ← goalState.tryAssign goal expr
|
pure <| Except.ok <| ← goalState.tryAssign goal expr
|
||||||
| .none, .none, .some type, .none, .none, .none => do
|
| .none, .none, .some type, .none, .none, .none, .none => do
|
||||||
let binderName := args.binderName?.getD ""
|
let binderName := args.binderName?.getD ""
|
||||||
pure <| Except.ok <| ← goalState.tryHave goal binderName type
|
pure <| Except.ok <| ← goalState.tryHave goal binderName type
|
||||||
| .none, .none, .none, .some type, .none, .none => do
|
| .none, .none, .none, .some type, .none, .none, .none => do
|
||||||
let binderName := args.binderName?.getD ""
|
let binderName := args.binderName?.getD ""
|
||||||
pure <| Except.ok <| ← goalState.tryLet goal binderName type
|
pure <| Except.ok <| ← goalState.tryLet goal binderName type
|
||||||
| .none, .none, .none, .none, .some pred, .none => do
|
| .none, .none, .none, .none, .some pred, .none, .none => do
|
||||||
pure <| Except.ok <| ← goalState.tryCalc goal pred
|
pure <| Except.ok <| ← goalState.tryCalc goal pred
|
||||||
| .none, .none, .none, .none, .none, .some true => do
|
| .none, .none, .none, .none, .none, .some true, .none => do
|
||||||
pure <| Except.ok <| ← goalState.conv goal
|
pure <| Except.ok <| ← goalState.conv goal
|
||||||
| .none, .none, .none, .none, .none, .some false => do
|
| .none, .none, .none, .none, .none, .some false, .none => do
|
||||||
pure <| Except.ok <| ← goalState.convExit
|
pure <| Except.ok <| ← goalState.convExit
|
||||||
| _, _, _, _, _, _ =>
|
| .none, .none, .none, .none, .none, .none, .some draft => do
|
||||||
|
pure <| Except.ok <| ← goalState.tryDraft goal draft
|
||||||
|
| _, _, _, _, _, _, _ =>
|
||||||
let error := errorI "arguments" "Exactly one of {tactic, expr, have, calc, conv} must be supplied"
|
let error := errorI "arguments" "Exactly one of {tactic, expr, have, calc, conv} must be supplied"
|
||||||
pure $ Except.error $ error
|
pure $ Except.error $ error
|
||||||
match nextGoalState? with
|
match nextGoalState? with
|
||||||
|
@ -265,7 +268,7 @@ def execute (command: Protocol.Command): MainM Lean.Json := do
|
||||||
else
|
else
|
||||||
pure .none
|
pure .none
|
||||||
let sorrys ← if args.sorrys then
|
let sorrys ← if args.sorrys then
|
||||||
Frontend.collectSorrys step
|
Frontend.collectSorrys step (options := { collectTypeErrors := args.typeErrorsAsGoals })
|
||||||
else
|
else
|
||||||
pure []
|
pure []
|
||||||
let messages ← step.messageStrings
|
let messages ← step.messageStrings
|
||||||
|
|
|
@ -48,6 +48,12 @@ namespace Condensed
|
||||||
deriving instance BEq, Repr for LocalDecl
|
deriving instance BEq, Repr for LocalDecl
|
||||||
deriving instance BEq, Repr for Goal
|
deriving instance BEq, Repr for Goal
|
||||||
|
|
||||||
|
-- Enable string interpolation
|
||||||
|
instance : ToString FVarId where
|
||||||
|
toString id := id.name.toString
|
||||||
|
instance : ToString MVarId where
|
||||||
|
toString id := id.name.toString
|
||||||
|
|
||||||
protected def LocalDecl.devolatilize (decl: LocalDecl): LocalDecl :=
|
protected def LocalDecl.devolatilize (decl: LocalDecl): LocalDecl :=
|
||||||
{
|
{
|
||||||
decl with fvarId := { name := .anonymous }
|
decl with fvarId := { name := .anonymous }
|
||||||
|
|
|
@ -35,7 +35,7 @@ def test_sexp_of_symbol (env: Environment): IO LSpec.TestSeq := do
|
||||||
("Nat.add", "(:forall a (:c Nat) (:forall a (:c Nat) (:c Nat)))"),
|
("Nat.add", "(:forall a (:c Nat) (:forall a (:c Nat) (:c Nat)))"),
|
||||||
-- These ones are normal and easy
|
-- These ones are normal and easy
|
||||||
("Nat.add_one", "(:forall n (:c Nat) ((:c Eq) (:c Nat) ((:c HAdd.hAdd) (:c Nat) (:c Nat) (:c Nat) ((:c instHAdd) (:c Nat) (:c instAddNat)) 0 ((:c OfNat.ofNat) (:c Nat) (:lit 1) ((:c instOfNatNat) (:lit 1)))) ((:c Nat.succ) 0)))"),
|
("Nat.add_one", "(:forall n (:c Nat) ((:c Eq) (:c Nat) ((:c HAdd.hAdd) (:c Nat) (:c Nat) (:c Nat) ((:c instHAdd) (:c Nat) (:c instAddNat)) 0 ((:c OfNat.ofNat) (:c Nat) (:lit 1) ((:c instOfNatNat) (:lit 1)))) ((:c Nat.succ) 0)))"),
|
||||||
("Nat.le_of_succ_le", "(:forall n (:c Nat) (:forall m (:c Nat) (:forall h ((:c LE.le) (:c Nat) (:c instLENat) ((:c Nat.succ) 1) 0) ((:c LE.le) (:c Nat) (:c instLENat) 2 1)) :implicit) :implicit)"),
|
("Nat.le_of_succ_le", "(:forall n (:c Nat) (:forall m (:c Nat) (:forall h ((:c LE.le) (:c Nat) (:c instLENat) ((:c Nat.succ) 1) 0) ((:c LE.le) (:c Nat) (:c instLENat) 2 1)) :i) :i)"),
|
||||||
-- Handling of higher order types
|
-- Handling of higher order types
|
||||||
("Or", "(:forall a (:sort 0) (:forall b (:sort 0) (:sort 0)))"),
|
("Or", "(:forall a (:sort 0) (:forall b (:sort 0) (:sort 0)))"),
|
||||||
("List", "(:forall α (:sort (+ u 1)) (:sort (+ u 1)))")
|
("List", "(:forall α (:sort (+ u 1)) (:sort (+ u 1)))")
|
||||||
|
@ -50,8 +50,8 @@ def test_sexp_of_elab (env: Environment): IO LSpec.TestSeq := do
|
||||||
let entries: List (String × (List Name) × String) := [
|
let entries: List (String × (List Name) × String) := [
|
||||||
("λ x: Nat × Bool => x.1", [], "(:lambda x ((:c Prod) (:c Nat) (:c Bool)) ((:c Prod.fst) (:c Nat) (:c Bool) 0))"),
|
("λ x: Nat × Bool => x.1", [], "(:lambda x ((:c Prod) (:c Nat) (:c Bool)) ((:c Prod.fst) (:c Nat) (:c Bool) 0))"),
|
||||||
("λ x: Array Nat => x.data", [], "(:lambda x ((:c Array) (:c Nat)) ((:c Array.data) (:c Nat) 0))"),
|
("λ x: Array Nat => x.data", [], "(:lambda x ((:c Array) (:c Nat)) ((:c Array.data) (:c Nat) 0))"),
|
||||||
("λ {α: Sort (u + 1)} => List α", [`u], "(:lambda α (:sort (+ u 1)) ((:c List) 0) :implicit)"),
|
("λ {α: Sort (u + 1)} => List α", [`u], "(:lambda α (:sort (+ u 1)) ((:c List) 0) :i)"),
|
||||||
("λ {α} => List α", [], "(:lambda α (:sort (+ (:mv _uniq.4) 1)) ((:c List) 0) :implicit)"),
|
("λ {α} => List α", [], "(:lambda α (:sort (+ (:mv _uniq.4) 1)) ((:c List) 0) :i)"),
|
||||||
("(2: Nat) <= (5: Nat)", [], "((:c LE.le) (:mv _uniq.18) (:mv _uniq.19) ((:c OfNat.ofNat) (:mv _uniq.4) (:lit 2) (:mv _uniq.5)) ((:c OfNat.ofNat) (:mv _uniq.14) (:lit 5) (:mv _uniq.15)))"),
|
("(2: Nat) <= (5: Nat)", [], "((:c LE.le) (:mv _uniq.18) (:mv _uniq.19) ((:c OfNat.ofNat) (:mv _uniq.4) (:lit 2) (:mv _uniq.5)) ((:c OfNat.ofNat) (:mv _uniq.14) (:lit 5) (:mv _uniq.15)))"),
|
||||||
]
|
]
|
||||||
entries.foldlM (λ suites (source, levels, target) =>
|
entries.foldlM (λ suites (source, levels, target) =>
|
||||||
|
@ -77,7 +77,7 @@ def test_sexp_of_expr (env: Environment): IO LSpec.TestSeq := do
|
||||||
.default)
|
.default)
|
||||||
.implicit)
|
.implicit)
|
||||||
.implicit,
|
.implicit,
|
||||||
"(:lambda p (:sort 0) (:lambda q (:sort 0) (:lambda k ((:c And) 1 0) ((:c And.right) _ _ 0)) :implicit) :implicit)"
|
"(:lambda p (:sort 0) (:lambda q (:sort 0) (:lambda k ((:c And) 1 0) ((:c And.right) _ _ 0)) :i) :i)"
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
let termElabM: Elab.TermElabM LSpec.TestSeq := entries.foldlM (λ suites (expr, target) => do
|
let termElabM: Elab.TermElabM LSpec.TestSeq := entries.foldlM (λ suites (expr, target) => do
|
||||||
|
|
|
@ -106,10 +106,10 @@ def test_symbol_location : TestT IO Unit := do
|
||||||
let .ok result ← Environment.inspect { name := "Nat.le_of_succ_le", source? := .some true } (options := {}) | fail "Inspect failed"
|
let .ok result ← Environment.inspect { name := "Nat.le_of_succ_le", source? := .some true } (options := {}) | fail "Inspect failed"
|
||||||
checkEq "module" result.module? <| .some "Init.Data.Nat.Basic"
|
checkEq "module" result.module? <| .some "Init.Data.Nat.Basic"
|
||||||
|
|
||||||
-- Doesn't work for symbols in `Init` for some reason
|
-- Extraction of source doesn't work for symbols in `Init` for some reason
|
||||||
--checkEq "file" result.sourceUri? <| .some "??"
|
checkTrue "file" result.sourceUri?.isNone
|
||||||
checkEq "pos" result.sourceStart? <| .some { line := 344, column := 0 }
|
checkEq "pos" (result.sourceStart?.map (·.column)) <| .some 0
|
||||||
checkEq "pos" result.sourceEnd? <| .some { line := 344, column := 88 }
|
checkEq "pos" (result.sourceEnd?.map (·.column)) <| .some 88
|
||||||
|
|
||||||
def suite: List (String × IO LSpec.TestSeq) :=
|
def suite: List (String × IO LSpec.TestSeq) :=
|
||||||
[
|
[
|
||||||
|
|
|
@ -6,11 +6,12 @@ import Test.Common
|
||||||
open Lean Pantograph
|
open Lean Pantograph
|
||||||
namespace Pantograph.Test.Frontend
|
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 filename := "<anonymous>"
|
||||||
let (context, state) ← do Frontend.createContextStateFromFile source filename (← getEnv) {}
|
let (context, state) ← do Frontend.createContextStateFromFile source filename (← getEnv) {}
|
||||||
let m := Frontend.mapCompilationSteps λ step => do
|
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 li ← m.run context |>.run' state
|
||||||
let goalStates ← li.filterMapM λ (env, sorrys) => withEnv env do
|
let goalStates ← li.filterMapM λ (env, sorrys) => withEnv env do
|
||||||
if sorrys.isEmpty then
|
if sorrys.isEmpty then
|
||||||
|
@ -181,9 +182,10 @@ def test_capture_type_mismatch : TestT MetaM Unit := do
|
||||||
let input := "
|
let input := "
|
||||||
def mystery (k: Nat) : Nat := true
|
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}"
|
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" },
|
target := { pp? := "Nat" },
|
||||||
vars := #[{
|
vars := #[{
|
||||||
|
@ -193,6 +195,16 @@ def mystery (k: Nat) : Nat := true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
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 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)) #[
|
||||||
|
]
|
||||||
|
|
||||||
def collectNewConstants (source: String) : MetaM (List (List Name)) := do
|
def collectNewConstants (source: String) : MetaM (List (List Name)) := do
|
||||||
let filename := "<anonymous>"
|
let filename := "<anonymous>"
|
||||||
let (context, state) ← do Frontend.createContextStateFromFile source filename (← getEnv) {}
|
let (context, state) ← do Frontend.createContextStateFromFile source filename (← getEnv) {}
|
||||||
|
@ -227,6 +239,7 @@ def suite (env : Environment): List (String × IO LSpec.TestSeq) :=
|
||||||
("sorry_in_coupled", test_sorry_in_coupled),
|
("sorry_in_coupled", test_sorry_in_coupled),
|
||||||
("environment_capture", test_environment_capture),
|
("environment_capture", test_environment_capture),
|
||||||
("capture_type_mismatch", test_capture_type_mismatch),
|
("capture_type_mismatch", test_capture_type_mismatch),
|
||||||
|
--("capture_type_mismatch_in_binder", test_capture_type_mismatch_in_binder),
|
||||||
("collect_one_constant", test_collect_one_constant),
|
("collect_one_constant", test_collect_one_constant),
|
||||||
("collect_one_theorem", test_collect_one_theorem),
|
("collect_one_theorem", test_collect_one_theorem),
|
||||||
]
|
]
|
||||||
|
|
|
@ -73,7 +73,7 @@ def test_tactic : Test :=
|
||||||
step "goal.tactic" [("stateId", .num 0), ("goalId", .num 0), ("tactic", .str "intro x")]
|
step "goal.tactic" [("stateId", .num 0), ("goalId", .num 0), ("tactic", .str "intro x")]
|
||||||
({ nextStateId? := .some 1, goals? := #[goal1], }: Protocol.GoalTacticResult),
|
({ nextStateId? := .some 1, goals? := #[goal1], }: Protocol.GoalTacticResult),
|
||||||
step "goal.print" [("stateId", .num 1), ("parentExpr", .bool true), ("rootExpr", .bool true)]
|
step "goal.print" [("stateId", .num 1), ("parentExpr", .bool true), ("rootExpr", .bool true)]
|
||||||
({ parent? := .some { pp? := .some "fun x => ?m.12 x" }, }: Protocol.GoalPrintResult),
|
({ parent? := .some { pp? := .some "fun x => ?m.11" }, }: Protocol.GoalPrintResult),
|
||||||
step "goal.tactic" [("stateId", .num 1), ("goalId", .num 0), ("tactic", .str "intro y")]
|
step "goal.tactic" [("stateId", .num 1), ("goalId", .num 0), ("tactic", .str "intro y")]
|
||||||
({ nextStateId? := .some 2, goals? := #[goal2], }: Protocol.GoalTacticResult),
|
({ nextStateId? := .some 2, goals? := #[goal2], }: Protocol.GoalTacticResult),
|
||||||
]
|
]
|
||||||
|
@ -90,27 +90,27 @@ def test_automatic_mode (automatic: Bool): Test :=
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
let goal2l: Protocol.Goal := {
|
let goal2l: Protocol.Goal := {
|
||||||
name := "_uniq.59",
|
name := "_uniq.61",
|
||||||
userName? := .some "inl",
|
userName? := .some "inl",
|
||||||
target := { pp? := .some "q ∨ p" },
|
target := { pp? := .some "q ∨ p" },
|
||||||
vars := varsPQ ++ #[
|
vars := varsPQ ++ #[
|
||||||
{ name := "_uniq.47", userName := "h✝", type? := .some { pp? := .some "p" }, isInaccessible := true}
|
{ name := "_uniq.49", userName := "h✝", type? := .some { pp? := .some "p" }, isInaccessible := true}
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
let goal2r: Protocol.Goal := {
|
let goal2r: Protocol.Goal := {
|
||||||
name := "_uniq.72",
|
name := "_uniq.74",
|
||||||
userName? := .some "inr",
|
userName? := .some "inr",
|
||||||
target := { pp? := .some "q ∨ p" },
|
target := { pp? := .some "q ∨ p" },
|
||||||
vars := varsPQ ++ #[
|
vars := varsPQ ++ #[
|
||||||
{ name := "_uniq.60", userName := "h✝", type? := .some { pp? := .some "q" }, isInaccessible := true}
|
{ name := "_uniq.62", userName := "h✝", type? := .some { pp? := .some "q" }, isInaccessible := true}
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
let goal3l: Protocol.Goal := {
|
let goal3l: Protocol.Goal := {
|
||||||
name := "_uniq.78",
|
name := "_uniq.80",
|
||||||
userName? := .some "inl.h",
|
userName? := .some "inl.h",
|
||||||
target := { pp? := .some "p" },
|
target := { pp? := .some "p" },
|
||||||
vars := varsPQ ++ #[
|
vars := varsPQ ++ #[
|
||||||
{ name := "_uniq.47", userName := "h✝", type? := .some { pp? := .some "p" }, isInaccessible := true}
|
{ name := "_uniq.49", userName := "h✝", type? := .some { pp? := .some "p" }, isInaccessible := true}
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
[
|
[
|
||||||
|
@ -171,10 +171,11 @@ def test_frontend_process : Test :=
|
||||||
let goal1 := "p q : Prop\nh : p\n⊢ p ∨ q"
|
let goal1 := "p q : Prop\nh : p\n⊢ p ∨ q"
|
||||||
step "frontend.process"
|
step "frontend.process"
|
||||||
[
|
[
|
||||||
("file", .str file),
|
("file", .str file),
|
||||||
("invocations", .bool true),
|
("invocations", .bool true),
|
||||||
("sorrys", .bool false),
|
("sorrys", .bool false),
|
||||||
("newConstants", .bool false),
|
("typeErrorsAsGoals", .bool false),
|
||||||
|
("newConstants", .bool false),
|
||||||
]
|
]
|
||||||
({
|
({
|
||||||
units := [{
|
units := [{
|
||||||
|
@ -215,6 +216,7 @@ def test_frontend_process_sorry : Test :=
|
||||||
("file", .str file),
|
("file", .str file),
|
||||||
("invocations", .bool false),
|
("invocations", .bool false),
|
||||||
("sorrys", .bool true),
|
("sorrys", .bool true),
|
||||||
|
("typeErrorsAsGoals", .bool false),
|
||||||
("newConstants", .bool false),
|
("newConstants", .bool false),
|
||||||
]
|
]
|
||||||
({
|
({
|
||||||
|
|
|
@ -53,6 +53,7 @@ def main (args: List String) := do
|
||||||
("Proofs", Proofs.suite env_default),
|
("Proofs", Proofs.suite env_default),
|
||||||
("Delate", Delate.suite env_default),
|
("Delate", Delate.suite env_default),
|
||||||
("Serial", Serial.suite env_default),
|
("Serial", Serial.suite env_default),
|
||||||
|
("Tactic/Assign", Tactic.Assign.suite env_default),
|
||||||
("Tactic/Congruence", Tactic.Congruence.suite env_default),
|
("Tactic/Congruence", Tactic.Congruence.suite env_default),
|
||||||
("Tactic/Motivated Apply", Tactic.MotivatedApply.suite env_default),
|
("Tactic/Motivated Apply", Tactic.MotivatedApply.suite env_default),
|
||||||
("Tactic/No Confuse", Tactic.NoConfuse.suite env_default),
|
("Tactic/No Confuse", Tactic.NoConfuse.suite env_default),
|
||||||
|
|
|
@ -239,7 +239,7 @@ def test_partial_continuation: TestM Unit := do
|
||||||
return ()
|
return ()
|
||||||
| .ok state => pure state
|
| .ok state => pure state
|
||||||
addTest $ LSpec.check "(continue)" ((← state1b.serializeGoals (options := ← read)).map (·.target.pp?) =
|
addTest $ LSpec.check "(continue)" ((← state1b.serializeGoals (options := ← read)).map (·.target.pp?) =
|
||||||
#[.some "2 ≤ ?m.succ", .some "?m.succ ≤ 5", .some "Nat"])
|
#[.some "2 ≤ Nat.succ ?m", .some "Nat.succ ?m ≤ 5", .some "Nat"])
|
||||||
addTest $ LSpec.test "(2 root)" state1b.rootExpr?.isNone
|
addTest $ LSpec.test "(2 root)" state1b.rootExpr?.isNone
|
||||||
|
|
||||||
-- Roundtrip
|
-- Roundtrip
|
||||||
|
@ -253,7 +253,7 @@ def test_partial_continuation: TestM Unit := do
|
||||||
return ()
|
return ()
|
||||||
| .ok state => pure state
|
| .ok state => pure state
|
||||||
addTest $ LSpec.check "(continue)" ((← state1b.serializeGoals (options := ← read)).map (·.target.pp?) =
|
addTest $ LSpec.check "(continue)" ((← state1b.serializeGoals (options := ← read)).map (·.target.pp?) =
|
||||||
#[.some "2 ≤ ?m.succ", .some "?m.succ ≤ 5", .some "Nat"])
|
#[.some "2 ≤ Nat.succ ?m", .some "Nat.succ ?m ≤ 5", .some "Nat"])
|
||||||
addTest $ LSpec.test "(2 root)" state1b.rootExpr?.isNone
|
addTest $ LSpec.test "(2 root)" state1b.rootExpr?.isNone
|
||||||
|
|
||||||
-- Continuation should fail if the state does not exist:
|
-- Continuation should fail if the state does not exist:
|
||||||
|
|
|
@ -97,7 +97,7 @@ def test_identity: TestM Unit := do
|
||||||
addTest $ LSpec.check tactic ((← state1.serializeGoals (options := ← read)).map (·.name) =
|
addTest $ LSpec.check tactic ((← state1.serializeGoals (options := ← read)).map (·.name) =
|
||||||
#[inner])
|
#[inner])
|
||||||
let state1parent ← state1.withParentContext do
|
let state1parent ← state1.withParentContext do
|
||||||
serializeExpressionSexp (← instantiateAll state1.parentExpr?.get!) (sanitize := false)
|
serializeExpressionSexp (← instantiateAll state1.parentExpr?.get!)
|
||||||
addTest $ LSpec.test "(1 parent)" (state1parent == s!"(:lambda p (:sort 0) (:lambda h 0 (:subst (:mv {inner}) 1 0)))")
|
addTest $ LSpec.test "(1 parent)" (state1parent == s!"(:lambda p (:sort 0) (:lambda h 0 (:subst (:mv {inner}) 1 0)))")
|
||||||
|
|
||||||
-- Individual test cases
|
-- Individual test cases
|
||||||
|
@ -241,13 +241,15 @@ def test_or_comm: TestM Unit := do
|
||||||
| other => do
|
| other => do
|
||||||
addTest $ assertUnreachable $ other.toString
|
addTest $ assertUnreachable $ other.toString
|
||||||
return ()
|
return ()
|
||||||
let fvP := "_uniq.10"
|
let [state1g0] := state1.goals | fail "Should have 1 goal"
|
||||||
let fvQ := "_uniq.13"
|
let (fvP, fvQ, fvH) ← state1.withContext state1g0 do
|
||||||
let fvH := "_uniq.16"
|
let lctx ← getLCtx
|
||||||
let state1g0 := "_uniq.17"
|
let #[fvP, fvQ, fvH] := lctx.getFVarIds.map (toString ·.name) |
|
||||||
|
panic! "Incorrect number of decls"
|
||||||
|
pure (fvP, fvQ, fvH)
|
||||||
addTest $ LSpec.check tactic ((← state1.serializeGoals (options := ← read)) =
|
addTest $ LSpec.check tactic ((← state1.serializeGoals (options := ← read)) =
|
||||||
#[{
|
#[{
|
||||||
name := state1g0,
|
name := state1g0.name.toString,
|
||||||
target := { pp? := .some "q ∨ p" },
|
target := { pp? := .some "q ∨ p" },
|
||||||
vars := #[
|
vars := #[
|
||||||
{ name := fvP, userName := "p", type? := .some { pp? := .some "Prop" } },
|
{ name := fvP, userName := "p", type? := .some { pp? := .some "Prop" } },
|
||||||
|
@ -259,7 +261,7 @@ def test_or_comm: TestM Unit := do
|
||||||
addTest $ LSpec.check "(1 root)" state1.rootExpr?.isNone
|
addTest $ LSpec.check "(1 root)" state1.rootExpr?.isNone
|
||||||
|
|
||||||
let state1parent ← state1.withParentContext do
|
let state1parent ← state1.withParentContext do
|
||||||
serializeExpressionSexp (← instantiateAll state1.parentExpr?.get!) (sanitize := false)
|
serializeExpressionSexp (← instantiateAll state1.parentExpr?.get!)
|
||||||
addTest $ LSpec.test "(1 parent)" (state1parent == s!"(:lambda p (:sort 0) (:lambda q (:sort 0) (:lambda h ((:c Or) 1 0) (:subst (:mv {state1g0}) 2 1 0))))")
|
addTest $ LSpec.test "(1 parent)" (state1parent == s!"(:lambda p (:sort 0) (:lambda q (:sort 0) (:lambda h ((:c Or) 1 0) (:subst (:mv {state1g0}) 2 1 0))))")
|
||||||
let tactic := "cases h"
|
let tactic := "cases h"
|
||||||
let state2 ← match ← state1.tacticOn (goalId := 0) (tactic := tactic) with
|
let state2 ← match ← state1.tacticOn (goalId := 0) (tactic := tactic) with
|
||||||
|
@ -269,14 +271,16 @@ def test_or_comm: TestM Unit := do
|
||||||
return ()
|
return ()
|
||||||
addTest $ LSpec.check tactic ((← state2.serializeGoals (options := ← read)).map (·.devolatilize) =
|
addTest $ LSpec.check tactic ((← state2.serializeGoals (options := ← read)).map (·.devolatilize) =
|
||||||
#[branchGoal "inl" "p", branchGoal "inr" "q"])
|
#[branchGoal "inl" "p", branchGoal "inr" "q"])
|
||||||
let (caseL, caseR) := ("_uniq.64", "_uniq.77")
|
let [state2g0, state2g1] := state2.goals |
|
||||||
|
fail s!"Should have 2 goals, but it has {state2.goals.length}"
|
||||||
|
let (caseL, caseR) := (state2g0.name.toString, state2g1.name.toString)
|
||||||
addTest $ LSpec.check tactic ((← state2.serializeGoals (options := ← read)).map (·.name) =
|
addTest $ LSpec.check tactic ((← state2.serializeGoals (options := ← read)).map (·.name) =
|
||||||
#[caseL, caseR])
|
#[caseL, caseR])
|
||||||
addTest $ LSpec.check "(2 parent exists)" state2.parentExpr?.isSome
|
addTest $ LSpec.check "(2 parent exists)" state2.parentExpr?.isSome
|
||||||
addTest $ LSpec.check "(2 root)" state2.rootExpr?.isNone
|
addTest $ LSpec.check "(2 root)" state2.rootExpr?.isNone
|
||||||
|
|
||||||
let state2parent ← state2.withParentContext do
|
let state2parent ← state2.withParentContext do
|
||||||
serializeExpressionSexp (← instantiateAll state2.parentExpr?.get!) (sanitize := false)
|
serializeExpressionSexp (← instantiateAll state2.parentExpr?.get!)
|
||||||
let orPQ := s!"((:c Or) (:fv {fvP}) (:fv {fvQ}))"
|
let orPQ := s!"((:c Or) (:fv {fvP}) (:fv {fvQ}))"
|
||||||
let orQP := s!"((:c Or) (:fv {fvQ}) (:fv {fvP}))"
|
let orQP := s!"((:c Or) (:fv {fvQ}) (:fv {fvP}))"
|
||||||
let motive := s!"(:lambda t {orPQ} (:forall h ((:c Eq) ((:c Or) (:fv {fvP}) (:fv {fvQ})) (:fv {fvH}) 0) {orQP}))"
|
let motive := s!"(:lambda t {orPQ} (:forall h ((:c Eq) ((:c Or) (:fv {fvP}) (:fv {fvQ})) (:fv {fvH}) 0) {orQP}))"
|
||||||
|
@ -292,8 +296,9 @@ def test_or_comm: TestM Unit := do
|
||||||
addTest $ assertUnreachable $ other.toString
|
addTest $ assertUnreachable $ other.toString
|
||||||
return ()
|
return ()
|
||||||
let state3_1parent ← state3_1.withParentContext do
|
let state3_1parent ← state3_1.withParentContext do
|
||||||
serializeExpressionSexp (← instantiateAll state3_1.parentExpr?.get!) (sanitize := false)
|
serializeExpressionSexp (← instantiateAll state3_1.parentExpr?.get!)
|
||||||
addTest $ LSpec.test "(3_1 parent)" (state3_1parent == s!"((:c Or.inr) (:fv {fvQ}) (:fv {fvP}) (:mv _uniq.91))")
|
let [state3_1goal0] := state3_1.goals | fail "Should have 1 goal"
|
||||||
|
addTest $ LSpec.test "(3_1 parent)" (state3_1parent == s!"((:c Or.inr) (:fv {fvQ}) (:fv {fvP}) (:mv {state3_1goal0}))")
|
||||||
addTest $ LSpec.check "· apply Or.inr" (state3_1.goals.length = 1)
|
addTest $ LSpec.check "· apply Or.inr" (state3_1.goals.length = 1)
|
||||||
let state4_1 ← match ← state3_1.tacticOn (goalId := 0) (tactic := "assumption") with
|
let state4_1 ← match ← state3_1.tacticOn (goalId := 0) (tactic := "assumption") with
|
||||||
| .success state => pure state
|
| .success state => pure state
|
||||||
|
@ -559,12 +564,15 @@ def test_nat_zero_add: TestM Unit := do
|
||||||
| other => do
|
| other => do
|
||||||
addTest $ assertUnreachable $ other.toString
|
addTest $ assertUnreachable $ other.toString
|
||||||
return ()
|
return ()
|
||||||
|
let [mvarMotive, mvarMajor, mvarInduct, mvarConduit] := state2.goals |
|
||||||
|
fail "Incorrect number of goals"
|
||||||
|
let .num _ major := mvarMajor.name | fail "Incorrect form of mvar id"
|
||||||
addTest $ LSpec.check s!"mapply {recursor}" ((← state2.serializeGoals (options := ← read)).map (·.devolatilizeVars) =
|
addTest $ LSpec.check s!"mapply {recursor}" ((← state2.serializeGoals (options := ← read)).map (·.devolatilizeVars) =
|
||||||
#[
|
#[
|
||||||
buildNamedGoal "_uniq.67" [("n", "Nat")] "Nat → Prop" (.some "motive"),
|
buildNamedGoal mvarMotive.name.toString [("n", "Nat")] "Nat → Prop" (.some "motive"),
|
||||||
buildNamedGoal "_uniq.68" [("n", "Nat")] "Nat",
|
buildNamedGoal mvarMajor.name.toString [("n", "Nat")] "Nat",
|
||||||
buildNamedGoal "_uniq.69" [("n", "Nat")] "∀ (t : Nat), Nat.below t → ?motive t",
|
buildNamedGoal mvarInduct.name.toString [("n", "Nat")] "∀ (t : Nat), Nat.below t → ?motive t",
|
||||||
buildNamedGoal "_uniq.70" [("n", "Nat")] "?motive ?m.68 = (n + 0 = n)" (.some "conduit")
|
buildNamedGoal mvarConduit.name.toString [("n", "Nat")] s!"?motive ?m.{major} = (n + 0 = n)" (.some "conduit")
|
||||||
])
|
])
|
||||||
|
|
||||||
let tactic := "exact n"
|
let tactic := "exact n"
|
||||||
|
@ -647,13 +655,15 @@ def test_nat_zero_add_alt: TestM Unit := do
|
||||||
| other => do
|
| other => do
|
||||||
addTest $ assertUnreachable $ other.toString
|
addTest $ assertUnreachable $ other.toString
|
||||||
return ()
|
return ()
|
||||||
let major := "_uniq.68"
|
let [mvarMotive, mvarMajor, mvarInduct, mvarConduit] := state2.goals |
|
||||||
|
fail "Incorrect number of goals"
|
||||||
|
let .num _ major := mvarMajor.name | fail "Incorrect form of mvar id"
|
||||||
addTest $ LSpec.check s!"mapply {recursor}" ((← state2.serializeGoals (options := ← read)).map (·.devolatilizeVars) =
|
addTest $ LSpec.check s!"mapply {recursor}" ((← state2.serializeGoals (options := ← read)).map (·.devolatilizeVars) =
|
||||||
#[
|
#[
|
||||||
buildNamedGoal "_uniq.67" [("n", "Nat")] "Nat → Prop" (.some "motive"),
|
buildNamedGoal mvarMotive.name.toString [("n", "Nat")] "Nat → Prop" (.some "motive"),
|
||||||
buildNamedGoal major [("n", "Nat")] "Nat",
|
buildNamedGoal mvarMajor.name.toString [("n", "Nat")] "Nat",
|
||||||
buildNamedGoal "_uniq.69" [("n", "Nat")] "∀ (t : Nat), Nat.below t → ?motive t",
|
buildNamedGoal mvarInduct.name.toString [("n", "Nat")] "∀ (t : Nat), Nat.below t → ?motive t",
|
||||||
buildNamedGoal "_uniq.70" [("n", "Nat")] "?motive ?m.68 = (n + 0 = n)" (.some "conduit")
|
buildNamedGoal mvarConduit.name.toString [("n", "Nat")] s!"?motive ?m.{major} = (n + 0 = n)" (.some "conduit")
|
||||||
])
|
])
|
||||||
|
|
||||||
let tactic := "intro x"
|
let tactic := "intro x"
|
||||||
|
@ -670,8 +680,7 @@ def test_nat_zero_add_alt: TestM Unit := do
|
||||||
| other => do
|
| other => do
|
||||||
addTest $ assertUnreachable $ other.toString
|
addTest $ assertUnreachable $ other.toString
|
||||||
return ()
|
return ()
|
||||||
let (eqL, eqR, eqT) := ("_uniq.88", "_uniq.89", "_uniq.87")
|
let [eqL, eqR, eqT] := state3m2.goals | fail "Incorrect number of goals"
|
||||||
addTest $ LSpec.check tactic $ state3m2.goals.map (·.name.toString) = [eqL, eqR, eqT]
|
|
||||||
let [_motive, _major, _step, conduit] := state2.goals | panic! "Goals conflict"
|
let [_motive, _major, _step, conduit] := state2.goals | panic! "Goals conflict"
|
||||||
let state2b ← match state3m2.resume [conduit] with
|
let state2b ← match state3m2.resume [conduit] with
|
||||||
| .ok state => pure state
|
| .ok state => pure state
|
||||||
|
@ -681,20 +690,26 @@ def test_nat_zero_add_alt: TestM Unit := do
|
||||||
|
|
||||||
let cNatAdd := "(:c HAdd.hAdd) (:c Nat) (:c Nat) (:c Nat) ((:c instHAdd) (:c Nat) (:c instAddNat))"
|
let cNatAdd := "(:c HAdd.hAdd) (:c Nat) (:c Nat) (:c Nat) ((:c instHAdd) (:c Nat) (:c instAddNat))"
|
||||||
let cNat0 := "((:c OfNat.ofNat) (:c Nat) (:lit 0) ((:c instOfNatNat) (:lit 0)))"
|
let cNat0 := "((:c OfNat.ofNat) (:c Nat) (:lit 0) ((:c instOfNatNat) (:lit 0)))"
|
||||||
let fvN := "_uniq.63"
|
let fvN ← state2b.withContext conduit do
|
||||||
|
let lctx ← getLCtx
|
||||||
|
pure $ lctx.getFVarIds.get! 0 |>.name
|
||||||
let conduitRight := s!"((:c Eq) (:c Nat) ({cNatAdd} (:fv {fvN}) {cNat0}) (:fv {fvN}))"
|
let conduitRight := s!"((:c Eq) (:c Nat) ({cNatAdd} (:fv {fvN}) {cNat0}) (:fv {fvN}))"
|
||||||
let substOf (mv: String) := s!"(:subst (:mv {mv}) (:fv {fvN}) (:mv {major}))"
|
let substOf (mvarId: MVarId) := s!"(:subst (:mv {mvarId.name}) (:fv {fvN}) (:mv {mvarMajor}))"
|
||||||
|
let .num _ nL := eqL.name | fail "Incorrect form of mvar id"
|
||||||
|
let .num _ nR := eqR.name | fail "Incorrect form of mvar id"
|
||||||
|
let nL' := nL + 4
|
||||||
|
let nR' := nR + 5
|
||||||
addTest $ LSpec.check "resume" ((← state2b.serializeGoals (options := { ← read with printExprAST := true })) =
|
addTest $ LSpec.check "resume" ((← state2b.serializeGoals (options := { ← read with printExprAST := true })) =
|
||||||
#[
|
#[
|
||||||
{
|
{
|
||||||
name := "_uniq.70",
|
name := mvarConduit.name.toString,
|
||||||
userName? := .some "conduit",
|
userName? := .some "conduit",
|
||||||
target := {
|
target := {
|
||||||
pp? := .some "(?m.92 ?m.68 = ?m.94 ?m.68) = (n + 0 = n)",
|
pp? := .some s!"(?m.{nL'} ?m.{major} = ?m.{nR'} ?m.{major}) = (n + 0 = n)",
|
||||||
sexp? := .some s!"((:c Eq) (:sort 0) ((:c Eq) {substOf eqT} {substOf eqL} {substOf eqR}) {conduitRight})",
|
sexp? := .some s!"((:c Eq) (:sort 0) ((:c Eq) {substOf eqT} {substOf eqL} {substOf eqR}) {conduitRight})",
|
||||||
},
|
},
|
||||||
vars := #[{
|
vars := #[{
|
||||||
name := fvN,
|
name := fvN.toString,
|
||||||
userName := "n",
|
userName := "n",
|
||||||
type? := .some { pp? := .some "Nat", sexp? := .some "(:c Nat)" },
|
type? := .some { pp? := .some "Nat", sexp? := .some "(:c Nat)" },
|
||||||
}],
|
}],
|
||||||
|
@ -720,7 +735,6 @@ def test_tactic_failure_unresolved_goals : TestM Unit := do
|
||||||
let .failure messages ← state1.tacticOn 0 tactic | addTest $ assertUnreachable s!"{tactic} should fail"
|
let .failure messages ← state1.tacticOn 0 tactic | addTest $ assertUnreachable s!"{tactic} should fail"
|
||||||
checkEq s!"{tactic} fails" messages #[s!"{← getFileName}:0:12: error: unsolved goals\np : Nat → Prop\n⊢ p 0\n"]
|
checkEq s!"{tactic} fails" messages #[s!"{← getFileName}:0:12: error: unsolved goals\np : Nat → Prop\n⊢ p 0\n"]
|
||||||
|
|
||||||
|
|
||||||
def test_tactic_failure_synthesize_placeholder : TestM Unit := do
|
def test_tactic_failure_synthesize_placeholder : TestM Unit := do
|
||||||
let state? ← startProof (.expr "∀ (p q r : Prop) (h : p → q), q ∧ r")
|
let state? ← startProof (.expr "∀ (p q r : Prop) (h : p → q), q ∧ r")
|
||||||
let state0 ← match state? with
|
let state0 ← match state? with
|
||||||
|
@ -736,20 +750,25 @@ def test_tactic_failure_synthesize_placeholder : TestM Unit := do
|
||||||
addTest $ assertUnreachable $ other.toString
|
addTest $ assertUnreachable $ other.toString
|
||||||
return ()
|
return ()
|
||||||
|
|
||||||
|
let iex : InternalExceptionId := { idx := 4 }
|
||||||
|
IO.println s!"{← iex.getName}"
|
||||||
let tactic := "simpa [h] using And.imp_left h _"
|
let tactic := "simpa [h] using And.imp_left h _"
|
||||||
let state2 ← match ← state1.tacticOn 0 tactic with
|
--let state2 ← match ← state1.tacticOn 0 tactic with
|
||||||
| .success state => pure state
|
-- | .success state => pure state
|
||||||
| other => do
|
-- | other => do
|
||||||
addTest $ assertUnreachable $ other.toString
|
-- addTest $ assertUnreachable $ other.toString
|
||||||
return ()
|
-- return ()
|
||||||
|
|
||||||
checkEq tactic ((← state2.serializeGoals).map (·.devolatilize)) #[
|
-- Volatile behaviour. This easily changes across Lean versions
|
||||||
buildGoal [("p", "Prop"), ("q", "Prop"), ("r", "Prop"), ("h", "p → q")] "p ∧ r"
|
|
||||||
]
|
--checkEq tactic ((← state2.serializeGoals).map (·.devolatilize)) #[
|
||||||
|
-- buildGoal [("p", "Prop"), ("q", "Prop"), ("r", "Prop"), ("h", "p → q")] "p ∧ r"
|
||||||
|
--]
|
||||||
|
|
||||||
|
let .failure messages ← state1.tacticOn 0 tactic | addTest $ assertUnreachable s!"{tactic} should fail"
|
||||||
|
let message := s!"<Pantograph>:0:31: error: don't know how to synthesize placeholder\ncontext:\np q r : Prop\nh : p → q\n⊢ p ∧ r\n"
|
||||||
|
checkEq s!"{tactic} fails" messages #[message]
|
||||||
|
|
||||||
--let .failure messages ← state1.tacticOn 0 tactic | addTest $ assertUnreachable s!"{tactic} should fail"
|
|
||||||
--let message := s!"<Pantograph>:0:31: error: don't know how to synthesize placeholder\ncontext:\np q r : Prop\nh : p → q\n⊢ p ∧ r\n"
|
|
||||||
--checkEq s!"{tactic} fails" messages #[message]
|
|
||||||
|
|
||||||
def suite (env: Environment): List (String × IO LSpec.TestSeq) :=
|
def suite (env: Environment): List (String × IO LSpec.TestSeq) :=
|
||||||
let tests := [
|
let tests := [
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import Test.Tactic.Assign
|
||||||
import Test.Tactic.Congruence
|
import Test.Tactic.Congruence
|
||||||
import Test.Tactic.MotivatedApply
|
import Test.Tactic.MotivatedApply
|
||||||
import Test.Tactic.NoConfuse
|
import Test.Tactic.NoConfuse
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
import Lean.Meta
|
||||||
|
import Lean.Elab
|
||||||
|
import LSpec
|
||||||
|
import Test.Common
|
||||||
|
|
||||||
|
open Lean
|
||||||
|
|
||||||
|
namespace Pantograph.Test.Tactic.Assign
|
||||||
|
|
||||||
|
def test_draft : TestT Elab.TermElabM Unit := do
|
||||||
|
let expr := "forall (p : Prop), (p ∨ p) ∨ p"
|
||||||
|
let skeleton := "by\nhave a : p ∨ p := sorry\nsorry"
|
||||||
|
let expr ← parseSentence expr
|
||||||
|
Meta.forallTelescope expr $ λ _ body => do
|
||||||
|
let skeleton' ← match Parser.runParserCategory
|
||||||
|
(env := ← MonadEnv.getEnv)
|
||||||
|
(catName := `term)
|
||||||
|
(input := skeleton)
|
||||||
|
(fileName := ← getFileName) with
|
||||||
|
| .ok syn => pure syn
|
||||||
|
| .error error => throwError "Failed to parse: {error}"
|
||||||
|
-- Apply the tactic
|
||||||
|
let target ← Meta.mkFreshExprSyntheticOpaqueMVar body
|
||||||
|
let tactic := Tactic.evalDraft skeleton'
|
||||||
|
let newGoals ← runTacticOnMVar tactic target.mvarId!
|
||||||
|
addTest $ LSpec.check "goals" ((← newGoals.mapM (λ g => do exprToStr (← g.getType))) = ["p ∨ p", "(p ∨ p) ∨ p"])
|
||||||
|
|
||||||
|
def suite (env: Environment): List (String × IO LSpec.TestSeq) :=
|
||||||
|
[
|
||||||
|
("draft", test_draft),
|
||||||
|
] |>.map (λ (name, t) => (name, runTestTermElabM env t))
|
||||||
|
|
||||||
|
end Pantograph.Test.Tactic.Assign
|
|
@ -28,7 +28,7 @@ def test_congr_arg_list : TestT Elab.TermElabM Unit := do
|
||||||
let results ← Meta.withAssignableSyntheticOpaque do f.apply (← parseSentence "List.reverse")
|
let results ← Meta.withAssignableSyntheticOpaque do f.apply (← parseSentence "List.reverse")
|
||||||
addTest $ LSpec.check "apply" (results.length = 0)
|
addTest $ LSpec.check "apply" (results.length = 0)
|
||||||
addTest $ LSpec.check "h" ((← exprToStr $ ← h.getType) = "?a₁ = ?a₂")
|
addTest $ LSpec.check "h" ((← exprToStr $ ← h.getType) = "?a₁ = ?a₂")
|
||||||
addTest $ LSpec.check "conduit" ((← exprToStr $ ← c.getType) = "(?a₁.reverse = ?a₂.reverse) = (l1.reverse = l2.reverse)")
|
addTest $ LSpec.check "conduit" ((← exprToStr $ ← c.getType) = "(List.reverse ?a₁ = List.reverse ?a₂) = (l1.reverse = l2.reverse)")
|
||||||
def test_congr_arg : TestT Elab.TermElabM Unit := do
|
def test_congr_arg : TestT Elab.TermElabM Unit := do
|
||||||
let expr := "λ (n m: Nat) (h: n = m) => n * n = m * m"
|
let expr := "λ (n m: Nat) (h: n = m) => n * n = m * m"
|
||||||
let expr ← parseSentence expr
|
let expr ← parseSentence expr
|
||||||
|
@ -37,7 +37,7 @@ def test_congr_arg : TestT Elab.TermElabM Unit := do
|
||||||
let newGoals ← runTacticOnMVar Tactic.evalCongruenceArg target.mvarId!
|
let newGoals ← runTacticOnMVar Tactic.evalCongruenceArg target.mvarId!
|
||||||
addTest $ LSpec.check "goals" ((← newGoals.mapM (λ x => mvarUserNameAndType x)) =
|
addTest $ LSpec.check "goals" ((← newGoals.mapM (λ x => mvarUserNameAndType x)) =
|
||||||
[
|
[
|
||||||
(`α, "Sort ?u.70"),
|
(`α, "Sort ?u.73"),
|
||||||
(`a₁, "?α"),
|
(`a₁, "?α"),
|
||||||
(`a₂, "?α"),
|
(`a₂, "?α"),
|
||||||
(`f, "?α → Nat"),
|
(`f, "?α → Nat"),
|
||||||
|
@ -52,7 +52,7 @@ def test_congr_fun : TestT Elab.TermElabM Unit := do
|
||||||
let newGoals ← runTacticOnMVar Tactic.evalCongruenceFun target.mvarId!
|
let newGoals ← runTacticOnMVar Tactic.evalCongruenceFun target.mvarId!
|
||||||
addTest $ LSpec.check "goals" ((← newGoals.mapM (λ x => mvarUserNameAndType x)) =
|
addTest $ LSpec.check "goals" ((← newGoals.mapM (λ x => mvarUserNameAndType x)) =
|
||||||
[
|
[
|
||||||
(`α, "Sort ?u.159"),
|
(`α, "Sort ?u.165"),
|
||||||
(`f₁, "?α → Nat"),
|
(`f₁, "?α → Nat"),
|
||||||
(`f₂, "?α → Nat"),
|
(`f₂, "?α → Nat"),
|
||||||
(`h, "?f₁ = ?f₂"),
|
(`h, "?f₁ = ?f₂"),
|
||||||
|
|
|
@ -40,7 +40,7 @@ def test_nat_brec_on : TestT Elab.TermElabM Unit := do
|
||||||
"Nat → Prop",
|
"Nat → Prop",
|
||||||
"Nat",
|
"Nat",
|
||||||
"∀ (t : Nat), Nat.below t → ?motive t",
|
"∀ (t : Nat), Nat.below t → ?motive t",
|
||||||
"?motive ?m.67 = (n + 0 = n)",
|
"?motive ?m.74 = (n + 0 = n)",
|
||||||
])
|
])
|
||||||
addTest test
|
addTest test
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ def test_partial_motive_instantiation : TestT Elab.TermElabM Unit := do
|
||||||
let target ← Meta.mkFreshExprSyntheticOpaqueMVar body
|
let target ← Meta.mkFreshExprSyntheticOpaqueMVar body
|
||||||
let tactic := Tactic.evalMotivatedApply recursor
|
let tactic := Tactic.evalMotivatedApply recursor
|
||||||
let newGoals ← runTacticOnMVar tactic target.mvarId!
|
let newGoals ← runTacticOnMVar tactic target.mvarId!
|
||||||
let majorId := 67
|
let majorId := 74
|
||||||
addTest $ (LSpec.check "goals" ((← newGoals.mapM (λ g => do exprToStr (← g.getType))) =
|
addTest $ (LSpec.check "goals" ((← newGoals.mapM (λ g => do exprToStr (← g.getType))) =
|
||||||
[
|
[
|
||||||
"Nat → Prop",
|
"Nat → Prop",
|
||||||
|
@ -100,7 +100,7 @@ def test_partial_motive_instantiation : TestT Elab.TermElabM Unit := do
|
||||||
|
|
||||||
addTest $ ← conduit.withContext do
|
addTest $ ← conduit.withContext do
|
||||||
let t := toString (← Meta.ppExpr $ ← conduit.getType)
|
let t := toString (← Meta.ppExpr $ ← conduit.getType)
|
||||||
return LSpec.check "conduit" (t = s!"(?m.{majorId}.add + 0 = ?m.138 ?m.{majorId}) = (n + 0 = n)")
|
return LSpec.check "conduit" (t = s!"(Nat.add ?m.{majorId} + 0 = ?m.149 ?m.{majorId}) = (n + 0 = n)")
|
||||||
|
|
||||||
def suite (env: Environment): List (String × IO LSpec.TestSeq) :=
|
def suite (env: Environment): List (String × IO LSpec.TestSeq) :=
|
||||||
[
|
[
|
||||||
|
|
12
doc/repl.md
12
doc/repl.md
|
@ -33,6 +33,7 @@ See `Pantograph/Protocol.lean` for a description of the parameters and return va
|
||||||
to the previous `rhs`.
|
to the previous `rhs`.
|
||||||
- `{ "conv": <bool> }`: Enter or exit conversion tactic mode. In the case of
|
- `{ "conv": <bool> }`: Enter or exit conversion tactic mode. In the case of
|
||||||
exit, the goal id is ignored.
|
exit, the goal id is ignored.
|
||||||
|
- `{ "draft": <expr> }`: Draft an expression with `sorry`s, turning them into goals. Coupling is not allowed.
|
||||||
* `goal.continue {"stateId": <id>, ["branch": <id>], ["goals": <names>]}`:
|
* `goal.continue {"stateId": <id>, ["branch": <id>], ["goals": <names>]}`:
|
||||||
Execute continuation/resumption
|
Execute continuation/resumption
|
||||||
- `{ "branch": <id> }`: Continue on branch state. The current state must have no goals.
|
- `{ "branch": <id> }`: Continue on branch state. The current state must have no goals.
|
||||||
|
@ -44,11 +45,12 @@ See `Pantograph/Protocol.lean` for a description of the parameters and return va
|
||||||
state. The user is responsible to ensure the sender/receiver instances share
|
state. The user is responsible to ensure the sender/receiver instances share
|
||||||
the same environment.
|
the same environment.
|
||||||
* `frontend.process { ["fileName": <fileName>,] ["file": <str>], invocations:
|
* `frontend.process { ["fileName": <fileName>,] ["file": <str>], invocations:
|
||||||
<bool>, sorrys: <bool>, newConstants: <bool> }`: Executes the Lean frontend on
|
<bool>, sorrys: <bool>, typeErrorsAsGoals: <bool>, newConstants: <bool> }`:
|
||||||
a file, collecting the tactic invocations (`"invocations": true`), the
|
Executes the Lean frontend on a file, collecting the tactic invocations
|
||||||
sorrys and type errors into goal states (`"sorrys": true`), and new constants
|
(`"invocations": true`), the sorrys and type errors into goal states
|
||||||
(`"newConstants": true`). In the case of `sorrys`, this command additionally
|
(`"sorrys": true`), and new constants (`"newConstants": true`). In the case of
|
||||||
outputs the position of each captured `sorry`.
|
`sorrys`, this command additionally outputs the position of each captured
|
||||||
|
`sorry`.
|
||||||
|
|
||||||
## Errors
|
## Errors
|
||||||
|
|
||||||
|
|
|
@ -42,11 +42,11 @@
|
||||||
"nixpkgs": "nixpkgs"
|
"nixpkgs": "nixpkgs"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1731711316,
|
"lastModified": 1736388194,
|
||||||
"narHash": "sha256-s5u+A2/Ea9gPveB5wwVM5dWW0NST6kamDsTeovGuLEs=",
|
"narHash": "sha256-ymSrd/A8Pw+9FzbxUbR7CkFHLJK1b4SnFFWg/1e0JeE=",
|
||||||
"owner": "lenianiva",
|
"owner": "lenianiva",
|
||||||
"repo": "lean4-nix",
|
"repo": "lean4-nix",
|
||||||
"rev": "136fc6057c48de970579e960b62421e9c295b67d",
|
"rev": "90f496bc0694fb97bdfa6adedfc2dc2c841a4cf2",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
157
flake.nix
157
flake.nix
|
@ -18,82 +18,89 @@
|
||||||
lean4-nix,
|
lean4-nix,
|
||||||
lspec,
|
lspec,
|
||||||
...
|
...
|
||||||
} : flake-parts.lib.mkFlake { inherit inputs; } {
|
}:
|
||||||
flake = {
|
flake-parts.lib.mkFlake {inherit inputs;} {
|
||||||
};
|
flake = {
|
||||||
systems = [
|
|
||||||
"aarch64-linux"
|
|
||||||
"aarch64-darwin"
|
|
||||||
"x86_64-linux"
|
|
||||||
"x86_64-darwin"
|
|
||||||
];
|
|
||||||
perSystem = { system, pkgs, ... }: let
|
|
||||||
pkgs = import nixpkgs {
|
|
||||||
inherit system;
|
|
||||||
overlays = [ (lean4-nix.readToolchainFile ./lean-toolchain) ];
|
|
||||||
};
|
};
|
||||||
lspecLib = pkgs.lean.buildLeanPackage {
|
systems = [
|
||||||
name = "LSpec";
|
"aarch64-linux"
|
||||||
roots = [ "Main" "LSpec" ];
|
"aarch64-darwin"
|
||||||
src = "${lspec}";
|
"x86_64-linux"
|
||||||
};
|
"x86_64-darwin"
|
||||||
project = pkgs.lean.buildLeanPackage {
|
];
|
||||||
name = "Pantograph";
|
perSystem = {
|
||||||
roots = [ "Pantograph" ];
|
system,
|
||||||
src = pkgs.lib.cleanSource (pkgs.lib.cleanSourceWith {
|
pkgs,
|
||||||
src = ./.;
|
...
|
||||||
filter = path: type:
|
}: let
|
||||||
!(pkgs.lib.hasInfix "/Test/" path) &&
|
pkgs = import nixpkgs {
|
||||||
!(pkgs.lib.hasSuffix ".md" path) &&
|
inherit system;
|
||||||
!(pkgs.lib.hasSuffix "Repl.lean" path);
|
overlays = [(lean4-nix.readToolchainFile ./lean-toolchain)];
|
||||||
});
|
};
|
||||||
};
|
lspecLib = pkgs.lean.buildLeanPackage {
|
||||||
repl = pkgs.lean.buildLeanPackage {
|
name = "LSpec";
|
||||||
name = "Repl";
|
roots = ["Main" "LSpec"];
|
||||||
roots = [ "Main" "Repl" ];
|
src = "${lspec}";
|
||||||
deps = [ project ];
|
};
|
||||||
src = pkgs.lib.cleanSource (pkgs.lib.cleanSourceWith {
|
project = pkgs.lean.buildLeanPackage {
|
||||||
src = ./.;
|
name = "Pantograph";
|
||||||
filter = path: type:
|
roots = ["Pantograph"];
|
||||||
!(pkgs.lib.hasInfix "/Test/" path) &&
|
src = pkgs.lib.cleanSource (pkgs.lib.cleanSourceWith {
|
||||||
!(pkgs.lib.hasSuffix ".md" path);
|
src = ./.;
|
||||||
});
|
filter = path: type:
|
||||||
};
|
!(pkgs.lib.hasInfix "/Test/" path)
|
||||||
test = pkgs.lean.buildLeanPackage {
|
&& !(pkgs.lib.hasSuffix ".md" path)
|
||||||
name = "Test";
|
&& !(pkgs.lib.hasSuffix "Repl.lean" path);
|
||||||
# NOTE: The src directory must be ./. since that is where the import
|
});
|
||||||
# root begins (e.g. `import Test.Environment` and not `import
|
};
|
||||||
# Environment`) and thats where `lakefile.lean` resides.
|
repl = pkgs.lean.buildLeanPackage {
|
||||||
roots = [ "Test.Main" ];
|
name = "Repl";
|
||||||
deps = [ lspecLib repl ];
|
roots = ["Main" "Repl"];
|
||||||
src = pkgs.lib.cleanSource (pkgs.lib.cleanSourceWith {
|
deps = [project];
|
||||||
src = ./.;
|
src = pkgs.lib.cleanSource (pkgs.lib.cleanSourceWith {
|
||||||
filter = path: type:
|
src = ./.;
|
||||||
!(pkgs.lib.hasInfix "Pantograph" path);
|
filter = path: type:
|
||||||
});
|
!(pkgs.lib.hasInfix "/Test/" path)
|
||||||
};
|
&& !(pkgs.lib.hasSuffix ".md" path);
|
||||||
in rec {
|
});
|
||||||
packages = {
|
};
|
||||||
inherit (pkgs.lean) lean lean-all;
|
test = pkgs.lean.buildLeanPackage {
|
||||||
inherit (project) sharedLib iTree;
|
name = "Test";
|
||||||
inherit (repl) executable;
|
# NOTE: The src directory must be ./. since that is where the import
|
||||||
default = repl.executable;
|
# root begins (e.g. `import Test.Environment` and not `import
|
||||||
};
|
# Environment`) and thats where `lakefile.lean` resides.
|
||||||
legacyPackages = {
|
roots = ["Test.Main"];
|
||||||
inherit project;
|
deps = [lspecLib repl];
|
||||||
leanPkgs = pkgs.lean;
|
src = pkgs.lib.cleanSource (pkgs.lib.cleanSourceWith {
|
||||||
};
|
src = ./.;
|
||||||
checks = {
|
filter = path: type:
|
||||||
test = pkgs.runCommand "test" {
|
!(pkgs.lib.hasInfix "Pantograph" path);
|
||||||
buildInputs = [ test.executable pkgs.lean.lean-all ];
|
});
|
||||||
} ''
|
};
|
||||||
#export LEAN_SRC_PATH="${./.}"
|
in rec {
|
||||||
${test.executable}/bin/test > $out
|
packages = {
|
||||||
'';
|
inherit (pkgs.lean) lean lean-all;
|
||||||
};
|
inherit (project) sharedLib iTree;
|
||||||
devShells.default = pkgs.mkShell {
|
inherit (repl) executable;
|
||||||
buildInputs = [ pkgs.lean.lean-all pkgs.lean.lean ];
|
default = repl.executable;
|
||||||
|
};
|
||||||
|
legacyPackages = {
|
||||||
|
inherit project;
|
||||||
|
leanPkgs = pkgs.lean;
|
||||||
|
};
|
||||||
|
checks = {
|
||||||
|
test =
|
||||||
|
pkgs.runCommand "test" {
|
||||||
|
buildInputs = [test.executable pkgs.lean.lean-all];
|
||||||
|
} ''
|
||||||
|
#export LEAN_SRC_PATH="${./.}"
|
||||||
|
${test.executable}/bin/test > $out
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
formatter = pkgs.alejandra;
|
||||||
|
devShells.default = pkgs.mkShell {
|
||||||
|
buildInputs = [pkgs.lean.lean-all pkgs.lean.lean];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
leanprover/lean4:v4.12.0
|
leanprover/lean4:v4.15.0
|
||||||
|
|
Loading…
Reference in New Issue