Skip to content

Commit

Permalink
fix: do not introduced additional lets that block match generalization
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-wieser committed Dec 20, 2023
1 parent ccba5d3 commit 1f0a2f7
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Qq/Match.lean
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,14 @@ macro_rules | `(assert! (_comefrom $n do $b); $body) => `(_comefrom $n do $b in
scoped macro "comefrom" n:ident "do" b:doSeq : doElem =>
`(doElem| assert! (_comefrom $n do $b))

def mkLetDoSeqItem [Monad m] [MonadQuotation m] (pat : Term) (rhs : TSyntax `doElem) (alt : TSyntax ``doSeq) : m (List (TSyntax ``doSeqItem)) := do
def mkLetDoSeqItem [Monad m] [MonadQuotation m] (pat : Term) (rhs : TSyntax `term) (alt : TSyntax ``doSeq) : m (List (TSyntax ``doSeqItem)) := do
match pat with
| `(_) => return []
| _ =>
if isIrrefutablePattern pat then
return [← `(doSeqItem| let $pat:term $rhs)]
return [← `(doSeqItem| let $pat:term := $rhs)]
else
return [← `(doSeqItem| let $pat:term $rhs | $alt)]
return [← `(doSeqItem| let $pat:term := $rhs | $alt)]

end Impl

Expand Down Expand Up @@ -335,11 +335,11 @@ private partial def floatExprAntiquot (depth : Nat) : Term → StateT (Array (TS
| stx => return stx

macro_rules
| `(doElem| let $pat:term $_) => do
| `(doElem| let $pat:term := $_) => do
if !hasQMatch pat then Macro.throwUnsupported
Macro.throwError "let-bindings with ~q(.) require an explicit alternative"

| `(doElem| let $pat:term $rhs:doElem | $alt:doSeq) => do
| `(doElem| let $pat:term := $rhs:term | $alt:doSeq) => do
if !hasQMatch pat then Macro.throwUnsupported
match pat with
| `(~q($pat)) =>
Expand All @@ -351,7 +351,7 @@ macro_rules
if id.getId.eraseMacroScopes == `pure then -- TODO: super hacky
return ← `(doSeqItem| assert! (_qq_match $pat ← $rhs | $alt))
| _ => pure ()
`(doSeqItem| do let rhs ← $rhs; assert! (_qq_match $pat ← rhs | $alt)))
`(doSeqItem| do assert! (_qq_match $pat ← $rhs | $alt)))

`(doElem| do $(lifts.push t):doSeqItem*)

Expand Down

0 comments on commit 1f0a2f7

Please sign in to comment.