Optimize pair operations, even in the absence of syntactic pair types.
This commit is contained in:
parent
2a4ce892ae
commit
b3bdb40ab7
|
@ -6,7 +6,7 @@
|
|||
(for-syntax racket/base syntax/parse racket/syntax)
|
||||
"../utils/utils.rkt"
|
||||
(rep type-rep)
|
||||
(types type-table utils)
|
||||
(types type-table utils base-abbrev)
|
||||
(typecheck typechecker)
|
||||
(optimizer utils logging))
|
||||
|
||||
|
@ -25,9 +25,11 @@
|
|||
|
||||
|
||||
(define (has-pair-type? e)
|
||||
(match (type-of e) ; type of the operand
|
||||
[(tc-result1: (Pair: _ _)) #t]
|
||||
[_ #f]))
|
||||
(and (subtypeof? e (-pair Univ Univ))
|
||||
;; sometimes composite operations end up with Nothing as result type,
|
||||
;; not sure why. TODO investigate
|
||||
(not (isoftype? e -Bottom))))
|
||||
;; can't do the above for mpairs, as they are invariant
|
||||
(define (has-mpair-type? e)
|
||||
(match (type-of e) ; type of the operand
|
||||
[(tc-result1: (MPair: _ _)) #t]
|
||||
|
|
41
typed-racket-test/optimizer/tests/gh60.rkt
Normal file
41
typed-racket-test/optimizer/tests/gh60.rkt
Normal file
|
@ -0,0 +1,41 @@
|
|||
#;#;
|
||||
#<<END
|
||||
TR opt: gh60.rkt 13:2 (car x) -- pair
|
||||
TR opt: gh60.rkt 20:2 (car x) -- pair
|
||||
TR opt: gh60.rkt 28:6 (car x) -- pair
|
||||
TR opt: gh60.rkt 29:6 (quote error) -- dead else branch
|
||||
TR opt: gh60.rkt 6:2 (car x) -- pair
|
||||
END
|
||||
""
|
||||
|
||||
#lang typed/racket #:optimize
|
||||
#reader typed-racket-test/optimizer/reset-port
|
||||
|
||||
(define-type foo (List Symbol Any))
|
||||
|
||||
(: foo-car (foo . -> . Symbol))
|
||||
(define (foo-car x)
|
||||
(car x))
|
||||
|
||||
|
||||
(define-type bar (List Symbol (U String bar)))
|
||||
|
||||
(: bar-car (bar . -> . Symbol))
|
||||
(define (bar-car x)
|
||||
(car x))
|
||||
|
||||
|
||||
(define-type zam (Rec z (List Symbol (U String z))))
|
||||
|
||||
(: zam-car (zam . -> . Symbol))
|
||||
(define (zam-car x)
|
||||
(car x))
|
||||
|
||||
|
||||
(define-type bar2 (List Symbol (U String bar)))
|
||||
|
||||
(: bar2-car (bar2 . -> . Symbol))
|
||||
(define (bar2-car x)
|
||||
(if (not (null? x))
|
||||
(car x)
|
||||
'error))
|
Loading…
Reference in New Issue
Block a user