@@ -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
inlining:: Bool
@@ -16,12 +23,15 @@ immutable InferenceParams
16
23
MAX_TUPLE_SPLAT:: Int
17
24
MAX_UNION_SPLITTING:: Int
18
25
26
+ hooks:: InferenceHooks
27
+
19
28
# reasonable defaults
20
29
InferenceParams (;inlining:: Bool = inlining_enabled (),
21
30
tupletype_len:: Int = 15 , tuple_depth:: Int = 4 ,
22
- tuple_splat:: Int = 16 , union_splitting:: Int = 4 ) =
31
+ tuple_splat:: Int = 16 , union_splitting:: Int = 4 ,
32
+ hooks:: InferenceHooks = InferenceHooks ()) =
23
33
new (inlining, tupletype_len,
24
- tuple_depth, tuple_splat, union_splitting)
34
+ tuple_depth, tuple_splat, union_splitting, hooks )
25
35
end
26
36
27
37
const UNION_SPLIT_MISMATCH_ERROR = false
@@ -1087,6 +1097,15 @@ end
1087
1097
argtypes_to_type (argtypes:: Array{Any,1} ) = Tuple{map (widenconst, argtypes)... }
1088
1098
1089
1099
function abstract_call (f:: ANY , fargs, argtypes:: Vector{Any} , vtypes:: VarTable , sv:: InferenceState )
1100
+ if sv. params. hooks. call != nothing
1101
+ hack = sv. params. hooks. call (f, argtypes_to_type (argtypes))
1102
+ if hack != nothing
1103
+ println (" NOTICE: overriding abstract_call of " , f, " with " , hack)
1104
+ f = hack
1105
+ argtypes[1 ] = typeof (f)
1106
+ end
1107
+ end
1108
+
1090
1109
if f === _apply
1091
1110
length (fargs)> 1 || return Any
1092
1111
aft = argtypes[2 ]
@@ -3109,6 +3128,19 @@ function inlining_pass(e::Expr, sv::InferenceState)
3109
3128
end
3110
3129
end
3111
3130
3131
+ if sv. params. hooks. call != nothing
3132
+ argtypes = Vector {Any} (length (e. args))
3133
+ argtypes[1 ] = ft
3134
+ argtypes[2 : end ] = map (a-> exprtype (a, sv. src, sv. mod), e. args[2 : end ])
3135
+
3136
+ hack = sv. params. hooks. call (f, argtypes_to_type (argtypes))
3137
+ if hack != nothing
3138
+ println (" NOTICE: overriding inlining_pass of " , f, " with " , hack)
3139
+ f = hack
3140
+ ft = typeof (hack)
3141
+ end
3142
+ end
3143
+
3112
3144
if sv. params. inlining
3113
3145
if isdefined (Main, :Base ) &&
3114
3146
((isdefined (Main. Base, :^ ) && f === Main. Base.:^ ) ||
0 commit comments