Skip to content

Commit 38b4dd5

Browse files
authored
Add a test for kwcall with overlays. (#402)
1 parent c51dab3 commit 38b4dd5

File tree

4 files changed

+52
-20
lines changed

4 files changed

+52
-20
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
version: ['1.6', '1.7', '1.8', '^1.9.0-rc1']
16+
version: ['1.6', '1.7', '1.8', '1.9.0-beta4']
1717
os: [ubuntu-latest, macOS-latest, windows-latest]
1818
arch: [x64]
1919
steps:
@@ -48,7 +48,7 @@ jobs:
4848
strategy:
4949
fail-fast: false
5050
matrix:
51-
branch: ['release-1.7', 'release-1.8', 'release-1.9', 'master']
51+
branch: ['release-1.7', 'release-1.8', 'backports-release-1.9', 'master']
5252
os: [ubuntu-latest, macOS-latest]
5353
arch: [x64]
5454
steps:

test/definitions/native.jl

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,33 @@ end
77

88
# create a native test compiler, and generate reflection methods for it
99

10+
# local method table for device functions
11+
@static if isdefined(Base.Experimental, Symbol("@overlay"))
12+
Base.Experimental.@MethodTable(test_method_table)
13+
else
14+
const test_method_table = nothing
15+
end
16+
1017
struct NativeCompilerParams <: AbstractCompilerParams
1118
entry_safepoint::Bool
12-
NativeCompilerParams(entry_safepoint::Bool=false) = new(entry_safepoint)
19+
method_table
20+
21+
NativeCompilerParams(entry_safepoint::Bool=false, method_table=test_method_table) =
22+
new(entry_safepoint, method_table)
1323
end
14-
GPUCompiler.runtime_module(::CompilerJob{<:Any,NativeCompilerParams}) = TestRuntime
1524

1625
NativeCompilerJob = CompilerJob{NativeCompilerTarget,NativeCompilerParams}
1726

18-
# local method table for device functions
19-
@static if isdefined(Base.Experimental, Symbol("@overlay"))
20-
Base.Experimental.@MethodTable(method_table)
21-
else
22-
const method_table = nothing
23-
end
24-
25-
GPUCompiler.method_table(@nospecialize(job::NativeCompilerJob)) = method_table
27+
GPUCompiler.method_table(@nospecialize(job::NativeCompilerJob)) = job.config.params.method_table
2628
GPUCompiler.can_safepoint(@nospecialize(job::NativeCompilerJob)) = job.config.params.entry_safepoint
29+
GPUCompiler.runtime_module(::NativeCompilerJob) = TestRuntime
2730

2831
function native_job(@nospecialize(func), @nospecialize(types); kernel::Bool=false,
2932
entry_abi=:specfunc, entry_safepoint::Bool=false, always_inline=false,
30-
kwargs...)
33+
method_table=test_method_table, kwargs...)
3134
source = FunctionSpec(typeof(func), Base.to_tuple_type(types))
3235
target = NativeCompilerTarget()
33-
params = NativeCompilerParams(entry_safepoint)
36+
params = NativeCompilerParams(entry_safepoint, method_table)
3437
config = CompilerConfig(target, params; kernel, entry_abi, always_inline)
3538
CompilerJob(config, source), kwargs
3639
end

test/native.jl

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -528,22 +528,27 @@ end
528528

529529
mod = @eval module $(gensym())
530530
using ..GPUCompiler
531-
import ..method_table
531+
532+
@static if isdefined(Base.Experimental, Symbol("@overlay"))
533+
Base.Experimental.@MethodTable(method_table)
534+
else
535+
const method_table = nothing
536+
end
532537

533538
kernel() = child()
534539
child() = 0
535540

536541
GPUCompiler.@override method_table child() = 1
537542
end
538543

539-
ir = sprint(io->native_code_llvm(io, mod.kernel, Tuple{}))
544+
ir = sprint(io->native_code_llvm(io, mod.kernel, Tuple{}; mod.method_table))
540545
@test occursin("ret i64 1", ir)
541546
end
542547

548+
if VERSION >= v"1.7"
543549
@testset "#366: semi-concrete interpretation + overlay methods = dynamic dispatch" begin
544550
mod = @eval module $(gensym())
545551
using ..GPUCompiler
546-
import ..method_table
547552
using StaticArrays
548553

549554
function kernel(width, height)
@@ -553,15 +558,40 @@ end
553558
return
554559
end
555560

561+
Base.Experimental.@MethodTable method_table
556562
GPUCompiler.@override method_table Base.isnan(x::Float32) =
557563
(ccall("extern __nv_isnanf", llvmcall, Int32, (Cfloat,), x)) != 0
558564
end
559565

560-
ir = sprint(io->native_code_llvm(io, mod.kernel, Tuple{Int, Int}; debuginfo=:none))
566+
ir = sprint(io->native_code_llvm(io, mod.kernel, Tuple{Int, Int};
567+
debuginfo=:none, mod.method_table))
561568
@test !occursin("apply_generic", ir)
562569
@test occursin("llvm.floor", ir)
563570
end
564571

572+
@testset "JuliaLang/julia#48097: kwcall inference in the presence of overlay method" begin
573+
mod = @eval module $(gensym())
574+
using ..GPUCompiler
575+
child(; kwargs...) = return
576+
function parent()
577+
child(; a=1f0, b=1.0)
578+
return
579+
end
580+
581+
Base.Experimental.@MethodTable method_table
582+
Base.Experimental.@overlay method_table @noinline Core.throw_inexacterror(f::Symbol, ::Type{T}, val) where {T} =
583+
return
584+
end
585+
586+
ir = sprint(io->native_code_llvm(io, mod.parent, Tuple{};
587+
debuginfo=:none, mod.method_table))
588+
@test !occursin("jl_invoke", ir)
589+
@test !occursin("apply_iterate", ir)
590+
@test !occursin("inttoptr", ir)
591+
@test occursin("ret void", ir)
592+
end
593+
end
594+
565595
############################################################################################
566596

567597
end

test/testhelpers.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,5 @@ module TestRuntime
5454
report_exception_frame(idx, func, file, line) = return
5555
end
5656

57-
struct TestCompilerParams <: AbstractCompilerParams
58-
end
57+
struct TestCompilerParams <: AbstractCompilerParams end
5958
GPUCompiler.runtime_module(::CompilerJob{<:Any,TestCompilerParams}) = TestRuntime

0 commit comments

Comments
 (0)