-
Notifications
You must be signed in to change notification settings - Fork 47
feat: istart with BI specified #505
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
base: master
Are you sure you want to change the base?
Changes from all commits
cabbf85
c2aa27a
392c4a0
5d7c8a1
d843263
674afa4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -109,29 +109,45 @@ def ProofModeM.synthInstanceQ (α : Q(Sort v)) : ProofModeM Q($α) := do | |
| return e | ||
|
|
||
| /-- Initialize proof mode for a metavariable, converting it to an Iris goal. -/ | ||
| def startProofMode (mvar : MVarId) : MetaM (MVarId × IrisGoal) := mvar.withContext do | ||
| def startProofMode (mvar : MVarId) (customProp : Option Expr := none) : | ||
| MetaM (MVarId × IrisGoal) := mvar.withContext do | ||
| -- parse goal | ||
| let goal ← instantiateMVars <| ← mvar.getType | ||
|
|
||
| -- check if already in proof mode | ||
| if let some irisGoal := parseIrisGoal? goal then | ||
| customProp.forM <| fun customProp => do | ||
| let eq ← isDefEq irisGoal.prop customProp | ||
| if !eq then throwError m!"istart: currently in the Iris Proof Mode with \ | ||
| {irisGoal.prop} rather than {customProp}" | ||
| return (mvar, irisGoal) | ||
|
|
||
| let some goal ← checkTypeQ goal q(Prop) | ||
| | throwError "type mismatch\n{← mkHasTypeButIsExpectedMsg (← inferType goal) q(Prop)}" | ||
| let u ← mkFreshLevelMVar | ||
| let prop ← mkFreshExprMVarQ q(Type u) | ||
|
|
||
| customProp.forM <| fun customProp => do | ||
| let eq ← isDefEq prop customProp | ||
| if !eq then throwError "istart: {customProp} is not a valid BI instance type" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can be simplified as above. |
||
|
|
||
| let P ← mkFreshExprMVarQ q($prop) | ||
| let bi ← mkFreshExprMVarQ q(BI $prop) | ||
| let .some (_, mvars) ← ProofMode.trySynthInstanceQ q(AsEmpValid .from $goal .out $prop .out $bi $P) | ||
| | throwError "istart: {goal} is not an emp valid" | ||
| if !mvars.isEmpty then throwError "istart does not support creating mvars" | ||
|
|
||
| let irisGoal := { u, prop, bi, hyps := .mkEmp bi, goal := P, .. } | ||
| let subgoal : Quoted q(⊢ $P) ← | ||
| mkFreshExprSyntheticOpaqueMVar (IrisGoal.toExpr irisGoal) (← mvar.getTag) | ||
| mvar.assign q(asEmpValid_2 $goal $subgoal) | ||
| pure (subgoal.mvarId!, irisGoal) | ||
| let io : Q(InOut) := if customProp.isSome then q(.in) else q(.out) | ||
| let synthResult ← ProofMode.trySynthInstanceQ q(AsEmpValid .from $goal $io $prop .out $bi $P) | ||
|
|
||
| match synthResult, customProp with | ||
| | .some (inst, mvars), _ => | ||
| if !mvars.isEmpty then throwError "istart does not support creating mvars" | ||
| let irisGoal := { u, prop, bi, hyps := .mkEmp bi, goal := P, .. } | ||
| let subgoal : Quoted q(⊢ $P) ← | ||
| mkFreshExprSyntheticOpaqueMVar (IrisGoal.toExpr irisGoal) (← mvar.getTag) | ||
| mvar.assign q(asEmpValid_2 $goal $inst $subgoal) | ||
| pure (subgoal.mvarId!, irisGoal) | ||
| | _, none => | ||
| throwError "istart: {goal} is not an emp valid" | ||
| | _, some _ => | ||
| throwError "istart: {goal} is not an emp valid in {customProp}" | ||
|
|
||
| /-- Run a ProofModeM computation on the main goal, ordering resulting goals with dependencies last. -/ | ||
| def ProofModeM.runTactic (x : MVarId → IrisGoal → ProofModeM α) (s : ProofModeM.State := {}) : TacticM α := do | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,10 +24,48 @@ open BI CMRA DFrac | |
| example [BI PROP] (Q : PROP) (H : Q ⊢ Q) : Q ⊢ Q := by | ||
| istart | ||
| iintro _HQ | ||
| have HH: True := by trivial | ||
| have HH : True := by trivial | ||
| istop | ||
| exact H | ||
|
|
||
| /-- Tests `istart` with a BI instance specified. -/ | ||
| example [BI PROP1] [BI PROP2] (P1 : PROP1) (P2 : PROP2) | ||
| (_ : ⊢@{PROP1} P1) : ⊢@{PROP2} P2 -∗ P2 := by | ||
| istart PROP2 | ||
| iintro HP | ||
| iassumption | ||
|
|
||
| /- Tests `istart` with the wrong BI instance specified. -/ | ||
| /-- error: istart: ⊢ P2 is not an emp valid in PROP1 -/ | ||
| #guard_msgs in | ||
| example [BI PROP1] [BI PROP2] (P1 : PROP1) (P2 : PROP2) | ||
| (h : ⊢@{PROP1} P1) : ⊢@{PROP2} P2 := by | ||
| istart PROP1 | ||
|
|
||
| /- Tests `istart` with an invalid type specified as the BI instance. -/ | ||
| /-- error: istart: True is not a valid BI instance type -/ | ||
| #guard_msgs in | ||
| example [BI PROP1] [BI PROP2] (P1 : PROP1) (P2 : PROP2) | ||
| (h : ⊢@{PROP1} P1) : ⊢@{PROP2} P2 := by | ||
| istart True | ||
|
|
||
| /- Tests `istart` within the Iris Proof Mode. -/ | ||
| example [BI PROP1] [BI PROP2] (P1 : PROP1) (P2 : PROP2) | ||
| (_ : ⊢@{PROP1} P1) : ⊢@{PROP2} P2 -∗ P2 := by | ||
| iintro P2 | ||
| istart PROP2 | ||
| istart | ||
| istart PROP2 | ||
| iassumption | ||
|
|
||
| /- Tests `istart` within the Iris Proof Mode with the wrong BI instance specified. -/ | ||
| /-- error: istart: currently in the Iris Proof Mode with PROP2 rather than PROP1 -/ | ||
| #guard_msgs in | ||
| example [BI PROP1] [BI PROP2] (P1 : PROP1) (P2 : PROP2) | ||
| (_ : ⊢@{PROP1} P1) : ⊢@{PROP2} P2 -∗ P2 := by | ||
| iintro P2 | ||
| istart PROP1 | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The usecase for specifying the type of propositions explicitly is for embeddings. Can you please port this instance and test that it works? |
||
| -- rename | ||
| namespace rename | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not tested, but I think something like the following would be a bit simpler: