chore: enforce naming convention

This commit is contained in:
Leonardo de Moura 2020-08-13 14:09:00 -07:00
parent 5b1b11ffe0
commit 08f1c2310b
5 changed files with 16 additions and 17 deletions

View file

@ -98,8 +98,8 @@ alts.map mkMatchAltView
def mkInaccessible (e : Expr) : Expr :=
mkAnnotation `_inaccessible e
def isInaccessible? (e : Expr) : Option Expr :=
isAnnotation? `_inaccessible e
def inaccessible? (e : Expr) : Option Expr :=
annotation? `_inaccessible e
inductive PatternVar
| localVar (userName : Name)

View file

@ -486,8 +486,8 @@ pure r
def markDefaultMissing (e : Expr) : Expr :=
mkAnnotation `structInstDefault e
def isDefaultMissing? (e : Expr) : Option Expr :=
isAnnotation? `structInstDefault e
def defaultMissing? (e : Expr) : Option Expr :=
annotation? `structInstDefault e
def throwFailedToElabField {α} (fieldName : Name) (structName : Name) (msgData : MessageData) : TermElabM α :=
throwError ("failed to elaborate field '" ++ fieldName ++ "' of '" ++ structName ++ ", " ++ msgData)
@ -581,7 +581,7 @@ partial def findDefaultMissing? (mctx : MetavarContext) : Struct → Option (Fie
| FieldVal.nested struct => findDefaultMissing? struct
| _ => match field.expr? with
| none => unreachable!
| some expr => match isDefaultMissing? expr with
| some expr => match defaultMissing? expr with
| some (Expr.mvar mvarId _) => if mctx.isExprAssigned mvarId then none else some field
| _ => none
@ -669,7 +669,7 @@ partial def reduce (structNames : Array Name) : Expr → MetaM Expr
pure (mkAppN f' args)
| e@(Expr.mdata _ b _) => do
b ← reduce b;
if (isDefaultMissing? e).isSome && !b.isMVar then
if (defaultMissing? e).isSome && !b.isMVar then
pure b
else
pure $ e.updateMData! b
@ -696,7 +696,7 @@ partial def tryToSynthesizeDefaultAux (structs : Array Struct) (allStructNames :
| none => do setMCtx mctx; tryToSynthesizeDefaultAux (i+1) (dist+1)
| some val => do
val ← liftMetaM $ reduce allStructNames val;
match val.find? $ fun e => (isDefaultMissing? e).isSome with
match val.find? $ fun e => (defaultMissing? e).isSome with
| some _ => do setMCtx mctx; tryToSynthesizeDefaultAux (i+1) (dist+1)
| none => do
mvarDecl ← getMVarDecl mvarId;
@ -718,7 +718,7 @@ partial def step : Struct → M Unit
| FieldVal.nested struct => step struct
| _ => match field.expr? with
| none => unreachable!
| some expr => match isDefaultMissing? expr with
| some expr => match defaultMissing? expr with
| some (Expr.mvar mvarId _) =>
unlessM (liftM $ isExprMVarAssigned mvarId) $ do
ctx ← read;

View file

@ -967,9 +967,9 @@ end Expr
def mkAnnotation (kind : Name) (e : Expr) : Expr :=
mkMData (KVMap.empty.insert kind (DataValue.ofBool true)) e
def isAnnotation? (kind : Name) (e : Expr) : Option Expr :=
def annotation? (kind : Name) (e : Expr) : Option Expr :=
match e with
| Expr.mdata d e _ => if d.size == 1 && d.getBool kind false then some e else none
| Expr.mdata d b _ => if d.size == 1 && d.getBool kind false then some b else none
| _ => none
end Lean

View file

@ -45,19 +45,19 @@ p.app4? `HEq
| Expr.forallE _ α β _ => if β.hasLooseBVars then none else some (α, β)
| _ => none
partial def listLitAux : Expr → List Expr → Option (List Expr)
partial def listLitAux : Expr → List Expr → Option (Expr × List Expr)
| e, acc =>
if e.isAppOfArity `List.nil 1 then
some acc.reverse
some (e.appArg!, acc.reverse)
else if e.isAppOfArity `List.cons 3 then
listLitAux e.appArg! (e.appFn!.appArg! :: acc)
else
none
def listLit? (e : Expr) : Option (List Expr) :=
def listLit? (e : Expr) : Option (Expr × List Expr) :=
listLitAux e []
def arrayLit? (e : Expr) : Option (List Expr) :=
def arrayLit? (e : Expr) : Option (Expr × List Expr) :=
match e.app2? `List.toArray with
| some (_, e) => e.listLit?
| none => none

View file

@ -734,13 +734,12 @@ check t;
t ← mkArrayLit nat [mkNatLit 1, mkNatLit 2];
print t;
check t;
match t.isArrayLit? with
match t.arrayLit? with
| some (_, xs) => do
check $ pure $ xs.size == 2;
match (xs.get! 0).isNatLit?, (xs.get! 1).isNatLit? with
match (xs.get! 0).natLit?, (xs.get! 1).natLit? with
| some 1, some 2 => pure ()
| _, _ => throwOther "nat lits expected"
| none => throwOther "array lit expected"
#eval tst42