| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
open CErrors |
| 12 |
open Util |
| 13 |
open Pp |
| 14 |
open CAst |
| 15 |
open Vernacextend |
| 16 |
open Vernacexpr |
| 17 |
|
| 18 |
let string_of_vernac_when = function |
| 19 |
| VtLater -> "Later" |
| 20 |
| VtNow -> "Now" |
| 21 |
|
| 22 |
let string_of_vernac_classification = function |
| 23 |
| VtStartProof _ -> "StartProof" |
| 24 |
| VtSideff (_,w) -> "Sideff"^" "^(string_of_vernac_when w) |
| 25 |
| VtQed (VtKeep VtKeepAxiom) -> "Qed(admitted)" |
| 26 |
| VtQed (VtKeep (VtKeepOpaque | VtKeepDefined)) -> "Qed(keep)" |
| 27 |
| VtQed VtDrop -> "Qed(drop)" |
| 28 |
| VtProofStep { proof_block_detection } -> |
| 29 |
"ProofStep " ^ Option.default "" proof_block_detection |
| 30 |
| VtQuery -> "Query" |
| 31 |
| VtMeta -> "Meta " |
| 32 |
| VtProofMode _ -> "Proof Mode" |
| 33 |
|
| 34 |
let vtkeep_of_opaque = function |
| 35 |
| Opaque -> VtKeepOpaque |
| 36 |
| Transparent -> VtKeepDefined |
| 37 |
|
| 38 |
let idents_of_name : Names.Name.t -> Names.Id.t list = |
| 39 |
function |
| 40 |
| Names.Anonymous -> [] |
| 41 |
| Names.Name n -> [n] |
| 42 |
|
| 43 |
let stm_allow_nested_proofs_option_name = ["Nested";"Proofs";"Allowed"] |
| 44 |
|
| 45 |
let options_affecting_stm_scheduling = |
| 46 |
[ Attributes.universe_polymorphism_option_name; |
| 47 |
stm_allow_nested_proofs_option_name; |
| 48 |
Pvernac.proof_mode_opt_name; |
| 49 |
Attributes.program_mode_option_name; |
| 50 |
Proof_using.proof_using_opt_name; |
| 51 |
] |
| 52 |
|
| 53 |
let classify_vernac e = |
| 54 |
let static_synterp_classifier ~atts e = match e with |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
| VernacSetOption (_, l,_) |
| 59 |
when CList.exists (CList.equal String.equal l) |
| 60 |
options_affecting_stm_scheduling -> |
| 61 |
VtSideff ([], VtNow) |
| 62 |
| VernacBeginSection {v=id} -> VtSideff ([id], VtLater) |
| 63 |
| VernacChdir _ | VernacExtraDependency _ |
| 64 |
| VernacSetOption _ -> VtSideff ([], VtLater) |
| 65 |
|
| 66 |
| VernacEndSegment _ -> VtSideff ([], VtNow) |
| 67 |
|
| 68 |
| VernacDeclareModule (exp,{v=id},bl,_) |
| 69 |
| VernacDefineModule (exp,{v=id},bl,_,_) -> |
| 70 |
VtSideff ([id], if bl = [] && exp = None then VtLater else VtNow) |
| 71 |
| VernacDeclareModuleType ({v=id},bl,_,_) -> |
| 72 |
VtSideff ([id], if bl = [] then VtLater else VtNow) |
| 73 |
|
| 74 |
| VernacDeclareCustomEntry _ |
| 75 |
| VernacNotation _ | VernacReservedNotation _ |
| 76 |
| VernacRequire _ | VernacImport _ | VernacInclude _ |
| 77 |
| VernacDeclareMLModule _ -> VtSideff ([], VtNow) |
| 78 |
| VernacProofMode pm -> |
| 79 |
(match Pvernac.lookup_proof_mode pm with |
| 80 |
| None -> |
| 81 |
CErrors.user_err Pp.(str (Format.sprintf "No proof mode named \"%s\"." pm)) |
| 82 |
| Some proof_mode -> VtProofMode proof_mode) |
| 83 |
|
| 84 |
| VernacLoad _ -> VtSideff ([], VtNow) |
| 85 |
| VernacExtend (s,l) -> |
| 86 |
try Vernacextend.get_vernac_classifier s ~atts l |
| 87 |
with Not_found -> anomaly(str"No classifier for"++spc()++str s.ext_entry ++str".") |
| 88 |
in |
| 89 |
let static_pure_classifier ~atts e = match e with |
| 90 |
|
| 91 |
| VernacAbort -> VtQed VtDrop |
| 92 |
| VernacEndProof Admitted -> VtQed (VtKeep VtKeepAxiom) |
| 93 |
| VernacEndProof (Proved (opaque,_)) -> VtQed (VtKeep (vtkeep_of_opaque opaque)) |
| 94 |
| VernacExactProof _ -> VtQed (VtKeep VtKeepOpaque) |
| 95 |
|
| 96 |
| VernacShow _ | VernacPrint _ | VernacSearch _ | VernacLocate _ |
| 97 |
| VernacCheckGuard | VernacValidateProof |
| 98 |
| VernacGlobalCheck _ | VernacCheckMayEval _ -> VtQuery |
| 99 |
|
| 100 |
| VernacProof _ |
| 101 |
| VernacFocus _ | VernacUnfocus |
| 102 |
| VernacSubproof _ |
| 103 |
| VernacUnfocused |
| 104 |
| VernacBullet _ -> |
| 105 |
VtProofStep { proof_block_detection = Some "bullet" } |
| 106 |
| VernacEndSubproof -> |
| 107 |
VtProofStep { proof_block_detection = Some "curly" } |
| 108 |
|
| 109 |
| VernacDefinition ((DoDischarge,_),({v=i},_),ProveBody _) -> |
| 110 |
VtStartProof(Doesn'tGuaranteeOpacity, idents_of_name i) |
| 111 |
|
| 112 |
| VernacDefinition (_,({v=i},_),ProveBody _) -> |
| 113 |
let polymorphic = Attributes.(parse_drop_extra polymorphic atts) in |
| 114 |
let guarantee = if polymorphic then Doesn'tGuaranteeOpacity else GuaranteesOpacity in |
| 115 |
VtStartProof(guarantee, idents_of_name i) |
| 116 |
| VernacStartTheoremProof (_,l) -> |
| 117 |
let polymorphic = Attributes.(parse_drop_extra polymorphic atts) in |
| 118 |
let ids = List.map (fun (({v=i}, _), _) -> i) l in |
| 119 |
let guarantee = if polymorphic then Doesn'tGuaranteeOpacity else GuaranteesOpacity in |
| 120 |
VtStartProof (guarantee,ids) |
| 121 |
| VernacFixpoint (discharge,(_,l)) -> |
| 122 |
let refine, polymorphic = Attributes.(parse_drop_extra Notations.(Classes.refine_att ++ polymorphic) atts) in |
| 123 |
let guarantee = |
| 124 |
if discharge = DoDischarge || polymorphic || refine then Doesn'tGuaranteeOpacity |
| 125 |
else GuaranteesOpacity |
| 126 |
in |
| 127 |
let ids, open_proof = |
| 128 |
List.fold_left (fun (l,b) {Vernacexpr.fname={CAst.v=id}; body_def} -> |
| 129 |
id::l, b || body_def = None) ([],refine) l in |
| 130 |
if open_proof |
| 131 |
then VtStartProof (guarantee,ids) |
| 132 |
else VtSideff (ids, VtLater) |
| 133 |
| VernacCoFixpoint (discharge,l) -> |
| 134 |
let refine, polymorphic = Attributes.(parse_drop_extra Notations.(Classes.refine_att ++ polymorphic) atts) in |
| 135 |
let guarantee = |
| 136 |
if discharge = DoDischarge || polymorphic || refine then Doesn'tGuaranteeOpacity |
| 137 |
else GuaranteesOpacity |
| 138 |
in |
| 139 |
let ids, open_proof = |
| 140 |
List.fold_left (fun (l,b) { Vernacexpr.fname={CAst.v=id}; body_def } -> |
| 141 |
id::l, b || body_def = None) ([],refine) l in |
| 142 |
if open_proof |
| 143 |
then VtStartProof (guarantee,ids) |
| 144 |
else VtSideff (ids, VtLater) |
| 145 |
|
| 146 |
| VernacAssumption (_,_,l) -> |
| 147 |
let ids = List.flatten (List.map (fun (_,(l,_)) -> List.map (fun (id, _) -> id.v) l) l) in |
| 148 |
VtSideff (ids, VtLater) |
| 149 |
| VernacSymbol l -> |
| 150 |
let ids = List.flatten (List.map (fun (_,(l,_)) -> List.map (fun (id, _) -> id.v) l) l) in |
| 151 |
VtSideff (ids, VtLater) |
| 152 |
| VernacPrimitive ((id,_),_,_) -> |
| 153 |
VtSideff ([id.CAst.v], VtLater) |
| 154 |
| VernacDefinition (_,({v=id},_),DefineBody _) -> |
| 155 |
let refine = Attributes.(parse_drop_extra Classes.refine_att atts) in |
| 156 |
if refine then |
| 157 |
|
| 158 |
VtStartProof (Doesn'tGuaranteeOpacity, idents_of_name id) |
| 159 |
else |
| 160 |
VtSideff (idents_of_name id, VtLater) |
| 161 |
| VernacInductive (_,l) -> |
| 162 |
let ids = List.map (fun (((_,({v=id},_)),_,_,cl),_) -> id :: match cl with |
| 163 |
| Constructors l -> List.map (fun (_,({v=id},_)) -> id) l |
| 164 |
| RecordDecl (oid,l,obinder) -> (match oid with Some {v=x} -> [x] | _ -> []) @ |
| 165 |
(match obinder with Some {v=x} -> [x] | _ -> []) @ |
| 166 |
CList.map_filter (function |
| 167 |
| AssumExpr({v=Names.Name n},_,_), _ -> Some n |
| 168 |
| _ -> None) l) l in |
| 169 |
VtSideff (List.flatten ids, VtLater) |
| 170 |
| VernacScheme l -> |
| 171 |
let ids = List.map (fun {v}->v) (CList.map_filter (fun (x,_) -> x) l) in |
| 172 |
VtSideff (ids, VtLater) |
| 173 |
| VernacCombinedScheme ({v=id},_) -> VtSideff ([id], VtLater) |
| 174 |
| VernacUniverse _ | VernacSort _ | VernacConstraint _ |
| 175 |
| VernacCanonical _ | VernacCoercion _ | VernacIdentityCoercion _ |
| 176 |
| VernacCreateHintDb _ | VernacRemoveHints _ | VernacHints _ |
| 177 |
| VernacArguments _ |
| 178 |
| VernacReserve _ |
| 179 |
| VernacGeneralizable _ |
| 180 |
| VernacSetOpacity _ | VernacSetStrategy _ |
| 181 |
| VernacAddOption _ | VernacRemoveOption _ |
| 182 |
| VernacMemOption _ | VernacPrintOption _ |
| 183 |
| VernacDeclareReduction _ |
| 184 |
| VernacExistingClass _ | VernacExistingInstance _ |
| 185 |
| VernacRegister _ |
| 186 |
| VernacNameSectionHypSet _ |
| 187 |
| VernacComments _ |
| 188 |
| VernacAttributes _ |
| 189 |
| VernacSchemeEquality _ |
| 190 |
| VernacSchemeAll _ |
| 191 |
| VernacAddRewRule _ |
| 192 |
| VernacDeclareInstance _ -> VtSideff ([], VtLater) |
| 193 |
|
| 194 |
| VernacOpenCloseScope _ | VernacDeclareScope _ |
| 195 |
| VernacDelimiters _ | VernacBindScope _ |
| 196 |
| VernacEnableNotation _ |
| 197 |
| VernacAbbreviation _ |
| 198 |
| VernacContext _ -> VtSideff ([], VtNow) |
| 199 |
| VernacInstance ((name,_),_,_,props,_) -> |
| 200 |
let program, refine = |
| 201 |
Attributes.(parse_drop_extra Notations.(program ++ Classes.refine_att) atts) |
| 202 |
in |
| 203 |
if program || (props <> None && not refine) then |
| 204 |
VtSideff (idents_of_name name.CAst.v, VtLater) |
| 205 |
else |
| 206 |
let polymorphic = Attributes.(parse_drop_extra polymorphic atts) in |
| 207 |
let guarantee = if polymorphic then Doesn'tGuaranteeOpacity else GuaranteesOpacity in |
| 208 |
VtStartProof (guarantee, idents_of_name name.CAst.v) |
| 209 |
|
| 210 |
| VernacBack _ | VernacAbortAll |
| 211 |
| VernacUndoTo _ | VernacUndo _ |
| 212 |
| VernacResetName _ | VernacResetInitial |
| 213 |
| VernacRestart -> VtMeta |
| 214 |
in |
| 215 |
let static_classifier ~atts e = match e with |
| 216 |
| VernacSynPure e -> static_pure_classifier ~atts e |
| 217 |
| VernacSynterp e -> static_synterp_classifier ~atts e |
| 218 |
in |
| 219 |
let static_control_classifier ({ CAst.v ; _ } as cmd) = |
| 220 |
|
| 221 |
|
| 222 |
if Vernacprop.has_query_control cmd then |
| 223 |
(match static_classifier ~atts:v.attrs v.expr with |
| 224 |
| VtQuery | VtProofStep _ | VtSideff _ |
| 225 |
| VtMeta as x -> x |
| 226 |
| VtQed _ -> VtProofStep { proof_block_detection = None } |
| 227 |
| VtStartProof _ | VtProofMode _ -> VtQuery) |
| 228 |
else |
| 229 |
static_classifier ~atts:v.attrs v.expr |
| 230 |
|
| 231 |
in |
| 232 |
static_control_classifier e |