Skip to content

Commit

Permalink
Add an inference option to ignore the recursion hardlimit
Browse files Browse the repository at this point in the history
We currently very aggressively limit recursion if we came from
a union split. The reason for this choice is to avoid accidental
exponential inference times from excessive exploration of the call
graph. Unfortunately, certain packages like Diffractor really like
triggering the recursion heuristic at the moment, causing any unions
to immediately cause imprecise inference. In the fullness of time,
we should improve the recursion heuristic to do better in this case,
but for the time being, add an inference option that simply lets
it ignore the hardlimit recursion case and proceed anyway.
  • Loading branch information
Keno committed Mar 8, 2023
1 parent 7eb9615 commit e08689c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ function edge_matches_sv(frame::InferenceState, method::Method, @nospecialize(si
if callee_method2 !== inf_method2
return false
end
if !hardlimit
if !hardlimit || InferenceParams(sv.interp).ignore_recursion_hardlimit
# if this is a soft limit,
# also inspect the parent of this edge,
# to see if they are the same Method as sv
Expand Down
16 changes: 11 additions & 5 deletions base/compiler/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ struct InferenceParams
aggressive_constant_propagation::Bool
unoptimize_throw_blocks::Bool
assume_bindings_static::Bool
ignore_recursion_hardlimit::Bool

function InferenceParams(
max_methods::Int,
Expand All @@ -151,7 +152,8 @@ struct InferenceParams
ipo_constant_propagation::Bool,
aggressive_constant_propagation::Bool,
unoptimize_throw_blocks::Bool,
assume_bindings_static::Bool)
assume_bindings_static::Bool,
ignore_recursion_hardlimit::Bool)
return new(
max_methods,
max_union_splitting,
Expand All @@ -161,7 +163,8 @@ struct InferenceParams
ipo_constant_propagation,
aggressive_constant_propagation,
unoptimize_throw_blocks,
assume_bindings_static)
assume_bindings_static,
ignore_recursion_hardlimit)
end
end
function InferenceParams(
Expand All @@ -174,7 +177,8 @@ function InferenceParams(
#=ipo_constant_propagation::Bool=# true,
#=aggressive_constant_propagation::Bool=# false,
#=unoptimize_throw_blocks::Bool=# true,
#=assume_bindings_static::Bool=# false);
#=assume_bindings_static::Bool=# false,
#=ignore_recursion_hardlimit::Bool=# false);
max_methods::Int = params.max_methods,
max_union_splitting::Int = params.max_union_splitting,
max_apply_union_enum::Int = params.max_apply_union_enum,
Expand All @@ -183,7 +187,8 @@ function InferenceParams(
ipo_constant_propagation::Bool = params.ipo_constant_propagation,
aggressive_constant_propagation::Bool = params.aggressive_constant_propagation,
unoptimize_throw_blocks::Bool = params.unoptimize_throw_blocks,
assume_bindings_static::Bool = params.assume_bindings_static)
assume_bindings_static::Bool = params.assume_bindings_static,
ignore_recursion_hardlimit::Bool = params.ignore_recursion_hardlimit)
return InferenceParams(
max_methods,
max_union_splitting,
Expand All @@ -193,7 +198,8 @@ function InferenceParams(
ipo_constant_propagation,
aggressive_constant_propagation,
unoptimize_throw_blocks,
assume_bindings_static)
assume_bindings_static,
ignore_recursion_hardlimit)
end

"""
Expand Down

0 comments on commit e08689c

Please sign in to comment.