]> gitweb.factorcode.org Git - factor.git/blob - extra/tools/image-analyzer/gc-info/gc-info-tests.factor
compiler.*: Remove the scrubbing part of the GC maps
[factor.git] / extra / tools / image-analyzer / gc-info / gc-info-tests.factor
1 USING: accessors alien.c-types alien.syntax arrays assocs bit-arrays
2 classes.struct combinators combinators.short-circuit compiler compiler.cfg
3 compiler.cfg.debugger compiler.cfg.instructions compiler.cfg.linearization
4 compiler.cfg.stack-frame compiler.codegen.gc-maps compiler.units fry generic
5 grouping io io.encodings.binary io.streams.byte-array kernel math namespaces
6 random sequences sequences.generalizations
7 tools.image-analyzer.gc-info tools.image-analyzer.utils tools.test vm
8 vocabs words ;
9 IN: tools.image-analyzer.gc-info.tests
10 QUALIFIED: cpu.x86.features.private
11 QUALIFIED: crypto.aes.utils
12 QUALIFIED: effects
13 QUALIFIED: gtk-samples.opengl
14 QUALIFIED: opencl
15
16 : normal? ( word -- ? )
17     { [ generic? ] [ primitive? ] [ inline? ] [ no-compile? ] } 1|| not ;
18
19 : word>gc-info ( word -- gc-info )
20     word>byte-array binary <byte-reader> <backwards-reader> [
21         gc-info read-struct-safe
22     ] with-input-stream ;
23
24 : cfg>gc-maps ( cfg -- gc-maps )
25     cfg>insns [ gc-map-insn? ] filter [ gc-map>> ] map
26     [ gc-map-needed? ] filter ;
27
28 : tally-gc-maps ( gc-maps -- seq/f )
29     [ f ] [
30         [ [ gc-root-offsets ] map largest-spill-slot ]
31         [ [ derived-root-offsets ] map [ keys ] map largest-spill-slot ]
32         [ length ] tri 3array
33     ] if-empty ;
34
35 ! Like word>gc-info but uses the compiler
36 : word>gc-info-expected ( word -- seq/f )
37     test-regs first [ cfg set ] [ cfg>gc-maps tally-gc-maps ] bi ;
38
39 ! Handle f f as input. Deferred words don't have any gc-info. See #1394.
40 : same-gc-info? ( compiler-gc-info/f gc-info/f -- ? )
41     2dup = [
42         2drop t
43     ] [
44         [ struct-slot-values = ]
45         [ [ not ] dip return-address-count>> 0 = and ] 2bi or
46     ] if ;
47
48 : base-pointer-groups-expected ( word -- seq )
49     test-regs first cfg>gc-maps [ derived-root-offsets { } like ] { } map-as ;
50
51 : base-pointer-groups-decoded ( word -- seq )
52     word>gc-maps [
53         second second [ swap 2array ] map-index
54         [ nip -1 = ] assoc-reject
55     ] map ;
56
57 ! byte-array>bit-array
58 {
59     ?{
60         t t t t f t t t
61         t f f f f f f f
62     }
63 } [
64     B{ 239 1 } byte-array>bit-array
65 ] unit-test
66
67 { ?{ t t t t t t t t } } [ B{ 255 } byte-array>bit-array ] unit-test
68
69 ! word>gc-maps
70 { f } [
71     \ effects:<effect> word>gc-maps empty?
72 ] unit-test
73
74 { f } [
75     \ + word>gc-maps empty?
76 ] unit-test
77
78 { { } } [
79     \ word>gc-maps word>gc-maps
80 ] unit-test
81
82 ! Big test
83 { { } } [
84     all-words [ normal? ] filter 50 sample
85     [ [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info? ] reject
86 ] unit-test
87
88 ! Originally from llvm.types, but llvm moved to unmaintained
89 TYPEDEF: void* LLVMTypeRef
90 TYPEDEF: void* LLVMTypeHandleRef
91 FUNCTION: LLVMTypeRef LLVMResolveTypeHandle ( LLVMTypeHandleRef TypeHandle )
92 FUNCTION: LLVMTypeHandleRef LLVMCreateTypeHandle ( LLVMTypeRef PotentiallyAbstractTy )
93 FUNCTION: void LLVMRefineType ( LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy )
94 FUNCTION: void LLVMDisposeTypeHandle ( LLVMTypeHandleRef TypeHandle )
95
96 : resolve-types ( typeref typeref -- typeref )
97     over LLVMCreateTypeHandle [ LLVMRefineType ] dip
98     [ LLVMResolveTypeHandle ] keep LLVMDisposeTypeHandle ;
99
100 ! base-pointer-groups
101 { t } [
102 \ resolve-types
103     [ base-pointer-groups-expected ] [ base-pointer-groups-decoded ] bi =
104 ] unit-test
105
106
107 ! Tough words #1227
108 { t } [
109     \ resolve-types
110     [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
111 ] unit-test
112
113 { t } [
114     \ opencl:cl-queue-kernel
115     [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
116 ] unit-test
117
118 { t } [
119     \ crypto.aes.utils:bytes>words
120     [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
121 ] unit-test
122
123 { t } [
124     \ cpu.x86.features.private:(sse-version)
125     [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
126 ] unit-test
127
128 ! #1436
129 { t } [
130     \ gtk-samples.opengl:opengl-main
131     [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
132 ] unit-test
133
134 ! Ensure deterministic gc map generation.
135 : recompile-word>gc-info ( word -- gc-info )
136     [ 1array compile ] keep word>gc-info ;
137
138 : deterministic-gc-info? ( word -- ? )
139     20 swap '[
140         _ recompile-word>gc-info struct-slot-values
141         dup last 0 = [ drop f ] when
142     ] replicate all-equal? ;
143
144 { t } [
145     \ opencl:cl-queue-kernel deterministic-gc-info?
146 ] unit-test
147
148
149
150 ! TODO: try on 32 bit \ feedback-format: