@@ -1011,25 +1011,30 @@ precompile_test_harness("invoke") do dir
10111011 module $InvokeModule
10121012 export f, g, h, q, fnc, gnc, hnc, qnc # nc variants do not infer to a Const
10131013 export f44320, g44320
1014- export getlast
1014+ export getlast, getdata
1015+
1016+ # use instead of `rand`
1017+ const data = Ref{Float64}(0)
1018+ getdata() = data[]
1019+
10151020 # f is for testing invoke that occurs within a dependency
10161021 f(x::Real) = 0
10171022 f(x::Int) = x < 5 ? 1 : invoke(f, Tuple{Real}, x)
1018- fnc(x::Real) = rand ()-1
1019- fnc(x::Int) = x < 5 ? rand ()+1 : invoke(fnc, Tuple{Real}, x)
1023+ fnc(x::Real) = getdata ()-1
1024+ fnc(x::Int) = x < 5 ? getdata ()+1 : invoke(fnc, Tuple{Real}, x)
10201025 # g is for testing invoke that occurs from a dependent
10211026 g(x::Real) = 0
10221027 g(x::Int) = 1
1023- gnc(x::Real) = rand ()-1
1024- gnc(x::Int) = rand ()+1
1028+ gnc(x::Real) = getdata ()-1
1029+ gnc(x::Int) = getdata ()+1
10251030 # h will be entirely superseded by a new method (full invalidation)
10261031 h(x::Real) = 0
10271032 h(x::Int) = x < 5 ? 1 : invoke(h, Tuple{Integer}, x)
1028- hnc(x::Real) = rand ()-1
1029- hnc(x::Int) = x < 5 ? rand ()+1 : invoke(hnc, Tuple{Integer}, x)
1033+ hnc(x::Real) = getdata ()-1
1034+ hnc(x::Int) = x < 5 ? getdata ()+1 : invoke(hnc, Tuple{Integer}, x)
10301035 # q will have some callers invalidated
10311036 q(x::Integer) = 0
1032- qnc(x::Integer) = rand ()-1
1037+ qnc(x::Integer) = getdata ()-1
10331038 # Issue #44320
10341039 f44320(::Int) = 1
10351040 f44320(::Any) = 2
@@ -1066,8 +1071,8 @@ precompile_test_harness("invoke") do dir
10661071 # Purely internal
10671072 internal(x::Real) = 0
10681073 internal(x::Int) = x < 5 ? 1 : invoke(internal, Tuple{Real}, x)
1069- internalnc(x::Real) = rand ()-1
1070- internalnc(x::Int) = x < 5 ? rand ()+1 : invoke(internalnc, Tuple{Real}, x)
1074+ internalnc(x::Real) = getdata ()-1
1075+ internalnc(x::Int) = x < 5 ? getdata ()+1 : invoke(internalnc, Tuple{Real}, x)
10711076
10721077 # Issue #44320
10731078 f44320(::Real) = 3
@@ -1094,10 +1099,10 @@ precompile_test_harness("invoke") do dir
10941099
10951100 # Now that we've precompiled, invalidate with a new method that overrides the `invoke` dispatch
10961101 $InvokeModule .h(x::Integer) = -1
1097- $InvokeModule .hnc(x::Integer) = rand () - 20
1102+ $InvokeModule .hnc(x::Integer) = getdata () - 20
10981103 # ...and for q, override with a more specialized method that should leave only the invoked version still valid
10991104 $InvokeModule .q(x::Int) = -1
1100- $InvokeModule .qnc(x::Int) = rand ()+1
1105+ $InvokeModule .qnc(x::Int) = getdata ()+1
11011106 end
11021107 """ )
11031108 Base. compilecache (Base. PkgId (string (CallerModule)))
@@ -1555,13 +1560,16 @@ precompile_test_harness("No external edges") do load_path
15551560 write (joinpath (load_path, " NoExternalEdges.jl" ),
15561561 """
15571562 module NoExternalEdges
1558- bar(x::Int) = hcat(rand())
1559- @inline bar() = hcat(rand())
1563+ const data = Ref{Float64}()
1564+ getdata() = data[]
1565+
1566+ bar(x::Int) = hcat(getdata())
1567+ @inline bar() = hcat(getdata())
15601568 bar(x::Float64) = bar()
15611569 foo1() = bar(1)
15621570 foo2() = bar(1.0)
15631571 foo3() = bar()
1564- foo4() = hcat(rand ())
1572+ foo4() = hcat(getdata ())
15651573 precompile(foo1, ())
15661574 precompile(foo2, ())
15671575 precompile(foo3, ())
0 commit comments