From 9311ee5f835447538ddd52014fb30b5684b0a4cc Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Fri, 15 Jul 2016 02:55:53 -0400 Subject: [PATCH] Generalized CPS optimization fix --- scheme/cyclone/cps-optimizations.sld | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/scheme/cyclone/cps-optimizations.sld b/scheme/cyclone/cps-optimizations.sld index 9da40a05..5910dfbb 100644 --- a/scheme/cyclone/cps-optimizations.sld +++ b/scheme/cyclone/cps-optimizations.sld @@ -26,6 +26,7 @@ adb:set! adb:get-db simple-lambda? + one-instance-of-new-mutable-obj? ;; Analyze variables adb:make-var %adb:make-var @@ -472,16 +473,14 @@ (every (lambda (arg) (and (prim-call? arg) - (not (prim:cont? (car arg))) - ;; Disallow primitives that allocate a new obj, - ;; because if the object is mutated all copies - ;; must be modified. - ;; - ;; TODO: Technically this could be allowed if - ;; there is only one reference of the variable - ;(not (prim-creates-mutable-obj? (car arg))) - )) + (not (prim:cont? (car arg))))) (cdr exp)) + ;; Disallow primitives that allocate a new obj, + ;; because if the object is mutated all copies + ;; must be modified. + (one-instance-of-new-mutable-obj? + (cdr exp) + (ast:lambda-formals->list (car exp))) (inline-prim-call? (ast:lambda-body (car exp)) (prim-calls->arg-variables (cdr exp)) @@ -546,7 +545,9 @@ ;; only one of the instances will be affected. (if (and (prim-call? call) (prim-creates-mutable-obj? (car call)) - ;; TODO: arg used more than once + ;; Make sure arg is not used more than once + (with-var arg (lambda (var) + (> (adbv:app-arg-count var) 1))) ) (return #f)))) calls/args)