From c733e440d45a644f4b953c51bc64843f7a454e45 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Thu, 14 Jul 2016 23:31:03 -0400 Subject: [PATCH] WIP --- scheme/cyclone/cps-optimizations.sld | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/scheme/cyclone/cps-optimizations.sld b/scheme/cyclone/cps-optimizations.sld index a2913499..252afeec 100644 --- a/scheme/cyclone/cps-optimizations.sld +++ b/scheme/cyclone/cps-optimizations.sld @@ -468,10 +468,19 @@ (not (adbv:reassigned? var)) )))) (ast:lambda-formals->list (car exp))) + ;; Check all args are valid primitives that can be inlined (every (lambda (arg) (and (prim-call? arg) - (not (prim:cont? (car 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))) + )) (cdr exp)) (inline-prim-call? (ast:lambda-body (car exp)) @@ -510,6 +519,16 @@ (else '()))) exps))) + ;; Does the given primitive return a new instance of an object that + ;; can be mutated? + ;; + ;; TODO: strings are a problem because there are + ;; a lot of primitives that allocate them fresh! + (define (prim-creates-mutable-obj? prim) + (member + prim + '(cons make-vector make-bytevector))) + ;; Find variables passed to a primitive (define (prim-call->arg-variables exp) (filter symbol? (cdr exp)))