-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1.11: allow external abstract interpreter compilation #53488
Open
aviatesk
wants to merge
1
commit into
release-1.11
Choose a base branch
from
avi/1.11-precompile-ext-absint
base: release-1.11
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+214
−179
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# This file is a part of Julia. License is MIT: https://julialang.org/license | ||
|
||
using Test | ||
|
||
include("precompile_utils.jl") | ||
|
||
precompile_test_harness() do load_path | ||
write(joinpath(load_path, "SimpleModule.jl"), :(module SimpleModule | ||
basic_callee(x) = x | ||
basic_caller(x) = basic_callee(x) | ||
end) |> string) | ||
|
||
newinterp_path = abspath("compiler/newinterp.jl") | ||
write(joinpath(load_path, "TestAbsIntPrecompile1.jl"), :(module TestAbsIntPrecompile1 | ||
import SimpleModule: basic_caller, basic_callee | ||
|
||
module Custom | ||
include("$($newinterp_path)") | ||
@newinterp PrecompileInterpreter | ||
end | ||
|
||
Base.return_types((Float64,)) do x | ||
basic_caller(x) | ||
end | ||
Base.return_types((Float64,); interp=Custom.PrecompileInterpreter()) do x | ||
basic_caller(x) | ||
end | ||
Base.return_types((Vector{Float64},)) do x | ||
sum(x) | ||
end | ||
Base.return_types((Vector{Float64},); interp=Custom.PrecompileInterpreter()) do x | ||
sum(x) | ||
end | ||
end) |> string) | ||
Base.compilecache(Base.PkgId("TestAbsIntPrecompile1")) | ||
|
||
@eval let | ||
using TestAbsIntPrecompile1 | ||
cache_owner = Core.Compiler.cache_owner( | ||
TestAbsIntPrecompile1.Custom.PrecompileInterpreter()) | ||
let m = only(methods(TestAbsIntPrecompile1.basic_callee)) | ||
mi = only(Base.specializations(m)) | ||
ci = mi.cache | ||
@test isdefined(ci, :next) | ||
@test ci.owner === nothing | ||
@test ci.max_world == typemax(UInt) | ||
ci = ci.next | ||
@test !isdefined(ci, :next) | ||
@test ci.owner === cache_owner | ||
@test ci.max_world == typemax(UInt) | ||
end | ||
let m = only(methods(sum, (Vector{Float64},))) | ||
found = false | ||
for mi in Base.specializations(m) | ||
if mi isa Core.MethodInstance && mi.specTypes == Tuple{typeof(sum),Vector{Float64}} | ||
ci = mi.cache | ||
@test isdefined(ci, :next) | ||
@test ci.owner === cache_owner | ||
@test ci.max_world == typemax(UInt) | ||
ci = ci.next | ||
@test !isdefined(ci, :next) | ||
@test ci.owner === nothing | ||
@test ci.max_world == typemax(UInt) | ||
found = true | ||
break | ||
end | ||
end | ||
@test found | ||
end | ||
end | ||
end | ||
|
||
finish_precompile_test!() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# This file is a part of Julia. License is MIT: https://julialang.org/license | ||
|
||
using Test | ||
|
||
include("precompile_utils.jl") | ||
|
||
precompile_test_harness() do load_path | ||
write(joinpath(load_path, "SimpleModule.jl"), :(module SimpleModule | ||
basic_callee(x) = x | ||
basic_caller(x) = basic_callee(x) | ||
end) |> string) | ||
|
||
newinterp_path = abspath("compiler/newinterp.jl") | ||
write(joinpath(load_path, "TestAbsIntPrecompile2.jl"), :(module TestAbsIntPrecompile2 | ||
import SimpleModule: basic_caller, basic_callee | ||
|
||
module Custom | ||
const CC = Core.Compiler | ||
include("$($newinterp_path)") | ||
@newinterp PrecompileInterpreter | ||
struct CustomData | ||
inferred | ||
CustomData(@nospecialize inferred) = new(inferred) | ||
end | ||
function CC.transform_result_for_cache(interp::PrecompileInterpreter, | ||
mi::Core.MethodInstance, valid_worlds::CC.WorldRange, result::CC.InferenceResult) | ||
inferred_result = @invoke CC.transform_result_for_cache(interp::CC.AbstractInterpreter, | ||
mi::Core.MethodInstance, valid_worlds::CC.WorldRange, result::CC.InferenceResult) | ||
return CustomData(inferred_result) | ||
end | ||
function CC.inlining_policy(interp::PrecompileInterpreter, @nospecialize(src), | ||
@nospecialize(info::CC.CallInfo), stmt_flag::UInt32) | ||
if src isa CustomData | ||
src = src.inferred | ||
end | ||
return @invoke CC.inlining_policy(interp::CC.AbstractInterpreter, src::Any, | ||
info::CC.CallInfo, stmt_flag::UInt32) | ||
end | ||
end | ||
|
||
Base.return_types((Float64,)) do x | ||
basic_caller(x) | ||
end | ||
Base.return_types((Float64,); interp=Custom.PrecompileInterpreter()) do x | ||
basic_caller(x) | ||
end | ||
Base.return_types((Vector{Float64},)) do x | ||
sum(x) | ||
end | ||
Base.return_types((Vector{Float64},); interp=Custom.PrecompileInterpreter()) do x | ||
sum(x) | ||
end | ||
end) |> string) | ||
Base.compilecache(Base.PkgId("TestAbsIntPrecompile2")) | ||
|
||
@eval let | ||
using TestAbsIntPrecompile2 | ||
cache_owner = Core.Compiler.cache_owner( | ||
TestAbsIntPrecompile2.Custom.PrecompileInterpreter()) | ||
let m = only(methods(TestAbsIntPrecompile2.basic_callee)) | ||
mi = only(Base.specializations(m)) | ||
ci = mi.cache | ||
@test isdefined(ci, :next) | ||
@test ci.owner === nothing | ||
@test ci.max_world == typemax(UInt) | ||
ci = ci.next | ||
@test !isdefined(ci, :next) | ||
@test ci.owner === cache_owner | ||
@test ci.max_world == typemax(UInt) | ||
end | ||
let m = only(methods(sum, (Vector{Float64},))) | ||
found = false | ||
for mi = Base.specializations(m) | ||
if mi isa Core.MethodInstance && mi.specTypes == Tuple{typeof(sum),Vector{Float64}} | ||
ci = mi.cache | ||
@test isdefined(ci, :next) | ||
@test ci.owner === cache_owner | ||
@test ci.max_world == typemax(UInt) | ||
ci = ci.next | ||
@test !isdefined(ci, :next) | ||
@test ci.owner === nothing | ||
@test ci.max_world == typemax(UInt) | ||
found = true | ||
break | ||
end | ||
end | ||
@test found | ||
end | ||
end | ||
end | ||
|
||
finish_precompile_test!() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the actual fix. The other changes are the refinements on the test cases (which were done in #53478).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm but on master we still have
julia/base/compiler/typeinfer.jl
Line 331 in b3b2736
So I am not sure how it would be fixed there. IIRC even on master I needed a abs int overload that set relocatability?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The relocatability indicates that we know the
inferred
field is safe to duplicate, which doesn't seem would be the case if this is not one of the expected objects? (i.e. String or Nothing)