Ai
21 Star 49 Fork 0

Gitee 极速下载/julia-language

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/JuliaLang/julia
Clone or Download
cicache.jl 2.31 KB
Copy Edit Raw Blame History
# This file is a part of Julia. License is MIT: https://julialang.org/license
struct WorldRange
min_world::UInt
max_world::UInt
end
WorldRange() = WorldRange(typemin(UInt), typemax(UInt))
WorldRange(w::UInt) = WorldRange(w, w)
WorldRange(r::UnitRange) = WorldRange(first(r), last(r))
first(wr::WorldRange) = wr.min_world
last(wr::WorldRange) = wr.max_world
in(world::UInt, wr::WorldRange) = wr.min_world <= world <= wr.max_world
min_world(wr::WorldRange) = first(wr)
max_world(wr::WorldRange) = last(wr)
function intersect(a::WorldRange, b::WorldRange)
ret = WorldRange(max(a.min_world, b.min_world), min(a.max_world, b.max_world))
@assert ret.min_world <= ret.max_world
return ret
end
function union(a::WorldRange, b::WorldRange)
if b.min_world < a.min_world
(b, a) = (a, b)
end
@assert a.max_world >= b.min_world - 1
return WorldRange(a.min_world, b.max_world)
end
"""
struct InternalCodeCache
Internally, each `MethodInstance` keep a unique global cache of code instances
that have been created for the given method instance, stratified by world age
ranges. This struct abstracts over access to this cache.
"""
struct InternalCodeCache
owner::Any # `jl_egal` is used for comparison
worlds::WorldRange
InternalCodeCache(@nospecialize(owner), wr::WorldRange) = new(owner, wr)
InternalCodeCache(@nospecialize(owner), args...) = new(owner, WorldRange(args...))
end
function setindex!(cache::InternalCodeCache, ci::CodeInstance, mi::MethodInstance)
@assert ci.owner === cache.owner
m = mi.def
if isa(m, Method)
ccall(:jl_push_newly_inferred, Cvoid, (Any,), ci)
end
ccall(:jl_mi_cache_insert, Cvoid, (Any, Any), mi, ci)
return cache
end
function haskey(wvc::InternalCodeCache, mi::MethodInstance)
return ccall(:jl_rettype_inferred, Any, (Any, Any, UInt, UInt), wvc.owner, mi, first(wvc.worlds), last(wvc.worlds)) !== nothing
end
function get(wvc::InternalCodeCache, mi::MethodInstance, default)
r = ccall(:jl_rettype_inferred, Any, (Any, Any, UInt, UInt), wvc.owner, mi, first(wvc.worlds), last(wvc.worlds))
if r === nothing
return default
end
return r::CodeInstance
end
function getindex(wvc::InternalCodeCache, mi::MethodInstance)
r = get(wvc, mi, nothing)
r === nothing && throw(KeyError(mi))
return r::CodeInstance
end
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/mirrors/julia-language.git
git@gitee.com:mirrors/julia-language.git
mirrors
julia-language
julia-language
master

Search