@@ -49,7 +49,6 @@ is_return(::Any) = false
49
49
50
50
# -------------------------------------------
51
51
#
52
- #
53
52
# Statistics gathered per method.
54
53
#
55
54
# -------------------------------------------
@@ -87,6 +86,23 @@ import Base.(+)
87
86
show_comma_sep (xs:: Vector ) = join (xs, " ," )
88
87
89
88
89
+ # --------------------------------------------------------
90
+ #
91
+ # Statistics for all types occured during instantiations.
92
+ #
93
+ # --------------------------------------------------------
94
+
95
+ # Note on "mutable": stats are only mutable during their calculation.
96
+ @kwdef mutable struct InTypeStats
97
+ modl :: String
98
+ occurs :: Int
99
+ end
100
+
101
+ InTypeStats (modl :: Module ) = InTypeStats (" $modl " , 0 )
102
+ InTypeStats (modl :: String ) = InTypeStats (modl, 0 )
103
+
104
+ @deriveEq (InTypeStats)
105
+
90
106
# -------------------------------------------
91
107
#
92
108
# Statistics gathered per module.
@@ -97,9 +113,15 @@ show_comma_sep(xs::Vector) = join(xs, ",")
97
113
modl :: Module
98
114
mestats :: Dict{Method, MethodStats}
99
115
mistats :: Dict{MethodInstance, MIStats}
116
+ tystats :: Dict{Any, InTypeStats}
100
117
end
101
118
102
- ModuleStats (modl :: Module ) = ModuleStats (modl, Dict {Method, MethodStats} (), Dict {Method, MIStats} ())
119
+ ModuleStats (modl :: Module ) = ModuleStats (
120
+ modl,
121
+ Dict {Method, MethodStats} (),
122
+ Dict {Method, MIStats} (),
123
+ Dict {Any, InTypeStats} ()
124
+ )
103
125
104
126
@deriveEq (ModuleStats)
105
127
@@ -133,17 +155,20 @@ module_stats(modl :: Module, errio :: IO = stderr) = begin
133
155
res = ModuleStats (modl)
134
156
mis = all_mis_of_module (modl)
135
157
for mi in mis
158
+
159
+ # Special cases: @generated, blocklisted
136
160
if isdefined (mi. def, :generator ) # can't handle @generated functions, Issue #11
137
161
@debug " GENERATED $(mi) "
138
162
continue
139
163
end
140
-
141
164
is_blocklisted (modl, mi. def. module) && (@debug " alien: $mi .def defined in $mi .def.module" ; continue )
142
165
166
+ # Lookup method stats object for this `mi`
143
167
fs = get! (res. mestats, mi. def,
144
168
fstats_default (mi. def. nospecialize,
145
169
occursin (" Vararg" ," $(mi. def. sig) " )))
146
170
try
171
+ # Get code of the `mi` for later analysis
147
172
call = reconstruct_func_call (mi)
148
173
if call === nothing # this mi is a constructor call - skip
149
174
delete! (res. mestats, mi. def)
@@ -152,7 +177,7 @@ module_stats(modl :: Module, errio :: IO = stderr) = begin
152
177
153
178
fs. occurs += 1
154
179
155
- # handle stability/groundedness
180
+ # Check stability/groundedness of the code
156
181
mi_st = false
157
182
mi_gd = false
158
183
(code,rettype) = run_type_inference (call... );
@@ -165,8 +190,18 @@ module_stats(modl :: Module, errio :: IO = stderr) = begin
165
190
end
166
191
end
167
192
168
- # handle instance CFG stats
193
+ # Handle instance CFG stats
169
194
res. mistats[mi] = MIStats (mi_st, mi_gd, cfg_stats (code)... , rettype, call[2 ] #= input types =# )
195
+
196
+ # Collect intypes
197
+ intypes = Base. unwrap_unionall (mi. specTypes). types[2 : end ]
198
+ for ty in intypes
199
+ tymodl = moduleChainOfType (ty)
200
+ tystat = get! (res. tystats,
201
+ ty,
202
+ InTypeStats (tymodl))
203
+ tystat. occurs += 1
204
+ end
170
205
catch err
171
206
fs. fail += 1
172
207
print (errio, " ERROR: " );
0 commit comments