Add #:literal-sets for several TR optimizer cases
The matching was too inclusive in some cases, causing spurious optimizations (or type-table lookup failures). Closes PR 14380
This commit is contained in:
parent
4d3baa3b7d
commit
07bde5063b
|
@ -18,6 +18,7 @@
|
|||
|
||||
(define-syntax-class box-opt-expr
|
||||
#:commit
|
||||
#:literal-sets (kernel-literals)
|
||||
(pattern (#%plain-app op:box-op b:opt-expr new:opt-expr ...)
|
||||
#:do [(log-opt "box" "Box check elimination.")]
|
||||
#:with opt #`(op.unsafe b.opt new.opt ...)))
|
||||
|
|
|
@ -364,6 +364,7 @@
|
|||
(define-syntax-class float-complex-opt-expr
|
||||
#:commit
|
||||
#:attributes (opt)
|
||||
#:literal-sets (kernel-literals)
|
||||
;; Dummy pattern that can't actually match.
|
||||
;; We just want to detect "unexpected" Complex _types_ that come up.
|
||||
;; (not necessarily complex _values_, in fact, most of the time this
|
||||
|
@ -418,6 +419,7 @@
|
|||
(define-syntax-class (float-complex-arith-expr* optimizing)
|
||||
#:commit
|
||||
#:attributes (opt)
|
||||
#:literal-sets (kernel-literals)
|
||||
|
||||
;; we can optimize taking the real of imag part of an unboxed complex
|
||||
;; hopefully, the compiler can eliminate unused bindings for the other part if it's not used
|
||||
|
|
|
@ -65,6 +65,7 @@
|
|||
(define-syntax-class float-arg-expr
|
||||
#:commit
|
||||
#:attributes (opt)
|
||||
#:literal-sets (kernel-literals)
|
||||
;; we can convert literals right away
|
||||
(pattern (quote n)
|
||||
#:when (and (real? (syntax->datum #'n))
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
(define-syntax-class list-opt-expr
|
||||
#:commit
|
||||
#:literal-sets (kernel-literals)
|
||||
;; Similar to known-length vectors opts.
|
||||
;; If we use `list-ref' or `list-tail' on a known-length list with a
|
||||
;; literal index, we can optimize if the index is within bounds.
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
(define-syntax-class number-opt-expr
|
||||
#:commit
|
||||
#:literal-sets (kernel-literals)
|
||||
;; these cases are all identity
|
||||
(pattern (#%plain-app op:unary-op f:opt-expr)
|
||||
#:do [(log-opt "unary number" "Identity elimination.")]
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
(not (subtypeof? t -Real))))
|
||||
|
||||
(define-syntax-class arith-expr
|
||||
#:literal-sets (kernel-literals)
|
||||
(pattern (#%plain-app op:arith-op args ...)))
|
||||
(define-syntax-class arith-op
|
||||
(pattern
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
(define-syntax-class pair-opt-expr
|
||||
#:commit
|
||||
#:attributes (opt)
|
||||
#:literal-sets (kernel-literals)
|
||||
|
||||
;; no logging here, redundant with actual pair opt
|
||||
(pattern :pair-derived-opt-expr)
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
|
||||
(define-syntax-class sequence-opt-expr
|
||||
#:commit
|
||||
#:literal-sets (kernel-literals)
|
||||
;; if we're iterating (with the for macros) over something we know is a list,
|
||||
;; we can generate code that would be similar to if in-list had been used
|
||||
(pattern (#%plain-app op:make-sequence _ l:list-expr)
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
(define-syntax-class string-opt-expr
|
||||
#:commit
|
||||
#:literal-sets (kernel-literals)
|
||||
(pattern (#%plain-app op:string-length^ s:opt-expr)
|
||||
#:do [(log-opt "string-length" "String check elimination.")]
|
||||
#:with opt #'(op.unsafe s.opt))
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
(define-syntax-class struct-opt-expr
|
||||
#:commit
|
||||
#:literal-sets (kernel-literals)
|
||||
;; we can always optimize struct accessors and mutators
|
||||
;; if they typecheck, they're safe
|
||||
(pattern (#%plain-app op:struct-op s:opt-expr v:opt-expr ...)
|
||||
|
|
|
@ -259,6 +259,7 @@
|
|||
(define-syntax-class unbox-fun-clause
|
||||
#:commit
|
||||
#:attributes ([bindings 1])
|
||||
#:literal-sets (kernel-literals)
|
||||
(pattern ((fun:unboxed-fun) (#%plain-lambda params body:opt-expr ...))
|
||||
#:with (real-params ...)
|
||||
(stx-map (lambda (x) (generate-temporary "unboxed-real-")) #'(fun.unboxed ...))
|
||||
|
|
|
@ -52,6 +52,16 @@
|
|||
(eval `(#%top-interaction .
|
||||
,(syntax->datum #'form)) (get-ns f.fresh))))))]))
|
||||
|
||||
(define-syntax (test-form-not-exn stx)
|
||||
(syntax-parse stx
|
||||
[(_ f:fresh-kw form:expr)
|
||||
(quasisyntax/loc stx
|
||||
(test-case #,(~a (syntax->datum #'form))
|
||||
(check-not-exn
|
||||
(lambda ()
|
||||
(eval `(#%top-interaction .
|
||||
,(syntax->datum #'form)) (get-ns f.fresh))))))]))
|
||||
|
||||
(define-syntax (test-form stx)
|
||||
(syntax-parse stx
|
||||
[(_ f:fresh-kw (~seq regexp:expr form:expr) ...)
|
||||
|
@ -90,6 +100,9 @@
|
|||
(test-form #rx"^$"
|
||||
(struct foo ()))
|
||||
|
||||
;; PR 14380
|
||||
(test-form-not-exn (begin - (void)))
|
||||
|
||||
(test-form #rx"1"
|
||||
(:type 1))
|
||||
(test-form (regexp-quote "(U Positive-Byte Zero)")
|
||||
|
|
Loading…
Reference in New Issue
Block a user