Skip to content

Commit 90c18a6

Browse files
vtjnashKristofferC
authored andcommitted
remove bad method specialization from cache (#39429)
This was inserting a method with signature [Int, Int], rather than Tuple{typeof(+), Int, Int}. Fix that and add a test for it so it doesn't happen again. (cherry picked from commit b9f8b8b)
1 parent 9952166 commit 90c18a6

File tree

2 files changed

+33
-32
lines changed

2 files changed

+33
-32
lines changed

base/Base.jl

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -394,37 +394,36 @@ in_sysimage(pkgid::PkgId) = pkgid in _sysimage_modules
394394
# Precompiles for Revise
395395
# TODO: move these to contrib/generate_precompile.jl
396396
# The problem is they don't work there
397-
let m = which(+, (Int, Int))
398-
while true # defeat interpreter heuristic to force compilation
399-
delete!(push!(Set{Method}(), m), m)
400-
copy(Core.Compiler.retrieve_code_info(Core.Compiler.specialize_method(m, [Int, Int], Core.svec())))
401-
402-
empty!(Set())
403-
push!(push!(Set{Union{GlobalRef,Symbol}}(), :two), GlobalRef(Base, :two))
404-
(setindex!(Dict{String,Base.PkgId}(), Base.PkgId(Base), "file.jl"))["file.jl"]
405-
(setindex!(Dict{Symbol,Vector{Int}}(), [1], :two))[:two]
406-
(setindex!(Dict{Base.PkgId,String}(), "file.jl", Base.PkgId(Base)))[Base.PkgId(Base)]
407-
(setindex!(Dict{Union{GlobalRef,Symbol}, Vector{Int}}(), [1], :two))[:two]
408-
(setindex!(IdDict{Type, Union{Missing, Vector{Tuple{LineNumberNode, Expr}}}}(), missing, Int))[Int]
409-
Dict{Symbol, Union{Nothing, Bool, Symbol}}(:one => false)[:one]
410-
Dict(Base => [:(1+1)])[Base]
411-
Dict(:one => [1])[:one]
412-
Dict("abc" => Set())["abc"]
413-
pushfirst!([], sum)
414-
get(Base.pkgorigins, Base.PkgId(Base), nothing)
415-
sort!([1,2,3])
416-
unique!([1,2,3])
417-
cumsum([1,2,3])
418-
append!(Int[], BitSet())
419-
isempty(BitSet())
420-
delete!(BitSet([1,2]), 3)
421-
deleteat!(Int32[1,2,3], [1,3])
422-
deleteat!(Any[1,2,3], [1,3])
423-
Core.svec(1, 2) == Core.svec(3, 4)
424-
any(t->t[1].line > 1, [(LineNumberNode(2,:none), :(1+1))])
425-
426-
break # end defeat interpreter heuristic
427-
end
397+
for match = _methods(+, (Int, Int), -1, get_world_counter())
398+
m = match.method
399+
delete!(push!(Set{Method}(), m), m)
400+
copy(Core.Compiler.retrieve_code_info(Core.Compiler.specialize_method(match)))
401+
402+
empty!(Set())
403+
push!(push!(Set{Union{GlobalRef,Symbol}}(), :two), GlobalRef(Base, :two))
404+
(setindex!(Dict{String,Base.PkgId}(), Base.PkgId(Base), "file.jl"))["file.jl"]
405+
(setindex!(Dict{Symbol,Vector{Int}}(), [1], :two))[:two]
406+
(setindex!(Dict{Base.PkgId,String}(), "file.jl", Base.PkgId(Base)))[Base.PkgId(Base)]
407+
(setindex!(Dict{Union{GlobalRef,Symbol}, Vector{Int}}(), [1], :two))[:two]
408+
(setindex!(IdDict{Type, Union{Missing, Vector{Tuple{LineNumberNode, Expr}}}}(), missing, Int))[Int]
409+
Dict{Symbol, Union{Nothing, Bool, Symbol}}(:one => false)[:one]
410+
Dict(Base => [:(1+1)])[Base]
411+
Dict(:one => [1])[:one]
412+
Dict("abc" => Set())["abc"]
413+
pushfirst!([], sum)
414+
get(Base.pkgorigins, Base.PkgId(Base), nothing)
415+
sort!([1,2,3])
416+
unique!([1,2,3])
417+
cumsum([1,2,3])
418+
append!(Int[], BitSet())
419+
isempty(BitSet())
420+
delete!(BitSet([1,2]), 3)
421+
deleteat!(Int32[1,2,3], [1,3])
422+
deleteat!(Any[1,2,3], [1,3])
423+
Core.svec(1, 2) == Core.svec(3, 4)
424+
any(t->t[1].line > 1, [(LineNumberNode(2,:none), :(1+1))])
425+
426+
break # only actually need to do this once
428427
end
429428

430429
if is_primary_base_module

src/gf.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ static int speccache_eq(size_t idx, const void *ty, jl_svec_t *data, uint_t hv)
104104
// get or create the MethodInstance for a specialization
105105
JL_DLLEXPORT jl_method_instance_t *jl_specializations_get_linfo(jl_method_t *m JL_PROPAGATES_ROOT, jl_value_t *type, jl_svec_t *sparams)
106106
{
107-
uint_t hv = ((jl_datatype_t*)(jl_is_unionall(type) ? jl_unwrap_unionall(type) : type))->hash;
107+
jl_value_t *ut = jl_is_unionall(type) ? jl_unwrap_unionall(type) : type;
108+
JL_TYPECHK(specializations, datatype, ut);
109+
uint_t hv = ((jl_datatype_t*)ut)->hash;
108110
for (int locked = 0; ; locked++) {
109111
jl_array_t *speckeyset = jl_atomic_load_acquire(&m->speckeyset);
110112
jl_svec_t *specializations = jl_atomic_load_acquire(&m->specializations);

0 commit comments

Comments
 (0)