From 42edda8fcf7146f1d62445f2847fef7119eeb849 Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Mon, 12 Oct 2026 13:18:02 +0200 Subject: [PATCH] Test for closure boxes on Julia 1.14+ Also fix the two boxes in the test suite helpers. Co-Authored-By: Claude Opus 5.5 --- test/runtests.jl | 9 +++++++++ test/testsuite.jl | 6 +++--- test/testsuite/alloc_cache.jl | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 5c808d991..fb7b3b679 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,4 +1,5 @@ using ParallelTestRunner: runtests, parse_args +using Test import GPUArrays include("testsuite.jl") @@ -25,4 +26,12 @@ for AT in (:JLArray, :Array), name in keys(TestSuite.tests) testsuite["$(AT)/$name"] = :(TestSuite.tests[$name]($AT)) end +# captured variables that get boxed (`Core.Box`) lose their type +if isdefined(Test, :detect_closure_boxes) + testsuite["closure boxes"] = quote + import GPUArrays + @test Test.detect_closure_boxes(GPUArrays, GPUArrays.GPUArraysCore, JLArrays) == [] + end +end + runtests(GPUArrays, args; init_code, init_worker_code, testsuite) diff --git a/test/testsuite.jl b/test/testsuite.jl index 86ccabff5..59dcbe05b 100644 --- a/test/testsuite.jl +++ b/test/testsuite.jl @@ -77,11 +77,11 @@ function exact_result(@nospecialize(f), @nospecialize(xs...)) catch err return typeof(err) end - exact(x::AbstractArray) = (eltype(x), size(x), collect(x)) - exact(x::Tuple) = map(exact, x) - exact(x) = (typeof(x), x) return exact(r) end +exact(x::AbstractArray) = (eltype(x), size(x), collect(x)) +exact(x::Tuple) = map(exact, x) +exact(x) = (typeof(x), x) compare_exact(@nospecialize(f), AT::Type{<:AbstractGPUArray}, @nospecialize(xs...)) = isequal(exact_result(f, map(deepcopy, xs)...), exact_result(f, map(x -> x isa AbstractArray ? adapt(AT, x) : x, xs)...)) diff --git a/test/testsuite/alloc_cache.jl b/test/testsuite/alloc_cache.jl index e63ca6c2c..01786d93b 100644 --- a/test/testsuite/alloc_cache.jl +++ b/test/testsuite/alloc_cache.jl @@ -59,7 +59,7 @@ end @test sizeof(cache) == sizeof(cached4) + sizeof(cached5) _keys = collect(keys(cache.free)) - key2 = _keys[findfirst(i -> i != key, _keys)] + key2 = _keys[findfirst(!=(key), _keys)] @test length(cache.free[key]) == 1 @test length(cache.free[key2]) == 1 @test cache.free[key2][1] === GPUArrays.storage(cached5)