Fix for beta expand of functions called once

The problem is an if expression within one of these functions may cause the same continuation to be expanded twice, introducing duplicate lambda defintions and identifiers. For now we are not going to beta expand such functions during the contraction phase.
This commit is contained in:
Justin Ethier 2019-01-10 12:52:03 -05:00
parent adb703c321
commit 84d9d114dc

View file

@ -1455,7 +1455,14 @@
(not (adbv:reassigned? var)) (not (adbv:reassigned? var))
(not (adbv:self-rec-call? var)) (not (adbv:self-rec-call? var))
;(not (fnc-depth>? (ast:lambda-body fnc) 4)))) ;(not (fnc-depth>? (ast:lambda-body fnc) 4))))
(not (fnc-depth>? (ast:lambda-body fnc) 5)))) (not (fnc-depth>? (ast:lambda-body fnc) 5))
;; Issue here is we can run into code that calls the
;; same continuation from both if branches. In this
;; case we do not want to beta-expand as a contraction
;; because duplicate instances of the same code may be
;; introduced, causing problems downstream.
(not (contains-if? (ast:lambda-body fnc)))
))
))) )))
(else #f))) (else #f)))
@ -1477,6 +1484,19 @@
(scan exp depth) (scan exp depth)
(return #f)))) (return #f))))
(define (contains-if? exp)
(call/cc
(lambda (return)
(define (scan exp)
(cond
((ast:lambda? exp) (scan (ast:lambda-body exp)))
((quote? exp) #f)
((if? exp) (return #t))
((app? exp) (for-each scan exp))
(else #f)))
(scan exp)
(return #f))))
;; Check app and beta expand if possible, else just return given code ;; Check app and beta expand if possible, else just return given code
(define (beta-expand-app exp rename-lambdas) (define (beta-expand-app exp rename-lambdas)
(let* ((args (cdr exp)) (let* ((args (cdr exp))