@@ -6,6 +6,13 @@ import Core: _apply, svec, apply_type, Builtin, IntrinsicFunction, MethodInstanc
6
6
const MAX_TYPEUNION_LEN = 3
7
7
const MAX_TYPE_DEPTH = 7
8
8
9
+ immutable InferenceHooks
10
+ call
11
+
12
+ InferenceHooks (call) = new (call)
13
+ InferenceHooks () = new (nothing )
14
+ end
15
+
9
16
immutable InferenceParams
10
17
# optimization
11
18
optimize:: Bool
@@ -18,13 +25,16 @@ immutable InferenceParams
18
25
MAX_TUPLE_SPLAT:: Int
19
26
MAX_UNION_SPLITTING:: Int
20
27
28
+ hooks:: InferenceHooks
29
+
21
30
# default values will be used for regular compilation, as the compiler calls typeinf_ext
22
31
# without specifying, or allowing to override, the inference parameters
23
32
InferenceParams (;optimize:: Bool = true , inlining:: Bool = inlining_enabled (), cached:: Bool = true ,
24
33
tupletype_len:: Int = 15 , tuple_depth:: Int = 16 ,
25
- tuple_splat:: Int = 4 , union_splitting:: Int = 4 ) =
34
+ tuple_splat:: Int = 4 , union_splitting:: Int = 4 ,
35
+ hooks:: InferenceHooks = InferenceHooks ()) =
26
36
new (optimize, inlining, cached, tupletype_len,
27
- tuple_depth, tuple_splat, union_splitting)
37
+ tuple_depth, tuple_splat, union_splitting, hooks )
28
38
29
39
# copy constructor for selectively overriding certain params
30
40
InferenceParams (params:: InferenceParams ; kwargs... ) =
@@ -33,6 +43,7 @@ immutable InferenceParams
33
43
tuple_depth= params. MAX_TUPLE_DEPTH,
34
44
tuple_splat= params. MAX_TUPLE_SPLAT,
35
45
union_splitting= params. MAX_UNION_SPLITTING,
46
+ hooks= params. hooks,
36
47
kwargs... )
37
48
end
38
49
@@ -1092,6 +1103,15 @@ end
1092
1103
argtypes_to_type (argtypes:: Array{Any,1} ) = Tuple{map (widenconst, argtypes)... }
1093
1104
1094
1105
function abstract_call (f:: ANY , fargs, argtypes:: Vector{Any} , vtypes:: VarTable , sv:: InferenceState )
1106
+ if sv. params. hooks. call != nothing
1107
+ hack = sv. params. hooks. call (f, argtypes_to_type (argtypes))
1108
+ if hack != nothing
1109
+ println (" NOTICE: overriding abstract_call of " , f, " with " , hack)
1110
+ f = hack
1111
+ argtypes[1 ] = typeof (f)
1112
+ end
1113
+ end
1114
+
1095
1115
if is (f,_apply)
1096
1116
length (fargs)> 1 || return Any
1097
1117
aft = argtypes[2 ]
@@ -3100,6 +3120,19 @@ function inlining_pass(e::Expr, sv::InferenceState)
3100
3120
end
3101
3121
end
3102
3122
3123
+ if sv. params. hooks. call != nothing
3124
+ argtypes = Vector {Any} (length (e. args))
3125
+ argtypes[1 ] = ft
3126
+ argtypes[2 : end ] = map (a-> exprtype (a, sv. src, sv. mod), e. args[2 : end ])
3127
+
3128
+ hack = sv. params. hooks. call (f, argtypes_to_type (argtypes))
3129
+ if hack != nothing
3130
+ println (" NOTICE: overriding inlining_pass of " , f, " with " , hack)
3131
+ f = hack
3132
+ ft = typeof (hack)
3133
+ end
3134
+ end
3135
+
3103
3136
if sv. params. inlining
3104
3137
if isdefined (Main, :Base ) &&
3105
3138
((isdefined (Main. Base, :^ ) && is (f, Main. Base.:^ )) ||
0 commit comments