[ [ allocation copy-allocation ] dip record-allocation ]
2bi ;
+: copy-values ( from to -- )
+ [ copy-value ] 2each ;
+
: copy-slot-value ( out slot# in -- )
allocation {
{ [ dup not ] [ 3drop ] }
] 2bi ;
M: #recursive escape-analysis* ( #recursive -- )
+ [ label>> return>> in-d>> introduce-values ]
[
- child>>
- [ first out-d>> introduce-values ]
- [ first analyze-recursive-phi ]
- [ (escape-analysis) ]
- tri
- ] until-fixed-point ;
+ [
+ child>>
+ [ first out-d>> introduce-values ]
+ [ first analyze-recursive-phi ]
+ [ (escape-analysis) ]
+ tri
+ ] until-fixed-point
+ ] bi ;
M: #enter-recursive escape-analysis* ( #enter-recursive -- )
#! Handled by #recursive
drop ;
-: return-allocations ( node -- allocations )
- label>> return>> node-input-allocations ;
-
M: #call-recursive escape-analysis* ( #call-label -- )
- [ ] [ return-allocations ] [ node-output-allocations ] tri
- [ check-fixed-point ] [ drop swap out-d>> record-allocations ] 3bi ;
+ [ ] [ label>> return>> ] [ node-output-allocations ] tri
+ [ [ node-input-allocations ] dip check-fixed-point ]
+ [ drop swap [ in-d>> ] [ out-d>> ] bi* copy-values ]
+ 3bi ;
M: #return-recursive escape-analysis* ( #return-recursive -- )
[ call-next-method ]
M: #terminate escape-analysis* drop ;
-M: #renaming escape-analysis* inputs/outputs [ copy-value ] 2each ;
+M: #renaming escape-analysis* inputs/outputs copy-values ;
M: #introduce escape-analysis* out-d>> unknown-allocations ;
H{ } clone rename-map set
dup [ collect-label-info ] each-node
dup count-introductions make-values
- [ (normalize) ] [ nip #introduce ] 2bi prefix
+ [ (normalize) ] [ nip ] 2bi
+ dup empty? [ drop ] [ #introduce prefix ] if
rename-node-values ;
[ bleach-node ] curry [ ] compose impeach-node ; inline recursive
[ ] [ [ [ ] bleach-node ] test-unboxing ] unit-test
+
+TUPLE: box { i read-only } ;
+
+: box-test ( m -- n )
+ dup box-test i>> swap box-test drop box boa ; inline recursive
+
+[ ] [ [ T{ box f 34 } box-test i>> ] test-unboxing ] unit-test
USING: accessors math kernel debugger ;
IN: benchmark.fib4
-TUPLE: box i ;
+TUPLE: box { i read-only } ;
C: <box> box
i>> 1- <box>
tuple-fib
swap i>> swap i>> + <box>
- ] if ;
+ ] if ; inline recursive
-: fib-main ( -- ) T{ box f 34 } tuple-fib T{ box f 9227465 } assert= ;
+: fib-main ( -- ) T{ box f 34 } tuple-fib i>> 9227465 assert= ;
MAIN: fib-main