Skip to content

Commit

Permalink
fix: workaround leanprover/lean4#3827 (#41)
Browse files Browse the repository at this point in the history
Once it lands in a release, the change in leanprover/lean4#3820 to detect accidental do lifting misfires on quotations.
To avoid breakage later, we manually lift out this expression.
  • Loading branch information
eric-wieser authored Apr 2, 2024
1 parent 8023e33 commit d7b8365
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions Qq/Match.lean
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,20 @@ def makeMatchCode {γ : Q(Type)} {m : Q(Type → Type v)} (_instLift : Q(MonadLi
decls.map fun decl => { decl with ty := decl.ty.map fun e => replaceTempExprsByQVars decls e }
let next ← withLocalDeclD (← mkFreshBinderName) (mkIsDefEqType decls) fun fv => do
let fv : Q($(mkIsDefEqType decls)) := fv
-- note: cannot inline into `$body` due to leanprover/lean4#3827
let body ← mkQqLets nextDecls fv do
have pat : Q(Quoted $ty) := replaceTempExprsByQVars decls pat
let (_, s) ← unquoteLCtx.run { mayPostpone := (← read).mayPostpone }
let _discr' ← (unquoteExpr discr).run' s
let _pat' ← (unquoteExpr pat).run' s
withLocalDeclDQ (← mkFreshUserName `match_eq) q(QuotedDefEq $discr $pat) fun h => do
let res ← k expectedType
let res : Q($m $γ) ← instantiateMVars res
let res : Q($m $γ) := (← res.abstractM #[h]).instantiate #[q(⟨⟩ : QuotedDefEq $discr $pat)]
return res
let next : Q($m $γ) :=
q(if $(mkIsDefEqResultVal decls fv) then
$(← mkQqLets nextDecls fv do
have pat : Q(Quoted $ty) := replaceTempExprsByQVars decls pat
let (_, s) ← unquoteLCtx.run { mayPostpone := (← read).mayPostpone }
let _discr' ← (unquoteExpr discr).run' s
let _pat' ← (unquoteExpr pat).run' s
withLocalDeclDQ (← mkFreshUserName `match_eq) q(QuotedDefEq $discr $pat) fun h => do
let res ← k expectedType
let res : Q($m $γ) ← instantiateMVars res
let res : Q($m $γ) := (← res.abstractM #[h]).instantiate #[q(⟨⟩ : QuotedDefEq $discr $pat)]
return res)
$body
else
$alt)
return show Q($(mkIsDefEqType decls) → $m $γ) from
Expand Down

0 comments on commit d7b8365

Please sign in to comment.