Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions test/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,17 @@ precompile_test_harness("code caching") do dir
use_stale(c) = stale(c[1]) + not_stale("hello")
build_stale(x) = use_stale(Any[x])

# bindings
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests for this code path are mostly in rebinding.jl. I don't really mind it being here, but I don't fully know yet what distinguishes this case from the ones already tested

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I hadn't found that yet. Likewise I'd have no objection to moving these tests to rebinding.jl.

Copy link
Member Author

@timholy timholy May 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One potential difference: from a quick scan, the tests in rebinding.jl seem to define the function in the same module in which it's precompiled. This test defines StaleA.fib() but defers its precompilation until StaleB, and yanks the rug out in between loading those two modules.

struct InvalidatedBinding
x::Int
end
struct Wrapper
ib::InvalidatedBinding
end
makewib(x) = Wrapper(InvalidatedBinding(x))
const gib = makewib(1)
fib() = gib.ib.x

# force precompilation
build_stale(37)
stale('c')
Expand Down Expand Up @@ -985,6 +996,7 @@ precompile_test_harness("code caching") do dir
Base.Experimental.@force_compile
useA2()
end
precompile($StaleA.fib, ())

## Reporting tests
call_nbits(x::Integer) = $StaleA.nbits(x)
Expand Down Expand Up @@ -1014,6 +1026,15 @@ precompile_test_harness("code caching") do dir
@eval using $StaleA
MA = invokelatest(getfield, @__MODULE__, StaleA)
Base.eval(MA, :(nbits(::UInt8) = 8))
Base.eval(MA, quote
struct InvalidatedBinding
x::Float64
end
struct Wrapper
ib::InvalidatedBinding
end
const gib = makewib(2.0)
end)
@eval using $StaleC
invalidations = Base.StaticData.debug_method_invalidation(true)
@eval using $StaleB
Expand Down Expand Up @@ -1044,6 +1065,11 @@ precompile_test_harness("code caching") do dir
m = only(methods(MC.call_buildstale))
mi = m.specializations::Core.MethodInstance
@test hasvalid(mi, world) # was compiled with the new method
m = only(methods(MA.fib))
mi = m.specializations::Core.MethodInstance
@test isdefined(mi, :cache) # it was precompiled by StaleB
@test_broken !hasvalid(mi, world) # invalidated by redefining `gib` before loading StaleB
@test_broken MA.fib() === 2.0

# Reporting test (ensure SnoopCompile works)
@test all(i -> isassigned(invalidations, i), eachindex(invalidations))
Expand Down
Loading