From d589f6a8ede7b790b94e307a4701e7d07ea7b034 Mon Sep 17 00:00:00 2001 From: Sam Tobin-Hochstadt Date: Mon, 26 Oct 2015 09:12:20 -0400 Subject: [PATCH] Avoid problematic reordering of `Or` patterns. This makes two changes to `(or ...)` pattern compilation. * Avoid reordering the individual elements of an `or` pattern. Since this reordering has broken programs with `and` patterns, avoid it here as well. * Avoid re-ordering sets of patterns that _contain_ an `or`. This is not semantically important for match itself, but Typed Racket relies on the previous behavior. Closes racket/typed-racket#150. Merge to 6.3 --- racket/collects/racket/match/compiler.rkt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/racket/collects/racket/match/compiler.rkt b/racket/collects/racket/match/compiler.rkt index 06ce3045c5..1b0204192a 100644 --- a/racket/collects/racket/match/compiler.rkt +++ b/racket/collects/racket/match/compiler.rkt @@ -234,7 +234,8 @@ #f seen)) qs) - #'esc*)]) + #'esc* + #f)]) ;; then compile the rest of the row (if success? #,(compile* xs @@ -242,7 +243,8 @@ (Row-rhs row) (Row-unmatch row) (append (map cons vars vars) seen))) - esc) + esc + #f) (#,esc))))))] ;; the App rule [(App? first) @@ -271,7 +273,6 @@ (define pats (Row-pats row)) ;; all the patterns (define qs (And-ps (car pats))) - (printf ">>> calling compile ~a\n " (append qs (cdr pats))) (compile* (append (map (lambda _ x) qs) xs) (list (make-Row (append qs (cdr pats)) (Row-rhs row) @@ -473,7 +474,10 @@ ;; and compile each block with a reference to its continuation [else (let*-values - ([(rows vars) (if reorder? + ([(rows vars) (if (and (>= 1 (length vars)) + reorder? + ;; moving Or patterns early breaks Typed Racket + (not (ormap Or? (apply append (map Row-pats rows))))) (reorder-columns rows vars) (values rows vars))] [(fns)