mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-15 16:57:35 +02:00
Store scopes in mutated-indirectly field
This commit is contained in:
parent
3065eae9a4
commit
11f3963864
1 changed files with 26 additions and 27 deletions
|
@ -105,7 +105,6 @@
|
||||||
(define-record-type <analysis-db-variable>
|
(define-record-type <analysis-db-variable>
|
||||||
(%adb:make-var
|
(%adb:make-var
|
||||||
global
|
global
|
||||||
;; TODO: defined-in-sym
|
|
||||||
defined-by
|
defined-by
|
||||||
defines-lambda-id
|
defines-lambda-id
|
||||||
const const-value
|
const const-value
|
||||||
|
@ -121,11 +120,6 @@
|
||||||
)
|
)
|
||||||
adb:variable?
|
adb:variable?
|
||||||
(global adbv:global? adbv:set-global!)
|
(global adbv:global? adbv:set-global!)
|
||||||
;; TODO: Symbol of the top-level define the variable is defined in, or *top-level-sym* (??) if
|
|
||||||
;; variable is defined at the top level.
|
|
||||||
;; TODO: defined-in-sym
|
|
||||||
;; TODO: once this is in place, populate it when mutating indirectly (will need to contain a list of these)
|
|
||||||
;; and use it when checking the value of mutated-indirectly
|
|
||||||
(defined-by adbv:defined-by adbv:set-defined-by!)
|
(defined-by adbv:defined-by adbv:set-defined-by!)
|
||||||
(defines-lambda-id adbv:defines-lambda-id adbv:set-defines-lambda-id!)
|
(defines-lambda-id adbv:defines-lambda-id adbv:set-defines-lambda-id!)
|
||||||
(const adbv:const? adbv:set-const!)
|
(const adbv:const? adbv:set-const!)
|
||||||
|
@ -144,7 +138,7 @@
|
||||||
;; Can a ref be safely inlined?
|
;; Can a ref be safely inlined?
|
||||||
(inlinable adbv:inlinable adbv:set-inlinable!)
|
(inlinable adbv:inlinable adbv:set-inlinable!)
|
||||||
;; Is the variable mutated indirectly? (EG: set-car! of a cdr)
|
;; Is the variable mutated indirectly? (EG: set-car! of a cdr)
|
||||||
(mutated-indirectly adbv:mutated-indirectly? adbv:set-mutated-indirectly!)
|
(mutated-indirectly adbv:mutated-indirectly adbv:set-mutated-indirectly!)
|
||||||
(cont adbv:cont? adbv:set-cont!)
|
(cont adbv:cont? adbv:set-cont!)
|
||||||
;; Following two indicate if a variable is defined/referenced in a loop
|
;; Following two indicate if a variable is defined/referenced in a loop
|
||||||
(def-in-loop adbv:def-in-loop? adbv:set-def-in-loop!)
|
(def-in-loop adbv:def-in-loop? adbv:set-def-in-loop!)
|
||||||
|
@ -194,7 +188,7 @@
|
||||||
0 ; app-fnc-count
|
0 ; app-fnc-count
|
||||||
0 ; app-arg-count
|
0 ; app-arg-count
|
||||||
#t ; inlinable
|
#t ; inlinable
|
||||||
#f ; mutated-indirectly
|
'() ; mutated-indirectly
|
||||||
#f ; cont
|
#f ; cont
|
||||||
#f ; def-in-loop
|
#f ; def-in-loop
|
||||||
#f ; ref-in-loop
|
#f ; ref-in-loop
|
||||||
|
@ -458,8 +452,8 @@
|
||||||
|
|
||||||
;; TODO: check app for const/const-value, also (for now) reset them
|
;; TODO: check app for const/const-value, also (for now) reset them
|
||||||
;; if the variable is modified via set/define
|
;; if the variable is modified via set/define
|
||||||
(define (analyze exp lid)
|
(define (analyze exp scope-sym lid)
|
||||||
;(trace:error `(analyze ,lid ,exp ,(app? exp)))
|
;(trace:error `(analyze ,scope-sym ,lid ,exp ,(app? exp)))
|
||||||
(cond
|
(cond
|
||||||
; Core forms:
|
; Core forms:
|
||||||
((ast:lambda? exp)
|
((ast:lambda? exp)
|
||||||
|
@ -479,7 +473,7 @@
|
||||||
(ast:lambda-formals->list exp))
|
(ast:lambda-formals->list exp))
|
||||||
(for-each
|
(for-each
|
||||||
(lambda (expr)
|
(lambda (expr)
|
||||||
(analyze expr id))
|
(analyze expr scope-sym id))
|
||||||
(ast:lambda-body exp))))
|
(ast:lambda-body exp))))
|
||||||
((const? exp) #f)
|
((const? exp) #f)
|
||||||
((quote? exp) #f)
|
((quote? exp) #f)
|
||||||
|
@ -497,7 +491,7 @@
|
||||||
(adbv-set-assigned-value-helper! (define->var exp) var (define->exp exp))
|
(adbv-set-assigned-value-helper! (define->var exp) var (define->exp exp))
|
||||||
(adbv:set-const! var #f)
|
(adbv:set-const! var #f)
|
||||||
(adbv:set-const-value! var #f)))
|
(adbv:set-const-value! var #f)))
|
||||||
(analyze (define->exp exp) lid))
|
(analyze (define->exp exp) (define->var exp) lid))
|
||||||
((set!? exp)
|
((set!? exp)
|
||||||
;(let ((var (adb:get/default (set!->var exp) (adb:make-var))))
|
;(let ((var (adb:get/default (set!->var exp) (adb:make-var))))
|
||||||
(with-var! (set!->var exp) (lambda (var)
|
(with-var! (set!->var exp) (lambda (var)
|
||||||
|
@ -508,10 +502,10 @@
|
||||||
(adbv:set-ref-by! var (cons lid (adbv:ref-by var)))
|
(adbv:set-ref-by! var (cons lid (adbv:ref-by var)))
|
||||||
(adbv:set-const! var #f)
|
(adbv:set-const! var #f)
|
||||||
(adbv:set-const-value! var #f)))
|
(adbv:set-const-value! var #f)))
|
||||||
(analyze (set!->exp exp) lid))
|
(analyze (set!->exp exp) scope-sym lid))
|
||||||
((if? exp) `(if ,(analyze (if->condition exp) lid)
|
((if? exp) `(if ,(analyze (if->condition exp) scope-sym lid)
|
||||||
,(analyze (if->then exp) lid)
|
,(analyze (if->then exp) scope-sym lid)
|
||||||
,(analyze (if->else exp) lid)))
|
,(analyze (if->else exp) scope-sym lid)))
|
||||||
|
|
||||||
; Application:
|
; Application:
|
||||||
((app? exp)
|
((app? exp)
|
||||||
|
@ -535,7 +529,7 @@
|
||||||
(if (adbv:assigned-value var)
|
(if (adbv:assigned-value var)
|
||||||
(set! e (adbv:assigned-value var))))))
|
(set! e (adbv:assigned-value var))))))
|
||||||
;(trace:error `(find-indirect-mutations ,e))
|
;(trace:error `(find-indirect-mutations ,e))
|
||||||
(find-indirect-mutations e))))
|
(find-indirect-mutations e scope-sym))))
|
||||||
|
|
||||||
;; TODO: if ast-lambda (car),
|
;; TODO: if ast-lambda (car),
|
||||||
;; for each arg
|
;; for each arg
|
||||||
|
@ -561,7 +555,7 @@
|
||||||
(app->args exp)))))
|
(app->args exp)))))
|
||||||
(for-each
|
(for-each
|
||||||
(lambda (e)
|
(lambda (e)
|
||||||
(analyze e lid))
|
(analyze e scope-sym lid))
|
||||||
exp))
|
exp))
|
||||||
;TODO ((app? exp) (map (lambda (e) (wrap-mutables e globals)) exp))
|
;TODO ((app? exp) (map (lambda (e) (wrap-mutables e globals)) exp))
|
||||||
|
|
||||||
|
@ -608,7 +602,7 @@
|
||||||
(for-each (lambda (e) (analyze2 e)) exp))
|
(for-each (lambda (e) (analyze2 e)) exp))
|
||||||
(else #f)))
|
(else #f)))
|
||||||
|
|
||||||
(define (find-indirect-mutations exp)
|
(define (find-indirect-mutations exp scope-sym)
|
||||||
(cond
|
(cond
|
||||||
; Core forms:
|
; Core forms:
|
||||||
;((ast:lambda? exp)
|
;((ast:lambda? exp)
|
||||||
|
@ -623,19 +617,24 @@
|
||||||
((quote? exp) #f)
|
((quote? exp) #f)
|
||||||
((ref? exp)
|
((ref? exp)
|
||||||
(with-var! exp (lambda (var)
|
(with-var! exp (lambda (var)
|
||||||
(adbv:set-mutated-indirectly! var #t))))
|
(adbv:set-mutated-indirectly!
|
||||||
|
var
|
||||||
|
(cons scope-sym (adbv:mutated-indirectly var))))))
|
||||||
;((define? exp)
|
;((define? exp)
|
||||||
; ;(let ((var (adb:get/default (define->var exp) (adb:make-var))))
|
; ;(let ((var (adb:get/default (define->var exp) (adb:make-var))))
|
||||||
; (analyze2 (define->exp exp)))
|
; (analyze2 (define->exp exp)))
|
||||||
;((set!? exp)
|
;((set!? exp)
|
||||||
; ;(let ((var (adb:get/default (set!->var exp) (adb:make-var))))
|
; ;(let ((var (adb:get/default (set!->var exp) (adb:make-var))))
|
||||||
; (analyze2 (set!->exp exp)))
|
; (analyze2 (set!->exp exp)))
|
||||||
((if? exp) `(if ,(find-indirect-mutations (if->condition exp))
|
((if? exp) `(if ,(find-indirect-mutations (if->condition exp) scope-sym)
|
||||||
,(find-indirect-mutations (if->then exp))
|
,(find-indirect-mutations (if->then exp) scope-sym)
|
||||||
,(find-indirect-mutations (if->else exp))))
|
,(find-indirect-mutations (if->else exp) scope-sym)))
|
||||||
; Application:
|
; Application:
|
||||||
((app? exp)
|
((app? exp)
|
||||||
(for-each find-indirect-mutations (cdr exp)))
|
(for-each
|
||||||
|
(lambda (e)
|
||||||
|
(find-indirect-mutations e scope-sym))
|
||||||
|
(cdr exp)))
|
||||||
(else #f)))
|
(else #f)))
|
||||||
|
|
||||||
;; TODO: make another pass for simple lambda's
|
;; TODO: make another pass for simple lambda's
|
||||||
|
@ -1127,8 +1126,8 @@
|
||||||
(for-each
|
(for-each
|
||||||
(lambda (v)
|
(lambda (v)
|
||||||
(with-var v (lambda (var)
|
(with-var v (lambda (var)
|
||||||
(if (adbv:mutated-indirectly? var)
|
;(if (adbv:mutated-indirectly var)
|
||||||
(set! cannot-inline #t))
|
; (set! cannot-inline #t))
|
||||||
(if (not (adbv:inlinable var))
|
(if (not (adbv:inlinable var))
|
||||||
(set! fast-inline #f)))))
|
(set! fast-inline #f)))))
|
||||||
ivars)
|
ivars)
|
||||||
|
@ -1518,7 +1517,7 @@
|
||||||
(analyze-find-lambdas exp -1)
|
(analyze-find-lambdas exp -1)
|
||||||
(analyze-lambda-side-effects exp -1)
|
(analyze-lambda-side-effects exp -1)
|
||||||
(analyze-lambda-side-effects exp -1) ;; 2nd pass guarantees lambda purity
|
(analyze-lambda-side-effects exp -1) ;; 2nd pass guarantees lambda purity
|
||||||
(analyze exp -1) ;; Top-level is lambda ID -1
|
(analyze exp -1 -1) ;; Top-level is lambda ID -1
|
||||||
(analyze2 exp) ;; Second pass
|
(analyze2 exp) ;; Second pass
|
||||||
(analyze:find-inlinable-vars exp '()) ;; Identify variables safe to inline
|
(analyze:find-inlinable-vars exp '()) ;; Identify variables safe to inline
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue