Skip to content

Commit

Permalink
inference: refactoring to allow irinterp to perform :call inference
Browse files Browse the repository at this point in the history
This commit implements a significant refactoring of the inference routines,
which is necessary to enable `:call` inference in irinterp. While this
commit does not yet enable `:call` inference, a subsequent small commit
will do so. This is because external `AbstractInterpreter`s first need
to adjust their code for this refactoring, and in the event of a
regression detected by the recursive `:call` inference, we will be able
to simply revert the small commit.

Additionally, this commit improves the robustness of irinterp by
allowing it to handle invoke calls, which currently result in a crash.

TODOs:
- [x] implement a simple recursion detection mechanism for `IRInterpretationState`
- [x] add proper invalidation support
- [x] allow constant inference from semi-concrete interpretation
- [x] propagate callinfo and allow double inlining
  • Loading branch information
aviatesk committed Apr 3, 2023
1 parent 46813d3 commit 10e2001
Show file tree
Hide file tree
Showing 12 changed files with 799 additions and 577 deletions.
387 changes: 207 additions & 180 deletions base/compiler/abstractinterpretation.jl

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion base/compiler/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ include("compiler/ssair/domtree.jl")
include("compiler/ssair/ir.jl")

include("compiler/abstractlattice.jl")

include("compiler/inferenceresult.jl")
include("compiler/inferencestate.jl")

Expand Down
8 changes: 3 additions & 5 deletions base/compiler/inferenceresult.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function va_process_argtypes(@nospecialize(va_handler!), 𝕃::AbstractLattice,
nargs = Int(def.nargs)
if isva || isvarargtype(given_argtypes[end])
isva_given_argtypes = Vector{Any}(undef, nargs)
for i = 1:(nargs - isva)
for i = 1:(nargs-isva)
isva_given_argtypes[i] = argtype_by_index(given_argtypes, i)
end
if isva
Expand All @@ -110,10 +110,8 @@ function most_general_argtypes(method::Union{Method, Nothing}, @nospecialize(spe
isva = !toplevel && method.isva
linfo_argtypes = Any[(unwrap_unionall(specTypes)::DataType).parameters...]
nargs::Int = toplevel ? 0 : method.nargs
if !withfirst
# For opaque closure, the closure environment is processed elsewhere
nargs -= 1
end
# For opaque closure, the closure environment is processed elsewhere
withfirst || (nargs -= 1)
cache_argtypes = Vector{Any}(undef, nargs)
# First, if we're dealing with a varargs method, then we set the last element of `args`
# to the appropriate `Tuple` type or `PartialStruct` instance.
Expand Down
Loading

0 comments on commit 10e2001

Please sign in to comment.