@@ -17,6 +17,15 @@ public section
1717
1818namespace Lean.Meta.Match
1919
20+ register_builtin_option backwards.match.rowMajor : Bool := {
21+ defValue := true
22+ group := "bootstrap"
23+ descr := "If true (the default), match compilation will split the discrimnants based \
24+ on position of the first constructor pattern in the first alternative. If false, \
25+ it splits them from left to right, which can lead to unnecessary code bloat."
26+ }
27+
28+
2029private def mkIncorrectNumberOfPatternsMsg [ToMessageData α]
2130 (discrepancyKind : String) (expected actual : Nat) (pats : List α) :=
2231 let patternsMsg := MessageData.joinSep (pats.map toMessageData) ", "
@@ -818,19 +827,20 @@ private partial def process (p : Problem) : StateRefT State MetaM Unit := do
818827 process p
819828 return
820829
821- match firstRefutablePattern p with
822- | some i =>
823- if i > 0 then
824- traceStep ("move var to front" )
825- process (moveToFront p i)
826- return
827- | none =>
828- if 1 < p.alts.length then
829- traceStep ("drop all but first alt" )
830- -- all patterns are irrefutable, we can drop all other alts
831- let p := { p with alts := p.alts.take 1 }
832- process p
833- return
830+ if backwards.match.rowMajor.get (← getOptions) then
831+ match firstRefutablePattern p with
832+ | some i =>
833+ if i > 0 then
834+ traceStep ("move var to front" )
835+ process (moveToFront p i)
836+ return
837+ | none =>
838+ if 1 < p.alts.length then
839+ traceStep ("drop all but first alt" )
840+ -- all patterns are irrefutable, we can drop all other alts
841+ let p := { p with alts := p.alts.take 1 }
842+ process p
843+ return
834844
835845 if (← isNatValueTransition p) then
836846 traceStep ("nat value to constructor" )
0 commit comments