1 IN: compiler.tree.escape-analysis.tests
2 USING: compiler.tree.escape-analysis
3 compiler.tree.escape-analysis.allocations compiler.tree.builder
4 compiler.tree.recursive compiler.tree.normalization
5 math.functions compiler.tree.propagation compiler.tree.cleanup
6 compiler.tree.combinators compiler.tree sequences math
7 math.private kernel tools.test accessors slots.private
8 quotations.private prettyprint classes.tuple.private classes
9 classes.tuple namespaces
10 compiler.tree.propagation.info stack-checker.errors
14 GENERIC: count-unboxed-allocations* ( m node -- n )
16 : (count-unboxed-allocations) ( m node -- n )
17 out-d>> first escaping-allocation? [ 1+ ] unless ;
19 M: #call count-unboxed-allocations*
20 dup immutable-tuple-boa?
21 [ (count-unboxed-allocations) ] [ drop ] if ;
23 M: #push count-unboxed-allocations*
24 dup literal>> class immutable-tuple-class?
25 [ (count-unboxed-allocations) ] [ drop ] if ;
27 M: node count-unboxed-allocations* drop ;
29 : count-unboxed-allocations ( quot -- sizes )
37 0 swap [ count-unboxed-allocations* ] each-node ;
39 [ 0 ] [ [ [ + ] curry ] count-unboxed-allocations ] unit-test
41 [ 1 ] [ [ [ + ] curry drop ] count-unboxed-allocations ] unit-test
43 [ 1 ] [ [ [ + ] curry 3 slot ] count-unboxed-allocations ] unit-test
45 [ 1 ] [ [ [ + ] curry 3 slot drop ] count-unboxed-allocations ] unit-test
47 [ 1 ] [ [ [ + ] curry uncurry ] count-unboxed-allocations ] unit-test
49 [ 1 ] [ [ [ + ] curry call ] count-unboxed-allocations ] unit-test
51 [ 1 ] [ [ [ + ] curry call ] count-unboxed-allocations ] unit-test
53 [ 0 ] [ [ [ [ + ] curry ] [ drop [ ] ] if ] count-unboxed-allocations ] unit-test
56 [ [ [ + ] curry ] [ [ * ] curry ] if uncurry ] count-unboxed-allocations
60 [ [ [ + ] curry ] [ [ * ] curry ] if ] count-unboxed-allocations
64 [ [ [ + ] curry ] [ dup [ [ * ] curry ] [ [ / ] curry ] if ] if uncurry ] count-unboxed-allocations
68 [ [ [ + ] curry 4 ] [ dup [ [ * ] curry ] [ [ / ] curry ] if uncurry ] if ] count-unboxed-allocations
72 [ [ [ + ] curry ] [ dup [ [ * ] curry ] [ [ / ] curry ] if ] if ] count-unboxed-allocations
75 TUPLE: cons { car read-only } { cdr read-only } ;
86 ] count-unboxed-allocations
100 ] count-unboxed-allocations
112 ] count-unboxed-allocations
126 ] count-unboxed-allocations
140 ] count-unboxed-allocations
145 [ dup cons boa ] [ drop 1 2 cons boa ] if car>>
146 ] count-unboxed-allocations
152 [ cons boa ] [ cons boa 3 cons boa ] if
153 [ car>> ] [ cdr>> ] bi
154 ] count-unboxed-allocations
159 3dup [ cons boa ] [ cons boa . 1 2 cons boa ] if
160 [ car>> ] [ cdr>> ] bi
161 ] count-unboxed-allocations
165 [ [ 3 cons boa ] [ "A" throw ] if car>> ]
166 count-unboxed-allocations
170 [ 10 [ drop ] each-integer ] count-unboxed-allocations
175 1 2 cons boa 10 [ 2drop 1 2 cons boa ] each-integer car>>
176 ] count-unboxed-allocations
181 1 2 cons boa 10 [ drop 2 cons boa ] each-integer car>>
182 ] count-unboxed-allocations
185 : infinite-cons-loop ( a -- b ) 2 cons boa infinite-cons-loop ; inline recursive
189 1 2 cons boa infinite-cons-loop
190 ] count-unboxed-allocations
197 [ 0 ] [ [ <rw-box> i>> ] count-unboxed-allocations ] unit-test
199 : fake-fib ( m -- n )
200 dup i>> 1 <= [ drop 1 <rw-box> ] when ; inline recursive
202 [ 0 ] [ [ <rw-box> fake-fib i>> ] count-unboxed-allocations ] unit-test
204 TUPLE: ro-box { i read-only } ;
208 : tuple-fib ( m -- n )
217 swap i>> swap i>> + <ro-box>
218 ] if ; inline recursive
220 [ 5 ] [ [ <ro-box> tuple-fib i>> ] count-unboxed-allocations ] unit-test
222 [ 3 ] [ [ <ro-box> tuple-fib ] count-unboxed-allocations ] unit-test
224 : tuple-fib' ( m -- n )
225 dup 1 <= [ 1- tuple-fib' i>> ] when <ro-box> ; inline recursive
227 [ 0 ] [ [ tuple-fib' ] count-unboxed-allocations ] unit-test
229 : bad-tuple-fib-1 ( m -- n )
237 bad-tuple-fib-1 dup .
238 swap i>> swap i>> + <ro-box>
239 ] if ; inline recursive
241 [ 3 ] [ [ <ro-box> bad-tuple-fib-1 i>> ] count-unboxed-allocations ] unit-test
243 : bad-tuple-fib-2 ( m -- n )
253 swap i>> swap i>> + <ro-box>
254 ] if ; inline recursive
256 [ 2 ] [ [ <ro-box> bad-tuple-fib-2 i>> ] count-unboxed-allocations ] unit-test
258 : tuple-fib-2 ( m -- n )
265 swap i>> swap i>> + <ro-box>
266 ] if ; inline recursive
268 [ 2 ] [ [ tuple-fib-2 i>> ] count-unboxed-allocations ] unit-test
270 : tuple-fib-3 ( m -- n )
277 swap i>> swap i>> + <ro-box>
278 ] if ; inline recursive
280 [ 0 ] [ [ tuple-fib-3 i>> ] count-unboxed-allocations ] unit-test
282 : bad-tuple-fib-3 ( m -- n )
286 1- dup bad-tuple-fib-3
290 ] if ; inline recursive
292 [ 0 ] [ [ bad-tuple-fib-3 i>> ] count-unboxed-allocations ] unit-test
294 [ 1 ] [ [ complex boa >rect ] count-unboxed-allocations ] unit-test
296 [ 0 ] [ [ 1 cons boa 2 cons boa ] count-unboxed-allocations ] unit-test
298 [ 1 ] [ [ 1 cons boa 2 cons boa car>> ] count-unboxed-allocations ] unit-test
300 [ 0 ] [ [ 1 cons boa 2 cons boa dup . car>> ] count-unboxed-allocations ] unit-test
302 [ 0 ] [ [ 1 cons boa "x" get slot ] count-unboxed-allocations ] unit-test
304 : impeach-node ( quot: ( node -- ) -- )
305 [ call ] keep impeach-node ; inline recursive
307 : bleach-node ( quot: ( node -- ) -- )
308 [ bleach-node ] curry [ ] compose impeach-node ; inline recursive
310 [ 3 ] [ [ [ ] bleach-node ] count-unboxed-allocations ] unit-test
313 [ dup -1 over >= [ 0 >= [ "A" throw ] unless ] [ drop ] if ]
314 count-unboxed-allocations
318 [ \ too-many->r boa f f \ inference-error boa ]
319 count-unboxed-allocations
323 [ { null } declare [ 1 ] [ 2 ] if ] count-unboxed-allocations