From ccf8329ffb629cea4cc5801c69d5f57c368ff707 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Thu, 14 Jul 2016 23:54:51 -0400 Subject: [PATCH] WIP --- scheme/cyclone/cps-optimizations.sld | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/scheme/cyclone/cps-optimizations.sld b/scheme/cyclone/cps-optimizations.sld index 252afeec..9da40a05 100644 --- a/scheme/cyclone/cps-optimizations.sld +++ b/scheme/cyclone/cps-optimizations.sld @@ -529,6 +529,29 @@ prim '(cons make-vector make-bytevector))) + ;; Check each pair of primitive call / corresponding lambda arg, + ;; and verify that if the primitive call creates a new mutable + ;; object, that only one instance of the object will be created. + (define (one-instance-of-new-mutable-obj? prim-calls lam-formals) + (let ((calls/args (map list prim-calls lam-formals))) + (call/cc + (lambda (return) + (for-each + (lambda (call/arg) + (let ((call (car call/arg)) + (arg (cadr call/arg))) + ;; Cannot inline prim call if the arg is used + ;; more than once and it creates a new mutable object, + ;; because otherwise if the object is mutated then + ;; 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 + ) + (return #f)))) + calls/args) + #t)))) + ;; Find variables passed to a primitive (define (prim-call->arg-variables exp) (filter symbol? (cdr exp)))