Skip to content

Commit

Permalink
Use get_world in FunctionSpec constructor, and delete bad tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
maleadt committed Feb 22, 2023
1 parent 35ad5a0 commit 22bd9c4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
27 changes: 22 additions & 5 deletions src/cache.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# compilation cache

export get_world

using Core.Compiler: retrieve_code_info, CodeInfo, MethodInstance, SSAValue, SlotNumber, ReturnNode
using Base: _methods_by_ftype

Expand Down Expand Up @@ -174,14 +172,33 @@ end
end

const cache_lock = ReentrantLock()

"""
cached_compilation(cache::Dict, job::CompilerJob, compiler, linker)
Compile `job` using `compiler` and `linker`, and store the result in `cache`.
The `cache` argument should be a dictionary that can be indexed using a `UInt` and store
whatever the `linker` function returns. The `compiler` function should take a `CompilerJob`
and return data that can be cached across sessions (e.g., LLVM IR). This data is then
forwarded, along with the `CompilerJob`, to the `linker` function which is allowed to create
session-dependent objects (e.g., a `CuModule`).
"""
function cached_compilation(cache::AbstractDict,
@nospecialize(job::CompilerJob),
compiler::Function, linker::Function)
# NOTE: it is OK to index the compilation cache directly with the compilation job, i.e.,
# using a world age instead of intersecting world age ranges, because we expect
# that the world age is aquired through calling `get_world` and thus will only
# ever change when the kernel function is redefined.
#
# if we ever want to be able to index the cache using a compilation job that
# contains a more recent world age, yet still return an older cached object that
# would still be valid, we'd need the cache to store world ranges instead and
# use an invalidation callback to add upper bounds to entries.
key = hash(job)
force_compilation = compile_hook[] !== nothing

# XXX: by taking the hash, we index the compilation cache directly with the world age.
# that's wrong; we should perform an intersection with the entry its bounds.
force_compilation = compile_hook[] !== nothing

# NOTE: no use of lock(::Function)/@lock/get! to keep stack traces clean
lock(cache_lock)
Expand Down
2 changes: 1 addition & 1 deletion src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ struct FunctionSpec
kernel::Bool
name::Union{Nothing,String}

FunctionSpec(f::Type, tt::Type, world::Integer=Base.get_world_counter();
FunctionSpec(f::Type, tt::Type, world::Integer=get_world(f, tt);
kernel=true, name=nothing) =
new(f, tt, world, kernel, name)
end
Expand Down
19 changes: 0 additions & 19 deletions test/native.jl
Original file line number Diff line number Diff line change
Expand Up @@ -368,25 +368,6 @@ end
occursin("BigInt", msg)
end

# test that we can handle abstract types
@test_throws_message(KernelError,
native_code_execution(foobar, Tuple{Any})) do msg
occursin("passing and using non-bitstype argument", msg) &&
occursin("Any", msg)
end

@test_throws_message(KernelError,
native_code_execution(foobar, Tuple{Union{Int32, Int64}})) do msg
occursin("passing and using non-bitstype argument", msg) &&
occursin("Union{Int32, Int64}", msg)
end

@test_throws_message(KernelError,
native_code_execution(foobar, Tuple{Union{Int32, Int64}})) do msg
occursin("passing and using non-bitstype argument", msg) &&
occursin("Union{Int32, Int64}", msg)
end

# test that we get information about fields and reason why something is not isbits
@test_throws_message(KernelError,
native_code_execution(foobar, Tuple{CleverType{BigInt}})) do msg
Expand Down

0 comments on commit 22bd9c4

Please sign in to comment.