feat: special support for 'fun x => x'
This commit is contained in:
parent
811bb56d10
commit
eed0fb6635
2 changed files with 22 additions and 0 deletions
|
|
@ -54,6 +54,12 @@ register_builtin_option pp.analyze.trustOfNat : Bool := {
|
|||
descr := "(pretty printer analyzer) always 'pretend' `OfNat.ofNat` applications can elab bottom-up"
|
||||
}
|
||||
|
||||
register_builtin_option pp.analyze.trustId : Bool := {
|
||||
defValue := true
|
||||
group := "pp.analyze"
|
||||
descr := "(pretty printer analyzer) always assume an implicit `fun x => x` can be inferred"
|
||||
}
|
||||
|
||||
register_builtin_option pp.analyze.trustKnownFOType2TypeHOFuns : Bool := {
|
||||
defValue := true
|
||||
group := "pp.analyze"
|
||||
|
|
@ -65,6 +71,7 @@ def getPPAnalyzeCheckInstances (o : Options) : Bool := o.get pp.ana
|
|||
def getPPAnalyzeTypeAscriptions (o : Options) : Bool := o.get pp.analyze.typeAscriptions.name pp.analyze.typeAscriptions.defValue
|
||||
def getPPAnalyzeTrustSubst (o : Options) : Bool := o.get pp.analyze.trustSubst.name pp.analyze.trustSubst.defValue
|
||||
def getPPAnalyzeTrustOfNat (o : Options) : Bool := o.get pp.analyze.trustOfNat.name pp.analyze.trustOfNat.defValue
|
||||
def getPPAnalyzeTrustId (o : Options) : Bool := o.get pp.analyze.trustId.name pp.analyze.trustId.defValue
|
||||
def getPPAnalyzeTrustKnownFOType2TypeHOFuns (o : Options) : Bool := o.get pp.analyze.trustKnownFOType2TypeHOFuns.name pp.analyze.trustKnownFOType2TypeHOFuns.defValue
|
||||
|
||||
def getPPAnalysisSkip (o : Options) : Bool := o.get `pp.analysis.skip false
|
||||
|
|
@ -96,6 +103,12 @@ def isFOLike (motive : Expr) : MetaM Bool := do
|
|||
let f := motive.getAppFn
|
||||
f.isFVar || f.isConst
|
||||
|
||||
def isIdLike (arg : Expr) : Bool := do
|
||||
-- TODO: allow `id` constant as well?
|
||||
match arg with
|
||||
| Expr.lam _ _ (Expr.bvar ..) .. => true
|
||||
| _ => false
|
||||
|
||||
namespace TopDownAnalyze
|
||||
|
||||
def replaceLPsWithVars (e : Expr) : MetaM Expr := do
|
||||
|
|
@ -290,6 +303,7 @@ where
|
|||
for i in [:args.size] do
|
||||
if not (← bInfos[i] == BinderInfo.implicit) then continue
|
||||
if not (← isHigherOrder (← inferType args[i])) then continue
|
||||
if getPPAnalyzeTrustId (← getOptions) && isIdLike args[i] then continue
|
||||
|
||||
if getPPAnalyzeTrustKnownFOType2TypeHOFuns (← getOptions) && not (← valUnknown mvars[i])
|
||||
&& (← isType2Type (args[i])) && (← isFOLike (args[i])) then continue
|
||||
|
|
|
|||
|
|
@ -185,6 +185,14 @@ set_option pp.analyze.trustSubst true in
|
|||
#testDelab (fun (x y z : Nat) (hxy : x = y) (hyz : x = z) => hxy ▸ hyz : ∀ (x y z : Nat), x = y → x = z → y = z)
|
||||
expecting fun x y z hxy hyz => hxy ▸ hyz
|
||||
|
||||
set_option pp.analyze.trustId true in
|
||||
#testDelab Sigma.mk (β := fun α => α) Bool true
|
||||
expecting { fst := Bool, snd := true : Sigma fun α => α }
|
||||
|
||||
set_option pp.analyze.trustId false in
|
||||
#testDelab Sigma.mk (β := fun α => α) Bool true
|
||||
expecting Sigma.mk (β := fun α => α) Bool true
|
||||
|
||||
#testDelab let xs := #[true]; xs
|
||||
expecting let xs := #[true]; xs
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue