Make sure that let-bound functions don't escape through a rhs before we change their interface.

original commit: 260de85a6efbc692abaec64d6837a4dfa965cb78
This commit is contained in:
Vincent St-Amour 2010-07-29 13:55:19 -04:00
parent 78a27d2bf9
commit a016db4697
2 changed files with 10 additions and 1 deletions

View File

@ -0,0 +1,7 @@
#lang typed/scheme #:optimize
(require racket/unsafe/ops)
(letrec: ((f : (Inexact-Complex -> Inexact-Complex) (lambda (x) (+ x 2.0+4.0i)))
(g : (Inexact-Complex -> Inexact-Complex) f)) ; f escapes! can't unbox it's args
(f 1.0+2.0i))

View File

@ -46,7 +46,8 @@
(define-syntax-class (unboxed-let-opt-expr-internal let-loop?)
#:literal-sets (kernel-literals)
(pattern (~and exp (letk:let-like-keyword
(clause:expr ...) body:expr ...))
((~and clause (lhs rhs ...)) ...)
body:expr ...))
;; we look for bindings of complexes that are not mutated and only
;; used in positions where we would unbox them
;; these are candidates for unboxing
@ -74,6 +75,7 @@
(and
;; if the function escapes, we can't change it's interface
(not (is-var-mutated? fun-name))
(not (escapes? fun-name #'(begin rhs ... ...) #f))
(not (escapes? fun-name #'(begin body ...) let-loop?))
(match (type-of (cadr p)) ; rhs, we want a lambda
[(tc-result1: (Function: (list (arr: doms rngs