diff --git a/src/core/abstract.ml b/src/core/abstract.ml index 8b32fe0ca..10c5b2f60 100644 --- a/src/core/abstract.ml +++ b/src/core/abstract.ml @@ -127,7 +127,7 @@ type flag = | Comp type sort = | LFTyp of I.typ - | MetaTyp of I.ctyp * I.depend + | MetaTyp of I.ctyp * Plicity.t * Inductivity.t type marker = | Pure of sort | Impure @@ -136,7 +136,7 @@ type free_var = | FDecl of kind * marker (* Bound variables. I think we could allow these to be more general than just contexts *) (* Would these in general be a kind of FDecl and have a marker? *) - | CtxV of (Id.name * cid_schema * I.depend) + | CtxV of (Id.name * cid_schema * Plicity.t * Inductivity.t) type fctx = free_var I.ctx @@ -155,33 +155,33 @@ let rec raiseType cPsi tA = | I.Null -> (None, tA) | I.CtxVar psi -> (Some psi, tA) | I.DDec (cPsi', decl) -> - raiseType cPsi' (I.PiTyp ((decl, I.Maybe), tA)) + raiseType cPsi' (I.PiTyp ((decl, Plicity.implicit), tA)) let rec raiseType' cPsi tA = match cPsi with | I.Empty -> (None, tA) | I.Dec (cPsi', decl) -> - raiseType' cPsi' (I.PiTyp ((decl, I.Maybe), tA)) + raiseType' cPsi' (I.PiTyp ((decl, Plicity.implicit), tA)) let rec raiseKind cPsi tK = match cPsi with | I.Empty -> tK | I.Dec (cPsi', decl) -> - raiseKind cPsi' (I.PiKind ((decl, I.Maybe), tK)) + raiseKind cPsi' (I.PiKind ((decl, Plicity.implicit), tK)) let rec fmt_ppr_collection ppf : free_var I.ctx -> unit = let open Format in function | I.Empty -> () - | I.Dec (cQ, FDecl (MMV _, Pure (MetaTyp (mtyp, dep)))) -> + | I.Dec (cQ, FDecl (MMV _, Pure (MetaTyp (mtyp, plicity, inductivity)))) -> fprintf ppf "%a MMV%a%a@," fmt_ppr_collection cQ (P.fmt_ppr_cmp_meta_typ I.Empty) mtyp - P.fmt_ppr_lf_depend dep + P.fmt_ppr_lf_depend (plicity, inductivity) | I.Dec (cQ, FDecl (MMV _, Impure)) -> fprintf ppf "%a MMV Impure@," fmt_ppr_collection cQ - | I.Dec (cQ, FDecl (FV u, Pure (MetaTyp (mtyp, _)))) -> + | I.Dec (cQ, FDecl (FV u, Pure (MetaTyp (mtyp, _, _)))) -> fprintf ppf "%a %a : %a@," fmt_ppr_collection cQ Id.print u @@ -252,7 +252,7 @@ let etaExpandHead loc h tA = function | I.Atom _ -> (k, tS) | I.PiTyp (_, tA') -> - let tN = I.Root (loc, I.BVar k, I.Nil, `explicit) in + let tN = I.Root (loc, I.BVar k, I.Nil, Plicity.explicit) in etaExpSpine (k + 1) (I.App (tN, tS)) tA' in let rec etaExpPrefix loc (tM, tA) = @@ -267,7 +267,7 @@ let etaExpandHead loc h tA = | I.BVar x -> I.BVar (x + k - 1) | I.FVar _ -> h in - etaExpPrefix loc (I.Root (loc, h', tS', `explicit), tA) + etaExpPrefix loc (I.Root (loc, h', tS', Plicity.explicit), tA) let rec constraints_solved = function @@ -316,7 +316,7 @@ let rec ctxToCtx = function | I.Empty -> I.Empty - | I.Dec (cQ', FDecl (MMV _, Pure (MetaTyp (I.ClTyp (I.MTyp tA, cPsi), _)))) -> + | I.Dec (cQ', FDecl (MMV _, Pure (MetaTyp (I.ClTyp (I.MTyp tA, cPsi), _, _)))) -> begin match raiseType cPsi tA with | (None, tA') -> let x = Id.mk_name (Id.MVarName (Typ.gen_mvar_name tA')) in @@ -334,13 +334,13 @@ let rec ctxToCtx = let rec ctxToMCtx f = function | I.Empty -> I.Empty - | I.Dec (cQ', FDecl (FV n, Pure (MetaTyp (ityp, dep)))) -> - I.Dec (ctxToMCtx f cQ', I.Decl (n, ityp, f dep)) - | I.Dec (cQ', FDecl (MMV (n, _), Pure (MetaTyp (ityp, dep)))) -> - I.Dec (ctxToMCtx f cQ', I.Decl (n, ityp, f dep)) - | I.Dec (cQ', CtxV (x, w, dep)) -> - I.Dec (ctxToMCtx f cQ', I.Decl (x, I.CTyp (Some w), dep)) - (* f dep here breaks things involving ctxvars... -je *) + | I.Dec (cQ', FDecl (FV n, Pure (MetaTyp (ityp, plicity, inductivity)))) -> + I.Dec (ctxToMCtx f cQ', I.Decl (n, ityp, f plicity, inductivity)) + | I.Dec (cQ', FDecl (MMV (n, _), Pure (MetaTyp (ityp, plicity, inductivity)))) -> + I.Dec (ctxToMCtx f cQ', I.Decl (n, ityp, f plicity, inductivity)) + | I.Dec (cQ', CtxV (x, w, plicity, inductivity)) -> + I.Dec (ctxToMCtx f cQ', I.Decl (x, I.CTyp (Some w), plicity, inductivity)) + (* f plicity here breaks things involving ctxvars... -je *) (* this case should not happen -bp *) | I.Dec (cQ', FDecl (FV _, Pure (LFTyp tA)))-> @@ -351,29 +351,29 @@ let rec ctxToMCtx f = let rec mctxToCtx = function | I.Empty -> I.Empty - | I.Dec (cQ', I.Decl (x, I.CTyp (Some w), dep)) -> - I.Dec (mctxToCtx cQ', CtxV (x, w, dep)) - | I.Dec (cQ', I.Decl (n, ityp, dep)) -> - I.Dec (mctxToCtx cQ', FDecl (FV n, Pure (MetaTyp (ityp, dep)))) + | I.Dec (cQ', I.Decl (x, I.CTyp (Some w), plicity, inductivity)) -> + I.Dec (mctxToCtx cQ', CtxV (x, w, plicity, inductivity)) + | I.Dec (cQ', I.Decl (n, ityp, plicity, inductivity)) -> + I.Dec (mctxToCtx cQ', FDecl (FV n, Pure (MetaTyp (ityp, plicity, inductivity)))) let rec ctxToMCtx_pattern names = function | I.Empty -> I.Empty - | I.Dec (cQ', FDecl (FV n, Pure (MetaTyp (ityp, _)))) -> - I.Dec (ctxToMCtx_pattern (n :: names) cQ', I.Decl (n, ityp, I.No)) + | I.Dec (cQ', FDecl (FV n, Pure (MetaTyp (ityp, _, _)))) -> + I.Dec (ctxToMCtx_pattern (n :: names) cQ', I.Decl (n, ityp, Plicity.explicit, Inductivity.not_inductive)) - | I.Dec (cQ', FDecl (MMV (n, _), Pure (MetaTyp (ityp, dep)))) -> + | I.Dec (cQ', FDecl (MMV (n, _), Pure (MetaTyp (ityp, plicity, inductivity)))) -> let n = NameGen.renumber names n in - I.Dec (ctxToMCtx_pattern (n :: names) cQ', I.Decl (n, ityp, dep)) + I.Dec (ctxToMCtx_pattern (n :: names) cQ', I.Decl (n, ityp, plicity, inductivity)) - | I.Dec (cQ', CtxV (x, w, dep)) -> - I.Dec (ctxToMCtx_pattern (x :: names) cQ', I.Decl (x, I.CTyp (Some w), dep)) + | I.Dec (cQ', CtxV (x, w, plicity, inductivity)) -> + I.Dec (ctxToMCtx_pattern (x :: names) cQ', I.Decl (x, I.CTyp (Some w), plicity, inductivity)) | I.Dec (cQ', FDecl (_, Impure)) -> ctxToMCtx_pattern names cQ' -(* collectTerm p cQ phat (tM,s) = cQ' +(* collectTerm p cQ phat (tM, s) = cQ' Invariant: @@ -443,9 +443,9 @@ and collectSpine (p : int) cQ phat = and collectBothTyp loc p cQ = function - | MetaTyp (tp, dep) -> + | MetaTyp (tp, plicity, inductivity) -> let (cQ', tp') = collectMetaTyp loc p cQ tp in - (cQ', MetaTyp (tp', dep)) + (cQ', MetaTyp (tp', plicity, inductivity)) | LFTyp tA -> (* tA must be closed *) (* Since we only use abstraction on pure LF objects, there are no context variables; different abstraction @@ -467,11 +467,11 @@ and getType loc p name f = match f with | LF -> let Int.LF.Type tA = FVar.get name in (LFTyp tA) | Comp -> - let (cD_d, I.Decl (_, mtyp, dep)) = FCVar.get name in + let (cD_d, I.Decl (_, mtyp, plicity, inductivity)) = FCVar.get name in let mtyp' = Whnf.cnormMTyp (mtyp, Int.LF.MShift (p - Context.length cD_d)) in if !pat_flag - then MetaTyp (mtyp', I.No) - else MetaTyp (mtyp', dep) + then MetaTyp (mtyp', Plicity.explicit, Inductivity.not_inductive) + else MetaTyp (mtyp', plicity, inductivity) with | Not_found -> raise (Error (loc, UnknownMTyp name)) @@ -489,7 +489,7 @@ and collectFVarSub p cQ phat (name, s') = (cQ, (name, s')) and collectMMVar loc p cQ (v : I.mm_var) = - let I.{ name; instantiation; cD; typ; constraints; depend; _ } = + let I.{ name; instantiation; cD; typ; constraints; plicity; inductivity; _ } = v in match cD with @@ -498,11 +498,11 @@ and collectMMVar loc p cQ (v : I.mm_var) = then match !instantiation with | None -> - let (cQ', MetaTyp (typ, depend)) = - addVar loc p cQ (MMV (name, instantiation)) (MetaTyp (typ, depend)) + let (cQ', MetaTyp (typ, plicity, inductivity)) = + addVar loc p cQ (MMV (name, instantiation)) (MetaTyp (typ, plicity, inductivity)) in ( cQ' - , I.{ v with typ; depend } + , I.{ v with typ; plicity; inductivity } ) | Some _ -> raise (Error.Violation "Expected whnf") else @@ -551,7 +551,7 @@ and collectSub (p : int) cQ phat = | I.Dot (I.Obj tM, s) -> let (cQ1, tM') = collectTerm p cQ phat (tM, LF.id) in - let (cQ2,s') = collectSub p cQ1 phat s in + let (cQ2, s') = collectSub p cQ1 phat s in (cQ2, I.Dot (I.Obj tM', s')) | I.FSVar (n, ns) -> @@ -559,7 +559,7 @@ and collectSub (p : int) cQ phat = (cQ', I.FSVar (n, ns)) | I.SVar (offset, n, s) -> - let (cQ1,s') = collectSub p cQ phat s in + let (cQ1, s') = collectSub p cQ phat s in (cQ1, I.SVar (offset, n, s')) | I.MSVar (k, i) -> @@ -647,10 +647,10 @@ and collectTyp p cQ ((cvar, offset) as phat) = let (cQ', tS') = collectSpine p cQ phat (tS, s) in (cQ', I.Atom (loc, a, tS')) - | (I.PiTyp ((I.TypDecl (x, tA), dep), tB), s) -> + | (I.PiTyp ((I.TypDecl (x, tA), plicity), tB), s) -> let (cQ', tA') = collectTyp p cQ phat (tA, s) in let (cQ'', tB') = collectTyp p cQ' (cvar, offset + 1) (tB, LF.dot1 s) in - (cQ'', I.PiTyp ((I.TypDecl (x, tA'), dep), tB')) + (cQ'', I.PiTyp ((I.TypDecl (x, tA'), plicity), tB')) | (I.TClo (tA, s'), s) -> collectTyp p cQ phat (tA, LF.comp s' s) @@ -664,20 +664,20 @@ and collectTypRec p cQ ((cvar, offset) as phat) = function | (I.SigmaLast (n, tA), s) -> let (cQ', tA') = collectTyp p cQ phat (tA, s) in - (cQ', I.SigmaLast (n,tA')) + (cQ', I.SigmaLast (n, tA')) | (I.SigmaElem (loc, tA, typRec), s) -> - let (cQ',tA') = collectTyp p cQ phat (tA, s) in + let (cQ', tA') = collectTyp p cQ phat (tA, s) in let (cQ'', typRec') = collectTypRec p cQ' (cvar, offset + 1) (typRec, LF.dot1 s) in (cQ'', I.SigmaElem (loc, tA', typRec')) and collectKind p cQ ((cvar, offset) as phat) = function | (I.Typ, _) -> (cQ, I.Typ) - | (I.PiKind ((I.TypDecl (x, tA), dep), tK), s) -> + | (I.PiKind ((I.TypDecl (x, tA), plicity), tK), s) -> let (cQ', tA') = collectTyp p cQ phat (tA, s) in let (cQ'', tK') = collectKind p cQ' (cvar, offset + 1) (tK, LF.dot1 s) in - (cQ'', I.PiKind ((I.TypDecl (x, tA'), dep), tK')) + (cQ'', I.PiKind ((I.TypDecl (x, tA'), plicity), tK')) and collectCVar loc p cQ = @@ -745,9 +745,9 @@ and collectMetaTyp loc p cQ = (cQ'', I.ClTyp (tp', cPsi')) -let collectCDecl p cQ (I.Decl (u, mtyp,dep)) = +let collectCDecl p cQ (I.Decl (u, mtyp, plicity, inductivity)) = let (cQ', mtyp') = collectMTyp p cQ mtyp in - (cQ', I.Decl (u, mtyp',dep)) + (cQ', I.Decl (u, mtyp', plicity, inductivity)) let rec collectMctx cQ = function @@ -772,9 +772,9 @@ let rec collectMctx cQ = let rec abstractKind cQ offset = function | (I.Typ, _) -> I.Typ - | (I.PiKind ((I.TypDecl (x, tA), dep), tK), s) -> + | (I.PiKind ((I.TypDecl (x, tA), plicity), tK), s) -> I.PiKind - ( (I.TypDecl (x, abstractTyp cQ offset (tA, s)), dep) + ( (I.TypDecl (x, abstractTyp cQ offset (tA, s)), plicity) , abstractKind cQ (offset + 1) (tK, LF.dot1 s) ) @@ -785,9 +785,9 @@ and abstractTypW cQ offset = | (I.Atom (loc, a, tS), s (* id *)) -> I.Atom (loc, a, abstractSpine cQ offset (tS, s)) - | (I.PiTyp ((I.TypDecl (x, tA), dep), tB), s) -> + | (I.PiTyp ((I.TypDecl (x, tA), plicity), tB), s) -> I.PiTyp - ( (I.TypDecl (x, abstractTyp cQ offset (tA, s)), dep) + ( (I.TypDecl (x, abstractTyp cQ offset (tA, s)), plicity) , abstractTyp cQ (offset + 1) (tB, LF.dot1 s) ) @@ -848,7 +848,7 @@ and subToSpine cQ offset (s, cPsi) tS = | (I.Dot (I.Head (I.BVar k), s), I.DDec (cPsi', I.TypDecl (_, tA))) -> let tN = etaExpandHead Syntax.Loc.ghost (I.BVar k) (Whnf.normTyp (tA, LF.id)) in - subToSpine cQ offset (s,cPsi') (I.App (tN, tS)) + subToSpine cQ offset (s, cPsi') (I.App (tN, tS)) | (I.Dot (I.Head (I.MVar _), _), I.DDec _) -> Error.not_implemented' "[subToSpine] found MVar as head" @@ -869,13 +869,13 @@ and abstractCtx = function | I.Empty -> I.Empty | I.Dec (cQ, FDecl (_, Impure)) -> abstractCtx cQ - | I.Dec (cQ, FDecl (MMV (n, r), Pure (MetaTyp (I.ClTyp (I.MTyp tA, cPsi), dep)))) -> + | I.Dec (cQ, FDecl (MMV (n, r), Pure (MetaTyp (I.ClTyp (I.MTyp tA, cPsi), plicity, inductivity)))) -> let cQ' = abstractCtx cQ in let l = length cPsi in let cPsi' = abstractDctx cQ cPsi l in let tA' = abstractTyp cQ l (tA, LF.id) in - let tp' = I.ClTyp (I.MTyp tA',cPsi') in - I.Dec (cQ', FDecl (MMV (n, r), Pure (MetaTyp (tp', dep)))) + let tp' = I.ClTyp (I.MTyp tA', cPsi') in + I.Dec (cQ', FDecl (MMV (n, r), Pure (MetaTyp (tp', plicity, inductivity)))) | I.Dec (cQ, FDecl (FV f, Pure (LFTyp tA))) -> let cQ' = abstractCtx cQ in @@ -919,9 +919,9 @@ and abstractMVarTypW cQ offset = function | (I.Atom (loc, a, tS), s (* id *)) -> I.Atom (loc, a, abstractMVarSpine cQ offset (tS, s)) - | (I.PiTyp ((I.TypDecl (x, tA), dep), tB), s) -> + | (I.PiTyp ((I.TypDecl (x, tA), plicity), tB), s) -> I.PiTyp - ( (I.TypDecl (x, abstractMVarTyp cQ offset (tA, s)), dep) + ( (I.TypDecl (x, abstractMVarTyp cQ offset (tA, s)), plicity) , abstractMVarTyp cQ offset (tB, LF.dot1 s) ) | (I.Sigma typRec, s) -> @@ -946,7 +946,7 @@ and abstractMVarTermW cQ offset = | (I.Tuple (loc, tuple), s) -> I.Tuple (loc, abstractMVarTuple cQ offset (tuple, s)) | (I.Root (loc, tH, tS, plicity), s (* LF.id *)) -> - I.Root (loc, abstractMVarHead cQ offset tH, abstractMVarSpine cQ offset (tS,s), plicity) + I.Root (loc, abstractMVarHead cQ offset tH, abstractMVarSpine cQ offset (tS, s), plicity) | (I.LFHole (loc, id, name), s) -> I.LFHole (loc, id, name) @@ -1029,7 +1029,7 @@ and abstractMVarSpine cQ offset = function | (I.Nil, _) -> I.Nil | (I.App (tM, tS), s) -> - I.App (abstractMVarTerm cQ offset (tM,s), abstractMVarSpine cQ offset (tS, s)) + I.App (abstractMVarTerm cQ offset (tM, s), abstractMVarSpine cQ offset (tS, s)) | (I.SClo (tS, s'), s) -> abstractMVarSpine cQ offset (tS, LF.comp s' s) @@ -1096,10 +1096,10 @@ and abstractMVarMTyp cQ mtyp loff = | I.ClTyp (tp, cPsi) -> I.ClTyp (abstractMVarClTyp cQ loff tp, abstractMVarDctx cQ loff cPsi) | I.CTyp sW -> I.CTyp sW -and abstractMVarCdecl cQ loff (I.Decl (u, mtyp, dep)) = - I.Decl (u, abstractMVarMTyp cQ mtyp loff, dep) +and abstractMVarCdecl cQ loff (I.Decl (u, mtyp, plicity, inductivity)) = + I.Decl (u, abstractMVarMTyp cQ mtyp loff, plicity, inductivity) -and abstractMVarMctx cQ cD (l,offset) = +and abstractMVarMctx cQ cD (l, offset) = match cD with | I.Empty -> I.Empty | I.Dec (cD, cdecl) -> @@ -1108,9 +1108,9 @@ and abstractMVarMctx cQ cD (l,offset) = and abstractMVarCtx cQ l = match cQ with | I.Empty -> I.Empty - | I.Dec (cQ, FDecl (v, Pure (MetaTyp (ityp, dep)))) -> + | I.Dec (cQ, FDecl (v, Pure (MetaTyp (ityp, plicity, inductivity)))) -> let cQ' = abstractMVarCtx cQ (l - 1) in - I.Dec (cQ', FDecl (v, Pure (MetaTyp (abstractMVarMTyp cQ ityp (l, 0), dep)))) + I.Dec (cQ', FDecl (v, Pure (MetaTyp (abstractMVarMTyp cQ ityp (l, 0), plicity, inductivity)))) | I.Dec (cQ, CtxV cdecl) -> let cQ' = abstractMVarCtx cQ (l - 1) in I.Dec (cQ', CtxV cdecl) @@ -1154,12 +1154,12 @@ and abstractMSub t = let rec ctxToMCtx' = function | I.Empty -> I.Empty - | I.Dec (cQ', FDecl (FV n, Pure (MetaTyp (ityp, dep)))) -> - I.Dec (ctxToMCtx' cQ', I.Decl (n, ityp, dep)) - | I.Dec (cQ', FDecl (MMV (n, _), Pure (MetaTyp (ityp, dep)))) -> - I.Dec (ctxToMCtx' cQ', I.Decl (n, ityp, dep)) - | I.Dec (cQ', CtxV (x, w, dep)) -> - I.Dec (ctxToMCtx' cQ', I.Decl (x, I.CTyp (Some w), dep)) + | I.Dec (cQ', FDecl (FV n, Pure (MetaTyp (ityp, plicity, inductivity)))) -> + I.Dec (ctxToMCtx' cQ', I.Decl (n, ityp, plicity, inductivity)) + | I.Dec (cQ', FDecl (MMV (n, _), Pure (MetaTyp (ityp, plicity, inductivity)))) -> + I.Dec (ctxToMCtx' cQ', I.Decl (n, ityp, plicity, inductivity)) + | I.Dec (cQ', CtxV (x, w, plicity, inductivity)) -> + I.Dec (ctxToMCtx' cQ', I.Decl (x, I.CTyp (Some w), plicity, inductivity)) | I.Dec (cQ', FDecl (_, Impure)) -> ctxToMCtx' cQ' in @@ -1180,8 +1180,8 @@ let abstrKind tK = let empty_phat = (None, 0) in let (cQ, tK') = collectKind 0 I.Empty empty_phat (tK, LF.id) in match cQ with - | Int.LF.Empty -> (tK', 0) - | _ -> + | Int.LF.Empty -> (tK', 0) (* Optimization *) + | cQ -> let cQ' = abstractCtx cQ in let tK'' = abstractKind cQ' 0 (tK', LF.id) in let cPsi = ctxToCtx cQ' in @@ -1337,7 +1337,7 @@ and collectExp' cQ = (cQ'', Comp.Apply (loc, i', e')) | Comp.MApp (loc, i, cM, cU, pl) -> - let (cQ', i') = collectExp' cQ i in (* cQ' is unused? -je *) + let (cQ', i') = collectExp' cQ i in let (cQ'', cM') = collect_meta_obj 0 cQ' cM in let (cQ''', cU') = collectMetaTyp loc 0 cQ'' cU in (cQ''', Comp.MApp (loc, i', cM', cU', pl)) @@ -1410,8 +1410,8 @@ let rec abstractMVarCompKind cQ (l, offset) = function | Comp.Ctype _ as cK -> cK | Comp.PiKind (loc, cdecl, cK) -> - let cK' = abstractMVarCompKind cQ (l,offset+1) cK in - let cdecl' = abstractMVarCdecl cQ (l,offset) cdecl in + let cK' = abstractMVarCompKind cQ (l, offset + 1) cK in + let cdecl' = abstractMVarCdecl cQ (l, offset) cdecl in Comp.PiKind (loc, cdecl', cK') let rec abstractMVarMetaObj cQ offset (loc, cM) = @@ -1521,8 +1521,8 @@ let raiseCompKind cD cK = in (* let rec roll = funciton - | Comp.PiKind (loc, (cdecl, dep), cK') -> - Comp.PiKind (loc, (cdecl, dep), roll cK') + | Comp.PiKind (loc, (cdecl, plicity), cK') -> + Comp.PiKind (loc, (cdecl, plicity), roll cK') | cK -> raisePiBox cD cK in *) @@ -1531,8 +1531,8 @@ let raiseCompKind cD cK = let abstrCompKind cK = let rec roll cK cQ = match cK with - | Comp.PiKind (_, I.Decl (psi, I.CTyp (Some w), dep), cK) -> - roll cK (I.Dec (cQ, CtxV (psi, w, dep))) + | Comp.PiKind (_, I.Decl (psi, I.CTyp (Some w), plicity, inductivity), cK) -> + roll cK (I.Dec (cQ, CtxV (psi, w, plicity, inductivity))) | cK -> (cQ, cK) in let (cQ, cK') = roll cK I.Empty in @@ -1543,21 +1543,21 @@ let abstrCompKind cK = let l = (k - l') in let cQ' = abstractMVarCtx cQ (l - 1 - p) in let cK' = abstractMVarCompKind cQ' (l, 0) cK1 in - let cD' = ctxToMCtx (fun _ -> I.Maybe) cQ' in + let cD' = ctxToMCtx (Fun.const Plicity.implicit) cQ' in let cK2 = raiseCompKind cD' cK' in (cK2, Context.length cD') let rec dropExplicitCTyp = function | I.Empty -> I.Empty - | I.Dec (cD', I.Decl (_, I.CTyp _, I.No)) -> dropExplicitCTyp cD' + | I.Dec (cD', I.Decl (_, I.CTyp _, Plicity.Explicit, _)) -> dropExplicitCTyp cD' | I.Dec (cD', d) -> I.Dec (dropExplicitCTyp cD', d) let abstrCompTyp tau = let rec roll tau cQ = match tau with - | Comp.TypPiBox (_, I.Decl (psi, I.CTyp (Some w), dep), tau) -> - roll tau (I.Dec (cQ, CtxV (psi, w, dep))) + | Comp.TypPiBox (_, I.Decl (psi, I.CTyp (Some w), plicity, inductivity), tau) -> + roll tau (I.Dec (cQ, CtxV (psi, w, plicity, inductivity))) | tau -> (cQ, tau) in let tau0 = Whnf.cnormCTyp (tau, Whnf.m_id) in @@ -1573,7 +1573,7 @@ let abstrCompTyp tau = let cQ' = abstractMVarCtx cQ (l - 1 - p) in (* let cQ' = abstractMVarCtx cQ (l-1) in *) let tau' = abstractMVarCompTyp cQ' (l, 0) tau1 in - let cD' = ctxToMCtx (fun _ -> I.Maybe) cQ' in + let cD' = ctxToMCtx (Fun.const Plicity.implicit) cQ' in let tau'' = raiseCompTyp cD' tau' in (* We can't just subtract l' because l' counts also implicit context quantifications. @@ -1585,8 +1585,8 @@ let abstrCompTyp tau = let abstrCompTypcD cD tau = let rec roll tau cQ = match tau with - | Comp.TypPiBox (_, I.Decl (psi, I.CTyp (Some w), dep), tau) -> - roll tau (I.Dec (cQ, CtxV (psi, w, dep))) + | Comp.TypPiBox (_, I.Decl (psi, I.CTyp (Some w), plicity, inductivity), tau) -> + roll tau (I.Dec (cQ, CtxV (psi, w, plicity, inductivity))) | tau -> (cQ, tau) in let tau0 = Whnf.cnormCTyp (tau, Whnf.m_id) in @@ -1603,7 +1603,7 @@ let abstrCompTypcD cD tau = let cQ' = abstractMVarCtx cQ (l - 1 - p) in (* let cQ' = abstractMVarCtx cQ (l-1) in *) let tau' = abstractMVarCompTyp cQ' (l, 0) tau1 in - let cD' = ctxToMCtx (fun _ -> I.Maybe) cQ' in + let cD' = ctxToMCtx (Fun.const Plicity.implicit) cQ' in let tau'' = raiseCompTyp cD' tau' in (* We can't just subtract l' because l' counts also implicit context quantifications. @@ -1616,7 +1616,7 @@ let abstrCompTypcD cD tau = let abstrCodataTyp cD tau tau' = let rec split = function - | I.Dec (cD', (I.Decl (psi, I.CTyp (Some w), dep) as decl)) -> + | I.Dec (cD', (I.Decl (psi, I.CTyp (Some w), _, _) as decl)) -> let (cD_ctx, cD_rest) = split cD' in (I.Dec (cD_ctx, decl), cD_rest) | I.Dec (cD', decl) -> @@ -1644,7 +1644,7 @@ let abstrCodataTyp cD tau tau' = let l = k - l' in let cQ' = abstractMVarCtx cQ3 (l - 1 - p) in let tau_obs = abstractMVarCompTyp cQ' (l, 0) tau0' in - let cD' = ctxToMCtx (fun _ -> I.Maybe) cQ' in + let cD' = ctxToMCtx (Fun.const Plicity.implicit) cQ' in dprintf begin fun p -> p.fmt "@[tau0' = %a@,tau_obs = %a@]" @@ -1660,7 +1660,7 @@ let abstrCodataTyp cD tau tau' = let l = k - l' in let cQ'' = abstractMVarCtx cQ4 0 in let tau_res = abstractMVarCompTyp cQ'' (l, 0) tau1' in - let cD'' = ctxToMCtx (fun _ -> I.Maybe) cQ'' in + let cD'' = ctxToMCtx (Fun.const Plicity.implicit) cQ'' in dprintf begin fun p -> p.fmt "cD'' = %a" @@ -1813,7 +1813,7 @@ let abstrCovGoal cPsi tM tA ms = let tM0 = abstractMVarTerm cQ' (0, 0) (tM', LF.id) in let tA0 = abstractMVarTyp cQ' (0, 0) (tA', LF.id) in - let cD0 = ctxToMCtx (fun x -> x) cQ' in + let cD0 = ctxToMCtx Fun.id cQ' in (cD0, cPsi0, tM0, tA0, ms0) let abstrCovPatt cG pat tau ms = @@ -1826,7 +1826,7 @@ let abstrCovPatt cG pat tau ms = let cG' = abstractMVarGctx cQ' (0, 0) cG in let pat' = abstractMVarPatObj cQ' cG' (0, 0) pat' in let tau' = abstractMVarCompTyp cQ' (0, 0) tau' in - let cD' = ctxToMCtx (fun x -> x) cQ' in + let cD' = ctxToMCtx Fun.id cQ' in (cD', cG', pat', tau', ms0) let abstrThm = diff --git a/src/core/abstract.mli b/src/core/abstract.mli index dbdd291a2..8b2cb6f27 100644 --- a/src/core/abstract.mli +++ b/src/core/abstract.mli @@ -18,14 +18,14 @@ type error = type sort = | LFTyp of LF.typ - | MetaTyp of LF.ctyp * LF.depend + | MetaTyp of LF.ctyp * Plicity.t * Inductivity.t type marker = | Pure of sort | Impure type free_var = | FDecl of kind * marker - | CtxV of (Id.name * Id.cid_schema * LF.depend) + | CtxV of (Id.name * Id.cid_schema * Plicity.t * Inductivity.t) type fctx = free_var LF.ctx diff --git a/src/core/apxnorm.ml b/src/core/apxnorm.ml index 847786bf1..550178373 100644 --- a/src/core/apxnorm.ml +++ b/src/core/apxnorm.ml @@ -43,7 +43,7 @@ let lengthApxMCtx = Context.length (* EtaExpansion of approximate terms *) let rec shiftApxTerm k = function - | Apx.LF.Lam (loc, x, m') -> Apx.LF.Lam(loc, x, shiftApxTerm (k+1) m') + | Apx.LF.Lam (loc, x, m') -> Apx.LF.Lam(loc, x, shiftApxTerm (k + 1) m') | Apx.LF.Root (loc, h , spine) -> let h' = shiftApxHead k h in let spine' = shiftApxSpine k spine in @@ -51,7 +51,7 @@ let rec shiftApxTerm k = and shiftApxHead k = function - | Apx.LF.BVar x -> Apx.LF.BVar (x+k) + | Apx.LF.BVar x -> Apx.LF.BVar (x + k) | Apx.LF.FMVar (u, s) -> Apx.LF.FMVar (u, Option.(s $> fun s -> shiftApxSub k s)) | Apx.LF.FPVar (p, s) -> @@ -230,10 +230,10 @@ let rec cnormApxTyp cD delta a (cD'', t) = | Apx.LF.Atom (loc, c, spine) -> Apx.LF.Atom (loc, c, cnormApxSpine cD delta spine (cD'', t)) - | Apx.LF.PiTyp ((t_decl, dep), a) -> + | Apx.LF.PiTyp ((t_decl, plicity), a) -> let t_decl' = cnormApxTypDecl cD delta t_decl (cD'', t) in let a' = cnormApxTyp cD delta a (cD'', t) in - Apx.LF.PiTyp ((t_decl', dep), a') + Apx.LF.PiTyp ((t_decl', plicity), a') | Apx.LF.Sigma typ_rec -> let typ_rec' = cnormApxTypRec cD delta typ_rec (cD'', t) in @@ -295,7 +295,7 @@ let rec cnormApxExp cD delta e (cD'', t) = dprint (fun () -> "cnormApxExp -- MLam (or could be PLam)"); let e' = cnormApxExp cD (Apx.LF.Dec(delta, Apx.LF.DeclOpt u)) e - (Int.LF.Dec (cD'', Int.LF.DeclOpt (u, `explicit)), Whnf.mvar_dot1 t) + (Int.LF.Dec (cD'', Int.LF.DeclOpt (u, Plicity.explicit)), Whnf.mvar_dot1 t) in Apx.Comp.MLam (loc, u, e') @@ -304,10 +304,10 @@ let rec cnormApxExp cD delta e (cD'', t) = let e2' = cnormApxExp cD delta e2 (cD'', t) in Apx.Comp.Pair (loc, e1', e2') - | Apx.Comp.LetPair (loc, i, (x,y, e)) -> + | Apx.Comp.LetPair (loc, i, (x, y, e)) -> let i' = cnormApxExp' cD delta i (cD'', t) in let e' = cnormApxExp cD delta e (cD'', t) in - Apx.Comp.LetPair (loc, i', (x,y, e')) + Apx.Comp.LetPair (loc, i', (x, y, e')) | Apx.Comp.Let (loc, i, (x, e)) -> let i' = cnormApxExp' cD delta i (cD'', t) in @@ -364,7 +364,7 @@ and cnormApxExp' cD delta i cDt = let mobj' = cnormApxMetaObj cD delta mobj cDt in Apx.Comp.BoxVal (loc, mobj') -and cnormApxMetaObj cD delta (loc,mobj) cDt = +and cnormApxMetaObj cD delta (loc, mobj) cDt = ( loc , match mobj with | Apx.Comp.ClObj (psi, sigma) -> @@ -397,9 +397,9 @@ and cnormApxBranch cD delta b (cD'', t) = let rec append_mctx cD'' = function | Apx.LF.Empty -> cD'' - | Apx.LF.Dec (delta2', Apx.LF.Decl(x, _, dep)) -> + | Apx.LF.Dec (delta2', Apx.LF.Decl (x, _, plicity)) -> let cD1'' = append_mctx cD'' delta2' in - Int.LF.Dec (cD1'', Int.LF.DeclOpt (x, Int.LF.Depend.to_plicity dep)) + Int.LF.Dec (cD1'', Int.LF.DeclOpt (x, plicity)) in match b with @@ -482,10 +482,10 @@ and collectApxSub fMVs = | Apx.LF.Dot (Apx.LF.Obj m, s) -> let fMVs' = collectApxTerm fMVs m in collectApxSub fMVs' s - | Apx.LF.SVar (i,s) -> + | Apx.LF.SVar (i, s) -> collectApxSubOpt fMVs s - | Apx.LF.FSVar (n,s) -> - collectApxSubOpt (n::fMVs) s + | Apx.LF.FSVar (n, s) -> + collectApxSubOpt (n :: fMVs) s and collectApxSpine fMVs = function @@ -566,7 +566,7 @@ let rec collectApxTyp fMVd = function | Apx.LF.Atom (loc, c, tS) -> collectApxSpine fMVd tS - | Apx.LF.PiTyp ((Apx.LF.TypDecl (x, tA),_ ), tB) -> + | Apx.LF.PiTyp ((Apx.LF.TypDecl (x, tA), _ ), tB) -> let fMVd1 = collectApxTyp fMVd tA in collectApxTyp fMVd1 tB | Apx.LF.Sigma trec -> @@ -588,7 +588,7 @@ let collectApxCDecl fMVd = | Apx.LF.Decl(_, Apx.LF.ClTyp (Apx.LF.PTyp tA, cPsi), _) -> let fMVd1 = collectApxDCtx fMVd cPsi in collectApxTyp fMVd1 tA - | Apx.LF.Decl (_,Apx.LF.CTyp _,_) -> fMVd + | Apx.LF.Decl (_, Apx.LF.CTyp _, _) -> fMVd let rec collectApxCompTyp fMVd = function @@ -601,11 +601,11 @@ let rec collectApxCompTyp fMVd = | Apx.Comp.TypPiBox (_, cdecl, tau) -> let fMVd1 = collectApxCDecl fMVd cdecl in collectApxCompTyp fMVd1 tau - | Apx.Comp.TypBox (loc, (loc',Apx.LF.ClTyp(Apx.LF.MTyp tA, cPsi))) - | Apx.Comp.TypBox (loc, (loc',Apx.LF.ClTyp(Apx.LF.PTyp tA, cPsi))) -> + | Apx.Comp.TypBox (loc, (loc', Apx.LF.ClTyp(Apx.LF.MTyp tA, cPsi))) + | Apx.Comp.TypBox (loc, (loc', Apx.LF.ClTyp(Apx.LF.PTyp tA, cPsi))) -> let fMVd1 = collectApxDCtx fMVd cPsi in collectApxTyp fMVd1 tA - | Apx.Comp.TypBox (loc, (loc',Apx.LF.ClTyp(Apx.LF.STyp (_ , cPhi), cPsi))) -> + | Apx.Comp.TypBox (loc, (loc', Apx.LF.ClTyp(Apx.LF.STyp (_ , cPhi), cPsi))) -> let fMVd1 = collectApxDCtx fMVd cPsi in collectApxDCtx fMVd1 cPhi | Apx.Comp.TypBase (_loc, _c, mS) -> @@ -764,10 +764,10 @@ let rec fmvApxTyp fMVs cD d_param = | Apx.LF.Atom (loc, c, spine) -> Apx.LF.Atom (loc, c, fmvApxSpine fMVs cD d_param spine) - | Apx.LF.PiTyp ((t_decl, dep), a) -> + | Apx.LF.PiTyp ((t_decl, plicity), a) -> let t_decl' = fmvApxTypDecl fMVs cD d_param t_decl in let a' = fmvApxTyp fMVs cD d_param a in - Apx.LF.PiTyp ((t_decl', dep), a') + Apx.LF.PiTyp ((t_decl', plicity), a') | Apx.LF.Sigma typ_rec -> let typ_rec' = fmvApxTypRec fMVs cD d_param typ_rec in @@ -853,10 +853,10 @@ let rec fmvApxExp fMVs cD ((l_cd1, l_delta, k) as d_param) = let e1' = fmvApxExp fMVs cD d_param e1 in let e2' = fmvApxExp fMVs cD d_param e2 in Apx.Comp.Pair (loc, e1', e2') - | Apx.Comp.LetPair (loc, i, (x,y, e)) -> + | Apx.Comp.LetPair (loc, i, (x, y, e)) -> let i' = fmvApxExp' fMVs cD d_param i in let e' = fmvApxExp fMVs cD d_param e in - Apx.Comp.LetPair (loc, i', (x,y, e')) + Apx.Comp.LetPair (loc, i', (x, y, e')) | Apx.Comp.Let (loc, i, (x, e)) -> let i' = fmvApxExp' fMVs cD d_param i in let e' = fmvApxExp fMVs cD d_param e in diff --git a/src/core/check.ml b/src/core/check.ml index 44ae2235b..20a29fa7f 100644 --- a/src/core/check.ml +++ b/src/core/check.ml @@ -433,8 +433,8 @@ module Comp = struct let mark_ind cD k = let rec lookup cD k' = match (cD, k') with - | (I.Dec (cD, I.Decl (u, cdec,dep)), 1) -> - I.Dec (cD, I.Decl (u, cdec, I.Inductive)) + | (I.Dec (cD, I.Decl (u, cdec, _, _)), 1) -> + I.Dec (cD, I.Decl (u, cdec, Plicity.explicit, Inductivity.inductive)) | (I.Dec (_, I.DeclOpt (u, _)), 1) -> raise (Error.Violation "Expected declaration to have type") @@ -542,26 +542,23 @@ module Comp = struct Error.violation "Contextual substitution ill-formed" | (I.MShift k, cD) -> (* k >= 0 *) - id_map_ind cD1' (I.MDot (I.MV (k+1), I.MShift (k+1))) cD + id_map_ind cD1' (I.MDot (I.MV (k + 1), I.MShift (k + 1))) cD - | (I.MDot (I.MV u, ms), I.Dec (cD, I.Decl (_, mtyp1, dep))) -> - if Total.is_inductive dep - then - begin - let cD1' = mark_ind cD1' u in - id_map_ind cD1' ms cD - end - else - id_map_ind cD1' ms cD + | (I.MDot (I.MV u, ms), I.Dec (cD, I.Decl (_, mtyp1, _, Inductivity.Inductive))) -> + let cD1' = mark_ind cD1' u in + id_map_ind cD1' ms cD + + | (I.MDot (I.MV u, ms), I.Dec (cD, I.Decl (_, mtyp1, _, Inductivity.NotInductive))) -> + id_map_ind cD1' ms cD - | (I.MDot (mf, ms), I.Dec (cD, I.Decl (_, mtyp1, dep))) -> + | (I.MDot (mf, ms), I.Dec (cD, I.Decl (_, mtyp1, _, inductivity))) -> begin match mf with | I.(ClObj (_, MObj (Root (_, MVar (Offset u, Shift 0), Nil, _)))) | I.(ClObj (_, MObj (Root (_, PVar (u, Shift 0), Nil, _)))) | I.(ClObj (_, PObj (PVar (u, Shift 0)))) | I.(CObj (CtxVar (CtxOffset u))) | I.(ClObj (_, SObj (SVar (u, 0, Shift 0)))) -> - if Total.is_inductive dep + if Inductivity.is_inductive inductivity then begin let cD1' = mark_ind cD1' u in @@ -581,7 +578,7 @@ module Comp = struct (* let is_ind _ _ = true match x with | I.Offset x, sigma -> - let (_, tA, cPsi', dp) = Whnf.mctxMDec cD u in + let (_, tA, cPsi', dep) = Whnf.mctxMDec cD u in let d = match dep with | I.Inductive -> true | _ -> false in @@ -700,16 +697,16 @@ module Comp = struct and genMAppW loc p cD (i, tau_t) = match tau_t with - | (Int.Comp.TypPiBox (_, (Int.LF.Decl (u, cU, dep) as d), tau), theta) + | (Int.Comp.TypPiBox (_, (Int.LF.Decl (u, cU, plicity, inductivity) as d), tau), theta) when p d -> - let (cM, t') = Whnf.dotMMVar loc cD theta (u, cU, dep) in + let (cM, t') = Whnf.dotMMVar loc cD theta (u, cU, plicity, inductivity) in let i = Int.Comp.MApp ( loc , i , cM , Whnf.cnormMTyp (cU, theta) - , Int.LF.Depend.to_plicity dep + , plicity (* the MApp's plicity depends on the type of the PiBox that it eliminates. *) ) @@ -759,8 +756,8 @@ module Comp = struct and checkMetaSpine loc cD mS cKt = match (mS, cKt) with | (MetaNil, (Ctype _, _)) -> () - | (MetaApp (mO, mT, mS, plicity), (PiKind (_, I.Decl (_, ctyp, dep), cK), t)) -> - if Stdlib.(<>) (Int.LF.Depend.to_plicity dep) plicity + | (MetaApp (mO, mT, mS, plicity_app), (PiKind (_, I.Decl (_, ctyp, plicity_pi, inductivity), cK), t)) -> + if not (Plicity.equal plicity_app plicity_pi) then Error.violation "[checkMetaSpine] plicity mismatch"; let loc = getLoc mO in LF.checkMetaObj cD mO (ctyp, t); @@ -802,7 +799,7 @@ module Comp = struct LF.checkDCtx cD cPsi; checkClTyp loc cD cPsi tp - let checkCDecl cD (I.Decl (x, ctyp, _)) = + let checkCDecl cD (I.Decl (x, ctyp, _, _)) = checkCLFTyp (Id.loc_of_name x) cD ctyp let rec checkKind cD = @@ -860,8 +857,8 @@ module Comp = struct cD, x:[t]U mctx *) - let extend_mctx cD (x, (I.Decl (_, cU, dep)), t) = - I.Dec (cD, I.Decl (x, C.cnormMTyp (cU, t), dep)) + let extend_mctx cD (x, (I.Decl (_, cU, plicity, inductivity)), t) = + I.Dec (cD, I.Decl (x, C.cnormMTyp (cU, t), plicity, inductivity)) let rec extract_var = function @@ -969,23 +966,23 @@ module Comp = struct ("MLam " ^ Fmt.stringify (P.fmt_ppr_cmp_exp_chk cD cG P.l0) e) | (Pair (loc, e1, e2), (TypCross (_, tau1, tau2), t)) -> - check mcid cD (cG,cIH) total_decs e1 (tau1, t); - check mcid cD (cG,cIH) total_decs e2 (tau2, t); + check mcid cD (cG, cIH) total_decs e1 (tau1, t); + check mcid cD (cG, cIH) total_decs e2 (tau2, t); Typeinfo.Comp.add loc (Typeinfo.Comp.mk_entry cD ttau) ("Pair " ^ Fmt.stringify (P.fmt_ppr_cmp_exp_chk cD cG P.l0) e) | (Let (loc, i, (x, e)), (tau, t)) -> - let (_, tau', t') = syn mcid cD (cG,cIH) total_decs i in - let (tau', t') = C.cwhnfCTyp (tau',t') in + let (_, tau', t') = syn mcid cD (cG, cIH) total_decs i in + let (tau', t') = C.cwhnfCTyp (tau', t') in let cG' = I.Dec (cG, CTypDecl (x, Whnf.cnormCTyp (tau', t'), false)) in - check mcid cD (cG', Total.shift cIH) total_decs e (tau,t); + check mcid cD (cG', Total.shift cIH) total_decs e (tau, t); Typeinfo.Comp.add loc (Typeinfo.Comp.mk_entry cD ttau) ("Let " ^ Fmt.stringify (P.fmt_ppr_cmp_exp_chk cD cG P.l0) e) | (LetPair (_, i, (x, y, e)), (tau, t)) -> - let (_, tau', t') = syn mcid cD (cG,cIH) total_decs i in - let (tau', t') = C.cwhnfCTyp (tau',t') in - begin match (tau',t') with + let (_, tau', t') = syn mcid cD (cG, cIH) total_decs i in + let (tau', t') = C.cwhnfCTyp (tau', t') in + begin match (tau', t') with | (TypCross (_, tau1, tau2), t') -> let cG' = I.Dec @@ -993,7 +990,7 @@ module Comp = struct , CTypDecl (y, Whnf.cnormCTyp (tau2, t'), false) ) in - check mcid cD (cG', (Total.shift (Total.shift cIH))) total_decs e (tau,t) + check mcid cD (cG', (Total.shift (Total.shift cIH))) total_decs e (tau, t) | _ -> raise (Error.Violation "Case scrutinee not of product type") end @@ -1021,7 +1018,7 @@ module Comp = struct allowing to consider more cases as covering, especially in situations with nested cases. *) let problem = Coverage.make loc prag cD branches tau_sc' None in - checkBranches mcid cD (cG,cIH) total_decs + checkBranches mcid cD (cG, cIH) total_decs (i, tau_sc) branches (tau, t); @@ -1029,7 +1026,7 @@ module Comp = struct | (Syn (loc, i), (tau, t)) -> dprint (fun () -> "check --> syn"); - let (cIH_opt, tau', t') = syn mcid cD (cG,cIH) total_decs i in + let (cIH_opt, tau', t') = syn mcid cD (cG, cIH) total_decs i in begin match cIH_opt with | None -> () | Some Int.LF.(Dec (_, WfRec (_, [], _))) -> () @@ -1043,7 +1040,7 @@ module Comp = struct Typeinfo.Comp.add loc (Typeinfo.Comp.mk_entry cD ttau) ("Syn " ^ Fmt.stringify (P.fmt_ppr_cmp_exp_chk cD cG P.l0) e) else - raise (Error (loc, MismatchChk (cD, cG, e, (tau,t), (tau',t')))) + raise (Error (loc, MismatchChk (cD, cG, e, (tau, t), (tau', t')))) | (Hole (loc, id, name), (tau, t)) -> Typeinfo.Comp.add loc (Typeinfo.Comp.mk_entry cD ttau) @@ -1180,11 +1177,11 @@ module Comp = struct end | Apply (loc, e1, e2) as e -> - let (cIH_opt, tau1, t1) = syn mcid cD (cG,cIH) total_decs e1 in - let (tau1,t1) = C.cwhnfCTyp (tau1,t1) in + let (cIH_opt, tau1, t1) = syn mcid cD (cG, cIH) total_decs e1 in + let (tau1, t1) = C.cwhnfCTyp (tau1, t1) in begin match (tau1, t1) with | (TypArr (_, tau2, tau), t) -> - check mcid cD (cG,cIH) total_decs e2 (tau2, t); + check mcid cD (cG, cIH) total_decs e2 (tau2, t); Typeinfo.Comp.add loc (Typeinfo.Comp.mk_entry cD (tau, t)) @@ -1207,7 +1204,7 @@ module Comp = struct P.(fmt_ppr_cmp_meta_typ cD) cU end; begin match (C.cwhnfCTyp (tau1,t1)) with - | (TypPiBox (_, (I.Decl (_, ctyp, _)), tau), t) -> + | (TypPiBox (_, (I.Decl (_, ctyp, _, _)), tau), t) -> dprintf begin fun p -> p.fmt "[syn] @[MApp\ @@ -1270,12 +1267,12 @@ module Comp = struct (* if Whnf.convCTyp (tau1, theta) (tau', theta') then *) (* (tau2, theta) *) (* else *) - (* raise (Error (loc, TypMismatch (cD, (tau1, theta), (tau',theta')))) *) + (* raise (Error (loc, TypMismatch (cD, (tau1, theta), (tau', theta')))) *) (* | (CopatApp (loc, dest, csp'), (TypArr (tau1, tau2), theta), (tau', theta')) -> *) (* if Whnf.convCTyp (tau1, theta) (tau', theta') then *) (* synObs cD csp' ((CompDest.get dest).CompDest.typ, Whnf.m_id) (tau2, theta) *) (* else *) - (* raise (Error (loc, TypMismatch (cD, (tau1, theta), (tau',theta')))) *) + (* raise (Error (loc, TypMismatch (cD, (tau1, theta), (tau', theta')))) *) and checkPattern cD cG pat ttau = match pat with @@ -1354,11 +1351,11 @@ module Comp = struct end; let tau0 = (CompDest.get obs).CompDest.Entry.obs_type in let tau1 = (CompDest.get obs).CompDest.Entry.return_type in - if Whnf.convCTyp (tau,theta) (tau0,t) + if Whnf.convCTyp (tau, theta) (tau0, t) then synPatSpine cD cG pat_spine (tau1, t) - else raise (Error (loc, TypMismatch (cD, (tau,theta), (tau0,t)))) + else raise (Error (loc, TypMismatch (cD, (tau, theta), (tau0, t)))) - and checkPatAgainstCDecl cD (PatMetaObj (loc, mO)) (I.Decl (_, ctyp, _), theta) = + and checkPatAgainstCDecl cD (PatMetaObj (loc, mO)) (I.Decl (_, ctyp, _, _), theta) = LF.checkMetaObj cD mO (ctyp, theta); I.MDot (metaObjToMFront mO, theta) @@ -1638,7 +1635,7 @@ module Comp = struct p.fmt "[check] [command] [Unbox] result ctyp = @[%a@]" P.(fmt_ppr_cmp_meta_typ cD) cU end; - extend_meta I.(Decl (name, cU, No)) + extend_meta I.(Decl (name, cU, Plicity.explicit, Inductivity.not_inductive)) (** Check a hypothetical derivation. Ensures that the contexts in the hypothetical are convertible @@ -1727,7 +1724,7 @@ module Comp = struct args let syn mcid cD cG (total_decs : total_dec list) ?cIH:(cIH = Syntax.Int.LF.Empty) e = - let (cIH, tau, ms) = syn mcid cD (cG,cIH) total_decs e in + let (cIH, tau, ms) = syn mcid cD (cG, cIH) total_decs e in (cIH, (tau, ms)) let check mcid cD cG (total_decs : total_dec list) ?cIH:(cIH = Syntax.Int.LF.Empty) e ttau = diff --git a/src/core/context.ml b/src/core/context.ml index b93e5415e..c3b7782fd 100644 --- a/src/core/context.ml +++ b/src/core/context.ml @@ -349,7 +349,7 @@ let rec getNameDCtx cPsi k = let rec getNameMCtx cD k = match (cD, k) with - | (Dec (_, Decl (u, _, _)), 1) -> u + | (Dec (_, Decl (u, _, _, _)), 1) -> u | (Dec (_, DeclOpt (u, _)), 1) -> u | (Dec (cD, _), k) -> getNameMCtx cD (k - 1) @@ -402,11 +402,11 @@ let rec lookup' ctx k = | (Dec (ctx', _), k) -> lookup' ctx' (k - 1) | _ -> None -let lookup_dep (cD : LF.mctx) k = +let lookup_inductivity (cD : LF.mctx) k = let open Option in lookup' cD k $ function - | LF.Decl (_, tau, dep) -> Some (tau, dep) + | LF.Decl (_, tau, _, inductivity) -> Some (tau, inductivity) | _ -> None let lookup cG k = @@ -418,7 +418,7 @@ let lookup cG k = let rec lookupSchema cD psi_offset = match (cD, psi_offset) with - | (Dec (_, Decl (_, CTyp (Some cid_schema), _)), 1) -> cid_schema + | (Dec (_, Decl (_, CTyp (Some cid_schema), _, _)), 1) -> cid_schema | (Dec (cD, _) , i) -> lookupSchema cD (i - 1) @@ -426,7 +426,7 @@ and lookupCtxVar cD cvar = let rec lookup cD offset = match cD with | Empty -> raise (Error.Violation "Context variable not found") - | Dec (cD, Decl (psi, CTyp (Some schemaName), _)) -> + | Dec (cD, Decl (psi, CTyp (Some schemaName), _, _)) -> begin match cvar with | CtxName phi when Id.equals psi phi -> (psi, schemaName) | CtxName _ -> lookup cD (offset + 1) @@ -435,7 +435,7 @@ and lookupCtxVar cD cvar = then (psi, schemaName) else lookup cD (offset + 1) end - | Dec (cD, _) -> lookup cD (offset+1) + | Dec (cD, _) -> lookup cD (offset + 1) in lookup cD 0 @@ -485,8 +485,8 @@ let names_of_proof_state g = let rec steal_mctx_names cD cD' = match (cD, cD') with - | (Dec (cD, Decl (_, cU, dep)), Dec (cD', Decl (u', _, _))) -> - Dec (steal_mctx_names cD cD', Decl (u', cU, dep)) + | (Dec (cD, Decl (_, cU, plicity, inductivity)), Dec (cD', Decl (u', _, _, _))) -> + Dec (steal_mctx_names cD cD', Decl (u', cU, plicity, inductivity)) | (Empty, Empty) -> Empty | _ -> Error.violation "[steal_mctx_names] inputs weren't convertible" diff --git a/src/core/context.mli b/src/core/context.mli index 4e654ad12..1af300c55 100644 --- a/src/core/context.mli +++ b/src/core/context.mli @@ -83,7 +83,7 @@ val emptyContextVariable : dctx -> dctx val lookup' : 'a LF.ctx -> int -> 'a option -(** Looks up an index in a meta-context, giving the type and `depend` field. +(** Looks up an index in a meta-context, giving the type and `inductivity` field. - Warning: This function does not MShift the type it returns; typically you should do this so the type makes sense in the whole context Delta. @@ -92,7 +92,7 @@ val lookup' : 'a LF.ctx -> int -> 'a option DeclOpt). If you need to distinguish these cases, then you should use `lookup'` and match on the `ctyp_decl` yourself. *) -val lookup_dep : LF.mctx -> int -> (LF.ctyp * LF.depend) option +val lookup_inductivity : LF.mctx -> int -> (LF.ctyp * Inductivity.t) option val lookup : Comp.gctx -> int -> Comp.typ option val lookupSchema : mctx -> int -> Id.cid_schema diff --git a/src/core/convSigma.ml b/src/core/convSigma.ml index c5d818bd3..188c23a67 100644 --- a/src/core/convSigma.ml +++ b/src/core/convSigma.ml @@ -53,8 +53,8 @@ let _ = (* ************************************************************************ *) let rec map conv_list k = match (conv_list, k) with - | (d::conv_list', 1) -> d - | (d::conv_list', _) -> d + map conv_list' (k-1) + | (d :: conv_list', 1) -> d + | (d :: conv_list', _) -> d + map conv_list' (k - 1) let rec strans_norm cD cPsi sM conv_list = strans_normW cD cPsi (Whnf.whnf sM) conv_list @@ -182,10 +182,10 @@ and strans_typW cD cPsi (tA, s) conv_list = | LF.Atom (loc, a, tS ) -> LF.Atom (loc, a, strans_spine cD cPsi (tS, s) conv_list ) - | LF.PiTyp ((LF.TypDecl (x, tA), dep), tB) -> + | LF.PiTyp ((LF.TypDecl (x, tA), plicity), tB) -> let tA' = strans_typ cD cPsi (tA, s) conv_list in - let tB' = strans_typ cD cPsi (tB, S.LF.dot1 s) (1::conv_list) in - LF.PiTyp ((LF.TypDecl (x, tA'), dep), tB') + let tB' = strans_typ cD cPsi (tB, S.LF.dot1 s) (1 :: conv_list) in + LF.PiTyp ((LF.TypDecl (x, tA'), plicity), tB') (* no sigma types allowed *) @@ -283,7 +283,7 @@ let gen_proj_sub conv_list = gen_projs (LF.Dot (LF.Head (LF.Proj (LF.BVar pos, index)), s)) pos - (k, index+1) + (k, index + 1) in let rec gen_sub conv_list pos = match conv_list with @@ -303,11 +303,11 @@ let gen_tup_sub conv_list = if k = index then (* only correct if pos stands for a variable of atomic type *) - LF.Last (LF.Root (Syntax.Loc.ghost, LF.BVar pos, LF.Nil, `explicit)) + LF.Last (LF.Root (Syntax.Loc.ghost, LF.BVar pos, LF.Nil, Plicity.explicit)) else begin - let tM = LF.Root (Syntax.Loc.ghost, LF.BVar pos, LF.Nil, `explicit) in - let tTup = gen_tup (pos - 1) (k, index+1) in + let tM = LF.Root (Syntax.Loc.ghost, LF.BVar pos, LF.Nil, Plicity.explicit) in + let tTup = gen_tup (pos - 1) (k, index + 1) in LF.Cons (tM, tTup) end in @@ -332,19 +332,19 @@ let gen_tup_sub conv_list = head. *) let rec etaExpandTuple tRec h k = let open LF in - let tM = Root (Loc.ghost, Proj (h, k), Nil, `explicit) in + let tM = Root (Loc.ghost, Proj (h, k), Nil, Plicity.explicit) in match tRec with | SigmaLast (_, _) -> Last tM | LF.SigmaElem (_, _, tRec) -> - LF.Cons (tM, etaExpandTuple tRec h (k+1)) + LF.Cons (tM, etaExpandTuple tRec h (k + 1)) *) -let rec etaExpandStrGeneric new_mxvar mk_head loc cD cPsi sA dep n names = +let rec etaExpandStrGeneric new_mxvar mk_head loc cD cPsi sA plicity n names = match Whnf.whnfTyp sA with | LF.Sigma tRec as tA, s -> (* XXX this doesn't do any strengthening !! -je *) let tH = - mk_head ((new_mxvar n (cD, cPsi, LF.tclo tA s) dep, Whnf.m_id), s) + mk_head ((new_mxvar n (cD, cPsi, LF.tclo tA s) plicity Inductivity.not_inductive, Whnf.m_id), s) in (* let tTup = @@ -352,7 +352,7 @@ let rec etaExpandStrGeneric new_mxvar mk_head loc cD cPsi sA dep n names = in LF.Tuple (Loc.ghost, tTup) *) - LF.Root (Loc.ghost, tH, LF.Nil, `explicit) + LF.Root (Loc.ghost, tH, LF.Nil, Plicity.explicit) | (LF.Atom (_, a, _tS) as tP, s) -> let (cPhi, conv_list) = flattenDCtx cD cPsi in @@ -369,7 +369,7 @@ let rec etaExpandStrGeneric new_mxvar mk_head loc cD cPsi sA dep n names = let ssi' = S.LF.invert ss' in (* cPhi' |- ssi : cPhi *) (* cPhi' |- [ssi]tQ *) - let u = new_mxvar n (cD, cPhi', LF.TClo (tQ, ssi')) dep in + let u = new_mxvar n (cD, cPhi', LF.TClo (tQ, ssi')) plicity Inductivity.not_inductive in (* cPhi |- ss' : cPhi' cPsi |- s_proj : cPhi cPsi |- comp ss' s_proj : cPhi' *) @@ -378,7 +378,7 @@ let rec etaExpandStrGeneric new_mxvar mk_head loc cD cPsi sA dep n names = ( loc , mk_head ((u, Whnf.m_id), ss_proj) , LF.Nil - , `explicit + , Plicity.explicit ) | (LF.PiTyp ((LF.TypDecl (x, tA), _), tB), s) -> @@ -386,7 +386,7 @@ let rec etaExpandStrGeneric new_mxvar mk_head loc cD cPsi sA dep n names = let decl = LF.TypDecl (x, tA) in let cPsi' = LF.DDec (cPsi, S.LF.decSub decl s) in let tN = - etaExpandStrGeneric new_mxvar mk_head loc cD cPsi' (tB, S.LF.dot1 s) dep n (x :: names) + etaExpandStrGeneric new_mxvar mk_head loc cD cPsi' (tB, S.LF.dot1 s) plicity n (x :: names) in LF.Lam (loc, x, tN) diff --git a/src/core/convSigma.mli b/src/core/convSigma.mli index 451f2914f..85c2d5b0c 100644 --- a/src/core/convSigma.mli +++ b/src/core/convSigma.mli @@ -28,11 +28,11 @@ val gen_tup_sub : t -> sub (** Constructs a unification variable for the given tclo, strengthening its type. *) -val etaExpandMMVstr : Loc.t -> mctx -> dctx -> tclo -> depend -> Id.name option -> Id.name list -> normal +val etaExpandMMVstr : Loc.t -> mctx -> dctx -> tclo -> Plicity.t -> Id.name option -> Id.name list -> normal (** Constructs a unification parameter variable for a given tclo, strengthening its type. *) -val etaExpandMPVstr : Loc.t -> mctx -> dctx -> tclo -> depend -> Id.name option -> Id.name list -> normal +val etaExpandMPVstr : Loc.t -> mctx -> dctx -> tclo -> Plicity.t -> Id.name option -> Id.name list -> normal (** gen_flattening cD cPsi = (cPhi, lazy s_proj, lazy s_tup) Generates a flattened LF context cPhi in which all blocks present diff --git a/src/core/coverage.ml b/src/core/coverage.ml index ffcd8d9a0..ebff4567c 100644 --- a/src/core/coverage.ml +++ b/src/core/coverage.ml @@ -193,7 +193,7 @@ let gen_str cD cPsi (LF.Atom (_, a, _) as tP) = let eta_expand (tH, tA) = let rec eta (tA, s) tS = match tA with - | LF.Atom _ -> LF.Root (Loc.ghost, tH, tS, `explicit) + | LF.Atom _ -> LF.Root (Loc.ghost, tH, tS, Plicity.explicit) | LF.PiTyp ((LF.TypDecl (x, tB0), _), tB) -> let tM = eta (tB0, s) LF.Nil in LF.Lam (Loc.ghost, x, eta (tB, S.LF.dot1 s) (LF.App (tM, tS))) @@ -348,7 +348,7 @@ end = struct begin fun ppf -> List.iteri begin fun i -> - fprintf ppf "%2d. @[%a@]@," (i+1) (fmt_ppr_equation cD cD_p) + fprintf ppf "%2d. @[%a@]@," (i + 1) (fmt_ppr_equation cD cD_p) end end @@ -444,7 +444,7 @@ end = struct | (LF.MV _, LF.Dec (cD0, _)) | (LF.CObj (LF.CtxVar _), LF.Dec (cD0, _)) -> id t cD0 - | (LF.ClObj _, LF.Dec (cD0, LF.Decl (_, tU, _))) -> + | (LF.ClObj _, LF.Dec (cD0, LF.Decl (_, tU, _, _))) -> check_meta_obj cD (Loc.ghost, m) @@ -779,12 +779,12 @@ and pre_match_sub cD cD_p covGoal patt matchCands splitCands = pre_match_sub cD cD_p covGoal patt matchCands' splitCands' | ((LF.Shift n, _), (LF.Dot (LF.Head LF.BVar _, _), _)) -> - let s0 = LF.Dot (LF.Head (LF.BVar (n+1)), LF.Shift (n+1)) in + let s0 = LF.Dot (LF.Head (LF.BVar (n + 1)), LF.Shift (n + 1)) in let covGoal = CovSub (cPsi0, s0, LF.STyp (r0, cPhi0)) in pre_match_sub cD cD_p covGoal patt matchCands splitCands | ((LF.Dot (LF.Head LF.BVar _, _), _), (LF.Shift n, _)) -> - let s1 = LF.Dot (LF.Head (LF.BVar (n+1)), LF.Shift (n+1)) in + let s1 = LF.Dot (LF.Head (LF.BVar (n + 1)), LF.Shift (n + 1)) in let patt = MetaSub (cPsi1, s1, LF.STyp (r1, cPhi1)) in pre_match_sub cD cD_p covGoal patt matchCands splitCands @@ -953,15 +953,15 @@ let match_metaobj cD cD_p ((loc, mO), mt) ((loc', mO_p), mtp) mC sC = | LF.((PObj tH, PTyp tA), (PObj tH', PTyp tA')) -> let (mC0, sC0) = pre_match_dctx cD cD_p cPsi cPsi' mC sC in let (mC1, sC1) = pre_match_typ cD cD_p (cPsi, (tA, S.LF.id)) (cPsi', (tA', S.LF.id)) mC0 sC0 in - let covGoal = CovGoal (cPsi, LF.Root (Loc.ghost, tH, LF.Nil, `explicit), (tA, S.LF.id)) in - let pat = MetaPatt (cPsi', LF.Root (Loc.ghost, tH', LF.Nil, `explicit), (tA', S.LF.id)) in + let covGoal = CovGoal (cPsi, LF.Root (Loc.ghost, tH, LF.Nil, Plicity.explicit), (tA, S.LF.id)) in + let pat = MetaPatt (cPsi', LF.Root (Loc.ghost, tH', LF.Nil, Plicity.explicit), (tA', S.LF.id)) in pre_match cD cD_p covGoal pat mC1 sC1 | LF.((MObj tR, PTyp tA), (PObj tH, PTyp tA')) -> let (mC0, sC0) = pre_match_dctx cD cD_p cPsi cPsi' mC sC in let (mC1, sC1) = pre_match_typ cD cD_p (cPsi, (tA, S.LF.id)) (cPsi', (tA', S.LF.id)) mC0 sC0 in let covGoal = CovGoal (cPsi, tR, (tA, S.LF.id)) in - let tR' = LF.(Root (Loc.ghost, tH, Nil, `explicit)) in + let tR' = LF.(Root (Loc.ghost, tH, Nil, Plicity.explicit)) in let pat = MetaPatt (cPsi', tR', (tA', S.LF.id)) in pre_match cD cD_p covGoal pat mC1 sC1 @@ -1063,8 +1063,8 @@ and match_spines (cD, cG) (cD_p, cG_p) pS pS' mC sC = match_spines (cD, cG) (cD_p, cG_p) (pS, (tau2, t)) (pS', (tau2', t')) mC1 sC1 - | Comp.( (PatApp (_, pat, pS), (TypPiBox (_, LF.(Decl (_, ClTyp (MTyp tA, cPsi), _)), tau2), t)) - , (PatApp (_, pat', pS'), (TypPiBox (_, LF.(Decl (_, ClTyp (MTyp tA', cPsi'), _)), tau2'), t')) + | Comp.( (PatApp (_, pat, pS), (TypPiBox (_, LF.(Decl (_, ClTyp (MTyp tA, cPsi), _, _)), tau2), t)) + , (PatApp (_, pat', pS'), (TypPiBox (_, LF.(Decl (_, ClTyp (MTyp tA', cPsi'), _, _)), tau2'), t')) ) -> let Comp.PatMetaObj (_, (loc, mO)) = pat in let Comp.PatMetaObj (_, (loc', mO')) = pat' in @@ -1081,8 +1081,8 @@ and match_spines (cD, cG) (cD_p, cG_p) pS pS' mC sC = mC1 sC1 - | Comp.( (PatApp (_, pat, pS), (TypPiBox (_, LF.(Decl (_, ClTyp (PTyp tA, cPsi), _)), tau2), t)) - , (PatApp (_, pat', pS'), (TypPiBox (_, LF.(Decl (_, ClTyp (PTyp tA', cPsi'), _)), tau2'), t')) + | Comp.( (PatApp (_, pat, pS), (TypPiBox (_, LF.(Decl (_, ClTyp (PTyp tA, cPsi), _, _)), tau2), t)) + , (PatApp (_, pat', pS'), (TypPiBox (_, LF.(Decl (_, ClTyp (PTyp tA', cPsi'), _, _)), tau2'), t')) ) -> let Comp.PatMetaObj (_, (loc, mO)) = pat in let Comp.PatMetaObj (_, (loc', mO')) = pat' in @@ -1099,8 +1099,8 @@ and match_spines (cD, cG) (cD_p, cG_p) pS pS' mC sC = mC1 sC1 - | Comp.( (PatApp (_, pat, pS), (TypPiBox (_, LF.Decl (_, LF.CTyp w, _), tau2), t)) - , (PatApp (_, pat', pS'), (TypPiBox (_, LF.Decl (_, LF.CTyp w', _), tau2'), t')) + | Comp.( (PatApp (_, pat, pS), (TypPiBox (_, LF.Decl (_, LF.CTyp w, _, _), tau2), t)) + , (PatApp (_, pat', pS'), (TypPiBox (_, LF.Decl (_, LF.CTyp w', _, _), tau2'), t')) ) -> let Comp.PatMetaObj (_, (loc, mO)) = pat in let Comp.PatMetaObj (_, (loc', mO')) = pat' in @@ -1111,8 +1111,8 @@ and match_spines (cD, cG) (cD_p, cG_p) pS pS' mC sC = let (mC1, sC1) = match_metaobj cD cD_p ((loc, mO), tau1) ((loc', mO'), tau1') mC sC in match_spines (cD, cG) (cD_p, cG_p) (pS, (tau2, t2)) (pS', (tau2', t2')) mC1 sC1 - | Comp.( (PatApp (_, pat, pS), (TypPiBox (_, LF.(Decl (_, ClTyp (STyp (cl, cPhi), cPsi), _)), tau2), t)) - , (PatApp (_, pat', pS'), (TypPiBox (_, LF.(Decl (_, ClTyp (STyp (cl', cPhi'), cPsi'), _)), tau2'), t'))) -> + | Comp.( (PatApp (_, pat, pS), (TypPiBox (_, LF.(Decl (_, ClTyp (STyp (cl, cPhi), cPsi), _, _)), tau2), t)) + , (PatApp (_, pat', pS'), (TypPiBox (_, LF.(Decl (_, ClTyp (STyp (cl', cPhi'), cPsi'), _, _)), tau2'), t'))) -> let Comp.PatMetaObj (_, (loc, mO)) = pat in let Comp.PatMetaObj (_, (loc', mO')) = pat' in let mk_cltyp cl cPhi cPsi t = LF.(ClTyp (STyp (cl, Whnf.cnormDCtx (cPhi, t)), Whnf.cnormDCtx (cPsi, t))) in @@ -1170,12 +1170,12 @@ let rec genSpine k names cD cPsi sA tP = *) (* let tN = Whnf.etaExpandMV cPsi (tA, s) S.LF.id in *) let u = NameGen.(mvar tA |> renumber names) in - let dep = + let plicity = if k > 0 - then LF.Maybe - else LF.No + then Plicity.implicit + else Plicity.explicit in - let tN = ConvSigma.etaExpandMMVstr Loc.ghost cD cPsi (tA, s) dep (Some u) (u :: names) in + let tN = ConvSigma.etaExpandMMVstr Loc.ghost cD cPsi (tA, s) plicity (Some u) (u :: names) in dprintf begin fun p -> p.fmt "[genSpine] @[Pi-type: extending spine with new (eta-expanded) variable@,\ @@ -1247,7 +1247,7 @@ let genObj (cD, cPsi, tP) (tH, tA, k) = with | None -> None | Some spine -> - let tM = LF.Root (Loc.ghost, tH', spine, `explicit) in + let tM = LF.Root (Loc.ghost, tH', spine, Plicity.explicit) in let (cD', cPsi', tR, tP', ms') = try Abstract.covgoal cPsi' tM tP' (Whnf.cnormMSub ms) (* cD0; cPsi0 |- tM : tP0 *) @@ -1366,7 +1366,8 @@ let genPVarGoal (LF.SchElem (decls, trec)) (cD : LF.mctx) cPsi psi Decl ( NameGen.(pvar tA |> renumber names) , ClTyp (PTyp tA, Whnf.cnormDCtx (LF.CtxVar psi, MShift offset)) - , No + , Plicity.explicit + , Inductivity.not_inductive ) in @@ -1451,7 +1452,7 @@ let rec genBCovGoals ((cD, cPsi, tA) as cov_problem) = (* I *think* Atom and Sigma can be treated identically here, since they're both the base types, essentially. -je *) - | LF.PiTyp ((tdecl, dep), tA) -> + | LF.PiTyp ((tdecl, plicity), tA) -> let x = match tdecl with | LF.TypDecl (x, _) -> x @@ -1463,7 +1464,7 @@ let rec genBCovGoals ((cD, cPsi, tA) as cov_problem) = let cg' = ( cPsi' , LF.Lam (Loc.ghost, x, tM) - , (LF.PiTyp ((tdecl', dep), LF.TClo (sA)), S.LF.id) + , (LF.PiTyp ((tdecl', plicity), LF.TClo (sA)), S.LF.id) ) in (cD', cg', ms) @@ -1515,7 +1516,7 @@ let rec genCovGoals ((cD, cPsi, tA) as cov_problem : (LF.mctx * LF.dctx * LF.typ end; g_pv @ g_bv @ g_cv - | LF.PiTyp ((tdecl, dep), tB) -> + | LF.PiTyp ((tdecl, plicity), tB) -> let LF.TypDecl (x, _) = tdecl in let cov_goals = genCovGoals (cD, LF.DDec (cPsi, tdecl), tB) in List.map @@ -1523,7 +1524,7 @@ let rec genCovGoals ((cD, cPsi, tA) as cov_problem : (LF.mctx * LF.dctx * LF.typ ( cD' , ( cPsi' , LF.Lam (Loc.ghost, x, tM) - , (LF.PiTyp ((tdecl', dep), LF.TClo (sA)), S.LF.id)) + , (LF.PiTyp ((tdecl', plicity), LF.TClo (sA)), S.LF.id)) , t ) end @@ -1598,7 +1599,7 @@ let rec solve' cD (matchCand, ms) cD_p mCands' sCands' = | "Pruning" -> (* Match Candidate is kept ? *) let sc = Split (CovSub (cPsi, s, sT), MetaSub (cPsi_p, s_p, sT_p)) in - solve' cD (mCands, ms) cD_p (mCands') (sc::sCands') + solve' cD (mCands, ms) cD_p (mCands') (sc :: sCands') | _ -> (* we are not trying to be clever and see if a context split would lead to progress *) dprint @@ -1641,7 +1642,7 @@ let rec solve' cD (matchCand, ms) cD_p mCands' sCands' = dprint (fun _ -> "[solve'] matched types; now trying to match terms."); U.matchTerm cD cPsi (tR, S.LF.id) (tR_p', S.LF.id); dprint (fun _ -> "[solve'] matched terms; now going to solve remaining equations"); - solve' cD (mCands, ms) cD_p (mc::mCands') sCands' + solve' cD (mCands, ms) cD_p (mc :: mCands') sCands' with (* should this case betaken care of during pre_match phase ? *) | U.GlobalCnstrFailure (_, cnstr) -> @@ -1657,7 +1658,7 @@ let rec solve' cD (matchCand, ms) cD_p mCands' sCands' = dctx cPsi dctx cPsi_p' end; - solve' cD (mCands, ms) cD_p mCands' (sc::sCands') + solve' cD (mCands, ms) cD_p mCands' (sc :: sCands') | U.Failure msg -> if U.unresolvedGlobalCnstrs () then @@ -1667,14 +1668,14 @@ let rec solve' cD (matchCand, ms) cD_p mCands' sCands' = " UNIFY FAILURE " ^ msg ^ "\n MOVED BACK TO SPLIT CAND" end; let sc = Split (CovGoal (cPsi, tR, sA), MetaPatt (cPsi_p, tR_p, sA_p)) in - solve' cD (mCands, ms) cD_p mCands' (sc::sCands') + solve' cD (mCands, ms) cD_p mCands' (sc :: sCands') end else begin match msg with | "Pruning" -> (* Match Candidate is kept ? *) let sc = Split (CovGoal (cPsi, tR, sA), MetaPatt (cPsi_p, tR_p, sA_p)) in - solve' cD (mCands, ms) cD_p (mCands') (sc::sCands') + solve' cD (mCands, ms) cD_p (mCands') (sc :: sCands') | _ -> dprint begin fun _ -> @@ -1912,14 +1913,14 @@ let rec refine_pattern cov_goals ((cD, cG, candidates, patt) as cov_problem) = let rec addToMCtx cD (cD_tail, ms) = match cD_tail with | [] -> (cD, ms) - | LF.Decl (u, LF.ClTyp (LF.MTyp tA, cPsi), dep) :: cD_tail -> - let mdec = LF.Decl (u, LF.ClTyp (LF.MTyp (Whnf.cnormTyp (tA, ms)), Whnf.cnormDCtx (cPsi, ms)), dep) in + | LF.Decl (u, LF.ClTyp (LF.MTyp tA, cPsi), plicity, inductivity) :: cD_tail -> + let mdec = LF.Decl (u, LF.ClTyp (LF.MTyp (Whnf.cnormTyp (tA, ms)), Whnf.cnormDCtx (cPsi, ms)), plicity, inductivity) in addToMCtx (LF.Dec (cD, mdec)) (cD_tail, Whnf.mvar_dot1 ms) - | LF.Decl (u, LF.ClTyp (LF.PTyp tA, cPsi), dep) :: cD_tail -> - let pdec = LF.Decl (u, LF.ClTyp (LF.PTyp (Whnf.cnormTyp (tA, ms)), Whnf.cnormDCtx (cPsi, ms)), dep) in + | LF.Decl (u, LF.ClTyp (LF.PTyp tA, cPsi), plicity, inductivity) :: cD_tail -> + let pdec = LF.Decl (u, LF.ClTyp (LF.PTyp (Whnf.cnormTyp (tA, ms)), Whnf.cnormDCtx (cPsi, ms)), plicity, inductivity) in addToMCtx (LF.Dec (cD, pdec)) (cD_tail, Whnf.mvar_dot1 ms) - | LF.Decl (u, LF.ClTyp (LF.STyp (cl, cPhi), cPsi), dep) :: cD_tail -> - let sdec = LF.Decl (u, LF.ClTyp (LF.STyp (cl, Whnf.cnormDCtx (cPhi, ms)), Whnf.cnormDCtx (cPsi, ms)), dep) in + | LF.Decl (u, LF.ClTyp (LF.STyp (cl, cPhi), cPsi), plicity, inductivity) :: cD_tail -> + let sdec = LF.Decl (u, LF.ClTyp (LF.STyp (cl, Whnf.cnormDCtx (cPhi, ms)), Whnf.cnormDCtx (cPsi, ms)), plicity, inductivity) in addToMCtx (LF.Dec (cD, sdec)) (cD_tail, Whnf.mvar_dot1 ms) | cdecl :: cD_tail -> addToMCtx (LF.Dec (cD, cdecl)) (cD_tail, Whnf.mvar_dot1 ms) @@ -1957,9 +1958,9 @@ let rec decTomdec names cD' (LF.CtxOffset k as cpsi) (d, decls) = (* .; decls |- tA : type *) (* cD'; cpsi, @x: _ |- s' : decls *) - let (cD'', s') = decTomdec names cD' cpsi (d-1, decls) in + let (cD'', s') = decTomdec names cD' cpsi (d - 1, decls) in let (cPsi, (LF.Atom (_, a, _) as tP, s)) = - Whnf.lowerTyp (LF.CtxVar (LF.CtxOffset (k+d))) (tA, s') + Whnf.lowerTyp (LF.CtxVar (LF.CtxOffset (k + d))) (tA, s') in (* bp : Context substitution associated with declaration is off by 1 *) let (ss', cPsi') = Subord.thin' cD'' a cPsi in @@ -1971,7 +1972,8 @@ let rec decTomdec names cD' (LF.CtxOffset k as cpsi) (d, decls) = LF.Decl ( x , LF.ClTyp (LF.MTyp (LF.TClo (tP, ssi)), cPsi') - , LF.Maybe + , Plicity.implicit + , Inductivity.not_inductive ) in let mv = @@ -1979,7 +1981,7 @@ let rec decTomdec names cD' (LF.CtxOffset k as cpsi) (d, decls) = ( Loc.ghost , LF.MVar (LF.Offset 1, Whnf.cnormSub (ss', LF.MShift 1)) , LF.Nil - , `explicit + , Plicity.explicit ) in ( LF.Dec (cD'', mdec) @@ -2018,7 +2020,7 @@ let genSchemaElemGoal names cD psi (LF.SchElem (cPhi, trec)) = p.fmt "[genCtx] @[s =@ @[%a@]@]" (P.fmt_ppr_lf_sub cD0 (LF.CtxVar psi) P.l0) s end; - let cpsi' = LF.CtxVar (LF.CtxOffset (d+1)) in + let cpsi' = LF.CtxVar (LF.CtxOffset (d + 1)) in (* cD0 = cD, decls *) let tA = LF.tclo (Whnf.collapse_sigma trec) s in dprintf @@ -2059,7 +2061,7 @@ let genNthSchemaElemGoal names cD n w = Id.(mk_name (SomeString "g")) |> NameGen.renumber names in - let cD' = LF.Dec (cD, LF.Decl (x, LF.CTyp (Some w), LF.Maybe)) in + let cD' = LF.Dec (cD, LF.Decl (x, LF.CTyp (Some w), Plicity.implicit, Inductivity.not_inductive)) in let psi = LF.CtxOffset 1 in genSchemaElemGoal (x :: names) cD' psi e end @@ -2098,9 +2100,9 @@ let genCtx names (LF.Dec (cD', LF.Decl _) as cD) cpsi = cD |- . ] *) -let genContextGoals cD (x, LF.CTyp (Some schema_cid), dep) = +let genContextGoals cD (x, LF.CTyp (Some schema_cid), plicity, inductivity) = let LF.Schema elems = Store.Cid.Schema.get_schema schema_cid in - let cD' = LF.Dec (cD, LF.Decl (x, LF.CTyp (Some schema_cid), dep)) in + let cD' = LF.Dec (cD, LF.Decl (x, LF.CTyp (Some schema_cid), plicity, inductivity)) in genCtx [] cD' (LF.CtxOffset 1) elems (* Find mvar to split on *) @@ -2112,13 +2114,13 @@ let genSVCovGoals (cD, (cPsi, (r0, cPhi))) (* cov_problem *) = let LF.TypDecl (x, tA) = decl in let s = LF.SVar (2, 0, S.LF.id) in let mT = LF.ClTyp (LF.STyp (r0, cPhi'), cPsi) in - let cD' = LF.Dec (cD, LF.Decl (Id.mk_name (Whnf.newMTypName mT), mT, LF.No)) in + let cD' = LF.Dec (cD, LF.Decl (Id.mk_name (Whnf.newMTypName mT), mT, Plicity.explicit, Inductivity.not_inductive)) in (* if ren = renaming, generate parameter variable *) - let tM = LF.Root (Loc.ghost, LF.MVar (LF.Offset 1, S.LF.id), LF.Nil, `explicit) in + let tM = LF.Root (Loc.ghost, LF.MVar (LF.Offset 1, S.LF.id), LF.Nil, Plicity.explicit) in let tA0 = Whnf.cnormTyp (tA, LF.MShift 1) in let cPhi0 = Whnf.cnormDCtx (cPhi', LF.MShift 1) in let mT' = LF.ClTyp (LF.MTyp tA0, cPhi0) in - let cD'' = LF.Dec (cD', LF.Decl (Id.mk_name (Whnf.newMTypName mT'), mT', LF.No)) in + let cD'' = LF.Dec (cD', LF.Decl (Id.mk_name (Whnf.newMTypName mT'), mT', Plicity.explicit, Inductivity.not_inductive)) in let cPsi' = Whnf.cnormDCtx (cPsi, LF.MShift 2) in let cPhi'' = Whnf.cnormDCtx (cPhi, LF.MShift 2) in [(cD'', CovSub (cPsi', LF.Dot (LF.Obj tM, s), LF.STyp (r0, cPhi'')), LF.MShift 2)] @@ -2192,8 +2194,8 @@ let rec best_ctx_cand (cD, cv_list) k cD_tail = then begin let ctx_goals = - let LF.Decl (x, cU, dep) = d in - genContextGoals cD' (x, cU, dep) + let LF.Decl (x, cU, plicity, inductivity) = d in + genContextGoals cD' (x, cU, plicity, inductivity) in let f (cD', cPhi, ms) = (* cD' |- ms : cD *) @@ -2221,13 +2223,13 @@ let rec best_ctx_cand (cD, cv_list) k cD_tail = SomeCtxCands ctx_goals' end else - best_ctx_cand (cD', cv_list) (k+1) (d :: cD_tail) + best_ctx_cand (cD', cv_list) (k + 1) (d :: cD_tail) let rec best_cand (cD, mv_list) k cD_tail = match (mv_list, cD) with | ([], _) -> NoCandidate - | (LF.Offset j :: mvlist', LF.(Dec (cD', (Decl (_, cT, _) as md)))) -> + | (LF.Offset j :: mvlist', LF.(Dec (cD', (Decl (_, cT, _, _) as md)))) -> if k = j then begin @@ -2278,7 +2280,7 @@ let rec best_cand (cD, mv_list) k cD_tail = cov_goals' in - match best_cand (cD', mvlist') (k+1) (md::cD_tail) with + match best_cand (cD', mvlist') (k + 1) (md :: cD_tail) with | NoCandidate -> SomeTermCands (dep0, cov_goals0) | SomeTermCands (dep, cov_goals) -> begin match dep, dep0 with @@ -2333,12 +2335,12 @@ let rec genPattSpine names mk_pat_var k = , Comp.PatApp (Loc.ghost, pat1, pS) , ttau ) - | Comp.TypPiBox (_, LF.Decl (u, LF.CTyp sW, dep), tau), t -> + | Comp.TypPiBox (_, LF.Decl (u, LF.CTyp sW, plicity, inductivity), tau), t -> let u = NameGen.renumber names u in let cPsi' = let open! LF in let mmvar = - Whnf.newMMVar' (Some u) LF.(Empty, CTyp sW) dep + Whnf.newMMVar' (Some u) LF.(Empty, CTyp sW) plicity inductivity in CtxVar (CInst (mmvar, Whnf.m_id)) in @@ -2364,7 +2366,7 @@ let rec genPattSpine names mk_pat_var k = *) | ( Comp.TypPiBox ( _ - , LF.(Decl (u, ClTyp ((PTyp tP | MTyp tP) as cl, cPsi), dep)) + , LF.(Decl (u, ClTyp ((PTyp tP | MTyp tP) as cl, cPsi), plicity, inductivity)) , tau ) , t @@ -2375,12 +2377,12 @@ let rec genPattSpine names mk_pat_var k = let clobj = match cl with | LF.PTyp _ -> - let v = Whnf.newMPVar (Some u) (LF.Empty, cPsi', tP') dep in + let v = Whnf.newMPVar (Some u) (LF.Empty, cPsi', tP') plicity inductivity in LF.(PObj (mpvar ((v, Whnf.m_id), S.LF.id))) | LF.MTyp _ -> LF.MObj (ConvSigma.etaExpandMMVstr - Loc.ghost LF.Empty cPsi' (tP', S.LF.id) dep (Some u) (u :: names) + Loc.ghost LF.Empty cPsi' (tP', S.LF.id) plicity (Some u) (u :: names) ) in let pat1 = @@ -2398,7 +2400,7 @@ let rec genPattSpine names mk_pat_var k = in (cG, Comp.PatApp (Loc.ghost, pat1, pS), ttau0) - | (Comp.TypPiBox (_, LF.(Decl (u, ClTyp (STyp (cl, cPhi), cPsi), _)), tau), t) -> + | (Comp.TypPiBox (_, LF.(Decl (u, ClTyp (STyp (cl, cPhi), cPsi), _, _)), tau), t) -> let cPhi' = Whnf.cnormDCtx (cPhi, t) in let cPsi' = Whnf.cnormDCtx (cPsi, t) in @@ -2409,7 +2411,7 @@ let rec genPattSpine names mk_pat_var k = let u = NameGen.renumber names u in let s = - let v = Whnf.newMSVar (Some u) (LF.Empty, cl, cPsi', cPhi') LF.No in + let v = Whnf.newMSVar (Some u) (LF.Empty, cl, cPsi', cPhi') Plicity.explicit Inductivity.not_inductive in LF.MSVar (0, ((v, Whnf.m_id), S.LF.id)) in let sO = LF.ClObj (Context.dctxToHat cPsi', LF.SObj s) in @@ -2581,7 +2583,7 @@ let genPatCGoals names mk_pat_var (cD : LF.mctx) tau = Id.(mk_name (SomeString "g")) |> NameGen.renumber names in - LF.Dec (cD, LF.Decl (u, LF.CTyp (Some w), LF.Maybe)) + LF.Dec (cD, LF.Decl (u, LF.CTyp (Some w), Plicity.implicit, Inductivity.not_inductive)) in genCtx names cD' (LF.CtxOffset 1) elems |> List.map @@ -3106,7 +3108,7 @@ let rec check_cov_problem (cD, cG, candidates, cg) = | (Solved, true) -> (* Coverage Fails *) let open_goal = (cD, cG, cg) in - existsCandidate cands nCands (open_goal::open_cg) + existsCandidate cands nCands (open_goal :: open_cg) | (PossSolvable cand, _) -> dprintf @@ -3168,7 +3170,7 @@ let gen_candidates loc cD covGoal pats = let initialize_coverage problem projOpt : cov_problems = match problem.ctype with | Comp.TypBox (loc, LF.CTyp w) -> - let cD' = LF.Dec (problem.cD, LF.Decl (Id.mk_name (Whnf.newMTypName (LF.CTyp w)), LF.CTyp w, LF.Maybe)) in + let cD' = LF.Dec (problem.cD, LF.Decl (Id.mk_name (Whnf.newMTypName (LF.CTyp w)), LF.CTyp w, Plicity.implicit, Inductivity.not_inductive)) in let cG' = Whnf.cnormGCtx (problem.cG, LF.MShift 1) in let cPsi = LF.CtxVar (LF.CtxOffset 1) in (* let covGoal = CovPatt (LF.Empty, Comp.PatMetaObj (loc, LF.CObj cPsi)) in *) @@ -3199,11 +3201,11 @@ let initialize_coverage problem projOpt : cov_problems = let mT = Whnf.(cnormMTyp (LF.ClTyp (LF.MTyp tA', cPsi'), m_id)) in let name = Id.mk_name (Whnf.newMTypName mT) in let cD' = - LF.Dec (problem.cD, LF.Decl (name, mT, LF.Maybe)) + LF.Dec (problem.cD, LF.Decl (name, mT, Plicity.implicit, Inductivity.not_inductive)) in let cG' = Whnf.cnormGCtx (problem.cG, LF.MShift 1) in let mv = LF.MVar (LF.Offset 1, s) in - let tM = LF.Root (Loc.ghost, mv, LF.Nil, `explicit) in + let tM = LF.Root (Loc.ghost, mv, LF.Nil, Plicity.explicit) in let cPsi = Whnf.cnormDCtx (cPsi, LF.MShift 1) in let tA = Whnf.cnormTyp (tA, LF.MShift 1) in let mC = Comp.PatMetaObj (Loc.ghost, (loc, LF.ClObj (Context.dctxToHat cPsi, LF.MObj tM))) in @@ -3238,14 +3240,14 @@ let initialize_coverage problem projOpt : cov_problems = | Comp.TypBox (loc, LF.ClTyp (LF.PTyp tA, cPsi)) -> let (s, (cPsi', tA')) = gen_str problem.cD cPsi tA in let mT = LF.ClTyp (LF.PTyp tA', cPsi') in - let cD' = LF.Dec (problem.cD, LF.Decl (Id.mk_name (Whnf.newMTypName mT), mT, LF.Maybe)) in + let cD' = LF.Dec (problem.cD, LF.Decl (Id.mk_name (Whnf.newMTypName mT), mT, Plicity.implicit, Inductivity.not_inductive)) in let cG' = Whnf.cnormGCtx (problem.cG, LF.MShift 1) in let mv = match projOpt with | None -> LF.PVar (1, s) | Some k -> LF.Proj (LF.PVar (1, s), k) in - let tM = LF.Root (Loc.ghost, mv, LF.Nil, `explicit) in + let tM = LF.Root (Loc.ghost, mv, LF.Nil, Plicity.explicit) in let cPsi = Whnf.cnormDCtx (cPsi, LF.MShift 1) in let tA = Whnf.cnormTyp (tA, LF.MShift 1) in let mC = Comp.PatMetaObj (Loc.ghost, (Loc.ghost, LF.ClObj (Context.dctxToHat cPsi, LF.MObj tM))) in @@ -3256,7 +3258,7 @@ let initialize_coverage problem projOpt : cov_problems = [(cD', cG', cand_list, mC)] | Comp.TypBox (loc, ((LF.ClTyp (LF.STyp (r, cPhi), cPsi)) as mT)) -> - let cD' = LF.Dec (problem.cD, LF.Decl (Id.mk_name (Whnf.newMTypName mT), mT, LF.Maybe)) in + let cD' = LF.Dec (problem.cD, LF.Decl (Id.mk_name (Whnf.newMTypName mT), mT, Plicity.implicit, Inductivity.not_inductive)) in let cG' = Whnf.cnormGCtx (problem.cG, LF.MShift 1) in let s = LF.SVar (1, 0, S.LF.id) in let cPhi = Whnf.cnormDCtx (cPhi, LF.MShift 1) in @@ -3290,7 +3292,7 @@ let initialize_coverage problem projOpt : cov_problems = let rec check_emptiness = function | LF.Empty -> false - | LF.Dec (cD', (LF.Decl (_, LF.ClTyp (LF.MTyp tA, cPsi), _) as cdecl)) -> + | LF.Dec (cD', (LF.Decl (_, LF.ClTyp (LF.MTyp tA, cPsi), _, _) as cdecl)) -> begin try match genCovGoals (cD', cPsi, Whnf.normTyp (tA, S.LF.id)) with @@ -3310,9 +3312,9 @@ let rec check_emptiness = (P.fmt_ppr_lf_typ cD' cPsi P.l0) tA; check_emptiness cD' end - | LF.Dec (cD', LF.Decl (_, LF.ClTyp (LF.PTyp LF.Sigma _, _), _)) -> + | LF.Dec (cD', LF.Decl (_, LF.ClTyp (LF.PTyp LF.Sigma _, _), _, _)) -> check_emptiness cD' - | LF.Dec (cD', LF.Decl (_, LF.ClTyp (LF.PTyp tA, cPsi), _)) -> + | LF.Dec (cD', LF.Decl (_, LF.ClTyp (LF.PTyp tA, cPsi), _, _)) -> begin try match genBCovGoals (cD', cPsi, Whnf.normTyp (tA, S.LF.id)) with @@ -3531,7 +3533,7 @@ let clear () = problems := [] let stage problem = - problems := problem::!problems + problems := problem :: !problems *) let map f = List.map (fun problem -> f (covers problem None)) (List.rev !problems) diff --git a/src/core/coverage.mli b/src/core/coverage.mli index 64dcf1f5d..ee4cd4b5a 100644 --- a/src/core/coverage.mli +++ b/src/core/coverage.mli @@ -159,7 +159,7 @@ val genPatCGoals : Id.name list -> LF.mctx -> Comp.typ -> (Comp.gctx * Comp.pattern * Comp.tclo) inside list -val genContextGoals : LF.mctx -> Id.name * LF.ctyp * LF.depend +val genContextGoals : LF.mctx -> Id.name * LF.ctyp * Plicity.t * Inductivity.t -> LF.dctx inside list val genCGoals : LF.mctx -> LF.ctyp -> (LF.mctx * cov_goal * LF.msub) list * depend diff --git a/src/core/ctxsub.ml b/src/core/ctxsub.ml index 71f8e2103..9d6927f08 100644 --- a/src/core/ctxsub.ml +++ b/src/core/ctxsub.ml @@ -40,7 +40,7 @@ let ctxShift cPsi = EmptySub (* match cPsi with *) (* | CtxVar psi -> Shift (CtxShift psi, 0) *) (* | DDec (cPsi, _x) -> *) (* let Shift (cshift, n) = ctxShift cPsi in *) -(* Shift (cshift, n+1) *) +(* Shift (cshift, n + 1) *) @@ -62,7 +62,7 @@ let rec lowerMVar cPsi sA' = ( Loc.ghost , MVar (Offset 1, Substitution.LF.id) , Nil - , `explicit + , Plicity.explicit ) , ClTyp(MTyp (TClo sA') , cPsi)) @@ -79,7 +79,7 @@ let rec lowerMVar cPsi sA' = s.t. cD, cD_ext; psi |- u1[id]/x1 ... un[id]/xn : cPsi and where cD_ext = u1:A1[psi], ... un:An[psi] - if ctxToSub_mclosed cD psi cPsi = (cD',s) then + if ctxToSub_mclosed cD psi cPsi = (cD', s) then cD' ; psi |- s : cPsi Concretely, this will extend the input cD with one MVar for each @@ -101,7 +101,7 @@ let rec ctxToSub_mclosed cD psi = ( Loc.ghost , MVar (Offset 1, Substitution.LF.id) , Nil - , `explicit + , Plicity.explicit ) in @@ -120,7 +120,8 @@ let rec ctxToSub_mclosed cD psi = , Decl ( u_name , ClTyp (MTyp tA', Whnf.cnormDCtx (CtxVar psi, MShift k)) - , Maybe + , Plicity.implicit + , Inductivity.not_inductive ) ) , result @@ -137,7 +138,7 @@ let rec ctxToSub_mclosed cD psi = let tA' = TClo (tA, s) in (* cD', u: _ ; psi |- s : cPsi', x:tA *) let s' = Whnf.cnormSub (s, MShift 1) in - let tM , clT = lowerMVar (Whnf.cnormDCtx (CtxVar psi, MShift k)) (tA,s) in (* where clT is the type of the mvar in M *) + let tM , clT = lowerMVar (Whnf.cnormDCtx (CtxVar psi, MShift k)) (tA, s) in (* where clT is the type of the mvar in M *) let u_name = Id.mk_name (Id.MVarName (Typ.gen_mvar_name tA')) in let result = Dot (Obj tM, s') in (* dprint (fun () -> "[ctxToSub_mclosed] result = " ^ subToString result); *) @@ -146,7 +147,8 @@ let rec ctxToSub_mclosed cD psi = , Decl ( u_name , clT - , Maybe + , Plicity.implicit + , Inductivity.not_inductive ) ) , result @@ -204,7 +206,7 @@ let rec ctxToSub' cD cPhi = dprint (fun () -> "composition = " ^ subToString composition); let u = Whnf.etaExpandMMV None cD cPhi (tA, composition) Substitution.LF.id in *) - let u = Whnf.etaExpandMMV Syntax.Loc.ghost cD cPhi (tA, s) n Substitution.LF.id Maybe in + let u = Whnf.etaExpandMMV Syntax.Loc.ghost cD cPhi (tA, s) n Substitution.LF.id Plicity.implicit Inductivity.not_inductive in let front = (Obj ((* Root (MVar (u, S.LF.id), Nil) *) u) : front) in (* cD ; cPhi |- s : cPsi' *) (* cD ; cPhi |- u[id] : [s]tA *) @@ -217,42 +219,42 @@ let rec ctxToSub' cD cPhi = -let mdeclToMMVar cD0 n mtyp dep = +let mdeclToMMVar cD0 n mtyp plicity inductivity = match mtyp with | ClTyp (MTyp tA, cPsi) -> - let u = Whnf.newMMVar (Some n) (cD0, cPsi, tA) dep in + let u = Whnf.newMMVar (Some n) (cD0, cPsi, tA) plicity inductivity in let phat = Context.dctxToHat cPsi in let tR = Root ( Loc.ghost , MMVar ((u, Whnf.m_id), Substitution.LF.id) , Nil - , `explicit + , Plicity.explicit ) in ClObj (phat, MObj tR) | ClTyp (STyp (cl, cPhi), cPsi) -> - let u = Whnf.newMSVar (Some n) (cD0, cl, cPsi, cPhi) dep in + let u = Whnf.newMSVar (Some n) (cD0, cl, cPsi, cPhi) plicity inductivity in let phat = Context.dctxToHat cPsi in ClObj (phat, SObj (MSVar (0, ((u, Whnf.m_id), Substitution.LF.id)))) | ClTyp (PTyp tA, cPsi) -> - let p = Whnf.newMPVar (Some n) (cD0, cPsi, tA) dep in + let p = Whnf.newMPVar (Some n) (cD0, cPsi, tA) plicity inductivity in let phat = dctxToHat cPsi in ClObj (phat, PObj (MPVar ((p, Whnf.m_id), Substitution.LF.id))) | CTyp sW -> - let cvar = Whnf.newCVar (Some n) cD0 sW dep in + let cvar = Whnf.newCVar (Some n) cD0 sW plicity inductivity in CObj (CtxVar cvar) let rec mctxToMMSub cD0 = function | Empty -> MShift (Context.length cD0) - | Dec (cD', Decl (n, mtyp, dep)) -> + | Dec (cD', Decl (n, mtyp, plicity, inductivity)) -> let t = mctxToMMSub cD0 cD' in - let mtyp' = Whnf.cnormMTyp (mtyp,t) in - MDot (mdeclToMMVar cD0 n mtyp' dep, t) + let mtyp' = Whnf.cnormMTyp (mtyp, t) in + MDot (mdeclToMMVar cD0 n mtyp' plicity inductivity, t) let mctxToMSub cD = mctxToMMSub Empty cD diff --git a/src/core/erase.ml b/src/core/erase.ml index d9cc99db1..2182b59f7 100644 --- a/src/core/erase.ml +++ b/src/core/erase.ml @@ -4,19 +4,17 @@ let rec numeric_order_arg tau n = let open Comp in match (tau, n) with | (_, 0) -> 0 - | (TypArr (_, _, tau), n) -> 1 + numeric_order_arg tau (n-1) - | (TypPiBox (_, LF.Decl (_, _, d), tau), n) -> - let c = - match d with - | LF.Maybe -> 0 - | LF.Inductive -> 1 - (* We count Inductive as 1 instead of throwing an error because - we would elaboration only works when we don't have - Inductive. Inductive can however show up later, but we know - that it couldn't have been on an implicit argument (this is - forbidden). *) - | LF.No -> 1 - in - c + numeric_order_arg tau (n-1) + | (TypArr (_, _, tau), n) -> 1 + numeric_order_arg tau (n - 1) + | (TypPiBox (_, LF.Decl (_, _, _, Inductivity.Inductive), tau), n) -> + (* We count [Inductive] as 1 instead of throwing an error because + elaboration only works when we don't have [Inductive]. + [Inductive] can however show up later, but we know + that it couldn't have been on an implicit argument (this is + forbidden). *) + 1 + numeric_order_arg tau (n - 1) + | (TypPiBox (_, LF.Decl (_, _, Plicity.Explicit, _), tau), n) -> + 1 + numeric_order_arg tau (n - 1) + | (TypPiBox (_, LF.Decl (_, _, Plicity.Implicit, _), tau), n) -> + numeric_order_arg tau (n - 1) let numeric_order tau n = Comp.map_order (numeric_order_arg tau) n diff --git a/src/core/html.ml b/src/core/html.ml index 0493a4b3a..ea34d87bd 100644 --- a/src/core/html.ml +++ b/src/core/html.ml @@ -120,6 +120,6 @@ let appendAsComment innerHtml = let ids = ref [] let addId s = - ids := s::!ids + ids := s :: !ids let idExists s = List.exists (String.equal s) !ids diff --git a/src/core/index.ml b/src/core/index.ml index 65a06d664..0abaac48a 100644 --- a/src/core/index.ml +++ b/src/core/index.ml @@ -141,7 +141,7 @@ let index_cvar' cvars (u : Id.name) : (cvar_error_status, Id.offset) Either.t = trying_index (fun _ -> CVar.index_of_name cvars u) with | None -> Either.Left `unbound - | Some (`implicit, _) -> Either.Left `implicit + | Some (Plicity.Implicit, _) -> Either.Left `implicit | Some (_, k) -> dprintf begin fun p -> @@ -342,7 +342,7 @@ let rec index_kind (k : Ext.LF.kind) : Apx.LF.kind index = let open Bind in let pi x a k = seq2 (index_typ a) (locally (extending_bvars x) (index_kind k)) - $> fun (a', k') -> Apx.LF.PiKind ((Apx.LF.TypDecl (x, a'), Apx.LF.No), k') + $> fun (a', k') -> Apx.LF.PiKind ((Apx.LF.TypDecl (x, a'), Plicity.explicit), k') in match k with | Ext.LF.Typ _ -> @@ -371,12 +371,12 @@ and index_typ (a : Ext.LF.typ) : Apx.LF.typ index = let x = Id.mk_name Id.NoName in seq2 (index_typ a) (locally (extending_bvars x) (index_typ b)) $> fun (a', b') -> - Apx.LF.PiTyp ((Apx.LF.TypDecl (x, a'), Apx.LF.No), b') + Apx.LF.PiTyp ((Apx.LF.TypDecl (x, a'), Plicity.explicit), b') | Ext.LF.PiTyp (_, Ext.LF.TypDecl (x, a), b) -> seq2 (index_typ a) (locally (extending_bvars x) (index_typ b)) $> fun (a', b') -> - Apx.LF.PiTyp ((Apx.LF.TypDecl (x, a'), Apx.LF.Maybe), b') + Apx.LF.PiTyp ((Apx.LF.TypDecl (x, a'), Plicity.implicit), b') | Ext.LF.Sigma (_, typRec) -> index_typ_rec typRec $> fun typRec' -> Apx.LF.Sigma typRec' @@ -425,7 +425,7 @@ and shunting_yard (l : Ext.LF.normal list) : Ext.LF.normal = (* let rec normalListToSpine : Ext.LF.normal list -> Ext.LF.spine = function | [] -> Ext.LF.Nil - | h::t -> Ext.LF.App (locOfNormal h, h, normalListToSpine t) + | h :: t -> Ext.LF.App (locOfNormal h, h, normalListToSpine t) in match l with | Ext.LF.Root (loc, h, Ext.LF.Nil) :: ms -> @@ -477,7 +477,7 @@ and shunting_yard' (l : Ext.LF.normal list) : Ext.LF.normal = let rec normalListToSpine : Ext.LF.normal list -> Ext.LF.spine = function | [] -> Ext.LF.Nil - | h::t -> Ext.LF.App (locOfNormal h, h, normalListToSpine t) + | h :: t -> Ext.LF.App (locOfNormal h, h, normalListToSpine t) in let rec parse : int * Ext.LF.normal list @@ -495,7 +495,7 @@ and shunting_yard' (l : Ext.LF.normal list) : Ext.LF.normal = when pragmaExists h -> let p = get_pragma h in let loc = locOfNormal h in - parse (i+1, t, exps, [(i, p, loc)]) + parse (i + 1, t, exps, [(i, p, loc)]) | (i, h :: t, exps, (x, o, loc_o) :: os) when pragmaExists h -> let p = get_pragma h in @@ -658,7 +658,7 @@ and shunting_yard' (l : Ext.LF.normal list) : Ext.LF.normal = and take i l = let rec aux n l c = match l with - | h :: t when n > 0 -> aux (n-1) t (h::c) + | h :: t when n > 0 -> aux (n - 1) t (h :: c) | _ -> (c, l) in aux i l [] @@ -1118,20 +1118,12 @@ let index_cltyp loc cvars fvars = throw loc (UnboundCtxSchemaName schema_name) end -let index_dep = - function - | Ext.LF.Maybe -> Apx.LF.Maybe - | Ext.LF.No -> Apx.LF.No - | Ext.LF.Inductive -> - Error.violation - "[index_dep] Inductive not allowed in external syntax" - -let index_cdecl plicity_of_dep cvars fvars = +let index_cdecl f cvars fvars = function | Ext.LF.DeclOpt _ -> Error.violation "[index_cdecl] DeclOpt not allowed in external syntax" - | Ext.LF.Decl (u, (loc, cl), dep) -> + | Ext.LF.Decl (u, (loc, cl), plicity) -> let (fvars, cl) = index_cltyp loc cvars fvars cl in dprintf begin fun p -> @@ -1146,9 +1138,9 @@ let index_cdecl plicity_of_dep cvars fvars = | Either.Left _ -> let cvars = CVar.extend cvars - (CVar.mk_entry u (plicity_of_dep dep)) + (CVar.mk_entry u (f plicity)) in - (Apx.LF.Decl (u, cl, index_dep dep), cvars, fvars) + (Apx.LF.Decl (u, cl, plicity), cvars, fvars) end let rec index_mctx cvars fvars = @@ -1157,7 +1149,7 @@ let rec index_mctx cvars fvars = | Ext.LF.Dec (delta, cdec) -> let (delta', cvars', fvars') = index_mctx cvars fvars delta in let (cdec', cvars'', fvars'') = - index_cdecl Ext.LF.Depend.to_plicity cvars' fvars' cdec + index_cdecl Fun.id cvars' fvars' cdec in (Apx.LF.Dec (delta', cdec'), cvars'', fvars'') @@ -1232,14 +1224,14 @@ let rec index_compkind cvars fcvars = | Ext.Comp.Ctype loc -> Apx.Comp.Ctype loc | Ext.Comp.PiKind (loc, cdecl, cK) -> let (cdecl', cvars', fcvars') = - index_cdecl (fun _ -> `explicit) cvars fcvars cdecl + index_cdecl (Fun.const Plicity.explicit) cvars fcvars cdecl in let cK' = index_compkind cvars' fcvars' cK in Apx.Comp.PiKind (loc, cdecl', cK') - | Ext.Comp.ArrKind (loc, (loc', ctau, dep), cK) -> + | Ext.Comp.ArrKind (loc, (loc', ctau, plicity), cK) -> let x = Id.mk_name ~loc Id.NoName in index_compkind cvars fcvars - @@ Ext.Comp.PiKind (loc, Ext.LF.Decl (x, (loc', ctau), dep), cK) + @@ Ext.Comp.PiKind (loc, Ext.LF.Decl (x, (loc', ctau), plicity), cK) let rec index_comptyp (tau : Ext.Comp.typ) cvars : Apx.Comp.typ fvar_state = fun fvars -> @@ -1286,7 +1278,7 @@ let rec index_comptyp (tau : Ext.Comp.typ) cvars : Apx.Comp.typ fvar_state = | Ext.Comp.TypPiBox (loc, cdecl, tau) -> let (cdecl', cvars, fvars) = - index_cdecl (fun _ -> `explicit) cvars fvars cdecl + index_cdecl (Fun.const Plicity.explicit) cvars fvars cdecl in let (fvars, tau') = index_comptyp tau cvars fvars in (fvars, Apx.Comp.TypPiBox (loc, cdecl', tau')) @@ -1334,7 +1326,7 @@ let rec index_exp cvars vars fcvars = Apx.Comp.Fun (loc, index_fbranches cvars vars fcvars fbr) | Ext.Comp.MLam (loc, u, e) -> - let cvars' = CVar.extend cvars (CVar.mk_entry u `explicit) in + let cvars' = CVar.extend cvars (CVar.mk_entry u Plicity.explicit) in Apx.Comp.MLam (loc, u, index_exp cvars' vars fcvars e) | Ext.Comp.Pair (loc, e1, e2) -> @@ -1699,7 +1691,7 @@ and index_command cvars vars fvars = Apx.Comp.By (loc, i', x), vars, cvars | Ext.Comp.Unbox (loc, i, x, modifier) -> let i' = index_exp' cvars vars fvars i in - let cvars = CVar.extend cvars (CVar.mk_entry x `explicit) in + let cvars = CVar.extend cvars (CVar.mk_entry x Plicity.explicit) in Apx.Comp.Unbox (loc, i', x, modifier), vars, cvars and index_directive cvars vars fvars = @@ -1740,7 +1732,7 @@ and index_hypothetical h = let Ext.Comp.{ hypotheses = { cD; cG }; proof; hypothetical_loc } = h in let cvars = Context.to_list_map_rev cD - Ext.LF.(fun _ (Decl (x, _, dep)) -> (x, Depend.to_plicity dep)) + Ext.LF.(fun _ (Decl (x, _, plicity)) -> (x, plicity)) |> CVar.of_list in let vars = @@ -1761,8 +1753,8 @@ let comptypdef (cT, cK) = let rec unroll cK cvars = match cK with | Apx.Comp.Ctype _ -> cvars - | Apx.Comp.PiKind (loc, Apx.LF.Decl (u, ctyp, dep), cK) -> - let cvars' = CVar.extend cvars (CVar.mk_entry u `explicit) in + | Apx.Comp.PiKind (loc, Apx.LF.Decl (u, ctyp, _), cK) -> + let cvars' = CVar.extend cvars (CVar.mk_entry u Plicity.explicit) in unroll cK cvars' in let (_, tau) = diff --git a/src/core/interactive.ml b/src/core/interactive.ml index 2051db865..24f49f8f7 100644 --- a/src/core/interactive.ml +++ b/src/core/interactive.ml @@ -38,7 +38,7 @@ let elaborate_typ (cD : LF.mctx) (tau : ExtComp.typ) : Comp.typ * int = (P.fmt_ppr_lf_mctx P.l0) cD end; let cvars = - Store.CVar.of_mctx (fun _ -> `explicit) cD + Store.CVar.of_mctx (Fun.const Plicity.explicit) cD in Index.hcomptyp cvars tau |> Reconstruct.comptyp_cD cD @@ -59,7 +59,7 @@ let elaborate_exp (cD : LF.mctx) (cG : Comp.gctx) (P.fmt_ppr_cmp_gctx cD P.l0) cG end; let var_store = Store.Var.of_gctx cG in - let cvar_store = Store.CVar.of_mctx LF.Depend.to_plicity' cD in + let cvar_store = Store.CVar.of_mctx (function _, Inductivity.Inductive -> Plicity.explicit | plicity, _ -> plicity) cD in let t = Index.hexp cvar_store var_store t in Reconstruct.elExp cD cG t tp @@ -75,7 +75,7 @@ let elaborate_exp' (cD : LF.mctx) (cG : Comp.gctx) (t : ExtComp.exp_syn) (P.fmt_ppr_cmp_gctx cD P.l0) cG end; let var_store = Store.Var.of_gctx cG in - let cvar_store = Store.CVar.of_mctx LF.Depend.to_plicity' cD in + let cvar_store = Store.CVar.of_mctx (function _, Inductivity.Inductive -> Plicity.explicit | plicity, _ -> plicity) cD in let t = Index.hexp' cvar_store var_store t in Reconstruct.elExp' cD cG t @@ -231,7 +231,7 @@ let intro (h : Holes.comp_hole_info Holes.hole) = when not (is_inferred tdec) -> let nam = LF.name_of_ctyp_decl tdec in let exp = crawl (LF.Dec (cD, tdec)) cG t' in - Comp.MLam (Loc.ghost, nam, exp, `explicit) + Comp.MLam (Loc.ghost, nam, exp, Plicity.explicit) | _ -> let id = Holes.allocate () in Comp.Hole (Loc.ghost, id, HoleId.Anonymous) @@ -249,10 +249,10 @@ let intro (h : Holes.comp_hole_info Holes.hole) = that were generated by splitting on cd *) -let genCGoals cD' (LF.Decl (n, mtyp, dep)) cD_tail = +let genCGoals cD' (LF.Decl (n, mtyp, plicity, inductivity)) cD_tail = match mtyp with | LF.CTyp _ -> - Cover.genContextGoals cD' (n, mtyp, dep) + Cover.genContextGoals cD' (n, mtyp, plicity, inductivity) |> List.map begin fun (cDg, cPhi, ms) -> (* cDg |- ms : cD' *) @@ -319,12 +319,12 @@ let split (e : string) (hi : HoleId.t * Holes.comp_hole_info Holes.hole) : Comp. ) in matchTyp tau - | LF.Dec (cG', _) -> searchGctx (i+1) cG' + | LF.Dec (cG', _) -> searchGctx (i + 1) cG' in let rec searchMctx i cD (cD_tail : LF.ctyp_decl list) = match cD with | LF.Empty -> None - | LF.Dec (cD', (LF.Decl (n, mtyp, dep) as cd)) -> + | LF.Dec (cD', (LF.Decl (n, mtyp, _, _) as cd)) -> if String.equal (Id.string_of_name n) e then begin @@ -345,7 +345,7 @@ let split (e : string) (hi : HoleId.t * Holes.comp_hole_info Holes.hole) : Comp. ( Loc.ghost , LF.MVar (LF.Offset i, LF.Shift 0) , LF.Nil - , `explicit + , Plicity.explicit ) ) ) @@ -361,7 +361,7 @@ let split (e : string) (hi : HoleId.t * Holes.comp_hole_info Holes.hole) : Comp. ( Loc.ghost , LF.PVar (i, LF.Shift 0) , LF.Nil - , `explicit + , Plicity.explicit ) ) ) @@ -443,16 +443,16 @@ let iterMctx (cD : LF.mctx) (cPsi : LF.dctx) (tA : LF.tclo) : Id.name list = let rec aux acc c = function | LF.Empty -> acc - | LF.Dec (cD', LF.Decl(n, LF.ClTyp (LF.MTyp tA', cPsi'), LF.No)) - | LF.Dec (cD', LF.Decl(n, LF.ClTyp (LF.PTyp tA', cPsi'), LF.No)) -> + | LF.Dec (cD', LF.Decl(n, LF.ClTyp (LF.MTyp tA', cPsi'), Plicity.Explicit, _)) + | LF.Dec (cD', LF.Decl(n, LF.ClTyp (LF.PTyp tA', cPsi'), Plicity.Explicit, _)) -> begin try Unify.StdTrail.resetGlobalCnstrs (); let tA' = Whnf.cnormTyp (tA', LF.MShift c) in Unify.StdTrail.unifyTyp cD cPsi tA (tA', sub); - aux (n::acc) (c+1) cD' + aux (n :: acc) (c + 1) cD' with - | _ -> aux acc (c+1) cD' + | _ -> aux acc (c + 1) cD' end | LF.Dec (cD', _) -> aux acc (c + 1) cD' in @@ -466,7 +466,7 @@ let iterDctx (cD : LF.mctx) (cPsi : LF.dctx) (tA : LF.tclo) : Id.name list = try Unify.StdTrail.resetGlobalCnstrs (); Unify.StdTrail.unifyTyp cD cPsi tA (tA', LF.EmptySub); - aux (n::acc) cPsi' + aux (n :: acc) cPsi' with | _ -> aux acc cPsi' end @@ -484,7 +484,7 @@ let iterGctx (cD : LF.mctx) (cG : Comp.gctx) (ttau : Comp.tclo) : Id.name list = try Unify.StdTrail.resetGlobalCnstrs (); Unify.StdTrail.unifyCompTyp cD ttau (tau', LF.MShift 0); - aux (n::acc) cG' + aux (n :: acc) cG' with | _ -> aux acc cG' end diff --git a/src/core/lfcheck.ml b/src/core/lfcheck.ml index a00c8fd7d..13809837f 100644 --- a/src/core/lfcheck.ml +++ b/src/core/lfcheck.ml @@ -229,7 +229,7 @@ let rec ctxToSub' cPhi = | Null -> Ctxsub.ctxShift cPhi (* S.LF.id *) | DDec (cPsi', TypDecl (n, tA)) -> let s = (ctxToSub' cPhi cPsi' : sub) in - let u = Whnf.etaExpandMV cPhi (tA, s) n S.LF.id Maybe in + let u = Whnf.etaExpandMV cPhi (tA, s) n S.LF.id Plicity.implicit Inductivity.not_inductive in Dot (Obj u, s) (* check cD cPsi (tM, s1) (tA, s2) = () @@ -479,7 +479,7 @@ and inferHead loc cD cPsi head cl = | (Const _, Ren) | (MVar _, Ren) | (MMVar _, Ren) -> - raise (Error (loc, TermWhenVar (cD, cPsi, (Root (loc, head, Nil, `explicit))))) + raise (Error (loc, TermWhenVar (cD, cPsi, (Root (loc, head, Nil, Plicity.explicit))))) | (PVar (p, s), _) -> (* cD ; cPsi' |- tA <= type *) @@ -888,7 +888,7 @@ and existsInstOfSchElemProj loc cD cPsi sA (h, i, n) elem = instanceOfSchElemProj cD cPsi sA (h, i) elem with | _ -> - existsInstOfSchElemProj loc cD cPsi sA (h, i+1, n) elem + existsInstOfSchElemProj loc cD cPsi sA (h, i + 1, n) elem end @@ -931,7 +931,7 @@ and checkElementAgainstSchema cD sch_elem elements = (* and subset f list = begin match list with [] -> true - | elem::elems -> f elem + | elem :: elems -> f elem *) and checkSchema loc cD cPsi schema_name (Schema elements as schema) = @@ -1105,10 +1105,10 @@ and checkMSub loc cD ms cD' = | (MShift k, cD') -> if k >= 0 - then checkMSub loc cD (MDot (MV (k+1), MShift (k+1))) cD' + then checkMSub loc cD (MDot (MV (k + 1), MShift (k + 1))) cD' else raise (Error.Violation ("Contextual substitution ill-formed")) - | (MDot (mft, ms), Dec (cD1, Decl (_, mtyp, _))) -> + | (MDot (mft, ms), Dec (cD1, Decl (_, mtyp, _, _))) -> checkMetaObj cD (loc, mft) (mtyp, ms); checkMSub loc cD ms cD1 diff --git a/src/core/lfrecon.ml b/src/core/lfrecon.ml index 345498fd5..41db65e60 100644 --- a/src/core/lfrecon.ml +++ b/src/core/lfrecon.ml @@ -251,7 +251,7 @@ let _ = let rec conv_listToString = function | [] -> " " - | x::xs -> string_of_int x ^ ", " ^ conv_listToString xs + | x :: xs -> string_of_int x ^ ", " ^ conv_listToString xs let rec what_head = function @@ -318,7 +318,7 @@ let unify_phat cD psihat = begin begin match c_var with | CtxName psi -> - FCVar.add psi (cD, Decl (psi, CTyp s_cid, Maybe)) + FCVar.add psi (cD, Decl (psi, CTyp s_cid, Plicity.implicit, Inductivity.not_inductive)) | _ -> () end; mmvar1.instantiation := Some (ICtx (CtxVar (c_var))); @@ -350,7 +350,7 @@ let getSchema cD ctxvar loc = | Some (Int.LF.CtxName n) -> begin try - let (_, Int.LF.Decl (_, Int.LF.CTyp (Some s_cid), _dep)) = FCVar.get n in + let (_, Int.LF.Decl (_, Int.LF.CTyp (Some s_cid), _, _)) = FCVar.get n in Schema.get_schema s_cid with | _ -> throw loc (CtxVarSchema n) @@ -380,7 +380,7 @@ let etaExpSub k s tA = function | Int.LF.Atom _ -> (k, s) | Int.LF.PiTyp (_, tA) -> - let (k', s') = go (k+1) s tA in + let (k', s') = go (k + 1) s tA in (k' - 1, Apx.LF.Dot (Apx.LF.Head (Apx.LF.BVar k'), s')) in match tA, s with @@ -401,8 +401,8 @@ let etaExpandHead loc h tA = function | Int.LF.Atom _ -> (k, tS) | Int.LF.PiTyp (_, tA') -> - let tN = Int.LF.Root (loc, Int.LF.BVar k, Int.LF.Nil, `explicit) in - etaExpSpine (k+1) (Int.LF.App (tN, tS)) tA' + let tN = Int.LF.Root (loc, Int.LF.BVar k, Int.LF.Nil, Plicity.explicit) in + etaExpSpine (k + 1) (Int.LF.App (tN, tS)) tA' in let rec etaExpPrefix loc (tM, tA) = @@ -415,10 +415,10 @@ let etaExpandHead loc h tA = let (k, tS') = etaExpSpine 1 (Int.LF.Nil) tA in let h' = match h with - | Int.LF.BVar x -> Int.LF.BVar (x+k-1) + | Int.LF.BVar x -> Int.LF.BVar (x + k - 1) | Int.LF.FVar _ -> h in - etaExpPrefix loc (Int.LF.Root (loc, h', tS', `explicit), tA) + etaExpPrefix loc (Int.LF.Root (loc, h', tS', Plicity.explicit), tA) @@ -431,7 +431,7 @@ let etaExpandHead loc h tA = * | Int.LF.Atom _ -> (k, tS) * | Int.LF.PiTyp (_, tA') -> * let tN = Apx.LF.Root (loc, Apx.LF.BVar k, Apx.LF.Nil) in - * etaExpApxSpine (k+1) (Apx.LF.App (tN, tS)) tA' + * etaExpApxSpine (k + 1) (Apx.LF.App (tN, tS)) tA' * in * let rec etaExpApxPrefix loc (tM, tA) = * match tA with @@ -442,7 +442,7 @@ let etaExpandHead loc h tA = * let (k, tS') = etaExpApxSpine 1 (Apx.LF.Nil) tA in * let h' = * match h with - * | Apx.LF.BVar x -> Apx.LF.BVar (x+k-1) + * | Apx.LF.BVar x -> Apx.LF.BVar (x + k - 1) * | Apx.LF.FVar _ -> h * in * etaExpApxPrefix loc (Apx.LF.Root (loc, h', tS'), tA) *) @@ -453,7 +453,7 @@ let etaExpandApxTerm loc h tS tA = | Int.LF.Atom _ -> (k, tS) | Int.LF.PiTyp (_, tA') -> let tN = Apx.LF.Root (loc, Apx.LF.BVar k, Apx.LF.Nil) in - etaExpApxSpine (k+1) (Apx.LF.App (tN, tS)) tA' + etaExpApxSpine (k + 1) (Apx.LF.App (tN, tS)) tA' in let rec etaExpApxPrefix loc (tM, tA) = match tA with @@ -477,7 +477,7 @@ let etaExpandApxTerm loc h tS tA = let h' = match h with - | Apx.LF.BVar x -> Apx.LF.BVar (x+k-1) + | Apx.LF.BVar x -> Apx.LF.BVar (x + k - 1) | _ -> h in etaExpApxPrefix loc (Apx.LF.Root (loc, h', tS''), tA) @@ -494,7 +494,7 @@ let etaExpandApxTerm loc h tS tA = let rec patSpine spine = let rec etaUnroll k = function - | Apx.LF.Lam (_, _, n) -> etaUnroll (k+1) n + | Apx.LF.Lam (_, _, n) -> etaUnroll (k + 1) n | m -> (k, m) in @@ -518,8 +518,8 @@ let rec patSpine spine = if l' = k && x > k then begin - let (l, p_spine) = patSpine' ((x-k)::seen_vars) spine in - (l+1, Apx.LF.App (Apx.LF.Root (loc, Apx.LF.BVar (x-k), Apx.LF.Nil), p_spine)) + let (l, p_spine) = patSpine' ((x - k) :: seen_vars) spine in + (l + 1, Apx.LF.App (Apx.LF.Root (loc, Apx.LF.BVar (x - k), Apx.LF.Nil), p_spine)) end else raise NotPatSpine @@ -529,7 +529,7 @@ let rec patSpine spine = then begin let (l, p_spine) = patSpine' seen_vars spine in - (l+1, Apx.LF.App (Apx.LF.Root (loc, Apx.LF.FVar x, Apx.LF.Nil), p_spine)) + (l + 1, Apx.LF.App (Apx.LF.Root (loc, Apx.LF.FVar x, Apx.LF.Nil), p_spine)) end else raise NotPatSpine @@ -872,16 +872,11 @@ exception SubTypingFailure let rec elKind cD cPsi = function | Apx.LF.Typ -> Int.LF.Typ - | Apx.LF.PiKind ((Apx.LF.TypDecl (x, a), dep), k) -> - let dep' = - match dep with - | Apx.LF.No -> Int.LF.No - | Apx.LF.Maybe -> Int.LF.Maybe - in + | Apx.LF.PiKind ((Apx.LF.TypDecl (x, a), plicity), k) -> let tA = elTyp Pi (*cD=*)Int.LF.Empty cPsi a in let cPsi' = Int.LF.DDec (cPsi, Int.LF.TypDecl (x, tA)) in let tK = elKind cD cPsi' k in - Int.LF.PiKind ((Int.LF.TypDecl (x, tA), dep'), tK) + Int.LF.PiKind ((Int.LF.TypDecl (x, tA), plicity), tK) (* elTyp recT cD cPsi a = A * @@ -909,16 +904,11 @@ and elTyp recT cD cPsi = let tS = elKSpineI loc recT cD cPsi s i (tK, s') in Int.LF.Atom (loc, a, tS) - | Apx.LF.PiTyp ((Apx.LF.TypDecl (x, a), dep), b) -> - let dep' = - match dep with - | Apx.LF.No -> Int.LF.No - | Apx.LF.Maybe -> Int.LF.Maybe - in + | Apx.LF.PiTyp ((Apx.LF.TypDecl (x, a), plicity), b) -> let tA = elTyp recT cD cPsi a in let cPsi' = Int.LF.DDec (cPsi, Int.LF.TypDecl (x, tA)) in let tB = elTyp recT cD cPsi' b in - Int.LF.PiTyp ((Int.LF.TypDecl (x, tA), dep'), tB) + Int.LF.PiTyp ((Int.LF.TypDecl (x, tA), plicity), tB) | Apx.LF.Sigma typRec -> let typRec' = elTypRec recT cD cPsi typRec in @@ -1064,7 +1054,7 @@ and elTerm' recT cD cPsi r sP = (* let s = mkShift recT cPsi in *) let s = S.LF.id in let (tS, sQ) = elSpineI loc recT cD cPsi spine i (tA, s) in - let tR = Int.LF.Root (loc, Int.LF.Const c, tS, `explicit) in + let tR = Int.LF.Root (loc, Int.LF.Const c, tS, Plicity.explicit) in begin try Unify.unifyTyp cD cPsi sQ sP; @@ -1084,7 +1074,7 @@ and elTerm' recT cD cPsi r sP = begin try Unify.unifyTyp cD cPsi sQ sP; - Int.LF.Root (loc, Int.LF.BVar x, tS, `explicit) + Int.LF.Root (loc, Int.LF.BVar x, tS, Plicity.explicit) with | Unify.Failure msg -> throw loc (TypMismatchElab (cD, cPsi, sP, sQ)) @@ -1111,7 +1101,7 @@ and elTerm' recT cD cPsi r sP = begin try Unify.unifyTyp cD cPsi sQ sP; - Int.LF.Root (loc, Int.LF.FVar x, tS, `explicit) + Int.LF.Root (loc, Int.LF.FVar x, tS, Plicity.explicit) with | Unify.Failure msg -> throw loc (TypMismatchElab (cD, cPsi, sP, sQ)) @@ -1131,14 +1121,14 @@ and elTerm' recT cD cPsi r sP = * This will be enforced during abstraction. *) FVar.add x (Int.LF.Type tA); - Int.LF.Root (loc, Int.LF.FVar x, tS, `explicit) + Int.LF.Root (loc, Int.LF.FVar x, tS, Plicity.explicit) with | NotPatSpine -> dprint (fun () -> "[elTerm'] FVar case -- Not a pattern spine..."); - let v = Whnf.newMVar None (cPsi, Int.LF.TClo sP) Int.LF.Maybe in + let v = Whnf.newMVar None (cPsi, Int.LF.TClo sP) Plicity.implicit Inductivity.not_inductive in let tAvar = Int.LF.TypVar (Int.LF.TInst (ref None, cPsi, Int.LF.Typ, ref [])) in add_fvarCnstr (tAvar, r, v); - Int.LF.Root (loc, Int.LF.MVar (v, S.LF.id), Int.LF.Nil, `explicit) + Int.LF.Root (loc, Int.LF.MVar (v, S.LF.id), Int.LF.Nil, Plicity.explicit) end end | Pibox -> throw loc (UnboundName x) @@ -1166,8 +1156,8 @@ and elTerm' recT cD cPsi r sP = | Pi -> (* let u = Whnf.newMVar (cPsi, tA) in Int.LF.Root (loc, Int.LF.MVar (u, S.LF.id), tS) *) - let u = Whnf.newMVar None (Int.LF.Null, tA) Int.LF.Maybe in - Int.LF.Root (loc, Int.LF.MVar (u, sshift), tS, `implicit) + let u = Whnf.newMVar None (Int.LF.Null, tA) Plicity.implicit Inductivity.not_inductive in + Int.LF.Root (loc, Int.LF.MVar (u, sshift), tS, Plicity.implicit) | Pibox -> begin match tA with | Int.LF.Atom (_, a, _) -> @@ -1189,17 +1179,17 @@ and elTerm' recT cD cPsi r sP = (* cPhi' |- ssi : cPhi *) (* cPhi' |- [ssi]tQ *) let u = - Whnf.newMMVar None (cD, cPhi', Int.LF.TClo (tA', ssi')) Int.LF.Maybe + Whnf.newMMVar None (cD, cPhi', Int.LF.TClo (tA', ssi')) Plicity.implicit Inductivity.not_inductive in Int.LF.MMVar ((u, Whnf.m_id), S.LF.comp ss' s_proj) end else begin - let u = Whnf.newMMVar None (cD, cPhi, tA') Int.LF.Maybe in + let u = Whnf.newMMVar None (cD, cPhi, tA') Plicity.implicit Inductivity.not_inductive in Int.LF.MMVar ((u, Whnf.m_id), s_proj) end in - Int.LF.Root (loc, h, tS, `implicit) + Int.LF.Root (loc, h, tS, Plicity.implicit) | _ -> throw loc HolesFunction end end @@ -1211,7 +1201,7 @@ and elTerm' recT cD cPsi r sP = | Apx.LF.Root (loc, Apx.LF.FMVar (u, s), Apx.LF.Nil) -> begin try - let (cD_d, Int.LF.Decl (_, Int.LF.ClTyp (Int.LF.MTyp tQ, cPhi), _)) = FCVar.get u in + let (cD_d, Int.LF.Decl (_, Int.LF.ClTyp (Int.LF.MTyp tQ, cPhi), _, _)) = FCVar.get u in dprintf begin fun p -> p.fmt "[elTerm'] @[FMV %a of type %a[%a]@,in cD_d = %a@,and cD = %a@]" @@ -1268,7 +1258,7 @@ and elTerm' recT cD cPsi r sP = end; (* We do not check here that tP approx. [s']tP' -- * this check is delayed to reconstruction *) - let tR = Int.LF.Root (loc, Int.LF.FMVar (u, s''), Int.LF.Nil, `explicit) in + let tR = Int.LF.Root (loc, Int.LF.FMVar (u, s''), Int.LF.Nil, Plicity.explicit) in begin try Unify.unifyTyp cD cPsi (tQ', s'') sP; @@ -1348,9 +1338,9 @@ and elTerm' recT cD cPsi r sP = (P.fmt_ppr_lf_typ cD cPhi P.l0) tP end; - FCVar.add u (cD, Int.LF.Decl (u, Int.LF.ClTyp (Int.LF.MTyp tP, cPhi), Int.LF.Maybe)); + FCVar.add u (cD, Int.LF.Decl (u, Int.LF.ClTyp (Int.LF.MTyp tP, cPhi), Plicity.implicit, Inductivity.not_inductive)); (*The depend paramater here affects both mlam vars and case vars*) - Int.LF.Root (loc, Int.LF.FMVar (u, s''), Int.LF.Nil, `explicit) + Int.LF.Root (loc, Int.LF.FMVar (u, s''), Int.LF.Nil, Plicity.explicit) | _ when isProjPatSub s -> dprint (fun () -> "Synthesize domain for meta-variable " ^ string_of_name u); dprint (fun () -> "isProjPatSub ... "); @@ -1416,8 +1406,8 @@ and elTerm' recT cD cPsi r sP = (P.fmt_ppr_lf_dctx cD P.l0) cPhi end; - FCVar.add u (cD, Int.LF.Decl (u, Int.LF.ClTyp (Int.LF.MTyp tP, cPhi), Int.LF.Maybe)); - Int.LF.Root (loc, Int.LF.FMVar (u, sorig), Int.LF.Nil, `explicit) + FCVar.add u (cD, Int.LF.Decl (u, Int.LF.ClTyp (Int.LF.MTyp tP, cPhi), Plicity.implicit, Inductivity.not_inductive)); + Int.LF.Root (loc, Int.LF.FMVar (u, sorig), Int.LF.Nil, Plicity.explicit) | _ -> (* TO BE ADDED, if we want to synthesize the type of meta-variables @@ -1449,9 +1439,9 @@ and elTerm' recT cD cPsi r sP = * * else *) (* if s = substvar whose type is known *) - let v = Whnf.newMMVar None (cD, cPsi, Int.LF.TClo sP) Int.LF.Maybe in + let v = Whnf.newMMVar None (cD, cPsi, Int.LF.TClo sP) Plicity.implicit Inductivity.not_inductive in add_fcvarCnstr (r, v); - Int.LF.Root (loc, Int.LF.MMVar ((v, Int.LF.MShift 0), S.LF.id), Int.LF.Nil, `explicit) + Int.LF.Root (loc, Int.LF.MMVar ((v, Int.LF.MShift 0), S.LF.id), Int.LF.Nil, Plicity.explicit) end @@ -1459,7 +1449,7 @@ and elTerm' recT cD cPsi r sP = | Apx.LF.Root (loc, Apx.LF.FPVar (p, s), spine) -> begin try - let (cD_d, Int.LF.Decl (_, Int.LF.ClTyp (Int.LF.PTyp tA, cPhi), _)) = FCVar.get p in + let (cD_d, Int.LF.Decl (_, Int.LF.ClTyp (Int.LF.PTyp tA, cPhi), _, _)) = FCVar.get p in let d = Context.length cD - Context.length cD_d in let (tA, cPhi) = if d = 0 @@ -1473,7 +1463,7 @@ and elTerm' recT cD cPsi r sP = let s'' = elSub loc recT cD cPsi s Int.LF.Subst cPhi in let (tS, sQ) = elSpine loc recT cD cPsi spine (tA, s'') in - let tR = Int.LF.Root (loc, Int.LF.FPVar (p, s''), tS, `explicit) in + let tR = Int.LF.Root (loc, Int.LF.FPVar (p, s''), tS, Plicity.explicit) in begin try Unify.unifyTyp cD cPsi sQ sP; @@ -1520,8 +1510,8 @@ and elTerm' recT cD cPsi r sP = end | _ -> () end; - FCVar.add p (cD, Int.LF.Decl (p, Int.LF.ClTyp (Int.LF.PTyp (Whnf.normTyp (tP, S.LF.id)), cPhi), Int.LF.Maybe)); - Int.LF.Root (loc, Int.LF.FPVar (p, s''), Int.LF.Nil, `explicit) + FCVar.add p (cD, Int.LF.Decl (p, Int.LF.ClTyp (Int.LF.PTyp (Whnf.normTyp (tP, S.LF.id)), cPhi), Plicity.implicit, Inductivity.not_inductive)); + Int.LF.Root (loc, Int.LF.FPVar (p, s''), Int.LF.Nil, Plicity.explicit) | (Apx.LF.Nil, false) -> (* cD ; cPsi |- #p[s] : sP *) @@ -1547,7 +1537,7 @@ and elTerm' recT cD cPsi r sP = ^ "." ^ string_of_proj proj end; - let (cD_d, Int.LF.Decl (_, Int.LF.ClTyp (Int.LF.PTyp ((Int.LF.Sigma typRec) as tA), cPhi), _)) = + let (cD_d, Int.LF.Decl (_, Int.LF.ClTyp (Int.LF.PTyp ((Int.LF.Sigma typRec) as tA), cPhi), _, _)) = FCVar.get p in let d = Context.length cD - Context.length cD_d in @@ -1577,7 +1567,7 @@ and elTerm' recT cD cPsi r sP = begin try Unify.unifyTyp cD cPsi (Int.LF.TClo sQ, s'') sP; - Int.LF.Root (loc, Int.LF.Proj (Int.LF.FPVar (p, s''), k), tS, `explicit) + Int.LF.Root (loc, Int.LF.Proj (Int.LF.FPVar (p, s''), k), tS, Plicity.explicit) with | Unify.Failure msg -> throw loc (TypMismatchElab (cD, cPsi, sP, sQ)) @@ -1634,9 +1624,9 @@ and elTerm' recT cD cPsi r sP = let tB = Whnf.collapse_sigma typRec in FCVar.add p ( cD - , Int.LF.(Decl (p, ClTyp (PTyp (Whnf.normTyp (tB, s_inst)), cPhi), Maybe)) + , Int.LF.(Decl (p, ClTyp (PTyp (Whnf.normTyp (tB, s_inst)), cPhi), Plicity.implicit, Inductivity.not_inductive)) ); - Int.LF.Root (loc, Int.LF.Proj (Int.LF.FPVar (p, s''), kIndex), Int.LF.Nil, `explicit) + Int.LF.Root (loc, Int.LF.Proj (Int.LF.FPVar (p, s''), kIndex), Int.LF.Nil, Plicity.explicit) | (false, Apx.LF.Nil) -> failwith "Not implemented" (* let q = Whnf.newPVar None (cPsi, Int.LF.TClo sP) in *) @@ -1744,7 +1734,7 @@ and elTerm' recT cD cPsi r sP = let (_, tA, cPhi) = Whnf.mctxMDec cD u in let s'' = elSub loc recT cD cPsi s' Int.LF.Subst cPhi in let (tS, sQ) = elSpine loc recT cD cPsi spine (tA, s'') in - let tR = Int.LF.Root (loc, Int.LF.MVar (Int.LF.Offset u, s''), tS, `explicit) in + let tR = Int.LF.Root (loc, Int.LF.MVar (Int.LF.Offset u, s''), tS, Plicity.explicit) in dprintf begin fun p -> p.fmt "cPsi = %a" @@ -1784,12 +1774,12 @@ and elTerm' recT cD cPsi r sP = | Int.LF.BVar k -> begin match S.LF.bvarSub k s'' with | Int.LF.Head (Int.LF.BVar j) -> - Int.LF.Root (loc, Int.LF.BVar j, tS, `explicit) + Int.LF.Root (loc, Int.LF.BVar j, tS, Plicity.explicit) | Int.LF.Head (Int.LF.PVar (p, r')) -> - Int.LF.Root (loc, Int.LF.PVar (p, S.LF.comp r' s''), tS, `explicit) + Int.LF.Root (loc, Int.LF.PVar (p, S.LF.comp r' s''), tS, Plicity.explicit) end | Int.LF.PVar (p, r) -> - Int.LF.Root (loc, Int.LF.PVar (p, S.LF.comp r s''), tS, `explicit) + Int.LF.Root (loc, Int.LF.PVar (p, S.LF.comp r s''), tS, Plicity.explicit) (* | Int.LF.Proj (Int.LF.PVar (p, r), i) -> Int.LF.Root (loc, Int.LF) *) end (* with @@ -1804,15 +1794,15 @@ and elTerm' recT cD cPsi r sP = dprintf (fun p -> - let (u, tp, dep) = Whnf.mctxLookupDep cD k in + let (u, tp, plicity, inductivity) = Whnf.mctxLookupDep cD k in p.fmt "[elTerm'] elaborating parameter variable at index %d -> %a" k - (P.fmt_ppr_lf_ctyp_decl cD) (Int.LF.Decl (u, tp, dep)) + (P.fmt_ppr_lf_ctyp_decl cD) (Int.LF.Decl (u, tp, plicity, inductivity)) ); let (_, tA, cPhi) = Whnf.mctxPDec cD k in let s'' = elSub loc recT cD cPsi s' Int.LF.Subst cPhi in let (tS, sQ) = elSpine loc recT cD cPsi spine (tA, s'') in - let tR = Int.LF.Root (loc, Int.LF.PVar (k, s''), tS, `explicit) in + let tR = Int.LF.Root (loc, Int.LF.PVar (k, s''), tS, Plicity.explicit) in begin try Unify.unifyTyp cD cPsi sQ sP; @@ -1849,7 +1839,7 @@ and elTerm' recT cD cPsi r sP = begin try Unify.unifyTyp cD cPsi sQ sP; - Int.LF.Root (loc, Int.LF.Proj (Int.LF.BVar x, k), tS, `explicit) + Int.LF.Root (loc, Int.LF.Proj (Int.LF.BVar x, k), tS, Plicity.explicit) with | Unify.Failure msg -> throw loc (TypMismatchElab (cD, cPsi, sP, sQ)) @@ -1877,7 +1867,7 @@ and elTerm' recT cD cPsi r sP = begin try Unify.unifyTyp cD cPsi sQ sP; - Int.LF.Root (loc, Int.LF.Proj (Int.LF.PVar (p, t'), k), tS, `explicit) + Int.LF.Root (loc, Int.LF.Proj (Int.LF.PVar (p, t'), k), tS, Plicity.explicit) with | Unify.Failure msg -> throw loc (TypMismatchElab (cD, cPsi, sP, sQ)) @@ -1917,13 +1907,13 @@ and elTerm' recT cD cPsi r sP = | Int.LF.BVar y -> begin match S.LF.bvarSub y s'' with | Int.LF.Head (Int.LF.BVar x) -> - Int.LF.Root (loc, Int.LF.Proj (Int.LF.BVar x, k), tS, `explicit) + Int.LF.Root (loc, Int.LF.Proj (Int.LF.BVar x, k), tS, Plicity.explicit) | Int.LF.Head (Int.LF.PVar (p, r')) -> Int.LF.Root ( loc , Int.LF.Proj (Int.LF.PVar (p, S.LF.comp r' s''), k) , tS - , `explicit + , Plicity.explicit ) end | Int.LF.PVar (p, r) -> @@ -1931,7 +1921,7 @@ and elTerm' recT cD cPsi r sP = ( loc , Int.LF.Proj (Int.LF.PVar (p, S.LF.comp r s''), k) , tS - , `explicit + , Plicity.explicit ) end with @@ -2074,12 +2064,12 @@ and elClosedTerm' recT cD cPsi = (* let s = mkShift recT cPsi in *) let s = S.LF.id in let (tS, sQ) = elSpineI loc recT cD cPsi spine i (tA, s) in - (Int.LF.Root (loc, Int.LF.Const c, tS, `explicit), sQ) + (Int.LF.Root (loc, Int.LF.Const c, tS, Plicity.explicit), sQ) | Apx.LF.Root (loc, Apx.LF.BVar x, spine) -> let Int.LF.TypDecl (_, tA) = Context.ctxDec cPsi x in let (tS, sQ) = elSpine loc recT cD cPsi spine (tA, S.LF.id) in - (Int.LF.Root (loc, Int.LF.BVar x, tS, `explicit), sQ) + (Int.LF.Root (loc, Int.LF.BVar x, tS, Plicity.explicit), sQ) | Apx.LF.Root (loc, Apx.LF.MVar (Apx.LF.Offset u, s), spine) -> begin @@ -2087,7 +2077,7 @@ and elClosedTerm' recT cD cPsi = let (_, tA, cPhi) = Whnf.mctxMDec cD u in let s'' = elSub loc recT cD cPsi s Int.LF.Subst cPhi in let (tS, sQ) = elSpine loc recT cD cPsi spine (tA, s'') in - (Int.LF.Root (loc, Int.LF.MVar (Int.LF.Offset u, s''), tS, `explicit), sQ) + (Int.LF.Root (loc, Int.LF.MVar (Int.LF.Offset u, s''), tS, Plicity.explicit), sQ) with | Error.Violation msg -> (* XXX this is probably bad -je *) dprint (fun () -> "[elClosedTerm] Violation: " ^ msg); @@ -2100,7 +2090,7 @@ and elClosedTerm' recT cD cPsi = let (_, tA, cPhi) = Whnf.mctxPDec cD p in let s'' = elSub loc recT cD cPsi s' Int.LF.Subst cPhi in let (tS, sQ) = elSpine loc recT cD cPsi spine (tA, s'') in - (Int.LF.Root (loc, Int.LF.PVar (p, s''), tS, `explicit), sQ) + (Int.LF.Root (loc, Int.LF.PVar (p, s''), tS, Plicity.explicit), sQ) with | Error.Violation msg -> (* XXX this is probably bad -je *) dprint (fun () -> "[elClosedTerm] Violation: " ^ msg); @@ -2113,7 +2103,7 @@ and elClosedTerm' recT cD cPsi = try let s'' = elSub loc recT cD cPsi s' Int.LF.Subst cPhi in let (tS, sQ) = elSpine loc recT cD cPsi spine (tA, s'') in - (Int.LF.Root (loc, Int.LF.PVar (p0, S.LF.comp s0 s''), tS, `explicit), sQ) + (Int.LF.Root (loc, Int.LF.PVar (p0, S.LF.comp s0 s''), tS, Plicity.explicit), sQ) with | Error.Violation msg -> dprint (fun () -> "[elClosedTerm] Violation: " ^ msg); @@ -2144,7 +2134,7 @@ and elClosedTerm' recT cD cPsi = throw loc (ProjNotValid (cD, cPsi, k, (Int.LF.Sigma recA, S.LF.id))) in let (tS, sQ) = elSpine loc recT cD cPsi spine sA in - (Int.LF.Root (loc, Int.LF.Proj (Int.LF.BVar x, k), tS, `explicit), sQ) + (Int.LF.Root (loc, Int.LF.Proj (Int.LF.BVar x, k), tS, Plicity.explicit), sQ) | Apx.LF.Root (loc, Apx.LF.Proj (Apx.LF.PVar (Apx.LF.Offset p, t), proj), spine) -> begin match Whnf.mctxPDec cD p with @@ -2158,7 +2148,7 @@ and elClosedTerm' recT cD cPsi = | _ -> throw loc (ProjNotValid (cD, cPsi, k, (Int.LF.Sigma recA, t'))) in let (tS, sQ) = elSpine loc recT cD cPsi spine sA in - (Int.LF.Root (loc, Int.LF.Proj (Int.LF.PVar (p, t'), k), tS, `explicit), sQ) + (Int.LF.Root (loc, Int.LF.Proj (Int.LF.PVar (p, t'), k), tS, Plicity.explicit), sQ) | _ -> dprintf begin fun pr -> @@ -2179,7 +2169,7 @@ and elClosedTerm' recT cD cPsi = try let sA = Int.LF.getType (Int.LF.PVar (p, s)) (recA, t') k 1 in let (tS, sQ) = elSpine loc recT cD cPsi spine sA in - (Int.LF.Root (loc, Int.LF.Proj (Int.LF.PVar (p, s), k), tS, `explicit), sQ) + (Int.LF.Root (loc, Int.LF.Proj (Int.LF.PVar (p, s), k), tS, Plicity.explicit), sQ) with | _ -> throw loc (ProjNotValid (cD, cPsi, k, (Int.LF.Sigma recA, t'))) end @@ -2251,7 +2241,7 @@ and elSub loc recT cD cPsi s cl cPhi = *) begin try - let (cD_d, Int.LF.Decl (_, Int.LF.ClTyp (Int.LF.STyp (cl0, cPhi0), cPsi0), dep)) = + let (cD_d, Int.LF.Decl (_, Int.LF.ClTyp (Int.LF.STyp (cl0, cPhi0), cPsi0), _, _)) = FCVar.get s_name in svar_le (cl0, cl); @@ -2267,7 +2257,7 @@ and elSub loc recT cD cPsi s cl cPhi = let rec createMSub d = if d = 0 then Int.LF.MShift 0 - else Int.LF.MDot (Int.LF.MUndef, createMSub (d+1)) + else Int.LF.MDot (Int.LF.MUndef, createMSub (d + 1)) in let t = createMSub d in (Whnf.cnormDCtx (cPhi0, t), Whnf.cnormDCtx (cPsi0, t)) @@ -2297,7 +2287,8 @@ and elSub loc recT cD cPsi s cl cPhi = , Int.LF.Decl ( s_name , Int.LF.ClTyp (Int.LF.STyp (cl, cPhi), cPsi') - , Int.LF.Maybe + , Plicity.implicit + , Inductivity.not_inductive ) ); Int.LF.FSVar (0, (s_name, sigma')) @@ -2627,7 +2618,7 @@ and elSpineIW loc recT cD cPsi spine i sA = * s.t. cPsi |- u[s'] => [s']A' where cPsi |- s' : . * and [s]A = [s']A'. Therefore A' = [s']^-1([s]A) *) - let tN = Whnf.etaExpandMV cPsi (tA, s) n S.LF.id Int.LF.Maybe in + let tN = Whnf.etaExpandMV cPsi (tA, s) n S.LF.id Plicity.implicit Inductivity.not_inductive in let (spine', sP) = elSpineI loc recT cD cPsi spine (i - 1) (tB, Int.LF.Dot (Int.LF.Obj tN, s)) in (Int.LF.App (tN, spine'), sP) @@ -2642,9 +2633,9 @@ and elSpineIW loc recT cD cPsi spine i sA = (* let tN = Whnf.etaExpandMMV loc cD cPsi (tA, s) n S.LF.id in *) let tN = if !strengthen - then ConvSigma.etaExpandMMVstr loc cD cPsi (tA, s) Int.LF.Maybe (Some n) + then ConvSigma.etaExpandMMVstr loc cD cPsi (tA, s) Plicity.implicit (Some n) Context.(names_of_dctx cPsi @ names_of_mctx cD) - else Whnf.etaExpandMMV loc cD cPsi (tA, s) n S.LF.id Int.LF.Maybe + else Whnf.etaExpandMMV loc cD cPsi (tA, s) n S.LF.id Plicity.implicit Inductivity.not_inductive in let (spine', sP) = elSpineI loc recT cD cPsi spine (i - 1) (tB, Int.LF.Dot (Int.LF.Obj tN, s)) in @@ -2654,7 +2645,7 @@ and elSpineIW loc recT cD cPsi spine i sA = (* elSpine loc recT cD cPsi spine sA = S * elSpineW cD cPsi spine sA = S - * where sA = (A,s) and sA in whnf + * where sA = (A, s) and sA in whnf * * Pre-condition: * U = free variables @@ -2719,7 +2710,7 @@ and elKSpineI loc recT cD cPsi spine i sK = | ((Int.LF.PiKind ((Int.LF.TypDecl (n, tA), _), tK), s), Pi) -> (* let sshift = mkShift recT cPsi in *) (* let tN = Whnf.etaExpandMV Int.LF.Null (tA, s) sshift in *) - let tN = Whnf.etaExpandMV cPsi (tA, s) n S.LF.id Int.LF.Maybe in + let tN = Whnf.etaExpandMV cPsi (tA, s) n S.LF.id Plicity.implicit Inductivity.not_inductive in let spine' = elKSpineI loc recT cD cPsi spine (i - 1) (tK, Int.LF.Dot (Int.LF.Obj tN, s)) in Int.LF.App (tN, spine') | ((Int.LF.PiKind ((Int.LF.TypDecl (n, tA), _), tK), s), Pibox) -> @@ -2728,10 +2719,10 @@ and elKSpineI loc recT cD cPsi spine i sK = let tN = if !strengthen then - ConvSigma.etaExpandMMVstr Syntax.Loc.ghost cD cPsi (tA, s) Int.LF.Maybe (Some n) + ConvSigma.etaExpandMMVstr Syntax.Loc.ghost cD cPsi (tA, s) Plicity.implicit (Some n) Context.(names_of_dctx cPsi @ names_of_mctx cD) else - Whnf.etaExpandMMV Syntax.Loc.ghost cD cPsi (tA, s) n S.LF.id Int.LF.Maybe + Whnf.etaExpandMMV Syntax.Loc.ghost cD cPsi (tA, s) n S.LF.id Plicity.implicit Inductivity.not_inductive in let spine' = elKSpineI loc recT cD cPsi spine (i - 1) (tK, Int.LF.Dot (Int.LF.Obj tN, s)) in Int.LF.App (tN, spine') @@ -2829,7 +2820,7 @@ and elSpineSynth recT cD cPsi spine s' sP = let tB' = Int.LF.PiTyp ( ( Int.LF.TypDecl (Id.mk_name (Id.BVarName (Typ.gen_var_name tA')), tA') - , Int.LF.Maybe + , Plicity.implicit ) , tB ) @@ -2850,7 +2841,7 @@ let rec elDCtx recT cD = function | Apx.LF.CtxHole -> dprint (fun () -> "Encountered _ (underscore) for context..."); - Int.LF.CtxVar (Whnf.newCVar (Some (Id.mk_name (Id.SomeString "j"))) cD None Int.LF.Maybe) + Int.LF.CtxVar (Whnf.newCVar (Some (Id.mk_name (Id.SomeString "j"))) cD None Plicity.implicit Inductivity.not_inductive) | Apx.LF.Null -> Int.LF.Null | Apx.LF.CtxVar c_var -> @@ -2896,7 +2887,7 @@ let checkCtxVar loc cD c_var w = ) ) | Apx.LF.CtxName psi -> - FCVar.add psi (cD, Int.LF.Decl (psi, Int.LF.CTyp (Some w), Int.LF.Maybe)); + FCVar.add psi (cD, Int.LF.Decl (psi, Int.LF.CTyp (Some w), Plicity.implicit, Inductivity.not_inductive)); Int.LF.CtxName psi (* ******************************************************************* *) @@ -2924,7 +2915,7 @@ let rec solve_fvarCnstr recT cD = begin try Unify.unifyTyp cD cPsi sQ (tP, S.LF.id); - instantiation := Some (Int.LF.INorm (Int.LF.Root (loc, Int.LF.FVar x, tS, `explicit))); + instantiation := Some (Int.LF.INorm (Int.LF.Root (loc, Int.LF.FVar x, tS, Plicity.explicit))); solve_fvarCnstr recT cD cnstrs with | Unify.Failure msg -> @@ -2955,7 +2946,7 @@ let rec solve_fvarCnstr recT cD = try Unify.unifyTyp cD cPsi sQ (tP, S.LF.id); Unify.unify cD cPsi - (Int.LF.Root (loc, Int.LF.FVar x, tS, `explicit), S.LF.id) + (Int.LF.Root (loc, Int.LF.FVar x, tS, Plicity.explicit), S.LF.id) (tR, S.LF.id); (* r := Some (Int.LF.Root (loc, Int.LF.FVar x, tS)); *) solve_fvarCnstr recT cD cnstrs @@ -2992,20 +2983,20 @@ let solve_fcvarCnstr cnstrs = match tM, Int.LF.(v.typ) with | Apx.LF.(Root (loc, FMVar (u, s), _nil_spine)), Int.LF.(ClTyp (MTyp _, cPsi)) -> assert (match _nil_spine with Apx.LF.Nil -> true | _ -> false); - let (cD_d, Int.LF.(Decl (_, ClTyp (MTyp _tP, cPhi), _))) = + let (cD_d, Int.LF.(Decl (_, ClTyp (MTyp _tP, cPhi), _, _))) = lookup_fcvar loc u in let cPhi = weakenAppropriately cD_d cPhi in let s'' = elSub loc cPsi s cPhi in - Int.LF.(v.instantiation := Some (INorm (Root (loc, FMVar (u, s''), Nil, `explicit)))) + Int.LF.(v.instantiation := Some (INorm (Root (loc, FMVar (u, s''), Nil, Plicity.explicit)))) | Apx.LF.(Root (loc, FPVar (x, s), spine)), Int.LF.(ClTyp (MTyp _, cPsi)) -> - let (cD_d, Int.LF.(Decl (_, ClTyp (PTyp tA, cPhi), _))) = + let (cD_d, Int.LF.(Decl (_, ClTyp (PTyp tA, cPhi), _, _))) = lookup_fcvar loc x in let cPhi = weakenAppropriately cD_d cPhi in let s'' = elSub loc cPsi s cPhi in let (tS, _) = elSpine loc Pibox Int.LF.(v.cD) cPsi spine (tA, s'') in - Int.LF.(v.instantiation := Some (INorm (Root (loc, FPVar (x, s''), tS, `explicit)))) + Int.LF.(v.instantiation := Some (INorm (Root (loc, FPVar (x, s''), tS, Plicity.explicit)))) in List.iter solve_one cnstrs diff --git a/src/core/linkStream.ml b/src/core/linkStream.ml index 53ce46ec4..09b421a84 100644 --- a/src/core/linkStream.ml +++ b/src/core/linkStream.ml @@ -10,7 +10,7 @@ let of_gen (g : unit -> 'a option) : 'a t = lazy begin match g () with | None -> Nil - | Some x -> Cons (x, go (n+1)) + | Some x -> Cons (x, go (n + 1)) end in go 0 @@ -26,7 +26,7 @@ let of_stream (s : 'a Stream.t) : 'a t = | Stream.Failure -> None with | None -> Nil - | Some x -> Cons (x, go (n+1)) + | Some x -> Cons (x, go (n + 1)) end in go 0 diff --git a/src/core/logic.ml b/src/core/logic.ml index 297e769a1..f203b942e 100644 --- a/src/core/logic.ml +++ b/src/core/logic.ml @@ -116,7 +116,7 @@ and atomic_spine = | End | Spine of atomic_spine * (Comp.meta_typ * LF.mfront - * Syncom.LF.plicity) (* For recreating type*) + * Plicity.t) (* For recreating type*) and comp_res = (* Residual Comp Goals *) | Base of Comp.typ (* cr ::= A *) @@ -237,9 +237,9 @@ module Convert = struct *) let rec typToClause' eV cG tA (cS, dS, dR) = match tA with - | LF.PiTyp ((tD, LF.Maybe), tA') -> + | LF.PiTyp ((tD, Plicity.Implicit), tA') -> typToClause' (LF.DDec (eV, tD)) cG tA' (cS, dS, dR) - | LF.PiTyp ((LF.TypDecl (_, tA), LF.No), tB) -> + | LF.PiTyp ((LF.TypDecl (_, tA), Plicity.Explicit), tB) -> typToClause' eV (Conjunct (cG, typToGoal tA (cS, dS, dR))) tB (cS + 1, dS, dR) | LF.Atom _ -> @@ -293,18 +293,18 @@ module Convert = struct *) and typToGoal tA (cS, dS, dR) = match tA with - | LF.PiTyp ((tdec, LF.Maybe), tA') -> + | LF.PiTyp ((tdec, Plicity.Implicit), tA') -> All (tdec, typToGoal tA' (cS, dS, dR + 1)) - | LF.PiTyp ((LF.TypDecl (x, tA) as tdec, LF.No), tB) -> + | LF.PiTyp ((LF.TypDecl (x, tA) as tdec, Plicity.Explicit), tB) -> Impl ((typToRes tA (cS, dS, dR), tdec), typToGoal tB (cS, dS, dR + 1)) | LF.Atom _ -> Atom (Shift.shiftAtom tA (-cS, -dS, dR)) and typToRes tM (cS, dS, dR) = match tM with - | LF.PiTyp ((tD, LF.Maybe), tM') -> + | LF.PiTyp ((tD, Plicity.Implicit), tM') -> Exists (tD, typToRes tM' (cS, dS, dR + 1)) - | LF.PiTyp ((LF.TypDecl (_, tA), LF.No), tB) -> + | LF.PiTyp ((LF.TypDecl (_, tA), Plicity.Explicit), tB) -> And (typToGoal tA (cS, dS, dR), typToRes tB (cS + 1, dS + 1, dR + 1)) | LF.Atom _ -> Head (Shift.shiftAtom tM (-cS, -dS, dR)) @@ -338,7 +338,7 @@ module Convert = struct let cg2 = comptypToCompGoal tau2 in let name = Id.mk_name Id.NoName in let typ_dec = Comp.CTypDecl (name, tau1 , true) in - Implies ((cr1,typ_dec), cg2) + Implies ((cr1, typ_dec), cg2) | Comp.TypBase (_, comp_cid, s) -> Atomic (comp_cid, msToAs s) @@ -346,9 +346,9 @@ module Convert = struct match tau with | Comp.TypBox (_) | Comp.TypBase(_) -> Base tau - | Comp.TypArr (_,tau1,tau2) -> + | Comp.TypArr (_, tau1, tau2) -> CAnd (comptypToCompGoal tau1, comptypToCompRes tau2) - | Comp.TypPiBox (_,typ_dec, tau') -> + | Comp.TypPiBox (_, typ_dec, tau') -> CExists (typ_dec, comptypToCompRes tau') let rec resToClause' eV cG (r, s) = @@ -427,8 +427,8 @@ module Convert = struct let (tA, s) = Whnf.whnfTyp sA in match tA with | LF.Atom _ -> - let u = LF.Inst (Whnf.newMMVar None (cD, cPsi, LF.TClo (tA, s)) LF.Maybe) in - LF.Root (Syntax.Loc.ghost, LF.MVar (u, S.id), LF.Nil, `explicit) + let u = LF.Inst (Whnf.newMMVar None (cD, cPsi, LF.TClo (tA, s)) Plicity.implicit Inductivity.not_inductive) in + LF.Root (Syntax.Loc.ghost, LF.MVar (u, S.id), LF.Nil, Plicity.explicit) | LF.PiTyp ((LF.TypDecl (x, tA) as tD, _), tB) -> LF.Lam ( Syntax.Loc.ghost @@ -464,44 +464,36 @@ module Convert = struct let rec mctxToMSub cD (mV, ms) fS = let etaExpand' cD cPsi (tA, ms) name = - let cvar = Whnf.newMMVar (Some name) (cD, cPsi, tA) LF.Maybe in - LF.Root (Syntax.Loc.ghost, LF.MMVar((cvar, ms), S.id), LF.Nil, `explicit) - in - let get_plicity dep = - match dep with - | LF.No -> `explicit - | LF.Maybe -> `implicit + let cvar = Whnf.newMMVar (Some name) (cD, cPsi, tA) Plicity.implicit Inductivity.not_inductive in + LF.Root (Syntax.Loc.ghost, LF.MMVar((cvar, ms), S.id), LF.Nil, Plicity.explicit) in let noLoc = Syntax.Loc.ghost in match mV with | LF.Empty -> (ms, fS) | LF.Dec (mV', - LF.Decl (name, ((LF.ClTyp (LF.MTyp tA, cPsi)) as ctyp), dep)) -> + LF.Decl (name, ((LF.ClTyp (LF.MTyp tA, cPsi)) as ctyp), plicity, _)) -> let (ms', fS') = mctxToMSub cD (mV', ms) fS in let tM = etaExpand' cD cPsi (tA, ms) name in let dctx_hat = Context.dctxToHat cPsi in - let plicity = get_plicity dep in let mfront = LF.ClObj (dctx_hat, LF.MObj tM) in (LF.MDot (mfront, ms'), (fun s -> fS' (Comp.MApp (noLoc, s, (noLoc, mfront), ctyp, plicity)))) | LF.Dec (mV', - LF.Decl (name, ((LF.ClTyp (LF.PTyp tA, cPsi)) as ctyp), dep)) -> + LF.Decl (name, ((LF.ClTyp (LF.PTyp tA, cPsi)) as ctyp), plicity, _)) -> let (ms', fS') = mctxToMSub cD (mV', ms) fS in let tM = etaExpand' cD cPsi (tA, ms') name in let LF.Root (noLoc, hd, LF.Nil, _) = tM in let dctx_hat = Context.dctxToHat cPsi in - let plicity = get_plicity dep in let mfront = LF.ClObj (dctx_hat, LF.PObj hd) in (LF.MDot (mfront, ms'), (fun s -> fS' (Comp.MApp (noLoc, s, (noLoc, mfront), ctyp, plicity)))) | LF.Dec (mV', - LF.Decl (name, ((LF.CTyp (Some cid)) as ctyp), dep)) -> + LF.Decl (name, ((LF.CTyp (Some cid)) as ctyp), plicity, inductivity)) -> let (ms', fS') = mctxToMSub cD (mV', ms) fS in - let plicity = get_plicity dep in - let dctx = Whnf.newCVar (Some name) cD (Some cid) dep in + let dctx = Whnf.newCVar (Some name) cD (Some cid) plicity inductivity in let mfront = LF.CObj (LF.CtxVar dctx) in (* let mf = Whnf.cnormMFt mfront ms' in *) (LF.MDot (mfront, ms'), @@ -521,7 +513,7 @@ module Convert = struct let typToQuery cD cPsi (tA, i) = let rec typToQuery' (tA, i) s xs = match tA with - | LF.PiTyp ((LF.TypDecl (x, tA), LF.Maybe), tB) when i > 0 -> + | LF.PiTyp ((LF.TypDecl (x, tA), Plicity.Implicit), tB) when i > 0 -> let tN' = etaExpand cD cPsi (tA, s) in typToQuery' (tB, i - 1) (LF.Dot (LF.Obj tN', s)) ((x, tN') :: xs) | _ -> ((typToGoal tA (0, 0, 0), s), tA, s, xs) @@ -541,7 +533,7 @@ module Convert = struct (* - comptypToMQuery (tau,i) = comp_goal + comptypToMQuery (tau, i) = comp_goal Precondition: @@ -567,24 +559,24 @@ let comptypToMQuery (tau, i) = *) match tau with | Comp.TypBox (_loc, LF.ClTyp (LF.MTyp _tA, _cPsi)) -> - (((comptypToCompGoal tau),ms), tau, ms, xs) + (((comptypToCompGoal tau), ms), tau, ms, xs) | Comp.TypBox (_loc, LF.ClTyp (LF.PTyp _tA, _cPsi)) -> - (((comptypToCompGoal tau),ms), tau, ms, xs) + (((comptypToCompGoal tau), ms), tau, ms, xs) | Comp.TypBox (loc, LF.ClTyp (LF.STyp (_svar_c, _cPhi), _cPsi)) -> raise NotImplementedYet | Comp.TypPiBox (loc, mdecl, tau') when i > 0 -> - let LF.Decl(x, mtyp, dep) = mdecl in (* where mtyp = (LF.MTyp tA, cPsi) *) + let LF.Decl(x, mtyp, plicity, inductivity) = mdecl in (* where mtyp = (LF.MTyp tA, cPsi) *) (* generate a meta-variable (instantiated by unification) of type (LF.MTyp tA, cPsi) and make sure it is an mfront *) - let mmV = Whnf.newMMVar' (Some x) (LF.Empty, mtyp) dep in + let mmV = Whnf.newMMVar' (Some x) (LF.Empty, mtyp) plicity inductivity in let mfront = Whnf.mmVarToMFront loc mmV mtyp in - comptypToMQuery' (tau', i-1) (LF.MDot (mfront, ms)) ((x, (loc, mfront)) :: xs) - | Comp.TypPiBox (_,_, tau') when i = 0 -> - (((comptypToCompGoal tau),ms), tau, ms, xs) + comptypToMQuery' (tau', i - 1) (LF.MDot (mfront, ms)) ((x, (loc, mfront)) :: xs) + | Comp.TypPiBox (_, _, tau') when i = 0 -> + (((comptypToCompGoal tau), ms), tau, ms, xs) | Comp.TypArr (loc, tau1, tau2) -> - (((comptypToCompGoal tau),ms), tau, ms, xs) + (((comptypToCompGoal tau), ms), tau, ms, xs) | Comp.TypBase (_) -> - (((comptypToCompGoal tau),ms), tau, ms, xs) + (((comptypToCompGoal tau), ms), tau, ms, xs) | _ -> raise NotImplementedYet in comptypToMQuery' (tau, i) (LF.MShift 0) [] @@ -799,9 +791,9 @@ module Index = struct let rec get_minst xs = match xs with | [] -> [] - | (a,(loc,b)) :: ys -> + | (a, (loc, b)) :: ys -> let ys' = get_minst ys in - (a,b) :: ys' + (a, b) :: ys' in let (mq, tau', ms, xs) = (Convert.comptypToMQuery (tau, i)) in let xs' = get_minst xs in @@ -1153,7 +1145,7 @@ module Printer = struct ms = %a \n" (fmt_ppr_mctx) cD (fmt_ppr_gctx cD) cG - (fmt_ppr_cmp_goal cD) (cg,S.id) + (fmt_ppr_cmp_goal cD) (cg, S.id) (Pretty.Int.DefaultPrinter.fmt_ppr_lf_msub cD Pretty.Int.DefaultPrinter.l0) ms *) end @@ -1267,7 +1259,7 @@ module Solver = struct *) and matchAtom dPool cD (cPsi, k) (tA, s) sc = (* some shorthands for creating syntax *) - let root x = LF.Root (Syntax.Loc.ghost, x, LF.Nil, `explicit) in + let root x = LF.Root (Syntax.Loc.ghost, x, LF.Nil, Plicity.explicit) in let pvar k = LF.PVar (k, LF.Shift 0) in let mvar k = LF.MVar (LF.Offset k, LF.Shift 0) in let proj x k = LF.Proj (x, k) in @@ -1297,7 +1289,7 @@ module Solver = struct ( Syntax.Loc.ghost , LF.BVar (k - k') , fS (spineFromRevList tS) - , `explicit + , Plicity.explicit ) in sc (u, tM) @@ -1374,7 +1366,7 @@ module Solver = struct let rec loop cD' k = match cD' with | LF.Empty -> matchDProg dPool - | LF.Dec (cD', LF.Decl (_, LF.ClTyp (cltyp, psi), _)) -> + | LF.Dec (cD', LF.Decl (_, LF.ClTyp (cltyp, psi), _, _)) -> begin let psi' = Whnf.cnormDCtx (psi, LF.MShift k) in let cltyp' = Whnf.cnormClTyp (cltyp, LF.MShift k) in @@ -1460,7 +1452,7 @@ module Solver = struct ( Syntax.Loc.ghost , LF.Const (cidTerm) , fS (spineFromRevList tS) - , `explicit + , Plicity.explicit ) in sc (u, tM) @@ -1534,14 +1526,14 @@ module CSolver = struct | Unboxed (* Dynamic Computation Assumptions *) - type cPool = (* cP ::= *) - | Emp (* | Emp *) + type cPool = (* cP ::= *) + | Emp (* | Emp *) | Full of - (cPool * (cclause * int * status)) (* | Full (cP', (cc, k,s)) *) + (cPool * (cclause * int * status)) (* | Full (cP', (cc, k, s)) *) (* where k denotes the postion of the correspoding type - declaration in cG *) + declaration in cG *) let noLoc = Syntax.Loc.ghost @@ -1646,14 +1638,14 @@ module CSolver = struct let rec normAtomicSpine ms aS = match aS with | End -> aS - | Spine (aS', (mt, mf,pl)) -> + | Spine (aS', (mt, mf, pl)) -> let aS'' = normAtomicSpine ms aS' in let mf' = Whnf.cnormMFt mf ms in - Spine (aS'', (mt, mf',pl)) + Spine (aS'', (mt, mf', pl)) in match cg with | Box (cPsi, Atom typ, _lfTyp) -> - let typ' = Whnf.cnormTyp (typ,ms) in + let typ' = Whnf.cnormTyp (typ, ms) in let cPsi' = Whnf.cnormDCtx (cPsi, ms) in Box (cPsi', Atom typ', _lfTyp) | Implies ((r, td), cg') -> @@ -1701,7 +1693,7 @@ module CSolver = struct let rec find_max cD cltyp_d k lst = match cD with | LF.Empty -> (cltyp_d, lst) - | LF.Dec (cD', ((LF.Decl (name, LF.ClTyp (cltyp', _cPsi), _dep)) as cltyp_d')) -> + | LF.Dec (cD', ((LF.Decl (name, LF.ClTyp (cltyp', _cPsi), _)) as cltyp_d')) -> let (k', lst') = consOfTyp cltyp' in if k' < k then find_max cD' cltyp_d' k' lst' @@ -1710,7 +1702,7 @@ module CSolver = struct in match cD with | LF.Empty -> raise NotImplementedYet - | LF.Dec (cD', ((LF.Decl (name, LF.ClTyp (cltyp, _cPsi), _dep)) as cltyp_d)) -> + | LF.Dec (cD', ((LF.Decl (name, LF.ClTyp (cltyp, _cPsi), _)) as cltyp_d)) -> let (k, lst) = consOfTyp cltyp in find_max cD' cltyp_d k lst *) @@ -1784,7 +1776,7 @@ module CSolver = struct | Ev_ss: Pi N:[ |- nat]. Even [ |- N] -> Even [ |- suc (suc N)] - 3) Q = Box(cPsi,A) or Inductive(a, meta-spine) we solve it using some assumption from cG + 3) Q = Box(cPsi, A) or Inductive(a, meta-spine) we solve it using some assumption from cG cG might contain f: tau₁ -> Q , x:tau₁ ===> Q @@ -1861,7 +1853,7 @@ module CSolver = struct sc e | Solve (sg', cg') -> (*printf "solve thm SG \n"; - let cg = normCompGoal (cg',ms) in + let cg = normCompGoal (cg', ms) in Printer.printState cD cG cg ms;*) cgSolve' cD cG cPool (cg', ms) (fun e -> @@ -1967,7 +1959,7 @@ module CSolver = struct (* let termEntry = Store.Cid.Term.get con in let tA = termEntry.Store.Cid.Term.Entry.typ in *) let hd = LF.Const con in - let norm = LF.Root (noLoc, hd, LF.Nil, `explicit) in + let norm = LF.Root (noLoc, hd, LF.Nil, Plicity.explicit) in let pattern = Comp.PatMetaObj (noLoc,(noLoc, LF.ClObj ((None, 0), LF.MObj (norm)))) in @@ -1991,7 +1983,7 @@ module CSolver = struct (* let termEntry = Store.Cid.Term.get con in let tA = termEntry.Store.Cid.Term.Entry.typ in *) let hd = LF.Const con in - let norm = LF.Root (noLoc, hd, LF.Nil, `explicit) in + let norm = LF.Root (noLoc, hd, LF.Nil, Plicity.explicit) in let (cD', ms', cG', cPool', cg') = instMV cg norm cD cG cPool in solveBranch cD' cG' cPool' cg' (name, con) con_list b_list ms' sc currD maxD @@ -2007,7 +1999,7 @@ module CSolver = struct let LF.Decl (name, ctyp, dep) = ctyp_d in let LF.ClTyp (cltyp, cPsi) = ctyp in let hd = LF.FVar name in - let norm = LF.Root (noLoc, hd, LF.Nil, `explicit) in + let norm = LF.Root (noLoc, hd, LF.Nil, Plicity.explicit) in let mf = LF.ClObj (Context.dctxToHat cPsi, LF.MObj norm) in let mo = (noLoc, mf) in let var = Comp.AnnBox (mo, ctyp) in @@ -2032,7 +2024,7 @@ module CSolver = struct proof term in the LF level, otherwise we focus on an assumption in our computation context cG *) let cg' = normCompGoal (cg, ms) in - let Box(_,g',_) = cg' in + let Box(_, g', _) = cg' in let Atom tA = g' in (* note, we take the goal's type because the main check is checking the meta_obj against meta_typ of the goal *) @@ -2054,7 +2046,7 @@ module CSolver = struct let cltyp = LF.PTyp tA in let sc' = (fun (cPsi', tM) -> - let LF.Root (_,hd,_,_) = tM in + let LF.Root (_, hd, _, _) = tM in let dctx_hat = Context.dctxToHat cPsi' in let mfront = LF.ClObj (dctx_hat, LF.PObj hd) in let meta_obj = (noLoc, mfront) in @@ -2140,12 +2132,12 @@ module CSolver = struct match cPool with | Emp -> focus cD cG cPool_ret cg ms sc currDepth maxDepth - | Full (cPool', ((({cHead = Comp.TypBox(m,r); cMVars = cmv;cSubGoals = Proved }, k', Boxed)) as cP)) -> + | Full (cPool', ((({cHead = Comp.TypBox(m, r); cMVars = cmv;cSubGoals = Proved }, k', Boxed)) as cP)) -> (* In this case, we want to "unbox" the assumption and add it to the cD. When an assumption gets unboxed, we no longer consider it in Gamma. *) let name = Id.mk_name (Whnf.newMTypName r) in - let mctx_decl = LF.Decl (name, r, LF.No) in + let mctx_decl = LF.Decl (name, r, Plicity.explicit, Inductivity.not_inductive) in let cD' = Whnf.extend_mctx cD (mctx_decl, ms) in let cG' = Whnf.cnormGCtx (cG, LF.MShift 1) in let box = Comp.Var (noLoc, k') in @@ -2155,10 +2147,10 @@ module CSolver = struct | LF.ClTyp (LF.MTyp _, cPsi) -> let tM = LF.Root - (noLoc - ,LF.MVar (LF.Offset 1, S.id) + ( noLoc + , LF.MVar (LF.Offset 1, S.id) , LF.Nil - , `explicit + , Plicity.explicit ) in LF.ClObj (Context.dctxToHat (Whnf.cnormDCtx (cPsi, LF.MShift 1)), LF.MObj tM) @@ -2173,7 +2165,7 @@ module CSolver = struct let sc' = (fun e -> sc (Comp.Case (noLoc, Comp.PragmaNotCase, box, - [Comp.Branch (noLoc, LF.Empty, (cD', LF.Empty), pattern, LF.MShift 1,e)]))) in + [Comp.Branch (noLoc, LF.Empty, (cD', LF.Empty), pattern, LF.MShift 1, e)]))) in let ms' = Whnf.mvar_dot1 ms in let cPool'' = cnormCPool (cPool', LF.MShift 1) cD' in let cPool_ret' = prependToCPool (unbox cP) cPool_ret in @@ -2242,7 +2234,7 @@ module CSolver = struct let cPool' = cnormCPool (cPool, LF.MShift 1) cD in let sc' = (fun e -> - sc (Comp.MLam (noLoc, name, e, `explicit))) in + sc (Comp.MLam (noLoc, name, e, Plicity.explicit))) in uniform_right cD' cG' cPool' cg' (Whnf.mvar_dot1 ms) sc' currDepth maxDepth | Implies ((r, tdecl), cg') -> (* We gain an assumption for the computation context *) diff --git a/src/core/parser.ml b/src/core/parser.ml index d2abd9ff2..91a4983f3 100644 --- a/src/core/parser.ml +++ b/src/core/parser.ml @@ -967,11 +967,11 @@ let name_or_blank : name_or_blank parser = (name $> fun x -> `name x) (token T.UNDERSCORE |> blankify) -(** Converts a name or blank into a depend and a name. *) -let dep_name_of_nb = +(** Converts a name or blank into a plicity and a name. *) +let plicity_name_of_nb = function - | `blank loc' -> (LF.Maybe, Id.mk_blank (Some loc')) - | `name x -> (LF.No, x) + | `blank loc' -> (Plicity.implicit, Id.mk_blank (Some loc')) + | `name x -> (Plicity.explicit, x) let dot_name : Id.name t = token T.DOT &> name @@ -1843,8 +1843,8 @@ let cltyp : (LF.dctx * typ_or_ctx) parser = (label ctx "contextual context type") end -let clf_ctyp_decl_bare : type a. a name_parser -> (a -> LF.depend * Id.name) -> LF.ctyp_decl t = - fun nameclass dep_of_name -> +let clf_ctyp_decl_bare : type a. a name_parser -> (a -> Plicity.t * Id.name) -> LF.ctyp_decl t = + fun nameclass plicity_of_name -> { run = fun s -> let hash_variable_decl p = @@ -1859,15 +1859,15 @@ let clf_ctyp_decl_bare : type a. a name_parser -> (a -> LF.depend * Id.name) -> (sigil_bracks_or_opt_parens T.DOLLAR) p in - let mk_decl dep f (loc, (p, w)) = - LF.Decl (p, (loc, f w), dep) + let mk_decl plicity f (loc, (p, w)) = + LF.Decl (p, (loc, f w), plicity) in - let mk_cltyp_decl dep f d = - mk_decl dep (fun (cPsi, x) -> LF.ClTyp (f x, cPsi)) d + let mk_cltyp_decl plicity f d = + mk_decl plicity (fun (cPsi, x) -> LF.ClTyp (f x, cPsi)) d in let mk_cltyp_decl_blank f (loc, (nb, (cPsi, tA))) = - let dep, x = dep_of_name nb in - mk_cltyp_decl dep f (loc, (x, (cPsi, tA))) + let plicity, x = plicity_of_name nb in + mk_cltyp_decl plicity f (loc, (x, (cPsi, tA))) in let param_variable = hash_variable_decl (trying clf_typ_atomic) @@ -1898,17 +1898,17 @@ let clf_ctyp_decl_bare : type a. a name_parser -> (a -> LF.depend * Id.name) -> *) ; nameclass `ordinary <& token T.COLON |> span $ fun (loc1, nb) -> - let dep, x = dep_of_name nb in + let plicity, x = plicity_of_name nb in alt (span name $> fun (loc2, ctx) -> - mk_decl dep + mk_decl plicity (fun w -> LF.CTyp w) (Loc.join loc1 loc2, (x, ctx))) (bracks_or_opt_parens (contextual clf_typ_atomic) |> span $> fun (loc2, d) -> mk_cltyp_decl - dep + plicity (fun tA -> LF.MTyp tA) (Loc.join loc1 loc2, (x, d))) ] @@ -1924,7 +1924,7 @@ let ctx_variable = (trying (name <& token T.COLON)) (name <& not_followed_by meta_obj) |> span - $> fun (loc, (p, w)) -> LF.Decl (p, (loc, LF.CTyp w), LF.Maybe) + $> fun (loc, (p, w)) -> LF.Decl (p, (loc, LF.CTyp w), Plicity.implicit) end (** Contextual LF contextual type declaration *) @@ -1938,11 +1938,11 @@ let clf_ctyp_decl = let dollar_variable_decl p = contextual_variable_decl dollar_name bracks_or_opt_parens p in - let mk_decl dep f (loc, (p, w)) = - LF.Decl (p, (loc, f w), dep) + let mk_decl plicity f (loc, (p, w)) = + LF.Decl (p, (loc, f w), plicity) in let mk_cltyp_decl f d = - mk_decl LF.No (fun (cPsi, x) -> LF.ClTyp (f x, cPsi)) d + mk_decl Plicity.explicit (fun (cPsi, x) -> LF.ClTyp (f x, cPsi)) d in let param_variable = @@ -1981,7 +1981,7 @@ let clf_ctyp_decl = alt (span name $> fun (loc2, ctx) -> - mk_decl LF.No + mk_decl Plicity.explicit (fun w -> LF.CTyp w) (Loc.join loc1 loc2, (x, ctx))) (bracks_or_opt_parens (contextual clf_typ_atomic) @@ -2030,7 +2030,7 @@ let rec cmp_typ = in let pibox = labelled "Pi-box type" - (pibox (clf_ctyp_decl_bare name' (fun x -> LF.No, x) |> braces) cmp_typ + (pibox (clf_ctyp_decl_bare name' (fun x -> Plicity.explicit, x) |> braces) cmp_typ (fun loc ctyp_decl tau -> Comp.TypPiBox (loc, ctyp_decl, tau))) in @@ -2168,7 +2168,7 @@ let rec cmp_kind = end , cPsi ) - , LF.No + , Plicity.explicit ) , k ) @@ -2232,7 +2232,7 @@ and cmp_branch = fun s -> let p = seq3 - (mctx ~sep: (pure ()) (clf_ctyp_decl_bare name' (fun x -> LF.No, x) |> braces)) + (mctx ~sep: (pure ()) (clf_ctyp_decl_bare name' (fun x -> Plicity.explicit, x) |> braces)) cmp_pattern (token T.THICK_ARROW &> cmp_exp_chk) |> span @@ -2374,7 +2374,7 @@ and cmp_exp_chk' = let lets = let let_pattern = seq4 - (mctx ~sep: (pure ()) (clf_ctyp_decl_bare name' (fun x -> LF.No, x) |> braces)) + (mctx ~sep: (pure ()) (clf_ctyp_decl_bare name' (fun x -> Plicity.explicit, x) |> braces)) (cmp_pattern <& token T.EQUALS) (cmp_exp_syn <& token T.KW_IN) cmp_exp_chk @@ -2681,7 +2681,7 @@ let sgn_query_pragma = pragma "query" &> seq4 (seq2 bound bound) - (mctx ~sep: (pure ()) (clf_ctyp_decl_bare name' (fun x -> LF.No, x) |> braces)) + (mctx ~sep: (pure ()) (clf_ctyp_decl_bare name' (fun x -> Plicity.explicit, x) |> braces)) (maybe (name <& token T.COLON)) lf_typ <& token T.DOT @@ -3020,7 +3020,7 @@ and harpoon_hypothetical : Comp.hypothetical parser = let open Comp in let hypotheses = seq2 - (mctx (clf_ctyp_decl_bare name_or_blank' dep_name_of_nb) <& token T.PIPE) + (mctx (clf_ctyp_decl_bare name_or_blank' plicity_name_of_nb) <& token T.PIPE) gctx $> fun (cD, cG) -> { cD; cG } in diff --git a/src/core/prettycom.ml b/src/core/prettycom.ml index b65b16834..5aaa06af5 100644 --- a/src/core/prettycom.ml +++ b/src/core/prettycom.ml @@ -29,22 +29,22 @@ type depend_print_style = let fmt_ppr_plicity ppf = function - | `explicit -> fprintf ppf "explicit" - | `implicit -> fprintf ppf "implicit" + | Plicity.Implicit -> pp_print_string ppf "implicit" + | Plicity.Explicit -> pp_print_string ppf "explicit" let fmt_ppr_lf_depend_clean ppf _ = () let fmt_ppr_lf_depend_inductive ppf = function - | LF.No -> fprintf ppf "" - | LF.Maybe -> fprintf ppf "" - | LF.Inductive -> fprintf ppf "*" + | Inductivity.NotInductive -> pp_print_string ppf "" + | Inductivity.Inductive -> pp_print_string ppf "*" let fmt_ppr_lf_depend ppf = function - | LF.No -> fprintf ppf "^e" - | LF.Maybe -> fprintf ppf "^i" - | LF.Inductive -> fprintf ppf "*" + | Plicity.Implicit, Inductivity.NotInductive -> pp_print_string ppf "^i" + | Plicity.Explicit, Inductivity.NotInductive -> pp_print_string ppf "^e" + | Plicity.Implicit, Inductivity.Inductive -> pp_print_string ppf "*i" + | Plicity.Explicit, Inductivity.Inductive -> pp_print_string ppf "*e" let fmt_ppr_cmp_split_kind ppf = function diff --git a/src/core/prettyext.ml b/src/core/prettyext.ml index daaa82c0f..5b59bf99a 100644 --- a/src/core/prettyext.ml +++ b/src/core/prettyext.ml @@ -601,7 +601,7 @@ module Make (_ : Store.Cid.RENDERER) : Printer.Ext.T = struct fprintf ppf "(%a * %a)" (fmt_ppr_cmp_typ 0) tau1 (fmt_ppr_cmp_typ 0) tau2 - | Comp.TypPiBox (_, LF.Decl (name, (l, LF.CTyp schema), LF.Maybe), tau) -> + | Comp.TypPiBox (_, LF.Decl (name, (l, LF.CTyp schema), Plicity.Implicit), tau) -> let cond = lvl > 1 in fprintf ppf "%s(%s:%s) %a%s" (l_paren_if cond) @@ -623,7 +623,7 @@ module Make (_ : Store.Cid.RENDERER) : Printer.Ext.T = struct | Comp.PatNil _ -> fprintf ppf "" | Comp.PatApp (_, pat, pat_spine) -> fprintf ppf "%a %a" - (fmt_ppr_pat_obj (lvl+1)) pat + (fmt_ppr_pat_obj (lvl + 1)) pat (fmt_ppr_pat_spine lvl) pat_spine | Comp.PatObs (_, x, pat_spine) -> fprintf ppf "%s %a" diff --git a/src/core/prettyint.ml b/src/core/prettyint.ml index 4a17ab3f9..22c74d69d 100644 --- a/src/core/prettyint.ml +++ b/src/core/prettyint.ml @@ -36,9 +36,9 @@ module Make (R : Store.Cid.RENDERER) : Printer.Int.T = struct let fresh_name_ctyp_decl (cD: LF.mctx) : LF.ctyp_decl -> LF.ctyp_decl = function - | LF.Decl (n, ct, dep) -> + | LF.Decl (n, ct, plicity, inductivity) -> let n' = fresh_name_mctx cD n in - LF.Decl (n', ct, dep) + LF.Decl (n', ct, plicity, inductivity) | LF.DeclOpt (n, plicity) -> let n' = fresh_name_mctx cD n in LF.DeclOpt (n', plicity) @@ -83,7 +83,7 @@ module Make (R : Store.Cid.RENDERER) : Printer.Int.T = struct (fmt_ppr_lf_spine cD cPsi 2) ms (r_paren_if cond) - | LF.PiTyp ((LF.TypDecl (x, a), LF.Maybe), b) -> + | LF.PiTyp ((LF.TypDecl (x, a), Plicity.Implicit), b) -> let x = fresh_name_dctx cPsi x in let cond = lvl > 0 in fprintf ppf "@[<1>%s{%s : %a} @ %a%s@]" @@ -93,7 +93,7 @@ module Make (R : Store.Cid.RENDERER) : Printer.Int.T = struct (fmt_ppr_lf_typ cD (LF.DDec(cPsi, LF.TypDecl(x, a))) 0) b (r_paren_if cond) - | LF.PiTyp ((LF.TypDecl (x, a), LF.No), b) -> + | LF.PiTyp ((LF.TypDecl (x, a), Plicity.Explicit), b) -> let x = fresh_name_dctx cPsi x in let cond = lvl > 0 in fprintf ppf "@[<1>%s%a -> %a%s@]" @@ -208,7 +208,7 @@ module Make (R : Store.Cid.RENDERER) : Printer.Int.T = struct | LF.Clo(tM, s) -> fmt_ppr_lf_normal cD cPsi lvl ppf (Whnf.norm (tM, s)) - | LF.Root (_, _, _, `implicit) when not !PC.printImplicit -> + | LF.Root (_, _, _, Plicity.Implicit) when not !PC.printImplicit -> fprintf ppf "_" (* XXX what to do about spines? -je *) | LF.Root (_, h, LF.Nil, _) -> @@ -603,9 +603,9 @@ module Make (R : Store.Cid.RENDERER) : Printer.Int.T = struct | LF.CtxOffset psi -> begin match Context.lookup' cD psi with - | Some LF.(Decl (u, _, Maybe) | DeclOpt (u, `implicit)) when !PC.printCtxUnderscore -> + | Some LF.(Decl (u, _, Plicity.Implicit, _) | DeclOpt (u, Plicity.Implicit)) when !PC.printCtxUnderscore -> fprintf ppf "_" - | Some LF.(Decl (u, _, _) | DeclOpt (u, _)) -> + | Some LF.(Decl (u, _, _, _) | DeclOpt (u, _)) -> fprintf ppf "%a" Id.print u | None -> fprintf ppf "FREE CtxVar %d" psi end @@ -759,9 +759,11 @@ module Make (R : Store.Cid.RENDERER) : Printer.Int.T = struct then fun _ -> true else function - | (_, LF.Decl (_, _, dep)) -> + | (_, LF.Decl (_, _, Plicity.Explicit, _)) -> not !Printer.Control.printNormal - && (!Printer.Control.printImplicit || not (isImplicit dep)) + | (_, LF.Decl (_, _, Plicity.Implicit, _)) -> + not !Printer.Control.printNormal + && !Printer.Control.printImplicit | _ -> true in fmt_ppr_ctx_filter ~sep: sep should_print @@ -776,7 +778,7 @@ module Make (R : Store.Cid.RENDERER) : Printer.Int.T = struct | LF.Typ -> fprintf ppf "type" - | LF.PiKind ((LF.TypDecl (x, a), LF.Maybe), k) -> + | LF.PiKind ((LF.TypDecl (x, a), Plicity.Implicit), k) -> let x = fresh_name_dctx cPsi x in let cond = lvl > 0 in fprintf ppf "@[<2>%s{@[%s :@ @[%a@]@]}@ @[%a@]%s@]" @@ -786,7 +788,7 @@ module Make (R : Store.Cid.RENDERER) : Printer.Int.T = struct (fmt_ppr_lf_kind (LF.DDec(cPsi, LF.TypDeclOpt x)) 0) k (r_paren_if cond) - | LF.PiKind ((LF.TypDecl (x, a), LF.No), k) -> + | LF.PiKind ((LF.TypDecl (x, a), Plicity.Explicit), k) -> let x = fresh_name_dctx cPsi x in let cond = lvl > 0 in fprintf ppf "%s@[<2>@[%a@] ->@ @[%a@]%s@]" @@ -837,10 +839,10 @@ module Make (R : Store.Cid.RENDERER) : Printer.Int.T = struct material. *) and fmt_ppr_lf_ctyp_decl ?(fmt_ppr_depend = fmt_ppr_lf_depend_clean) cD ppf = function - | LF.Decl (u, mtyp, dep) -> + | LF.Decl (u, mtyp, plicity, inductivity) -> fprintf ppf "@[<2>%a%a :@ @[%a@]@]" Id.print u - fmt_ppr_depend dep + fmt_ppr_depend (plicity, inductivity) (fmt_ppr_lf_mtyp' cD ("(", ")")) mtyp | LF.DeclOpt (name, _) -> @@ -849,26 +851,18 @@ module Make (R : Store.Cid.RENDERER) : Printer.Int.T = struct and fmt_ppr_lf_ctyp_decl_harpoon cD ppf = function - | LF.Decl (_, _, dep) as d -> - let f = - match dep with - | LF.Maybe -> fun ppf _ -> fprintf ppf " (not in scope)" - | _ -> fun _ _ -> () - in - fprintf ppf "@[%a%a@]" + | LF.Decl (_, _, Plicity.Implicit, _) as d -> + fprintf ppf "@[%a (not in scope)@]" + (fmt_ppr_lf_ctyp_decl cD) d + | LF.Decl (_, _, _, _) as d -> + fprintf ppf "@[%a@]" (fmt_ppr_lf_ctyp_decl cD) d - f () | LF.DeclOpt _ -> Error.violation "[fmt_ppr_lf_ctyp_decl_harpoon] DeclOpt impossible" - and isImplicit = - function - | LF.Maybe -> true - | LF.(No | Inductive) -> false - and isImplicitDecl = function - | LF.Decl (_, _, dep) when isImplicit dep -> true + | LF.Decl (_, _, Plicity.Implicit, _) -> true | _ -> false and fmt_ppr_lf_iterm cD cPsi lvl ppf = @@ -934,9 +928,9 @@ module Make (R : Store.Cid.RENDERER) : Printer.Int.T = struct function | Comp.MetaNil -> fprintf ppf "" - | Comp.MetaApp (mO, _, mS, `implicit) -> + | Comp.MetaApp (mO, _, mS, Plicity.Implicit) -> fmt_ppr_cmp_meta_spine cD lvl ppf mS - | Comp.MetaApp (mO, mT, mS, `explicit) -> + | Comp.MetaApp (mO, mT, mS, Plicity.Explicit) -> fprintf ppf "@ @[%a@]%a" (fmt_ppr_cmp_meta_obj_typed cD (lvl + 1)) (mO, mT) (fmt_ppr_cmp_meta_spine cD lvl) mS @@ -980,7 +974,7 @@ module Make (R : Store.Cid.RENDERER) : Printer.Int.T = struct (* Special case for printing implicit context variable quantifiers; these can never be omitted, and are printed with parentheses instead of curly braces. *) - | Comp.TypPiBox (_, LF.(Decl (u, CTyp w, Maybe) as d), tau) -> + | Comp.TypPiBox (_, LF.(Decl (u, CTyp w, Plicity.Implicit, _) as d), tau) -> let cond = lvl > 1 in fprintf ppf "%s@[<2>(@[<2>%a@])@ @[%a@]%s@]" (l_paren_if cond) @@ -988,7 +982,7 @@ module Make (R : Store.Cid.RENDERER) : Printer.Int.T = struct (* furthermore, they need to be considered *EXPLICIT* when printing the remaining type, so that they don't appear as _ *) - (fmt_ppr_cmp_typ (LF.(Dec(cD, Decl (u, CTyp w, No)))) 1) tau + (fmt_ppr_cmp_typ (LF.(Dec(cD, Decl (u, CTyp w, Plicity.explicit, Inductivity.not_inductive)))) 1) tau (r_paren_if cond) | Comp.TypPiBox (_, ctyp_decl, tau) -> @@ -1025,7 +1019,7 @@ module Make (R : Store.Cid.RENDERER) : Printer.Int.T = struct | Comp.PatNil -> fprintf ppf "" | Comp.PatApp (_, pat, pat_spine) -> fprintf ppf "@[%a@]@ @[%a@]" - (fmt_ppr_cmp_pattern cD cG (lvl+1)) pat + (fmt_ppr_cmp_pattern cD cG (lvl + 1)) pat (fmt_ppr_pat_spine cD cG lvl) pat_spine and fmt_ppr_cmp_pattern cD cG lvl ppf = @@ -1060,10 +1054,10 @@ module Make (R : Store.Cid.RENDERER) : Printer.Int.T = struct fprintf ppf "(%a , %a)" (fmt_ppr_cmp_pattern cD cG 0) pat1 (fmt_ppr_cmp_pattern cD cG 0) pat2 - | Comp.PatAnn (_, pat, _, `implicit) -> + | Comp.PatAnn (_, pat, _, Plicity.Implicit) -> fmt_ppr_cmp_pattern cD cG 0 ppf pat - | Comp.PatAnn (_, pat, tau, `explicit) -> + | Comp.PatAnn (_, pat, tau, Plicity.Explicit) -> fprintf ppf "(%a : %a)" (fmt_ppr_cmp_pattern cD cG 0) pat (fmt_ppr_cmp_typ cD 0) tau @@ -1150,10 +1144,10 @@ module Make (R : Store.Cid.RENDERER) : Printer.Int.T = struct (* (r_paren_if cond); *) - | Comp.MLam (_, x, e, `explicit) -> + | Comp.MLam (_, x, e, Plicity.Explicit) -> let x = fresh_name_mctx cD x in let cond = lvl > 0 in - let cD' = LF.Dec(cD, LF.DeclOpt (x, `explicit)) in + let cD' = LF.Dec(cD, LF.DeclOpt (x, Plicity.explicit)) in let cG' = Whnf.cnormGCtx (cG, LF.MShift 1) in fprintf ppf "%smlam %s =>@ %a%s" (l_paren_if cond) @@ -1161,9 +1155,9 @@ module Make (R : Store.Cid.RENDERER) : Printer.Int.T = struct (fmt_ppr_cmp_exp_chk cD' cG' 0) e (r_paren_if cond); - | Comp.MLam (_, x, e, `implicit) -> + | Comp.MLam (_, x, e, Plicity.Implicit) -> let x = fresh_name_mctx cD x in - let cD' = LF.(Dec(cD, DeclOpt (x, `implicit))) in + let cD' = LF.(Dec(cD, DeclOpt (x, Plicity.implicit))) in let cG' = Whnf.cnormGCtx (cG, LF.MShift 1) in fmt_ppr_cmp_exp_chk cD' cG' 0 ppf e @@ -1279,17 +1273,16 @@ module Make (R : Store.Cid.RENDERER) : Printer.Int.T = struct (fmt_ppr_cmp_exp_chk cD cG 2) e (r_paren_if cond) - | Comp.MApp (_, i, cM, cU, pl) -> - let cond = lvl > 1 in - if !PC.printImplicit || Comp.is_explicit pl - then - fprintf ppf "%s@[<2>@[%a@]@ @[%a@]@]%s" - (l_paren_if cond) - (fmt_ppr_cmp_exp_syn cD cG 1) i - (fmt_ppr_cmp_meta_obj_typed cD 0) (cM, cU) - (r_paren_if cond) - else - fmt_ppr_cmp_exp_syn cD cG lvl ppf i (* not printing implicits *) + | Comp.MApp (_, i, cM, cU, plicity) -> + if Plicity.is_explicit plicity || !PC.printImplicit then + let cond = lvl > 1 in + fprintf ppf "%s@[<2>@[%a@]@ @[%a@]@]%s" + (l_paren_if cond) + (fmt_ppr_cmp_exp_syn cD cG 1) i + (fmt_ppr_cmp_meta_obj_typed cD 0) (cM, cU) + (r_paren_if cond) + else + fmt_ppr_cmp_exp_syn cD cG lvl ppf i (* not printing implicits *) | Comp.PairVal (loc, i1, i2) -> fprintf ppf "@[( %a@,, %a)@]" @@ -1467,7 +1460,7 @@ module Make (R : Store.Cid.RENDERER) : Printer.Int.T = struct let open Comp in match c with | Unbox (_, u, _, _) -> - (LF.(Dec (cD, DeclOpt (u, `explicit))), Whnf.cnormGCtx (cG, LF.MShift 1)) + (LF.(Dec (cD, DeclOpt (u, Plicity.explicit))), Whnf.cnormGCtx (cG, LF.MShift 1)) | By (_, x, _) -> (cD, LF.Dec (cG, Comp.CTypDeclOpt x)) in @@ -1743,7 +1736,7 @@ module Make (R : Store.Cid.RENDERER) : Printer.Int.T = struct theorems (* - | Sgn.Rec (((f, _, _) as h)::t) -> + | Sgn.Rec (((f, _, _) as h) :: t) -> let total = if (Store.Cid.Comp.get f).Store.Cid.Comp.total then " total" else "" in diff --git a/src/core/printer.ml b/src/core/printer.ml index d5de5ed7a..b2e742347 100644 --- a/src/core/printer.ml +++ b/src/core/printer.ml @@ -45,10 +45,10 @@ module Common = struct | `clean ] - val fmt_ppr_plicity : formatter -> LF.plicity -> unit - val fmt_ppr_lf_depend : formatter -> LF.depend -> unit - val fmt_ppr_lf_depend_clean : formatter -> LF.depend -> unit - val fmt_ppr_lf_depend_inductive : formatter -> LF.depend -> unit + val fmt_ppr_plicity : formatter -> Plicity.t -> unit + val fmt_ppr_lf_depend : formatter -> Plicity.t * Inductivity.t -> unit + val fmt_ppr_lf_depend_clean : formatter -> Inductivity.t -> unit + val fmt_ppr_lf_depend_inductive : formatter -> Inductivity.t -> unit val fmt_ppr_lf_svar_class : formatter -> LF.svar_class -> unit val fmt_ppr_cmp_split_kind : formatter -> Harpoon.split_kind -> unit val fmt_ppr_cmp_context_case : formatter -> Comp.context_case -> unit @@ -70,7 +70,7 @@ module Int = struct (* LF printers *) val fmt_ppr_lf_svar_class : formatter -> LF.svar_class -> unit val fmt_ppr_lf_kind : LF.dctx -> lvl -> formatter -> LF.kind -> unit - val fmt_ppr_lf_ctyp_decl : ?fmt_ppr_depend:(formatter -> LF.depend -> unit) -> + val fmt_ppr_lf_ctyp_decl : ?fmt_ppr_depend:(formatter -> (Plicity.t * Inductivity.t) -> unit) -> LF.mctx -> formatter -> LF.ctyp_decl -> unit val fmt_ppr_lf_typ_rec : LF.mctx -> LF.dctx -> lvl -> formatter -> LF.typ_rec -> unit val fmt_ppr_lf_typ : LF.mctx -> LF.dctx -> lvl -> formatter -> LF.typ -> unit diff --git a/src/core/reconstruct.ml b/src/core/reconstruct.ml index 048cc386f..607dca27f 100644 --- a/src/core/reconstruct.ml +++ b/src/core/reconstruct.ml @@ -240,7 +240,7 @@ let extend_mctx cD (_, cdecl, t) = let mk_name_cdec = function - | Int.LF.Decl (u, _, _) -> mk_name (SomeName u) + | Int.LF.Decl (u, _, _, _) -> mk_name (SomeName u) (* etaExpandMMV loc cD cPsi sA = tN * @@ -282,17 +282,14 @@ let elNumericOrder (tau : I.typ) (order : Ext.Comp.numeric_order) let rec skip tau n = match tau, n with | _, 0 -> 0 - | I.TypPiBox (_, Int.LF.Decl (u, cU, dep), tau), n -> - begin match dep with - | Int.LF.Inductive -> - Error.violation "[elaborate_numeric_order] impossible LF.Inductive" - | Int.LF.Maybe -> - 1 + skip tau n (* implicits are free *) - | Int.LF.No -> - 1 + skip tau (n - 1) (* explicits pi-types cost 1 *) - end + | I.TypPiBox (_, Int.LF.Decl (u, cU, _, Inductivity.Inductive), tau), n -> + Error.violation "[elNumericOrder] impossible LF.Inductive" + | I.TypPiBox (_, Int.LF.Decl (u, cU, Plicity.Implicit, _), tau), n -> + 1 + skip tau n (* implicits are free *) + | I.TypPiBox (_, Int.LF.Decl (u, cU, Plicity.Explicit, _), tau), n -> + 1 + skip tau (n - 1) (* explicits pi-types cost 1 *) | I.TypArr (_, _, tau), n -> - 1 + skip tau (n - 1) (* simple functions cost 1 *) + 1 + skip tau (n - 1) (* simple functions cost 1 *) in Ext.Comp.map_order (skip tau) order |> Order.of_numeric_order @@ -306,7 +303,7 @@ let rec elDCtxAgainstSchema loc recT cD psi s_cid = end; Int.LF.Null | Apx.LF.CtxHole -> - Int.LF.CtxVar (Whnf.newCVar None cD (Some s_cid) Int.LF.Maybe) + Int.LF.CtxVar (Whnf.newCVar None cD (Some s_cid) Plicity.implicit Inductivity.not_inductive) | Apx.LF.CtxVar ((Apx.LF.CtxOffset _) as c_var) -> let { Schema.Entry.name; schema; decl = _ } = Schema.get s_cid in @@ -318,7 +315,7 @@ let rec elDCtxAgainstSchema loc recT cD psi s_cid = (* This case should only be executed when c_var occurs in a pattern *) begin try - let (_, Int.LF.Decl (_, Int.LF.CTyp (Some s_cid'), _)) = FCVar.get psi in + let (_, Int.LF.Decl (_, Int.LF.CTyp (Some s_cid'), _, _)) = FCVar.get psi in if Id.cid_equals s_cid s_cid' then Int.LF.CtxVar (Int.LF.CtxName psi) else @@ -327,7 +324,7 @@ let rec elDCtxAgainstSchema loc recT cD psi s_cid = Check.LF.(CtxVarMismatch (cD, c_var', name, schema) |> throw (Id.loc_of_name psi)) with | Not_found -> - FCVar.add psi (cD, Int.LF.Decl (psi, Int.LF.CTyp (Some s_cid), Int.LF.Maybe)); + FCVar.add psi (cD, Int.LF.Decl (psi, Int.LF.CTyp (Some s_cid), Plicity.implicit, Inductivity.not_inductive)); Int.LF.CtxVar (Int.LF.CtxName psi) end @@ -367,7 +364,7 @@ let unifyDCtxWithFCVar loc cD cPsi1 cPsi2 = match Context.ctxVar cPsi with | None -> () | Some (Int.LF.CtxName psi) -> - FCVar.add psi (cD, Int.LF.(Decl (psi, CTyp (Some s_cid), v.depend))) + FCVar.add psi (cD, Int.LF.(Decl (psi, CTyp (Some s_cid), v.plicity, v.inductivity))) | _ -> () end @@ -468,13 +465,8 @@ let elCTyp recT cD = Int.LF.ClTyp (elClTyp recT cD cPsi cl, cPsi) | Apx.LF.CTyp schema_cid -> Int.LF.CTyp (Some schema_cid) -let elCDecl recT cD (Apx.LF.Decl (u, ctyp, dep)) = - let dep = - match dep with - | Apx.LF.No -> Int.LF.No - | Apx.LF.Maybe -> Int.LF.Maybe - in - Int.LF.Decl (u, elCTyp recT cD ctyp, dep) +let elCDecl recT cD (Apx.LF.Decl (u, ctyp, plicity)) = + Int.LF.Decl (u, elCTyp recT cD ctyp, plicity, Inductivity.not_inductive) let rec elMCtx recT = @@ -528,7 +520,7 @@ let mgAtomicTyp cD cPsi a kK = | (Int.LF.Typ, _s) -> Int.LF.Nil - | (Int.LF.(PiKind ((TypDecl (u, tA1), dep), kK), s)) -> + | (Int.LF.(PiKind ((TypDecl (u, tA1), plicity), kK), s)) -> let tA1' = strans_typ cD cPsi (tA1, s) conv_list in let tR = if !strengthen @@ -542,10 +534,10 @@ let mgAtomicTyp cD cPsi a kK = Id.print u end; Whnf.etaExpandMMV Loc.ghost cD - cPhi' (tA1', ssi') u ss_proj dep + cPhi' (tA1', ssi') u ss_proj plicity Inductivity.not_inductive else Whnf.etaExpandMMV Loc.ghost cD - flat_cPsi (tA1', Substitution.LF.id) u s_proj dep + flat_cPsi (tA1', Substitution.LF.id) u s_proj plicity Inductivity.not_inductive in dprintf begin fun p -> @@ -570,10 +562,10 @@ let rec mgTyp cD cPsi = | Int.LF.Sigma trec -> Int.LF.Sigma (mgTypRec cD cPsi trec) - | Int.LF.PiTyp ((tdecl, dep), tA) -> + | Int.LF.PiTyp ((tdecl, plicity), tA) -> let tdecl' = mgTypDecl cD cPsi tdecl in Int.LF.PiTyp - ( (tdecl', dep) + ( (tdecl', plicity) , mgTyp cD (Int.LF.DDec (cPsi, tdecl')) tA ) @@ -630,7 +622,7 @@ let elClObj cD loc cPsi' clobj mtyp = | ( Apx.LF.Dot (Apx.LF.Obj (Apx.LF.Root (_, Apx.LF.Hole, Apx.LF.Nil)), Apx.LF.EmptySub) , Int.LF.PTyp _tA' ) -> - let mV = Whnf.newMMVar' None (cD, Int.LF.ClTyp (mtyp, cPsi')) Int.LF.Maybe in + let mV = Whnf.newMMVar' None (cD, Int.LF.ClTyp (mtyp, cPsi')) Plicity.implicit Inductivity.not_inductive in Whnf.mmVarToClObj loc mV mtyp (* ordinary parameter variable elaboration *) @@ -716,13 +708,13 @@ and elMetaSpine loc cD s cKt = | (Apx.Comp.MetaApp (m, s), (Int.Comp.Ctype _, _)) -> raise (Error (loc, TooManyMetaObj)) - | (s, (Int.Comp.PiKind (loc', Int.LF.Decl (u, cU, Int.LF.Maybe), cK), t)) -> - let (mO, t') = Whnf.dotMMVar loc cD t (u, cU, Int.LF.Maybe) in - Int.Comp.MetaApp(mO, Whnf.cnormMTyp (cU, t), elMetaSpine loc cD s (cK, t'), `implicit) + | (s, (Int.Comp.PiKind (loc', Int.LF.Decl (u, cU, Plicity.Implicit, inductivity), cK), t)) -> + let (mO, t') = Whnf.dotMMVar loc cD t (u, cU, Plicity.implicit, inductivity) in + Int.Comp.MetaApp(mO, Whnf.cnormMTyp (cU, t), elMetaSpine loc cD s (cK, t'), Plicity.implicit) - | (Apx.Comp.MetaApp (m, s), (Int.Comp.PiKind (_, Int.LF.Decl(_, ctyp, _), cK), theta)) -> + | (Apx.Comp.MetaApp (m, s), (Int.Comp.PiKind (_, Int.LF.Decl(_, ctyp, _, _), cK), theta)) -> let (mO, t') = elMetaObjCTyp loc cD m theta ctyp in - Int.Comp.MetaApp(mO, Whnf.cnormMTyp (ctyp, theta), elMetaSpine loc cD s (cK, t'), `explicit) + Int.Comp.MetaApp(mO, Whnf.cnormMTyp (ctyp, theta), elMetaSpine loc cD s (cK, t'), Plicity.explicit) let rec spineToMSub cS' ms = match cS' with @@ -796,10 +788,10 @@ let mgCompTypSpine cD (loc, cK) = let rec genMetaSpine = function | (Int.Comp.Ctype _, _t) -> Int.Comp.MetaNil - | (Int.Comp.PiKind (loc', Int.LF.Decl(u, cU, dep), cK), t) -> - let (mO, t') = Whnf.dotMMVar loc cD t (u, cU, dep) in + | (Int.Comp.PiKind (loc', Int.LF.Decl(u, cU, plicity, inductivity), cK), t) -> + let (mO, t') = Whnf.dotMMVar loc cD t (u, cU, plicity, inductivity) in let mS = genMetaSpine (cK, t') in - Int.Comp.MetaApp (mO, Whnf.cnormMTyp (cU, t), mS, Int.LF.Depend.to_plicity dep) + Int.Comp.MetaApp (mO, Whnf.cnormMTyp (cU, t), mS, plicity) in genMetaSpine (cK, Whnf.m_id) @@ -831,7 +823,7 @@ let rec mgCtx cD' (cD, cPsi) = let (n, sW) = Whnf.mctxCDec cD psi_var in let v = let open Int.LF in - Whnf.newMMVar' (Some n) (cD', CTyp (Some sW)) Maybe + Whnf.newMMVar' (Some n) (cD', CTyp (Some sW)) Plicity.implicit Inductivity.not_inductive in Int.LF.(CtxVar (CInst (v, Whnf.m_id))) | Int.LF.Null -> Int.LF.Null @@ -874,13 +866,13 @@ let rec inferPatTyp' cD' (cD_s, tau_s) = let tau2' = inferPatTyp' cD' (cD_s, tau2) in Int.Comp.TypArr (loc, tau1', tau2') - | Int.Comp.TypPiBox (loc, (Int.LF.Decl (x, mtyp, dep)), tau) -> + | Int.Comp.TypPiBox (loc, (Int.LF.Decl (x, mtyp, plicity, inductivity)), tau) -> let mtyp' = mgCTyp cD' cD_s mtyp in let tau' = - inferPatTyp' (Int.LF.Dec (cD', Int.LF.Decl(x, mtyp', dep))) - (Int.LF.Dec (cD_s, Int.LF.Decl(x, mtyp, dep)), tau) + inferPatTyp' (Int.LF.Dec (cD', Int.LF.Decl(x, mtyp', plicity, inductivity))) + (Int.LF.Dec (cD_s, Int.LF.Decl(x, mtyp, plicity, inductivity)), tau) in - Int.Comp.TypPiBox (loc, Int.LF.Decl (x, mtyp', dep), tau') + Int.Comp.TypPiBox (loc, Int.LF.Decl (x, mtyp', plicity, inductivity), tau') | Int.Comp.TypBox (loc, mtyp) -> let mtyp' = mgCTyp cD' cD_s mtyp in @@ -1000,22 +992,22 @@ and elExpW cD cG e theta_tau = (* Allow uniform abstractions for all meta-objects *) | ( Apx.Comp.MLam (loc, u, e) - , (Int.Comp.TypPiBox(_, (Int.LF.Decl (_, _, Int.LF.No) as cdec), tau), theta) + , (Int.Comp.TypPiBox(_, (Int.LF.Decl (_, _, Plicity.Explicit, _) as cdec), tau), theta) ) -> let cD' = extend_mctx cD (u, cdec, theta) in let cG' = Whnf.cnormGCtx (cG, Int.LF.MShift 1) in let e' = elExp cD' cG' e (tau, C.mvar_dot1 theta) in - Int.Comp.MLam (loc, u, e', `explicit) + Int.Comp.MLam (loc, u, e', Plicity.explicit) | ( e - , (Int.Comp.TypPiBox(_, (Int.LF.Decl(_, _, Int.LF.Maybe) as cdec), tau), theta) + , (Int.Comp.TypPiBox(_, (Int.LF.Decl(_, _, Plicity.Implicit, _) as cdec), tau), theta) ) -> let u = mk_name_cdec cdec in let cG' = Whnf.cnormGCtx (cG, Int.LF.MShift 1) in let cD' = extend_mctx cD (u, cdec, theta) in let e' = Apxnorm.cnormApxExp cD (Apx.LF.Empty) e (cD', Int.LF.MShift 1) in let e' = elExp cD' cG' e' (tau, C.mvar_dot1 theta) in - Int.Comp.MLam (Syntax.Loc.ghost, u, e', `implicit) + Int.Comp.MLam (Syntax.Loc.ghost, u, e', Plicity.implicit) | (Apx.Comp.Syn (loc, i), (tau, t)) -> dprintf @@ -1303,7 +1295,7 @@ and elExp' cD cG i = MetaObj are off *) (i'', (tau', Whnf.m_id)) - | Apx.Comp.Box (_, cM), (Int.Comp.TypPiBox (_, Int.LF.Decl (_, ctyp, _), tau), theta) -> + | Apx.Comp.Box (_, cM), (Int.Comp.TypPiBox (_, Int.LF.Decl (_, ctyp, _, _), tau), theta) -> dprintf begin fun p -> p.fmt "[elExp'] @[Apply -> elMetaObj at type\ @@ -1311,11 +1303,11 @@ and elExp' cD cG i = P.(fmt_ppr_cmp_meta_typ cD) (Whnf.cnormMTyp (ctyp, theta)) end; let cM = elMetaObj cD cM (ctyp, theta) in - ( Int.Comp.MApp (loc, i', cM, Whnf.cnormMTyp (ctyp, theta), `explicit) + ( Int.Comp.MApp (loc, i', cM, Whnf.cnormMTyp (ctyp, theta), Plicity.explicit) , (tau, Int.LF.MDot (metaObjToFt cM, theta)) ) - | Apx.Comp.BoxHole loc, (Int.Comp.TypPiBox (_, Int.LF.Decl (_, ctyp, _), tau), theta) -> + | Apx.Comp.BoxHole loc, (Int.Comp.TypPiBox (_, Int.LF.Decl (_, ctyp, _, _), tau), theta) -> dprintf begin fun p -> p.fmt "[elExp'] @[Apply -> elMetaObj at type\ @@ -1323,7 +1315,7 @@ and elExp' cD cG i = P.(fmt_ppr_cmp_meta_typ cD) (Whnf.cnormMTyp (ctyp, theta)) end; let cM = elMetaObj cD (box_hole_cM loc ctyp) (ctyp, theta) in - ( Int.Comp.MApp (loc, i', cM, Whnf.cnormMTyp (ctyp, theta), `explicit) + ( Int.Comp.MApp (loc, i', cM, Whnf.cnormMTyp (ctyp, theta), Plicity.explicit) , (tau, Int.LF.MDot (metaObjToFt cM, theta)) ) @@ -1594,7 +1586,7 @@ and elPatSyn (cD : Int.LF.mctx) (cG : Int.Comp.gctx) = | Apx.Comp.PatAnn (loc, pat, tau) -> let tau' = elCompTyp cD tau in let (cG', pat') = elPatChk cD cG pat (tau', Whnf.m_id) in - (cG', Int.Comp.PatAnn (loc, pat', tau', `explicit), (tau', Whnf.m_id)) + (cG', Int.Comp.PatAnn (loc, pat', tau', Plicity.explicit), (tau', Whnf.m_id)) | Apx.Comp.PatConst (loc, c, pat_spine) -> let tau = (CompConst.get c).CompConst.Entry.typ in @@ -1609,8 +1601,8 @@ and elPatSpineW cD cG pat_spine ttau = match pat_spine with | Apx.Comp.PatNil loc -> begin match ttau with - | (Int.Comp.TypPiBox (_, Int.LF.Decl (u, cU, Int.LF.Maybe), tau), t) -> - let (mO, t') = Whnf.dotMMVar loc cD t (u, cU, Int.LF.Maybe) in + | (Int.Comp.TypPiBox (_, Int.LF.Decl (u, cU, Plicity.Implicit, inductivity), tau), t) -> + let (mO, t') = Whnf.dotMMVar loc cD t (u, cU, Plicity.implicit, inductivity) in let pat' = Int.Comp.PatMetaObj (loc, mO) in let ttau' = (tau, t') in let (cG', pat_spine', ttau2) = elPatSpine cD cG pat_spine ttau' in @@ -1630,13 +1622,13 @@ and elPatSpineW cD cG pat_spine ttau = let (cG', pat) = elPatChk cD cG pat' (tau1, theta) in let (cG'', pat_spine, ttau2) = elPatSpine cD cG' pat_spine' (tau2, theta) in (cG'', Int.Comp.PatApp (loc, pat, pat_spine), ttau2) - | (Int.Comp.TypPiBox (_, (Int.LF.Decl (u, cU, Int.LF.Maybe)), tau), theta) -> + | (Int.Comp.TypPiBox (_, (Int.LF.Decl (u, cU, Plicity.Implicit, inductivity)), tau), theta) -> dprintf begin fun p -> p.fmt "[elPatSpine] @[TypPiBox implicit ttau =@,@[%a@]@]" (P.fmt_ppr_cmp_typ cD P.l0) (Whnf.cnormCTyp ttau) end; - let (mO, t') = Whnf.dotMMVar loc cD theta (u, cU, Int.LF.Maybe) in + let (mO, t') = Whnf.dotMMVar loc cD theta (u, cU, Plicity.implicit, inductivity) in let pat' = Int.Comp.PatMetaObj (loc, mO) in let ttau' = (tau, t') in @@ -1649,7 +1641,7 @@ and elPatSpineW cD cG pat_spine ttau = let (cG', pat_spine', ttau2) = elPatSpine cD cG pat_spine ttau' in (cG', Int.Comp.PatApp (loc, pat', pat_spine'), ttau2) - | (Int.Comp.TypPiBox (_, Int.LF.Decl (_, ctyp, dep), tau), theta) -> + | (Int.Comp.TypPiBox (_, Int.LF.Decl (_, ctyp, _, _), tau), theta) -> dprintf begin fun p -> p.fmt "[elPatSpine] @[TypPiBox explicit ttau = @[%a@]" @@ -1711,8 +1703,8 @@ and elPatSpineW cD cG pat_spine ttau = | Unify.Failure _ -> raise (Error (loc, TypMismatch (cD, ttau, (tau0, t)))) end - | (Int.Comp.TypPiBox (_, Int.LF.Decl (u, cU, Int.LF.Maybe), tau), theta) -> - let (mO, t') = Whnf.dotMMVar loc cD theta (u, cU, Int.LF.Maybe) in + | (Int.Comp.TypPiBox (_, Int.LF.Decl (u, cU, Plicity.Implicit, inductivity), tau), theta) -> + let (mO, t') = Whnf.dotMMVar loc cD theta (u, cU, Plicity.implicit, inductivity) in let pat' = Int.Comp.PatMetaObj (loc, mO) in let ttau' = (tau, t') in let (cG', pat_spine', ttau2) = elPatSpine cD cG pat_spine ttau' in @@ -1741,7 +1733,7 @@ and recPatObj' cD pat (cD_s, tau_s) = let ttau' = (tau', Whnf.m_id) in let (cG', pat') = elPatChk cD Int.LF.Empty pat' ttau' in (* Return annotated pattern? Int.Comp.PatAnn (l, pat', tau') *) - (cG', Int.Comp.PatAnn (l, pat', tau', `explicit), ttau') + (cG', Int.Comp.PatAnn (l, pat', tau', Plicity.explicit), ttau') | Apx.Comp.PatAnn (_, pat, tau) -> dprintf @@ -1793,7 +1785,7 @@ and recPatObj' cD pat (cD_s, tau_s) = let (cG', pat') = elPatChk cD Int.LF.Empty pat ttau' in (* here the annotation is implicit because it did not appear in the user-supplied syntax; we just reconstructed it. *) - (cG', Int.Comp.PatAnn(loc, pat', tau_p, `implicit), ttau') + (cG', Int.Comp.PatAnn(loc, pat', tau_p, Plicity.implicit), ttau') | _ -> dprintf @@ -2090,7 +2082,7 @@ and elCommand cD cG = |> Whnf.cnormMTyp |> Check.Comp.apply_unbox_modifier_opt cD modifier in - let d = Int.LF.(Decl (x, cU, No)) in + let d = Int.LF.(Decl (x, cU, Plicity.explicit, Inductivity.not_inductive)) in let t = Int.LF.MShift 1 in (* No need to check for shadowing since that already happened during indexing. *) @@ -2232,7 +2224,7 @@ and elSplit loc cD cG pb i tau_i bs ttau = , let open Int.LF in ClObj ( Context.dctxToHat cPsi' - , MObj (Root (Loc.ghost, (proj_maybe h k), Nil, `explicit)) + , MObj (Root (Loc.ghost, (proj_maybe h k), Nil, Plicity.explicit)) ) ) ) diff --git a/src/core/recsgn.ml b/src/core/recsgn.ml index 56b15e0e1..449b599db 100644 --- a/src/core/recsgn.ml +++ b/src/core/recsgn.ml @@ -1018,7 +1018,7 @@ let recSgnDecls decls = try Unify.forceGlobalCnstr () with - | Unify.GlobalCnstrFailure (loc,cnstr) -> + | Unify.GlobalCnstrFailure (loc, cnstr) -> raise ( Check.Comp.Error ( loc @@ -1216,7 +1216,7 @@ let recSgnDecls decls = Logic.storeMQuery (tau', i) expected tries depth) ; Int.Sgn.MQuery { location=loc - ; typ=(tau',i) + ; typ=(tau', i) ; expected_solutions=expected ; search_tries=tries ; search_depth=depth diff --git a/src/core/showext.ml b/src/core/showext.ml index 5fcdc79f3..f98666a53 100644 --- a/src/core/showext.ml +++ b/src/core/showext.ml @@ -6,11 +6,10 @@ open Support module LF = struct open Syntax.Ext.LF - let show_dep ppf = + let show_plicity ppf = function - | Maybe -> fprintf ppf "Maybe" - | No -> fprintf ppf "No" - | Inductive -> fprintf ppf "Inductive" + | Plicity.Implicit -> pp_print_string ppf "Implicit" + | Plicity.Explicit -> pp_print_string ppf "Explicit" let rec show_kind ppf = function @@ -57,11 +56,11 @@ module LF = struct and show_ctyp_decl ppf = function - | Decl (x, d, dep) -> + | Decl (x, d, plicity) -> fprintf ppf "Decl(@[%a,@ %a,@ %a@])" Id.print x show_loc_ctyp d - show_dep dep + show_plicity plicity | DeclOpt x -> fprintf ppf "DeclOpt(%a)" Id.print x diff --git a/src/core/store.ml b/src/core/store.ml index e10791ac4..4f137d1ee 100644 --- a/src/core/store.ml +++ b/src/core/store.ml @@ -117,7 +117,7 @@ module Modules = struct let x = DynArray.get rev_directory id in match List.fold_left - begin fun acc (ab,o) -> + begin fun acc (ab, o) -> if List.equal String.equal o x then Some ab else acc @@ -1074,7 +1074,7 @@ module FPatVar = struct let store = ref Syntax.Int.LF.Empty let add x tau = - store := Syntax.Int.LF.Dec (!store, Syntax.Int.Comp.CTypDecl (x,tau, false)) + store := Syntax.Int.LF.Dec (!store, Syntax.Int.Comp.CTypDecl (x, tau, false)) let get x = let rec lookup str = match str with @@ -1177,7 +1177,7 @@ module CVar = struct type entry = { name : cvar - ; plicity : Int.Comp.plicity + ; plicity : Plicity.t } let mk_entry name plicity = @@ -1218,13 +1218,15 @@ module CVar = struct let f d v = let open Int.LF in match d with - | Decl (u, _, dep) -> mk_entry u (f dep) |> extend v + | Decl (u, _, plicity, inductivity) -> + let plicity' = f (plicity, inductivity) in + mk_entry u plicity' |> extend v | DeclOpt _ -> Error.violation "[of_mctx] DeclOpt impossible" in List.fold_right f (Context.to_list_rev cD) (create ()) - let of_list (l : (Id.name * Int.Comp.plicity) list) : t = + let of_list (l : (Id.name * Plicity.t) list) : t = List.map (fun (u, p) -> mk_entry u p) l end diff --git a/src/core/store.mli b/src/core/store.mli index 0a2f872c7..bc2bab2da 100644 --- a/src/core/store.mli +++ b/src/core/store.mli @@ -462,10 +462,10 @@ module CVar : sig type entry = { name : cvar - ; plicity : Comp.plicity + ; plicity : Plicity.t } - val mk_entry : cvar -> Comp.plicity -> entry + val mk_entry : cvar -> Plicity.t -> entry type t (* NOTE: t is an ordered data structure *) @@ -477,14 +477,14 @@ module CVar : sig Raises Not_found if no such variable is in scope. Returns the plicity of the variable together with its offset. *) - val index_of_name : t -> cvar -> Comp.plicity * offset + val index_of_name : t -> cvar -> Plicity.t * offset val append : t -> t -> t val length : t -> int (** Erases the context down to a list of names using the given function to interpret the plicity of declarations. *) - val of_mctx : (LF.depend -> Comp.plicity) -> LF.mctx -> t + val of_mctx : (Plicity.t * Inductivity.t -> Plicity.t) -> LF.mctx -> t val to_string : t -> string - val of_list : (Id.name * Comp.plicity) list -> t + val of_list : (Id.name * Plicity.t) list -> t end diff --git a/src/core/subord.ml b/src/core/subord.ml index 075cfcbf7..4830ffc27 100644 --- a/src/core/subord.ml +++ b/src/core/subord.ml @@ -213,7 +213,7 @@ let thin0 cD a cPsi = | CtxOffset _ -> Context.lookupCtxVarSchema cD psi | CInst ({ typ = CTyp (Some cid_schema); _ }, _) -> cid_schema | CtxName psi -> - let (_, Decl (_, CTyp (Some s_cid), _)) = Store.FCVar.get psi in + let (_, Decl (_, CTyp (Some s_cid), _, _)) = Store.FCVar.get psi in s_cid | _ -> raise NoSchema in @@ -247,7 +247,7 @@ let thin' cD a cPsi = try dprintf begin fun p -> - let (_, Decl (_, CTyp _, _)) = Store.FCVar.get psi in + let (_, Decl (_, CTyp _, _, _)) = Store.FCVar.get psi in p.fmt "[thin'] CtxName psi = %a FOUND" Id.print psi end; diff --git a/src/core/substitution.ml b/src/core/substitution.ml index d14d539ac..30752283a 100644 --- a/src/core/substitution.ml +++ b/src/core/substitution.ml @@ -47,9 +47,9 @@ module LF = struct | (0, s) -> s | (n, EmptySub) -> raise (NotComposable ("Shift " ^ string_of_int n ^", EmptySub")) | (n, Undefs) -> Undefs - | (n, SVar (s, k, r)) -> SVar (s, (k+n), r) - | (n, MSVar (k, ((s, t), r))) -> MSVar (k+n, ((s, t), r)) - | (n, FSVar (k, (s, tau))) -> FSVar (k+n, (s, tau)) + | (n, SVar (s, k, r)) -> SVar (s, (k + n), r) + | (n, MSVar (k, ((s, t), r))) -> MSVar (k + n, ((s, t), r)) + | (n, FSVar (k, (s, tau))) -> FSVar (k + n, (s, tau)) | (n, Shift m) -> Shift (n + m) | (n, Dot (_, s)) -> shiftComp (n - 1) s @@ -108,16 +108,16 @@ module LF = struct | (n, Shift k) -> Head (BVar (n + k)) (* | (n, MSVar (s, (_cshift, k), (mt, sigma ))) -> (* Should be fixed; we really need phat of n to avoid printing - Free BVar (n+k) ... - (Head (HClo (phat. BVar n+k, s, sigma )) + Free BVar (n + k) ... + (Head (HClo (phat. BVar n + k, s, sigma )) -bp *) - Head (HMClo (n+k, s, (mt, sigma))) + Head (HMClo (n + k, s, (mt, sigma))) Can this happen ? *) | (n, SVar (s, k, sigma)) -> (* Should be fixed; we really need phat of n to avoid printing - Free BVar (n+k) ... -bp *) + Free BVar (n + k) ... -bp *) Head (HClo (n + k, s, sigma)) | (n, MSVar (k, ((s, t), sigma))) -> Head (HMClo (n + k, ((s, t), sigma))) diff --git a/src/core/synapx.ml b/src/core/synapx.ml index 4da5619cb..81c5dcfc9 100644 --- a/src/core/synapx.ml +++ b/src/core/synapx.ml @@ -11,7 +11,7 @@ module LF = struct type kind = | Typ - | PiKind of (typ_decl * depend) * kind + | PiKind of (typ_decl * Plicity.t) * kind and typ_decl = | TypDecl of name * typ @@ -27,12 +27,12 @@ module LF = struct | CTyp of cid_schema and ctyp_decl = - | Decl of name * ctyp * depend + | Decl of name * ctyp * Plicity.t | DeclOpt of name and typ = | Atom of Location.t * cid_typ * spine - | PiTyp of (typ_decl * depend) * typ + | PiTyp of (typ_decl * Plicity.t) * typ | Sigma of typ_rec and typ_rec = diff --git a/src/core/syncom.ml b/src/core/syncom.ml index 5f4b142df..e74adca12 100644 --- a/src/core/syncom.ml +++ b/src/core/syncom.ml @@ -3,79 +3,16 @@ *) open Support -module Common = struct - type plicity = - [ `implicit - | `explicit - ] - - let is_explicit : plicity -> bool = - function - | `explicit -> true - | _ -> false - - let is_implicit : plicity -> bool = - function - | `implicit -> true - | _ -> false -end - (** General snoc-lists. *) module LF = struct - include Common - type 'a ctx = (* Generic context declaration *) | Empty (* C ::= Empty *) | Dec of 'a ctx * 'a (* | C, x:'a *) type svar_class = Ren | Subst - - type depend = - | Maybe (* implicit *) - | No (* explicit *) - | Inductive (* used for induction *) - - module Depend = struct - type t = depend - - let equals d1 d2 = - match d1, d2 with - | Maybe, Maybe -> true - | No, No -> true - | Inductive, Inductive -> true - | _ -> false - - let of_plicity : plicity -> t = - function - | `implicit -> Maybe - | `explicit -> No - - let to_plicity : t -> plicity = - function - | Maybe -> `implicit - | No -> `explicit - | Inductive -> - Error.violation - "[Depend] [to_plicity] Inductive is impossible" - - (** Variant of to_plicity that does not fail on Inductive, instead - sending it to `explicit. - *) - let to_plicity' : t -> plicity = - function - | Inductive -> `explicit - | d -> to_plicity d - - let max d1 d2 = - match d1, d2 with - | No, No -> No - | _ -> Maybe - end end module Comp = struct - include Common - type unbox_modifier = [ `strengthened ] diff --git a/src/core/synext.ml b/src/core/synext.ml index 2fb299d97..41565add5 100644 --- a/src/core/synext.ml +++ b/src/core/synext.ml @@ -28,7 +28,7 @@ module LF = struct and loc_ctyp = Location.t * ctyp and ctyp_decl = - | Decl of name * loc_ctyp * depend + | Decl of name * loc_ctyp * Plicity.t | DeclOpt of name and typ = @@ -140,7 +140,7 @@ module Comp = struct type kind = | Ctype of Location.t - | ArrKind of Location.t * (Location.t * LF.ctyp * LF.depend) * kind + | ArrKind of Location.t * (Location.t * LF.ctyp * Plicity.t) * kind | PiKind of Location.t * LF.ctyp_decl * kind type meta_obj = Location.t * LF.mfront diff --git a/src/core/synint.ml b/src/core/synint.ml index 0e2909751..2e097c2c5 100644 --- a/src/core/synint.ml +++ b/src/core/synint.ml @@ -10,7 +10,7 @@ module LF = struct type kind = | Typ - | PiKind of (typ_decl * depend) * kind + | PiKind of (typ_decl * Plicity.t) * kind and typ_decl = (* LF Declarations *) | TypDecl of name * typ (* D := x:A *) @@ -26,12 +26,12 @@ module LF = struct | CTyp of cid_schema option and ctyp_decl = (* Contextual Declarations *) - | Decl of name * ctyp * depend - | DeclOpt of name * plicity + | Decl of name * ctyp * Plicity.t * Inductivity.t + | DeclOpt of name * Plicity.t and typ = (* LF level *) - | Atom of Location.t * cid_typ * spine (* A ::= a M1 ... Mn *) - | PiTyp of (typ_decl * depend) * typ (* | Pi x:A.B *) + | Atom of Location.t * cid_typ * spine (* A ::= a M1 ... Mn *) + | PiTyp of (typ_decl * Plicity.t) * typ (* | Pi x:A.B *) | Sigma of typ_rec | TClo of (typ * sub) (* | TClo(A,s) *) @@ -39,11 +39,11 @@ module LF = struct (* The plicity annotation is set to `implicit when reconstructing an a hole (_) so that when printing, it can be reproduced correctly. *) - and normal = (* normal terms *) + and normal = (* normal terms *) | Lam of Location.t * name * normal (* M ::= \x.M *) - | Root of Location.t * head * spine * plicity (* | h . S *) + | Root of Location.t * head * spine * Plicity.t (* | h . S *) | LFHole of Location.t * HoleId.t * HoleId.name - | Clo of (normal * sub) (* | Clo(N,s) *) + | Clo of (normal * sub) (* | Clo(N,s) *) | Tuple of Location.t * tuple (* TODO: Heads ought to carry their location. @@ -120,7 +120,8 @@ module LF = struct ; mmvar_id : int (* unique to each MMVar *) ; typ : ctyp ; constraints : cnstr list ref (* not really used *) - ; depend : depend + ; plicity : Plicity.t + ; inductivity : Inductivity.t } and mm_var_inst' = mm_var * msub @@ -209,7 +210,7 @@ module LF = struct let rename_ctyp_decl f = function - | Decl (x, tA, ind) -> Decl (f x, tA, ind) + | Decl (x, tA, plicity, inductivity) -> Decl (f x, tA, plicity, inductivity) | DeclOpt (x, plicity) -> DeclOpt (f x, plicity) (** Embeds a head into a normal by using an empty spine. @@ -218,7 +219,7 @@ module LF = struct carry a location. *) let head (tH : head) : normal = - Root (Location.ghost, tH, Nil, `explicit) + Root (Location.ghost, tH, Nil, Plicity.explicit) let mvar cvar sub : head = MVar (cvar, sub) @@ -231,9 +232,9 @@ module LF = struct not a DeclOpt. Raises a violation if it is a DeclOpt. *) - let require_decl : ctyp_decl -> Id.name * ctyp * depend = + let require_decl : ctyp_decl -> Id.name * ctyp * Plicity.t * Inductivity.t = function - | Decl (u, cU, dep) -> (u, cU, dep) + | Decl (u, cU, plicity, inductivity) -> (u, cU, plicity, inductivity) | DeclOpt _ -> Error.violation "[require_decl] DeclOpt is forbidden" @@ -328,18 +329,13 @@ module LF = struct let is_explicit = function - | Decl(_, _, dep) -> - begin - match dep with - | No -> true - | Maybe -> false - | Inductive -> true - end - | _ -> true + | Decl(_, _, _, Inductivity.Inductive) + | Decl(_, _, Plicity.Explicit, _) -> true + | _ -> false let name_of_ctyp_decl (d : ctyp_decl) = match d with - | Decl (n, _, _) -> n + | Decl (n, _, _, _) -> n | DeclOpt (n, _) -> n (** Decides whether the given mfront is a variable, @@ -350,14 +346,14 @@ module LF = struct *) let variable_of_mfront (mf : mfront) : (offset * offset option) option = match mf with - | ClObj (_, MObj (Root (_, MVar (Offset x,_), _, _))) + | ClObj (_, MObj (Root (_, MVar (Offset x, _), _, _))) | CObj (CtxVar (CtxOffset x)) - | ClObj (_ , MObj (Root (_,PVar (x,_), _, _))) - | ClObj (_ , PObj (PVar (x,_))) -> + | ClObj (_ , MObj (Root (_, PVar (x, _), _, _))) + | ClObj (_ , PObj (PVar (x, _))) -> Some (x, None) - | ClObj (_, MObj (Root (_, Proj (PVar (x, _), k ),_, _))) - | ClObj (_, PObj (Proj (PVar (x,_), k))) -> + | ClObj (_, MObj (Root (_, Proj (PVar (x, _), k ), _, _))) + | ClObj (_, PObj (Proj (PVar (x, _), k))) -> Some (x, Some k) | _ -> None @@ -391,7 +387,7 @@ module Comp = struct type meta_spine = | MetaNil | MetaApp of meta_obj * meta_typ (* annotation for pretty printing*) - * meta_spine * plicity + * meta_spine * Plicity.t type typ = | TypBase of Location.t * cid_comp_typ * meta_spine @@ -452,7 +448,7 @@ module Comp = struct | Syn of Location.t * exp_syn (* | n *) | Fn of Location.t * name * exp_chk (* | \x. e' *) | Fun of Location.t * fun_branches (* | b_1...b_k *) - | MLam of Location.t * name * exp_chk * plicity (* | Pi X.e' *) + | MLam of Location.t * name * exp_chk * Plicity.t (* | Pi X.e' *) | Pair of Location.t * exp_chk * exp_chk (* | (e_1, e_2) *) | LetPair of Location.t * exp_syn * (name * name * exp_chk) (* | letpair n (x, y, e) := let (x=n.1, y=n.2) in e *) | Let of Location.t * exp_syn * (name * exp_chk) (* | let x = n in e *) @@ -470,7 +466,7 @@ and exp_syn = | Const of Location.t * cid_prog (* | theorem cp *) | Apply of Location.t * exp_syn * exp_chk (* | (n:tau_1 -> tau_2) (e:tau_1) *) | MApp of Location.t * exp_syn * meta_obj * meta_typ (* annotation, *) (* | (Pi X:U. n': tau) ([cPsihat |- tM] : [U']) *) - * plicity (* for printing *) + * Plicity.t (* for printing *) | AnnBox of meta_obj * meta_typ (* | [cPsihat |- tM] : [cPsi |- tA] *) | PairVal of Location.t * exp_syn * exp_syn @@ -480,7 +476,7 @@ and exp_syn = | PatFVar of Location.t * name (* used only _internally_ by coverage *) | PatVar of Location.t * offset | PatPair of Location.t * pattern * pattern - | PatAnn of Location.t * pattern * typ * plicity + | PatAnn of Location.t * pattern * typ * Plicity.t and pattern_spine = | PatNil diff --git a/src/core/total.ml b/src/core/total.ml index 2423efd37..4a7a58318 100644 --- a/src/core/total.ml +++ b/src/core/total.ml @@ -97,11 +97,6 @@ let rec shiftIH k = let shift = shiftIH 1 -let is_inductive = - function - | LF.Inductive -> true - | _ -> false - let sub_smaller (_, n) = function | LF.Shift n' -> @@ -215,7 +210,7 @@ let is_valid_args tau n = P.expSynToString cD cG i ^ " - comparing to arg. " ^ string_of_int y ^ " - comparing to relative position " ^ string_of_int (y-k) ^ "? - No\n");*) - relative_order (Comp.Var x) (tau, order, l+1, k, w)) + relative_order (Comp.Var x) (tau, order, l + 1, k, w)) | _ -> false) @@ -300,20 +295,20 @@ let gen_var' loc cD (x, cU) = match cU with | LF.ClTyp (LF.MTyp tA, cPsi) -> let psihat = Context.dctxToHat cPsi in - let tM = Whnf.etaExpandMMV loc cD cPsi (tA, Substitution.LF.id) x Substitution.LF.id LF.Maybe in + let tM = Whnf.etaExpandMMV loc cD cPsi (tA, Substitution.LF.id) x Substitution.LF.id Plicity.implicit Inductivity.not_inductive in ( (loc, LF.ClObj (psihat, LF.MObj tM)) , LF.ClObj (psihat, LF.MObj tM) ) | LF.ClTyp (LF.PTyp tA, cPsi) -> let psihat = Context.dctxToHat cPsi in - let p = Whnf.newMPVar (Some x) (cD, cPsi, tA) LF.Maybe in + let p = Whnf.newMPVar (Some x) (cD, cPsi, tA) Plicity.implicit Inductivity.not_inductive in let h = LF.MPVar ((p, Whnf.m_id), Substitution.LF.id) in ( (loc, LF.ClObj (psihat, LF.PObj h)) , LF.ClObj (psihat, LF.PObj h) ) | LF.ClTyp (LF.STyp (cl, cPhi), cPsi) -> let psihat = Context.dctxToHat cPsi in - let s = Whnf.newMSVar (Some x) (cD, cl, cPsi, cPhi) LF.Maybe in + let s = Whnf.newMSVar (Some x) (cD, cl, cPsi, cPhi) Plicity.implicit Inductivity.not_inductive in let sigma = LF.MSVar (0, ((s, Whnf.m_id), Substitution.LF.id)) in ( (loc, LF.ClObj (psihat, LF.SObj sigma)) , LF.ClObj (psihat, LF.SObj sigma) @@ -322,14 +317,14 @@ let gen_var' loc cD (x, cU) = | LF.CTyp (schema_cid) -> let mmvar = let open! LF in - Whnf.newMMVar' (Some x) (cD, CTyp schema_cid) Maybe + Whnf.newMMVar' (Some x) (cD, CTyp schema_cid) Plicity.implicit Inductivity.not_inductive in let cPsi = LF.CtxVar (LF.CInst (mmvar, Whnf.m_id)) in ( (loc, LF.CObj cPsi) , LF.CObj (cPsi) ) -let gen_var loc cD (LF.Decl (x, cU, dep)) = +let gen_var loc cD (LF.Decl (x, cU, _, _)) = gen_var' loc cD (x, cU) (* Given i and tau, compute vector V @@ -358,7 +353,7 @@ let rec rec_spine cD (cM, cU) = (Comp.DC :: spine, tau_r) else *) - | (1, (Comp.TypPiBox (_, (LF.Decl (_, cU', _)), tau), theta)) -> + | (1, (Comp.TypPiBox (_, (LF.Decl (_, cU', _, _)), tau), theta)) -> begin try (*print_string ("rec_spine: Unify " ^ P.cdeclToString cD cdecl ^ @@ -378,7 +373,7 @@ let rec rec_spine cD (cM, cU) = try Unify.unifyMetaTyp cD (cU, Whnf.m_id) (cU', theta); let (spine, tau_r) = rec_spine cD (cM, cU) (0, (tau, theta)) in - (Comp.M cM::spine, tau_r) + (Comp.M cM :: spine, tau_r) with | e -> raise Not_compatible @@ -446,7 +441,7 @@ let gen_meta_obj (cdecl, theta) k = let phat = Context.dctxToHat cPsi in let psihat' = Whnf.cnorm_psihat phat theta in let mv = LF.MVar (LF.Offset k, Substitution.LF.id) in - let tM = LF.Root (Syntax.Loc.ghost, mv, LF.Nil, `explicit) in + let tM = LF.Root (Syntax.Loc.ghost, mv, LF.Nil, Plicity.explicit) in (Syntax.Loc.ghost, LF.ClObj (psihat', LF.MObj tM)) | LF.ClTyp (LF.PTyp tA, cPsi) -> @@ -488,7 +483,7 @@ let rec generalize = then Comp.DC :: generalize args else Comp.M cM :: generalize args | Comp.V x :: args -> - Comp.V x:: generalize args + Comp.V x :: generalize args | Comp.DC :: args -> Comp.DC :: generalize args @@ -501,8 +496,7 @@ let rec gen_rec_calls cD cIH (cD', j) mfs = match cD' with | LF.Empty -> cIH - | LF.Dec (cD', LF.Decl (u, cU, dep)) - when not (is_inductive dep) -> + | LF.Dec (cD', LF.Decl (u, cU, _, Inductivity.NotInductive)) -> dprintf begin fun p -> p.fmt "[gen_rec_calls] @[ignoring cD' entry %d, i.e.\ @@ -513,9 +507,9 @@ let rec gen_rec_calls cD cIH (cD', j) mfs = Id.print u P.(fmt_ppr_cmp_meta_typ cD') cU end; - gen_rec_calls cD cIH (cD', j+1) mfs + gen_rec_calls cD cIH (cD', j + 1) mfs - | LF.Dec (cD', LF.Decl (u, cU, dep)) -> + | LF.Dec (cD', LF.Decl (u, cU, plicity, inductivity)) -> let cM = gen_meta_obj (cU, LF.MShift (j + 1)) (j + 1) in let cU' = Whnf.cnormMTyp (cU, LF.MShift (j + 1)) in let mf_list = get_order mfs in @@ -523,7 +517,7 @@ let rec gen_rec_calls cD cIH (cD', j) mfs = begin fun p -> p.fmt "[gen_rec_calls] @[Generate rec. calls given variable@,@[%a@]\ @,considering a total of %d recursive functions@]" - (P.fmt_ppr_lf_ctyp_decl cD') (LF.Decl (u, cU, dep)) + (P.fmt_ppr_lf_ctyp_decl cD') (LF.Decl (u, cU, plicity, inductivity)) (List.length mf_list) end; @@ -532,7 +526,7 @@ let rec gen_rec_calls cD cIH (cD', j) mfs = begin fun p -> p.fmt "[mk_wf_rec] @[for @[%a@] for position %d\ @,@[type of recursive call:@ @[%a@]@]@]" - (P.fmt_ppr_lf_ctyp_decl cD') (LF.Decl (u, cU, dep)) + (P.fmt_ppr_lf_ctyp_decl cD') (LF.Decl (u, cU, plicity, inductivity)) x (P.fmt_ppr_cmp_typ cD P.l0) (Whnf.cnormCTyp ttau) end; @@ -589,8 +583,8 @@ let rec gen_rec_calls cD cIH (cD', j) mfs = in dprint (fun () -> "[gen_rec_calls] for j = " ^ string_of_int j ^ "\n"); let cIH' = mk_all (cIH, j) mf_list in - dprint (fun () -> "[gen_rec_calls] for j = " ^ string_of_int (j+1) ^ "\n"); - gen_rec_calls cD cIH' (cD', j+1) mfs + dprint (fun () -> "[gen_rec_calls] for j = " ^ string_of_int (j + 1) ^ "\n"); + gen_rec_calls cD cIH' (cD', j + 1) mfs (* Generating recursive calls on computation-level variables *) let rec get_return_type cD x = @@ -848,7 +842,7 @@ let shiftMetaObj cM (cPsi', s_proj, cPsi) = | (l, LF.ClObj (phat', LF.PObj tH)) when Whnf.convDCtxHat phat phat' -> let LF.Root (_, tH', _, _) = - Whnf.norm (LF.Root (l, tH, LF.Nil, `explicit), s_proj) + Whnf.norm (LF.Root (l, tH, LF.Nil, Plicity.explicit), s_proj) in (l, LF.ClObj (phat0, LF.PObj tH')) @@ -978,12 +972,12 @@ let annotate' let open Option in let rec ann tau pos = match (tau, pos) with - | (Comp.TypPiBox (loc, LF.Decl (x, cU, _), tau), 1) -> - Comp.TypPiBox (loc, LF.Decl (x, cU, LF.Inductive), tau) - |> some + | (Comp.TypPiBox (loc, LF.Decl (x, cU, plicity, _), tau), 1) -> + Option.some + @@ Comp.TypPiBox (loc, LF.Decl (x, cU, plicity, Inductivity.inductive), tau) | (Comp.TypArr (loc, tau1, tau2), 1) -> - Comp.TypArr (loc, Comp.TypInd tau1, tau2) - |> some + Option.some + @@ Comp.TypArr (loc, Comp.TypInd tau1, tau2) | (Comp.TypArr (loc, tau1, tau2), n) -> ann tau2 (n - 1) $> fun tau2' -> @@ -996,23 +990,12 @@ let annotate' in fold_left (fun tau' x -> ann tau' x) tau order -(* TODO rethink LF.Inductive annotations for pi-types. - Inductivity markings are ORTHOGONAL to plicity markings - (explicit vs implicit) so there ought to be two flags on each - pi-type: plicity and inductivity. -je - *) -(** Removes all TypInd marks in a computational type. - WARNING: this is NOT an inverse for `annotate`. - This function will only remove TypInd annotations, but not - LF.Inductive annotations on Pi-types, which are in fact also - generated by annotate. - This is by design, as it is IMPOSSIBLE to remove LF.Inductive - annotations correctly: we can't figure out whether the pi-type was - explicit or implicit. - *) +(** Removes all TypInd marks in a computational type. *) let rec strip : Syntax.Int.Comp.typ -> Syntax.Int.Comp.typ = function | Comp.TypInd tau' -> strip tau' + | Comp.TypPiBox (loc, LF.Decl (x, cU, plicity, Inductivity.Inductive), tau') -> + Comp.TypPiBox (loc, LF.Decl (x, cU, plicity, Inductivity.not_inductive), strip tau') | Comp.TypPiBox (loc, d, tau') -> Comp.TypPiBox (loc, d, strip tau') | Comp.TypArr (loc, tau1, tau2) -> Comp.TypArr (loc, strip tau1, strip tau2) | Comp.TypCross (loc, tau1, tau2) -> Comp.TypCross (loc, strip tau1, strip tau2) @@ -1364,10 +1347,10 @@ let is_meta_inductive (cD : LF.mctx) (mf : LF.mfront) : bool = let open Id in let open LF in let is_inductive_meta_variable (k : offset) : bool = - Context.lookup_dep cD k + Context.lookup_inductivity cD k |> Option.get' (Failure "Metavariable out of bounds or missing type") |> function - | (_, LF.Inductive) -> true + | (_, Inductivity.Inductive) -> true | _ -> false in let open Option in diff --git a/src/core/unify.ml b/src/core/unify.ml index 4029d823b..00a5adbd9 100644 --- a/src/core/unify.ml +++ b/src/core/unify.ml @@ -189,12 +189,12 @@ module Make (T : TRAIL) : UNIFY = struct let ssi' = Substitution.LF.invert ss' in (* cPhi' |- ssi : cPhi *) (* cPhi' |- [ssi]tQ *) - let u = Whnf.newMMVar None (cD, cPhi', TClo (tQ, ssi')) Maybe in + let u = Whnf.newMMVar None (cD, cPhi', TClo (tQ, ssi')) Plicity.implicit Inductivity.not_inductive in (* cPhi |- ss' : cPhi' cPsi |- s_proj : cPhi cPsi |- comp ss' s_proj : cPhi' *) let ss_proj = Substitution.LF.comp ss' s_proj in - Root (loc, MMVar ((u, Whnf.m_id), ss_proj), Nil, `explicit) + Root (loc, MMVar ((u, Whnf.m_id), ss_proj), Nil, Plicity.explicit) (* isPatSub s = B @@ -490,7 +490,7 @@ module Make (T : TRAIL) : UNIFY = struct let expandMVarAtType loc (v, (mt, s)) = function - | MTyp _ -> INorm (Root (loc, MMVar ((v, mt), s), Nil, `explicit)) + | MTyp _ -> INorm (Root (loc, MMVar ((v, mt), s), Nil, Plicity.explicit)) | PTyp _ -> IHead (MPVar ((v, mt), s)) | STyp _ -> ISub (MSVar (0, ((v, mt), s))) @@ -571,7 +571,7 @@ module Make (T : TRAIL) : UNIFY = struct | (MShift k, Dec _) -> pruneMCtx' cD (MDot (MV (k + 1), MShift (k + 1)), cD1) ms - | (MDot (MV k, mt), Dec (cD1, Decl (n, ctyp, dep))) -> + | (MDot (MV k, mt), Dec (cD1, Decl (n, ctyp, plicity, inductivity))) -> let (mt', cD2) = pruneMCtx' cD (mt, cD1) ms in (* cD1 |- mt' <= cD2 *) begin match applyMSub k ms with @@ -583,7 +583,7 @@ module Make (T : TRAIL) : UNIFY = struct (* cD1, u:A[Psi] |- mt' <= cD2, u:([mt']^-1 (A[cPsi])) since A = [mt']([mt']^-1 A) and cPsi = [mt']([mt']^-1 cPsi *) let mtt' = Whnf.m_invert (Whnf.cnormMSub mt') in - (Whnf.mvar_dot1 mt', Dec (cD2, (Decl (n, Whnf.cnormMTyp (ctyp, mtt'), dep)))) + (Whnf.mvar_dot1 mt', Dec (cD2, (Decl (n, Whnf.cnormMTyp (ctyp, mtt'), plicity, inductivity)))) end | (MDot (MUndef, mt), Dec (cD1, _)) -> @@ -689,7 +689,7 @@ module Make (T : TRAIL) : UNIFY = struct *) let rec m_intersection subst1 subst2 cD' = match (subst1, subst2, cD') with - | (MDot (MV k1, mt1), MDot (MV k2, mt2), Dec (cD', Decl (x, ctyp, dep))) -> + | (MDot (MV k1, mt1), MDot (MV k2, mt2), Dec (cD', Decl (x, ctyp, plicity, inductivity))) -> let (mt', cD'') = m_intersection mt1 mt2 cD' in (* cD' |- mt' : cD'' where cD'' =< cD' *) if k1 = k2 @@ -698,7 +698,7 @@ module Make (T : TRAIL) : UNIFY = struct let mtt' = Whnf.m_invert (Whnf.cnormMSub mt') in (* cD'' |- mtt' <= cD' *) (* NOTE: Can't create m-closures CtxMClo (cPsi, mtt') and TMClo (tA'', mtt') *) - (Whnf.mvar_dot1 mt', Dec (cD'', Decl (x, Whnf.cnormMTyp (ctyp, mtt'), dep))) + (Whnf.mvar_dot1 mt', Dec (cD'', Decl (x, Whnf.cnormMTyp (ctyp, mtt'), plicity, inductivity))) end else (Whnf.mcomp mt' (MShift 1), cD'') @@ -821,7 +821,7 @@ module Make (T : TRAIL) : UNIFY = struct end | (Root (loc, FMVar (u, t), _ (* Nil *), plicity), s (* id *)) -> - let (cD_d, Decl (_, ClTyp (_, cPsi1), _)) = Store.FCVar.get u in + let (cD_d, Decl (_, ClTyp (_, cPsi1), _, _)) = Store.FCVar.get u in let d = Context.length cD0 - Context.length cD_d in let cPsi1 = if d = 0 @@ -832,7 +832,7 @@ module Make (T : TRAIL) : UNIFY = struct Root (loc, FMVar (u, s'), Nil, plicity) | (Root (loc, FPVar (p, t), _ (* Nil *), plicity), s (* id *)) -> - let (cD_d, Decl (_, ClTyp (_, cPsi1), _)) = Store.FCVar.get p in + let (cD_d, Decl (_, ClTyp (_, cPsi1), _, _)) = Store.FCVar.get p in let d = Context.length cD0 - Context.length cD_d in let cPsi1 = if d = 0 @@ -1032,7 +1032,7 @@ module Make (T : TRAIL) : UNIFY = struct end | (FSVar (n, (s_name, t)), cPsi1) -> dprint (fun () -> "invSub FSVar"); - let (_, Decl (_, ClTyp (STyp (LF.Subst, _), cPsi'), _)) = Store.FCVar.get s_name in + let (_, Decl (_, ClTyp (STyp (LF.Subst, _), cPsi'), _, _)) = Store.FCVar.get s_name in FSVar (n, (s_name, invSub cD0 phat (t, cPsi') ss rOccur)) (* if ssubst = id * then s @@ -1064,7 +1064,7 @@ module Make (T : TRAIL) : UNIFY = struct and invMSub cD0 (mt, cD1) ms rOccur = match (mt, cD1) with | (MShift n, _) -> checkDefined (Whnf.mcomp (MShift n) ms) - | (MDot (ClObj (phat, SObj sigma), mt'), Dec (cD', Decl (_, ClTyp (STyp (_, cPhi), _), _))) -> + | (MDot (ClObj (phat, SObj sigma), mt'), Dec (cD', Decl (_, ClTyp (STyp (_, cPhi), _), _, _))) -> let sigma' = invSub cD0 phat (sigma, cPhi) (ms, id) rOccur in MDot (ClObj (phat, SObj sigma'), invMSub cD0 (mt', cD') ms rOccur) | (MDot (mobj, mt'), Dec (cD', _)) -> @@ -1179,7 +1179,7 @@ module Make (T : TRAIL) : UNIFY = struct begin let (id2, (cD2, cPsi2')) = pruneBoth cD0 cPsi' (mtt, (mmvar.cD, cPsi1)) ss rOccur in let tP' = normClTyp2 (tp, invert2 id2) in - let v = Whnf.newMMVar' (Some mmvar.name) (cD2, ClTyp (tP', cPsi2')) mmvar.depend in + let v = Whnf.newMMVar' (Some mmvar.name) (cD2, ClTyp (tP', cPsi2')) mmvar.plicity mmvar.inductivity in instantiateMMVarWithMMVar mmvar.instantiation loc (v, id2) tP' mmvar.constraints.contents; let (mr, r) = comp2 (comp2 id2 mtt) ss in ((v, mr), r) @@ -1192,16 +1192,16 @@ module Make (T : TRAIL) : UNIFY = struct else let (idsub, cPsi2) = pruneSub cD0 cPsi' (Context.dctxToHat cPsi') (t, cPsi1) ss rOccur in let tP' = Whnf.normTyp (tP, invert idsub) in - let v = Whnf.newMVar (Some mmvar.name) (cPsi2, tP') mmvar.depend in + let v = Whnf.newMVar (Some mmvar.name) (cPsi2, tP') mmvar.plicity mmvar.inductivity in instantiateMVar ( mmvar.instantiation - , Root (loc, MVar (v, idsub), Nil, `explicit) + , Root (loc, MVar (v, idsub), Nil, Plicity.explicit) , mmvar.constraints.contents ); (v, comp (comp idsub t) ssubst) and pruneFVar cD0 cPsi (u, t) ss rOccur = - let (cD_d, Decl (_, ClTyp (_, cPsi1), _)) = Store.FCVar.get u in + let (cD_d, Decl (_, ClTyp (_, cPsi1), _, _)) = Store.FCVar.get u in let d = Context.length cD0 - Context.length cD_d in let cPsi1 = if d = 0 @@ -1397,7 +1397,7 @@ module Make (T : TRAIL) : UNIFY = struct D ; Psi'' |- ss <= Psi [ss] ([s[sigma] ] id) exists *) - let (_, Decl (_, ClTyp (STyp _, cPsi'), _)) = Store.FCVar.get s in + let (_, Decl (_, ClTyp (STyp _, cPsi'), _, _)) = Store.FCVar.get s in ignore (invSub cD0 phat (sigma, cPsi') ss rOccur); (id, cPsi1) @@ -1475,14 +1475,14 @@ module Make (T : TRAIL) : UNIFY = struct and pruneTypW cD0 cPsi phat sA (mss, ss) rOccur = match sA with | (Atom (loc, a, tS), s) -> Atom (loc, a, pruneSpine cD0 cPsi phat (tS, s) (mss, ss) rOccur) - | (PiTyp ((TypDecl (x, tA), dep), tB), s) -> + | (PiTyp ((TypDecl (x, tA), plicity), tB), s) -> let tA' = pruneTyp cD0 cPsi phat (tA, s) (mss, ss) rOccur in let tB' = pruneTyp cD0 cPsi phat (tB, dot1 s) (mss, dot1 ss) rOccur in - PiTyp ((TypDecl (x, tA'), dep), tB') + PiTyp ((TypDecl (x, tA'), plicity), tB') - | (PiTyp ((TypDeclOpt x, dep), tB), s) -> + | (PiTyp ((TypDeclOpt x, plicity), tB), s) -> let tB' = pruneTyp cD0 cPsi phat (tB, dot1 s) (mss, dot1 ss) rOccur in - PiTyp ((TypDeclOpt x, dep), tB') + PiTyp ((TypDeclOpt x, plicity), tB') | (Sigma typ_rec, s) -> let typ_rec' = pruneTypRec cD0 cPsi phat (typ_rec, s) (mss, ss) rOccur in @@ -1700,7 +1700,7 @@ module Make (T : TRAIL) : UNIFY = struct cPsi |- tN <= [s]tA cPsi |- tN . s <= cPsi', x:A *) - let tN = Whnf.etaExpandMV cPsi1 (tA, s) n id LF.Maybe in + let tN = Whnf.etaExpandMV cPsi1 (tA, s) n id Plicity.implicit Inductivity.not_inductive in let tS = genSpine cD1 cPsi1 (tB, LF.Dot (LF.Obj tN, s)) in LF.App (tN, tS) @@ -1723,7 +1723,7 @@ module Make (T : TRAIL) : UNIFY = struct cPsi |- tN . s <= cPsi', x:A *) let tN = - ConvSigma.etaExpandMMVstr Loc.ghost cD1 cPsi1 (tA, s) Maybe (Some n) + ConvSigma.etaExpandMMVstr Loc.ghost cD1 cPsi1 (tA, s) Plicity.implicit (Some n) Context.(names_of_dctx cPsi @ names_of_mctx cD0) in let tS = genSpine cD1 cPsi1 (tB, LF.Dot (LF.Obj tN, s)) in @@ -1748,7 +1748,7 @@ module Make (T : TRAIL) : UNIFY = struct | Root (loc, MPVar _, _, plicity) -> dprnt "[craftMMVTerm] MPVar ..."; - let p = Whnf.newMPVar None (mmvar.cD, cPsi1, tB) Maybe in + let p = Whnf.newMPVar None (mmvar.cD, cPsi1, tB) Plicity.implicit Inductivity.not_inductive in let tM1 = Root ( loc @@ -1886,8 +1886,9 @@ module Make (T : TRAIL) : UNIFY = struct let cPsi_n = Whnf.cnormDCtx (cPsi', mtt') in let tp1' = normClTyp2 (tp1, (mtt', ss')) in - let dep = Depend.max mmvar1.depend mmvar2.depend in - let w = Whnf.newMMVar' (Some mmvar1.name) (cD', ClTyp (tp1', cPsi_n)) dep in + let plicity = Plicity.max mmvar1.plicity mmvar2.plicity in + let inductivity = Inductivity.max mmvar1.inductivity mmvar2.inductivity in + let w = Whnf.newMMVar' (Some mmvar1.name) (cD', ClTyp (tp1', cPsi_n)) plicity inductivity in (* w :: [s'^-1](tP1)[cPsi'] in cD' *) (* cD' ; cPsi1 |- w[s'] <= [s']([s'^-1] tP1) [|w[s']/u|](u[t1]) = [t1](w[s']) @@ -1933,7 +1934,7 @@ module Make (T : TRAIL) : UNIFY = struct in (* cD ; cPsi' |- [s']^-1(tP1) <= type *) - let w = Whnf.newMVar None (cPsi', TClo (tP1, ss')) mmvar1.depend in + let w = Whnf.newMVar None (cPsi', TClo (tP1, ss')) mmvar1.plicity mmvar1.inductivity in (* w::[s'^-1](tP1)[cPsi'] in cD' *) (* cD' ; cPsi1 |- w[s'] <= [s']([s'^-1] tP1) [|w[s']/u|](u[t1]) = [t1](w[s']) @@ -1941,7 +1942,7 @@ module Make (T : TRAIL) : UNIFY = struct *) instantiateMVar ( mmvar1.instantiation - , Root (Syntax.Loc.ghost, MVar (w, s'), Nil, `explicit) + , Root (Syntax.Loc.ghost, MVar (w, s'), Nil, Plicity.explicit) , mmvar1.constraints.contents ) end @@ -2042,7 +2043,7 @@ module Make (T : TRAIL) : UNIFY = struct end; instantiateMMVar ( mmvar2.instantiation - , Root (loc', MMVar (mv, id), tS', `explicit) + , Root (loc', MMVar (mv, id), tS', Plicity.explicit) , mmvar2.constraints.contents ); dprintf @@ -2109,7 +2110,7 @@ module Make (T : TRAIL) : UNIFY = struct begin try unifySub mflag cD0 cPsi s1 EmptySub; - instantiateMMVar (instantiation, Root (loc', MVar (Offset u, id), tS', `explicit), !constraints) + instantiateMMVar (instantiation, Root (loc', MVar (Offset u, id), tS', Plicity.explicit), !constraints) with _ -> let id = next_constraint_id () in addConstraint (constraints, ref (Eqn (id, cD0, cPsi, INorm sM1, INorm sM2))) @@ -2142,7 +2143,7 @@ module Make (T : TRAIL) : UNIFY = struct try unifyDCtx1 mflag cD0 cPsi1 cPsi;unifyTyp mflag cD0 cPsi (tP, id) (tQ, id); unifySub mflag cD0 cPsi s1 s2; - instantiateMMVar (instantiation, Root (loc', MVar (Offset u, id), tS', `explicit), !constraints) + instantiateMMVar (instantiation, Root (loc', MVar (Offset u, id), tS', Plicity.explicit), !constraints) with _ -> let id = next_constraint_id () in addConstraint (constraints, ref (Eqn (id, cD0, cPsi, INorm sM1, INorm sM2))) @@ -2198,7 +2199,7 @@ module Make (T : TRAIL) : UNIFY = struct unifyTyp mflag cD0 cPsi0 (tP0, Substitution.LF.id) (tP1', Substitution.LF.id); instantiateMMVar ( instantiation - , Root (loc, MVar (Offset (u - k), Substitution.LF.id), tS, `explicit) + , Root (loc, MVar (Offset (u - k), Substitution.LF.id), tS, Plicity.explicit) , !constraints ); unifySub mflag cD0 cPsi0 s s' @@ -2216,7 +2217,7 @@ module Make (T : TRAIL) : UNIFY = struct unifyTyp mflag cD0 cPsi0 (tP0, Substitution.LF.id) (tP1', Substitution.LF.id); instantiateMMVar ( instantiation - , Root (loc, MVar (Offset (u - k), Substitution.LF.id), tS, `explicit) + , Root (loc, MVar (Offset (u - k), Substitution.LF.id), tS, Plicity.explicit) , !constraints ) else @@ -2556,7 +2557,7 @@ module Make (T : TRAIL) : UNIFY = struct mflag cD0 cPsi - (Root (Syntax.Loc.ghost, head, Nil, `explicit), id) + (Root (Syntax.Loc.ghost, head, Nil, Plicity.explicit), id) (tN, id) | (Undef, Undef) -> () @@ -2586,7 +2587,7 @@ module Make (T : TRAIL) : UNIFY = struct end; raise (Failure "Type constant clash") - | ((PiTyp ((TypDecl (x, tA1), dep), tA2), s1), (PiTyp ((TypDecl (_, tB1), _), tB2), s2)) -> + | ((PiTyp ((TypDecl (x, tA1), _), tA2), s1), (PiTyp ((TypDecl (_, tB1), _), tB2), s2)) -> unifyTyp mflag cD0 cPsi (tA1, s1) (tB1, s2); unifyTyp mflag cD0 (DDec (cPsi, TypDecl (x, tA1))) (tA2, dot1 s1) (tB2, dot1 s2) @@ -2656,7 +2657,8 @@ module Make (T : TRAIL) : UNIFY = struct instantiation = ref None; cD = cD'; constraints = ref []; - depend = Maybe + plicity = Plicity.implicit; + inductivity = Inductivity.not_inductive; } in let cPsi = CtxVar (CInst (mmvar, mt')) in @@ -2704,7 +2706,7 @@ module Make (T : TRAIL) : UNIFY = struct ignore (FCVar.get psi) with | Not_found -> - FCVar.add psi (cD0, Decl (psi, CTyp s_cid, Maybe)) + FCVar.add psi (cD0, Decl (psi, CTyp s_cid, Plicity.implicit, Inductivity.not_inductive)) end | _ -> () end @@ -2750,7 +2752,7 @@ module Make (T : TRAIL) : UNIFY = struct (* **************************************************************** *) let rec unifyMetaObj cD (mO, t) (mO', t') (cdecl, mt) = - let Decl (_, cT, _) = cdecl in + let Decl (_, cT, _, _) = cdecl in unifyMObj cD (mO, t) (mO', t') (cT, mt) and unifyClObj' cD mO mO' mT = @@ -2887,14 +2889,14 @@ module Make (T : TRAIL) : UNIFY = struct else raise (Failure "CtxPi schema clash") *) - | ( (Comp.TypPiBox (_, (Decl (u, ctyp1, dep)), tau), t) - , (Comp.TypPiBox (_, (Decl (_, ctyp2, _)), tau'), t') + | ( (Comp.TypPiBox (_, (Decl (u, ctyp1, plicity, inductivity)), tau), t) + , (Comp.TypPiBox (_, (Decl (_, ctyp2, _, _)), tau'), t') ) -> let ctyp1n = Whnf.cnormMTyp (ctyp1, t) in let ctyp2n = Whnf.cnormMTyp (ctyp2, t') in unifyCLFTyp Unification cD ctyp1n ctyp2n; unifyCompTyp - (Dec (cD, Decl (u, ctyp1n, dep))) + (Dec (cD, Decl (u, ctyp1n, plicity, inductivity))) (tau, Whnf.mvar_dot1 t) (tau', Whnf.mvar_dot1 t') @@ -3082,7 +3084,8 @@ module Make (T : TRAIL) : UNIFY = struct { mmvar1 with instantiation = ref None; cD = cD'; - depend = Maybe; + plicity = Plicity.implicit; + inductivity = Inductivity.not_inductive; constraints = ref [] } in @@ -3099,7 +3102,13 @@ module Make (T : TRAIL) : UNIFY = struct then begin let mtt1 = Whnf.m_invert (Whnf.cnormMSub theta1) in - let mmvar2' = { mmvar2 with depend = Maybe; constraints = ref [] } in + let mmvar2' = + { mmvar2 with + plicity = Plicity.implicit; + inductivity = Inductivity.not_inductive; + constraints = ref [] + } + in (* why do we drop the constraints here ? -je *) let i = CInst (mmvar2', Whnf.mcomp theta2 mtt1) in mmvar1.instantiation := Some (ICtx (CtxVar i)) @@ -3126,7 +3135,7 @@ module Make (T : TRAIL) : UNIFY = struct then mmvar1.instantiation := Some (ICtx Null) else if d' < d then - (* (Some (cref), d) == (None, d') d' = d0+d *) + (* (Some (cref), d) == (None, d') d' = d0 + d *) fail "Hat Context's do not unify" else begin diff --git a/src/core/whnf.ml b/src/core/whnf.ml index 03d176f5a..2fe97dcd3 100644 --- a/src/core/whnf.ml +++ b/src/core/whnf.ml @@ -37,7 +37,7 @@ let rec raiseType cPsi tA = match cPsi with | Null -> tA | DDec (cPsi', decl) -> - raiseType cPsi' (PiTyp ((decl, Maybe), tA)) + raiseType cPsi' (PiTyp ((decl, Plicity.implicit), tA)) (* Eta-contract elements in substitutions *) let etaContract = @@ -108,7 +108,7 @@ let next_mmvar_id = incr c; !c -let newMMVar' n (cD, mtyp) depend = +let newMMVar' n (cD, mtyp) plicity inductivity = let name = match n with | None -> @@ -122,47 +122,48 @@ let newMMVar' n (cD, mtyp) depend = ; cD ; typ = mtyp ; constraints = ref [] - ; depend + ; plicity + ; inductivity } -let newMMVar n (cD, cPsi, tA) dep = newMMVar' n (cD, ClTyp (MTyp tA, cPsi)) dep -let newMPVar n (cD, cPsi, tA) dep = newMMVar' n (cD, ClTyp (PTyp tA, cPsi)) dep +let newMMVar n (cD, cPsi, tA) plicity inductivity = newMMVar' n (cD, ClTyp (MTyp tA, cPsi)) plicity inductivity +let newMPVar n (cD, cPsi, tA) plicity inductivity = newMMVar' n (cD, ClTyp (PTyp tA, cPsi)) plicity inductivity -let newMSVar n (cD, cl, cPsi, cPhi) dep = newMMVar' n (cD, ClTyp (STyp (cl, cPhi), cPsi)) dep -let newCVar n cD (sW) dep = CInst (newMMVar' n (cD, CTyp sW) dep, MShift 0) +let newMSVar n (cD, cl, cPsi, cPhi) plicity inductivity = newMMVar' n (cD, ClTyp (STyp (cl, cPhi), cPsi)) plicity inductivity +let newCVar n cD (sW) plicity inductivity = CInst (newMMVar' n (cD, CTyp sW) plicity inductivity, MShift 0) -let newMVar n (cPsi, tA) dep = Inst (newMMVar' n (Empty, ClTyp (MTyp tA, cPsi)) dep) +let newMVar n (cPsi, tA) plicity inductivity = Inst (newMMVar' n (Empty, ClTyp (MTyp tA, cPsi)) plicity inductivity) (******************************) (* Lowering *) (******************************) (* lowerMVar' cPsi tA[s] = (u, tM), see lowerMVar *) -let rec lowerMVar' cPsi sA' dep = +let rec lowerMVar' cPsi sA' plicity inductivity = match sA' with | (PiTyp ((decl, _), tA'), s') -> let (u', tM) = lowerMVar' (DDec (cPsi, LF.decSub decl s')) (tA', LF.dot1 s') - dep + plicity inductivity in (u', Lam (Syntax.Loc.ghost, Id.mk_name Id.NoName, tM)) | (TClo (tA, s), s') -> - lowerMVar' cPsi (tA, LF.comp s s') dep + lowerMVar' cPsi (tA, LF.comp s s') plicity inductivity | (Atom (loc, a, tS), s') -> - let u' = newMVar None (cPsi, Atom (loc, a, SClo (tS, s'))) dep in - (u', Root (Syntax.Loc.ghost, MVar (u', LF.id), Nil, Depend.to_plicity dep)) (* cvar * normal *) + let u' = newMVar None (cPsi, Atom (loc, a, SClo (tS, s'))) plicity inductivity in + (u', Root (Syntax.Loc.ghost, MVar (u', LF.id), Nil, plicity)) (* cvar * normal *) (* lowerMVar1 (u, tA[s]), tA[s] in whnf, see lowerMVar *) and lowerMVar1 u sA = match (u, sA) with - | ( Inst { instantiation; typ = ClTyp (_, cPsi); depend; _ } + | ( Inst { instantiation; typ = ClTyp (_, cPsi); plicity; inductivity; _ } , (PiTyp _, _) ) -> - let (u', tM) = lowerMVar' cPsi sA depend in + let (u', tM) = lowerMVar' cPsi sA plicity inductivity in instantiation := Some (INorm tM); (* [| tM / u |] *) u' (* this is the new lowered meta-variable of atomic type *) @@ -568,8 +569,8 @@ and normTyp (tA, sigma) = | Atom (loc, a, tS) -> Atom (loc, a, normSpine (tS, sigma)) - | PiTyp ((TypDecl _ as decl, dep), tB) -> - PiTyp ((normDecl (decl, sigma), dep), normTyp (tB, LF.dot1 sigma)) + | PiTyp ((TypDecl _ as decl, plicity), tB) -> + PiTyp ((normDecl (decl, sigma), plicity), normTyp (tB, LF.dot1 sigma)) | TClo (tA, s) -> normTyp (tA, LF.comp s sigma) @@ -628,8 +629,8 @@ and cnorm_psihat (phat : dctx_hat) t = | Some (ICtx cPsi) -> (* | (Some (CInst ((_, { contents = Some (ICtx cPsi) }, _, _, _, _), theta)), k) -> *) begin match Context.dctxToHat (cnormDCtx (cPsi, mcomp theta t)) with - | (None, i) -> (None, k+i) (* cnorm_psihat (None, k+i) t *) - | (Some cvar', i) -> (Some cvar', i+k) (* cnorm_psihat (Some cvar', i+k) t *) + | (None, i) -> (None, k + i) (* cnorm_psihat (None, k + i) t *) + | (Some cvar', i) -> (Some cvar', k + i) (* cnorm_psihat (Some cvar', k + i) t *) end end | (Some (CtxOffset offset), k) -> @@ -637,7 +638,7 @@ and cnorm_psihat (phat : dctx_hat) t = | CObj cPsi -> begin match Context.dctxToHat cPsi with | (None, i) -> (None, k + i) - | (Some cvar', i) -> (Some cvar', i + k) + | (Some cvar', i) -> (Some cvar', k + i) end | MV offset' -> (Some (CtxOffset offset'), k) | ClObj _ -> @@ -799,8 +800,8 @@ and cnormTyp (tA, t) = | Atom (loc, a, tS) -> Atom (loc, a, cnormSpine (tS, t)) - | PiTyp ((TypDecl _ as decl, dep), tB) -> - PiTyp ((cnormDecl (decl, t), dep), cnormTyp (tB, t)) + | PiTyp ((TypDecl _ as decl, plicity), tB) -> + PiTyp ((cnormDecl (decl, t), plicity), cnormTyp (tB, t)) | TClo (tA, s) -> normTyp (cnormTyp (tA, t), cnormSub (s, t)) @@ -881,8 +882,8 @@ and cnormMSub = and normKind = function | (Typ, _) -> Typ - | (PiKind ((decl, dep), tK), s) -> - PiKind ((normDecl (decl, s), dep), normKind (tK, LF.dot1 s)) + | (PiKind ((decl, plicity), tK), s) -> + PiKind ((normDecl (decl, s), plicity), normKind (tK, LF.dot1 s)) and normDCtx = function @@ -1538,13 +1539,13 @@ let mctxLookupDep cD k = ) ) |> function - | Decl (u, mtyp, dep) -> - (u, cnormMTyp (mtyp, MShift k), dep) + | Decl (u, mtyp, plicity, inductivity) -> + (u, cnormMTyp (mtyp, MShift k), plicity, inductivity) | DeclOpt _ -> raise (Error.Violation "Expected declaration to have a type") let mctxLookup cD k = - let (u, tp, dep) = mctxLookupDep cD k in + let (u, tp, _, _) = mctxLookupDep cD k in (u, tp) (* ************************************************* *) @@ -1576,7 +1577,7 @@ let mctxCDec cD k = let mctxMVarPos cD u = let rec lookup cD k = match cD with - | Dec (cD, Decl (v, mtyp, _)) -> + | Dec (cD, Decl (v, mtyp, _, _)) -> if Id.equals v u then (k, cnormMTyp (mtyp, MShift k)) else lookup cD (k + 1) @@ -1622,8 +1623,9 @@ let rec normCTyp = | Comp.TypCross (loc, tT1, tT2) -> Comp.TypCross (loc, normCTyp tT1, normCTyp tT2) - | Comp.TypPiBox (loc, (Decl (u, mtyp, dep)), tau) -> - Comp.TypPiBox (loc, (Decl (u, normMTyp mtyp, dep)), normCTyp tau) + | Comp.TypPiBox (loc, (Decl (u, mtyp, plicity, inductivity)), tau) -> + Comp.TypPiBox + (loc, (Decl (u, normMTyp mtyp, plicity, inductivity)), normCTyp tau) | Comp.TypInd tau -> Comp.TypInd (normCTyp tau) @@ -1642,7 +1644,8 @@ and cnormMetaSpine (mS, t) = let cnormCDecl (cdecl, t) = match cdecl with - | Decl (u, mtyp, dep) -> Decl (u, cnormMTyp (mtyp, t), dep) + | Decl (u, mtyp, plicity, inductivity) -> + Decl (u, cnormMTyp (mtyp, t), plicity, inductivity) let rec cnormCTyp = function @@ -1673,7 +1676,7 @@ let rec cnormCTyp = let cnormCCDecl (cdecl, t) = match cdecl with | Comp.CTypDecl(n, typ, wf_t) -> - Comp.CTypDecl(n, cnormCTyp (typ,t), wf_t) + Comp.CTypDecl(n, cnormCTyp (typ, t), wf_t) let rec cnormCKind (cK, t) = match cK with @@ -1935,7 +1938,8 @@ let normGCtx = Context.map normCTypDecl let rec normMCtx cD = match cD with | Empty -> Empty - | Dec (cD, Decl (u, mtyp, dep)) -> Dec (normMCtx cD, Decl (u, normMTyp mtyp, dep)) + | Dec (cD, Decl (u, mtyp, plicity, inductivity)) -> + Dec (normMCtx cD, Decl (u, normMTyp mtyp, plicity, inductivity)) (* ----------------------------------------------------------- *) @@ -2002,8 +2006,8 @@ and convCTyp' thetaT1 thetaT2 = | ((Comp.TypCross (_, tT1, tT2), t), (Comp.TypCross (_, tT1', tT2'), t')) -> convCTyp (tT1, t) (tT1', t') && convCTyp (tT2, t) (tT2', t') - | ( (Comp.TypPiBox (_, Decl (_, mtyp1, _), tT), t) - , (Comp.TypPiBox (_, Decl (_, mtyp2, _), tT'), t') + | ( (Comp.TypPiBox (_, Decl (_, mtyp1, _, _), tT), t) + , (Comp.TypPiBox (_, Decl (_, mtyp2, _, _), tT'), t') ) -> convMTyp (cnormMTyp (mtyp1, t)) (cnormMTyp (mtyp2, t')) && convCTyp (tT, mvar_dot1 t) (tT', mvar_dot1 t') @@ -2024,8 +2028,10 @@ and convSchElem (SchElem (cPsi, trec)) (SchElem (cPsi', trec')) = let convCTypDecl d1 d2 = match (d1, d2) with - | (Decl (x1, cT1, dep1), Decl (x2, cT2, dep2)) -> - Id.equals x1 x2 && Depend.equals dep1 dep2 + | (Decl (x1, cT1, plicity1, inductivity1), Decl (x2, cT2, plicity2, inductivity2)) -> + Id.equals x1 x2 + && Plicity.equal plicity1 plicity2 + && Inductivity.equal inductivity1 inductivity2 && convMTyp cT1 cT2 | (DeclOpt (x1, _), DeclOpt (x2, _)) -> Id.equals x1 x2 @@ -2056,20 +2062,20 @@ let mctx_to_list_shifted x = * * cPsi' |- tN <= [s'][s]A *) -let rec etaExpandMV cPsi sA n s' dep = - etaExpandMV' cPsi (whnfTyp sA) n s' dep +let rec etaExpandMV cPsi sA n s' plicity inductivity = + etaExpandMV' cPsi (whnfTyp sA) n s' plicity inductivity -and etaExpandMV' cPsi sA n s' dep = +and etaExpandMV' cPsi sA n s' plicity inductivity = match sA with | (Atom (loc, _, _) as tP, s) -> - let u = newMVar (Some (Id.inc n)) (cPsi, tclo tP s) dep in - Root (loc, MVar (u, s'), Nil, Depend.to_plicity dep) + let u = newMVar (Some (Id.inc n)) (cPsi, tclo tP s) plicity inductivity in + Root (loc, MVar (u, s'), Nil, plicity) | (PiTyp ((TypDecl (x, _) as decl, _), tB), s) -> Lam ( Id.loc_of_name x , x - , etaExpandMV (DDec (cPsi, LF.decSub decl s)) (tB, LF.dot1 s) n (LF.dot1 s') dep + , etaExpandMV (DDec (cPsi, LF.decSub decl s)) (tB, LF.dot1 s) n (LF.dot1 s') plicity inductivity ) (* Coverage.etaExpandMVstr s' cPsi sA *) @@ -2081,17 +2087,21 @@ and etaExpandMV' cPsi sA n s' dep = * * cD ; cPsi' |- tN <= [s'][s]A *) -let rec etaExpandMMV loc cD cPsi sA n s' dep = - etaExpandMMV' loc cD cPsi (whnfTyp sA) n s' dep +let rec etaExpandMMV loc cD cPsi sA n s' plicity inductivity = + etaExpandMMV' loc cD cPsi (whnfTyp sA) n s' plicity inductivity -and etaExpandMMV' loc cD cPsi sA n s' dep = +and etaExpandMMV' loc cD cPsi sA n s' plicity inductivity = match sA with | (Atom _ as tP, s) -> - let u = newMMVar (Some (Id.inc n)) (cD, cPsi, tclo tP s) dep in - Root (loc, MMVar ((u, m_id), s'), Nil, Depend.to_plicity dep) + let u = newMMVar (Some (Id.inc n)) (cD, cPsi, tclo tP s) plicity inductivity in + Root (loc, MMVar ((u, m_id), s'), Nil, plicity) | (PiTyp ((TypDecl (x, _) as decl, _), tB), s) -> - Lam (loc, x, etaExpandMMV loc cD (DDec (cPsi, LF.decSub decl s)) (tB, LF.dot1 s) n (LF.dot1 s') dep) + Lam + ( loc + , x + , etaExpandMMV loc cD (DDec (cPsi, LF.decSub decl s)) (tB, LF.dot1 s) n (LF.dot1 s') plicity inductivity + ) let rec closed sM = closedW (whnf sM) @@ -2211,7 +2221,7 @@ and closedMetaObj (_, mF) = closedMFront mF let closedDecl = function - | Decl (_, cU, _) -> closedMetaTyp cU + | Decl (_, cU, _, _) -> closedMetaTyp cU | DeclOpt _ -> Error.violation "[closedDecl] DeclOpt outside printing" @@ -2380,7 +2390,7 @@ let convGCtx (cG1, t1) (cG2, t2) = conv_ctx f cG1 cG2 let convMCtx cD1 cD2 = - let f (Decl (_, cU1, _)) (Decl (_, cU2, _)) = + let f (Decl (_, cU1, _, _)) (Decl (_, cU2, _, _)) = convMetaTyp cU1 cU2 in conv_ctx f cD1 cD2 @@ -2392,7 +2402,7 @@ let rec lowerTyp cPsi = let mmVarToClObj loc' (mV : mm_var) : cltyp -> clobj = function - | MTyp tA -> MObj (Root (loc', MMVar ((mV, m_id), LF.id), Nil, `explicit)) + | MTyp tA -> MObj (Root (loc', MMVar ((mV, m_id), LF.id), Nil, Plicity.explicit)) | PTyp tA -> PObj (MPVar ((mV, m_id), LF.id)) | STyp (_, cPhi) -> SObj (MSVar (0, ((mV, m_id), LF.id))) @@ -2404,20 +2414,20 @@ let mmVarToMFront loc' mV = CObj (CtxVar (CInst (mV, m_id))) (** Extends the given meta-substitution with a fresh unification - variable for the contextual declaration (u, cU, dep). + variable for the contextual declaration (u, cU, plicity, inductivity). Returns a meta-object containing the MMVar and the extended substitution. - dotMMVar loc' cD t (u, cU, dep) = (cM, t') if + dotMMVar loc' cD t (u, cU, plicity, inductivity) = (cM, t') if * cD |- [t]cU metatype This function is useful when eliminating PiBoxes via unification. See {!require_decl}. *) -let dotMMVar loc' cD t (u, cU, dep) = +let dotMMVar loc' cD t (u, cU, plicity, inductivity) = let cU = cnormMTyp (cU, t) in - let mO = mmVarToMFront loc' (newMMVar' (Some u) (cD, cU) dep) cU in + let mO = mmVarToMFront loc' (newMMVar' (Some u) (cD, cU) plicity inductivity) cU in ((loc', mO), MDot (mO, t)) (** extend_mctx cD (cdecl, t) = cD' diff --git a/src/core/whnf.mli b/src/core/whnf.mli index c17f3a699..cd712ba44 100644 --- a/src/core/whnf.mli +++ b/src/core/whnf.mli @@ -40,20 +40,21 @@ val convDCtxHat : dctx_hat -> dctx_hat -> bool (* Creating new contextual variables *) (*************************************) -val newMMVar' : Id.name option -> mctx * ctyp -> depend -> mm_var -val newMMVar : Id.name option -> mctx * dctx * typ -> depend -> mm_var -val newMPVar : Id.name option -> mctx * dctx * typ -> depend -> mm_var +val newMMVar' : Id.name option -> mctx * ctyp -> Plicity.t -> Inductivity.t -> mm_var +val newMMVar : Id.name option -> mctx * dctx * typ -> Plicity.t -> Inductivity.t -> mm_var +val newMPVar : Id.name option -> mctx * dctx * typ -> Plicity.t -> Inductivity.t -> mm_var val newMSVar : Id.name option -> mctx (* cD *) * svar_class * dctx (* cPsi *) * dctx (* cPhi *) - -> depend + -> Plicity.t + -> Inductivity.t -> mm_var (* cD ; cPsi |- msvar : cPhi *) -val newMVar : Id.name option -> dctx * typ -> depend -> cvar -val newCVar : Id.name option -> mctx -> Id.cid_schema option -> depend -> ctx_var +val newMVar : Id.name option -> dctx * typ -> Plicity.t -> Inductivity.t -> cvar +val newCVar : Id.name option -> mctx -> Id.cid_schema option -> Plicity.t -> Inductivity.t -> ctx_var val raiseType : dctx -> typ -> typ @@ -61,9 +62,9 @@ val raiseType : dctx -> typ -> typ (* Other operations *) (*************************************) -val etaExpandMV : dctx -> tclo -> Id.name -> sub -> depend -> normal +val etaExpandMV : dctx -> tclo -> Id.name -> sub -> Plicity.t -> Inductivity.t -> normal -val etaExpandMMV : Location.t -> mctx -> dctx -> tclo -> Id.name -> sub -> depend -> normal +val etaExpandMMV : Location.t -> mctx -> dctx -> tclo -> Id.name -> sub -> Plicity.t -> Inductivity.t -> normal exception Fmvar_not_found @@ -123,7 +124,7 @@ val m_invert : msub -> msub val invTerm : normal * msub -> int -> normal *) val mctxLookup : mctx -> int -> Id.name * ctyp -val mctxLookupDep : mctx -> int -> Id.name * ctyp * depend +val mctxLookupDep : mctx -> int -> Id.name * ctyp * Plicity.t * Inductivity.t val mctxMDec : mctx -> int -> Id.name * typ * dctx val mctxPDec : mctx -> int -> Id.name * typ * dctx val mctxSDec : mctx -> int -> Id.name * dctx * svar_class * dctx @@ -233,7 +234,7 @@ val mmVarToClObj : Location.t -> mm_var -> cltyp -> clobj (** Converts an MMVar to a meta object according to its meta type. *) val mmVarToMFront : Location.t -> mm_var -> Comp.meta_typ -> mfront -val dotMMVar : Location.t -> mctx -> msub -> Id.name * ctyp * depend +val dotMMVar : Location.t -> mctx -> msub -> Id.name * ctyp * Plicity.t * Inductivity.t -> Comp.meta_obj * msub val extend_mctx : mctx -> (LF.ctyp_decl * msub ) -> mctx diff --git a/src/harpoon/automation.ml b/src/harpoon/automation.ml index 2c0d96c60..3bc07e61e 100644 --- a/src/harpoon/automation.ml +++ b/src/harpoon/automation.ml @@ -92,20 +92,20 @@ let auto_solve_trivial : t = (P.fmt_ppr_lf_ctyp_decl cD) m end; match m with - | LF.Decl (_, mtyp, _) -> + | LF.Decl (_, mtyp, _, _) -> Whnf.convCTyp g.goal (TypBox (Loc.ghost, mtyp), LF.MShift idx) | LF.DeclOpt _ -> B.Error.violation "[auto_solve_trivial] Unexpected DeclOpt" in let build_mwitness (m : LF.ctyp_decl * int) = match m with - | (LF.Decl (_, (LF.ClTyp (_, _) as cU), _), idx) -> + | (LF.Decl (_, (LF.ClTyp (_, _) as cU), _, _), idx) -> let open LF in let open Loc in let t = LF.MShift idx in let LF.ClTyp (_, cPsi) as cU = Whnf.cnormMTyp (cU, t) in let head = MVar (Offset idx, S.LF.id) in - let clobj = MObj (Root (ghost, head, Nil, `explicit)) in + let clobj = MObj (Root (ghost, head, Nil, B.Plicity.explicit)) in let psi_hat = Context.dctxToHat cPsi in Box ( ghost diff --git a/src/harpoon/prover.ml b/src/harpoon/prover.ml index 2af8f7b19..ac45b4ef1 100644 --- a/src/harpoon/prover.ml +++ b/src/harpoon/prover.ml @@ -84,7 +84,7 @@ module Elab = struct let p (d, _) = Id.equals name (LF.name_of_ctyp_decl d) in match Context.find_with_index_rev' cD p with | None -> Lfrecon.(throw loc (UnboundName name)) - | Some LF.(Decl (_, cT, dep), k) -> + | Some LF.(Decl (_, cT, _, _), k) -> let cT = Whnf.cnormMTyp (cT, LF.MShift k) in dprintf begin fun p -> @@ -186,8 +186,8 @@ let process_command end; Logic.prepare (); let (mquery, skinnyCTyp, mquerySub, instMMVars) = - let (typ',k) = Abstract.comptyp typ in - Logic.Convert.comptypToMQuery (typ',k) + let (typ', k) = Abstract.comptyp typ in + Logic.Convert.comptypToMQuery (typ', k) in try Logic.CSolver.cgSolve cDh cGh mquery diff --git a/src/harpoon/tactic.ml b/src/harpoon/tactic.ml index 29a7aed44..07ac4b0b2 100644 --- a/src/harpoon/tactic.ml +++ b/src/harpoon/tactic.ml @@ -101,9 +101,9 @@ let intros' : Theorem.t -> tau_2 | `duplicate -> Either.Left (DuplicateName (cD, cG, d)) end - | Comp.TypPiBox (_, (LF.Decl (x, cU, dep)), tau_2) -> + | Comp.TypPiBox (_, (LF.Decl (x, cU, plicity, inductivity)), tau_2) -> let x = B.NameGen.renumber active_names x in - let d = LF.Decl (x, cU, dep) in + let d = LF.Decl (x, cU, plicity, inductivity) in go true (x :: active_names) user_names (LF.Dec (cD, d)) cG tau_2 | _ when updated -> Either.Right (cD, cG, tau) | _ -> Either.Left NothingToIntro @@ -586,7 +586,7 @@ let solve_with_new_comp_decl action_name decl f t g = g let solve_by_unbox' f (cT : Comp.meta_typ) (name : B.Id.name) : t = - solve_with_new_meta_decl "unbox" LF.(Decl (name, cT, No)) f + solve_with_new_meta_decl "unbox" LF.(Decl (name, cT, B.Plicity.explicit, B.Inductivity.not_inductive)) f let solve_by_unbox (m : Comp.exp_syn) (mk_cmd : Comp.meta_typ -> Comp.command) (tau : Comp.typ) (name : B.Id.name) modifier : t = let open Comp in diff --git a/src/harpoon/translate.ml b/src/harpoon/translate.ml index 7196399da..d351540c5 100644 --- a/src/harpoon/translate.ml +++ b/src/harpoon/translate.ml @@ -28,11 +28,10 @@ let rec unroll cD cG = function (cD', cG', fun e -> Comp.Fn (Loc.ghost, x, f e)) | Comp.TypPiBox (_, _, tau2) -> let (cD', cG', f) = unroll cD cG tau2 in - let LF.Dec (cD', LF.Decl (x, _, dep)) = cD' in + let LF.Dec (cD', LF.Decl (x, _, plicity, _)) = cD' in ( cD' , cG' - , let plicity = LF.Depend.to_plicity dep in - fun e -> Comp.MLam (Loc.ghost, x, f e, plicity) + , fun e -> Comp.MLam (Loc.ghost, x, f e, plicity) ) | _ -> (cD, cG, fun e -> e) @@ -49,7 +48,7 @@ let unbox cD cG i x cU modifier = p.fmt "[unbox] cU = @[%a@]" P.(fmt_ppr_cmp_meta_typ cD) cU end; - let cD' = LF.(Dec (cD, Decl (x, cU', No))) in + let cD' = LF.(Dec (cD, Decl (x, cU', Plicity.explicit, Inductivity.not_inductive))) in let t = LF.MShift 1 in let pat = Comp.PatMetaObj @@ -63,7 +62,7 @@ let unbox cD cG i x cU modifier = ( Loc.ghost , MVar (Offset 1, s) , Nil - , `explicit + , Plicity.explicit ) in ClObj (Context.dctxToHat (Whnf.cnormDCtx (cPsi, t)), MObj tM)