From e08689c57751f4288e6a148e324b639743ac6bb6 Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Wed, 8 Mar 2023 04:00:41 +0000 Subject: [PATCH] Add an inference option to ignore the recursion hardlimit 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. --- base/compiler/abstractinterpretation.jl | 2 +- base/compiler/types.jl | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/base/compiler/abstractinterpretation.jl b/base/compiler/abstractinterpretation.jl index 93ead3207fce2..13ee9abc14387 100644 --- a/base/compiler/abstractinterpretation.jl +++ b/base/compiler/abstractinterpretation.jl @@ -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 diff --git a/base/compiler/types.jl b/base/compiler/types.jl index cac15e9a69513..b59159301d620 100644 --- a/base/compiler/types.jl +++ b/base/compiler/types.jl @@ -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, @@ -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, @@ -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( @@ -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, @@ -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, @@ -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 """