mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-09 05:57:34 +02:00
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:
parent
adb703c321
commit
84d9d114dc
1 changed files with 21 additions and 1 deletions
|
@ -1455,7 +1455,14 @@
|
|||
(not (adbv:reassigned? var))
|
||||
(not (adbv:self-rec-call? var))
|
||||
;(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)))
|
||||
|
||||
|
@ -1477,6 +1484,19 @@
|
|||
(scan exp depth)
|
||||
(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
|
||||
(define (beta-expand-app exp rename-lambdas)
|
||||
(let* ((args (cdr exp))
|
||||
|
|
Loading…
Add table
Reference in a new issue