@@ -17,32 +17,32 @@ DOWN_ARROW = "\e[B"
17
17
18
18
hardcoded_precompile_statements = """
19
19
# used by Revise.jl
20
- @assert precompile(Tuple{typeof(Base.parse_cache_header), String})
21
- @assert precompile(Base.read_dependency_src, (String, String))
20
+ precompile(Tuple{typeof(Base.parse_cache_header), String})
21
+ precompile(Base.read_dependency_src, (String, String))
22
22
23
23
# used by Requires.jl
24
- @assert precompile(Tuple{typeof(get!), Type{Vector{Function}}, Dict{Base.PkgId,Vector{Function}}, Base.PkgId})
25
- @assert precompile(Tuple{typeof(haskey), Dict{Base.PkgId,Vector{Function}}, Base.PkgId})
26
- @assert precompile(Tuple{typeof(delete!), Dict{Base.PkgId,Vector{Function}}, Base.PkgId})
27
- @assert precompile(Tuple{typeof(push!), Vector{Function}, Function})
24
+ precompile(Tuple{typeof(get!), Type{Vector{Function}}, Dict{Base.PkgId,Vector{Function}}, Base.PkgId})
25
+ precompile(Tuple{typeof(haskey), Dict{Base.PkgId,Vector{Function}}, Base.PkgId})
26
+ precompile(Tuple{typeof(delete!), Dict{Base.PkgId,Vector{Function}}, Base.PkgId})
27
+ precompile(Tuple{typeof(push!), Vector{Function}, Function})
28
28
29
29
# miscellaneous
30
- @assert precompile(Tuple{typeof(Base.require), Base.PkgId})
31
- @assert precompile(Tuple{typeof(Base.recursive_prefs_merge), Base.Dict{String, Any}})
32
- @assert precompile(Tuple{typeof(isassigned), Core.SimpleVector, Int})
33
- @assert precompile(Tuple{typeof(getindex), Core.SimpleVector, Int})
34
- @assert precompile(Tuple{typeof(Base.Experimental.register_error_hint), Any, Type})
35
- @assert precompile(Tuple{typeof(Base.display_error), MethodError, Vector{Union{Ptr{Nothing}, Base.InterpreterIP}}})
36
- @assert precompile(Tuple{typeof(Base.display_error), ErrorException})
37
- @assert precompile(Tuple{typeof(Base.display_error), BoundsError})
38
- @assert precompile(Tuple{Core.kwftype(typeof(Type)), NamedTuple{(:sizehint,), Tuple{Int64 }}, Type{IOBuffer}})
39
- @assert precompile(Base.CoreLogging.current_logger_for_env, (Base.CoreLogging.LogLevel, String, Module))
40
- @assert precompile(Base.CoreLogging.current_logger_for_env, (Base.CoreLogging.LogLevel, Symbol, Module))
30
+ precompile(Tuple{typeof(Base.require), Base.PkgId})
31
+ precompile(Tuple{typeof(Base.recursive_prefs_merge), Base.Dict{String, Any}})
32
+ precompile(Tuple{typeof(isassigned), Core.SimpleVector, Int})
33
+ precompile(Tuple{typeof(getindex), Core.SimpleVector, Int})
34
+ precompile(Tuple{typeof(Base.Experimental.register_error_hint), Any, Type})
35
+ precompile(Tuple{typeof(Base.display_error), MethodError, Vector{Union{Ptr{Nothing}, Base.InterpreterIP}}})
36
+ precompile(Tuple{typeof(Base.display_error), ErrorException})
37
+ precompile(Tuple{typeof(Base.display_error), BoundsError})
38
+ precompile(Tuple{Core.kwftype(typeof(Type)), NamedTuple{(:sizehint,), Tuple{Int }}, Type{IOBuffer}})
39
+ precompile(Base.CoreLogging.current_logger_for_env, (Base.CoreLogging.LogLevel, String, Module))
40
+ precompile(Base.CoreLogging.current_logger_for_env, (Base.CoreLogging.LogLevel, Symbol, Module))
41
41
"""
42
42
43
43
for T in (Float16, Float32, Float64), IO in (IOBuffer, IOContext{IOBuffer}, Base. TTY, IOContext{Base. TTY})
44
44
global hardcoded_precompile_statements
45
- hardcoded_precompile_statements *= " @assert precompile(Tuple{typeof(show), $IO , $T })\n "
45
+ hardcoded_precompile_statements *= " precompile(Tuple{typeof(show), $IO , $T })\n "
46
46
end
47
47
48
48
repl_script = """
@@ -108,7 +108,7 @@ have_repl = haskey(Base.loaded_modules,
108
108
Base. PkgId (Base. UUID (" 3fa0cd96-eef1-5676-8a61-b3b8758bbffb" ), " REPL" ))
109
109
if have_repl
110
110
hardcoded_precompile_statements *= """
111
- @assert precompile(Tuple{typeof(getproperty), REPL.REPLBackend, Symbol})
111
+ precompile(Tuple{typeof(getproperty), REPL.REPLBackend, Symbol})
112
112
"""
113
113
end
114
114
@@ -117,9 +117,9 @@ Distributed = get(Base.loaded_modules,
117
117
nothing )
118
118
if Distributed != = nothing
119
119
hardcoded_precompile_statements *= """
120
- @assert precompile(Tuple{typeof(Distributed.remotecall),Function,Int,Module,Vararg{Any, 100}})
121
- @assert precompile(Tuple{typeof(Distributed.procs)})
122
- @assert precompile(Tuple{typeof(Distributed.finalize_ref), Distributed.Future})
120
+ precompile(Tuple{typeof(Distributed.remotecall),Function,Int,Module,Vararg{Any, 100}})
121
+ precompile(Tuple{typeof(Distributed.procs)})
122
+ precompile(Tuple{typeof(Distributed.finalize_ref), Distributed.Future})
123
123
"""
124
124
# This is disabled because it doesn't give much benefit
125
125
# and the code in Distributed is poorly typed causing many invalidations
@@ -164,9 +164,9 @@ FileWatching = get(Base.loaded_modules,
164
164
nothing )
165
165
if FileWatching != = nothing
166
166
hardcoded_precompile_statements *= """
167
- @assert precompile(Tuple{typeof(FileWatching.watch_file), String, Float64})
168
- @assert precompile(Tuple{typeof(FileWatching.watch_file), String, Int})
169
- @assert precompile(Tuple{typeof(FileWatching._uv_hook_close), FileWatching.FileMonitor})
167
+ precompile(Tuple{typeof(FileWatching.watch_file), String, Float64})
168
+ precompile(Tuple{typeof(FileWatching.watch_file), String, Int})
169
+ precompile(Tuple{typeof(FileWatching._uv_hook_close), FileWatching.FileMonitor})
170
170
"""
171
171
end
172
172
@@ -184,33 +184,33 @@ Test = get(Base.loaded_modules,
184
184
nothing )
185
185
if Test != = nothing
186
186
hardcoded_precompile_statements *= """
187
- @assert precompile(Tuple{typeof(Test.do_test), Test.ExecutionResult, Any})
188
- @assert precompile(Tuple{typeof(Test.testset_beginend), Tuple{String, Expr}, Expr, LineNumberNode})
189
- @assert precompile(Tuple{Type{Test.DefaultTestSet}, String})
190
- @assert precompile(Tuple{Type{Test.DefaultTestSet}, AbstractString})
191
- @assert precompile(Tuple{Core.kwftype(Type{Test.DefaultTestSet}), Any, Type{Test.DefaultTestSet}, AbstractString})
192
- @assert precompile(Tuple{typeof(Test.finish), Test.DefaultTestSet})
193
- @assert precompile(Tuple{typeof(Test.eval_test), Expr, Expr, LineNumberNode, Bool})
194
- @assert precompile(Tuple{typeof(Test._inferred), Expr, Module})
195
- @assert precompile(Tuple{typeof(Test.push_testset), Test.DefaultTestSet})
196
- @assert precompile(Tuple{typeof(Test.get_alignment), Test.DefaultTestSet, Int})
197
- @assert precompile(Tuple{typeof(Test.get_test_result), Any, Any})
198
- @assert precompile(Tuple{typeof(Test.do_test_throws), Test.ExecutionResult, Any, Any})
199
- @assert precompile(Tuple{typeof(Test.print_counts), Test.DefaultTestSet, Int, Int, Int, Int, Int, Int, Int})
200
- @assert precompile(Tuple{typeof(Test._check_testset), Type, Expr})
201
- @assert precompile(Tuple{typeof(Test.test_expr!), Any, Any})
202
- @assert precompile(Tuple{typeof(Test.test_expr!), Any, Any, Vararg{Any, 100}})
203
- @assert precompile(Tuple{typeof(Test.pop_testset)})
204
- @assert precompile(Tuple{typeof(Test.match_logs), Function, Tuple{Symbol, Regex}})
205
- @assert precompile(Tuple{typeof(Test.match_logs), Function, Tuple{String, Regex}})
206
- @assert precompile(Tuple{typeof(Base.CoreLogging.shouldlog), Test.TestLogger, Base.CoreLogging.LogLevel, Module, Symbol, Symbol})
207
- @assert precompile(Tuple{typeof(Base.CoreLogging.handle_message), Test.TestLogger, Base.CoreLogging.LogLevel, String, Module, Symbol, Symbol, String, Int})
208
- @assert precompile(Tuple{typeof(Core.kwfunc(Base.CoreLogging.handle_message)), typeof((exception=nothing,)), typeof(Base.CoreLogging.handle_message), Test.TestLogger, Base.CoreLogging.LogLevel, String, Module, Symbol, Symbol, String, Int})
209
- @assert precompile(Tuple{typeof(Test.detect_ambiguities), Any})
210
- @assert precompile(Tuple{typeof(Test.collect_test_logs), Function})
211
- @assert precompile(Tuple{typeof(Test.do_broken_test), Test.ExecutionResult, Any})
212
- @assert precompile(Tuple{typeof(Test.record), Test.DefaultTestSet, Union{Test.Error, Test.Fail}})
213
- @assert precompile(Tuple{typeof(Test.filter_errors), Test.DefaultTestSet})
187
+ precompile(Tuple{typeof(Test.do_test), Test.ExecutionResult, Any})
188
+ precompile(Tuple{typeof(Test.testset_beginend), Tuple{String, Expr}, Expr, LineNumberNode})
189
+ precompile(Tuple{Type{Test.DefaultTestSet}, String})
190
+ precompile(Tuple{Type{Test.DefaultTestSet}, AbstractString})
191
+ precompile(Tuple{Core.kwftype(Type{Test.DefaultTestSet}), Any, Type{Test.DefaultTestSet}, AbstractString})
192
+ precompile(Tuple{typeof(Test.finish), Test.DefaultTestSet})
193
+ precompile(Tuple{typeof(Test.eval_test), Expr, Expr, LineNumberNode, Bool})
194
+ precompile(Tuple{typeof(Test._inferred), Expr, Module})
195
+ precompile(Tuple{typeof(Test.push_testset), Test.DefaultTestSet})
196
+ precompile(Tuple{typeof(Test.get_alignment), Test.DefaultTestSet, Int})
197
+ precompile(Tuple{typeof(Test.get_test_result), Any, Any})
198
+ precompile(Tuple{typeof(Test.do_test_throws), Test.ExecutionResult, Any, Any})
199
+ precompile(Tuple{typeof(Test.print_counts), Test.DefaultTestSet, Int, Int, Int, Int, Int, Int, Int})
200
+ precompile(Tuple{typeof(Test._check_testset), Type, Expr})
201
+ precompile(Tuple{typeof(Test.test_expr!), Any, Any})
202
+ precompile(Tuple{typeof(Test.test_expr!), Any, Any, Vararg{Any, 100}})
203
+ precompile(Tuple{typeof(Test.pop_testset)})
204
+ precompile(Tuple{typeof(Test.match_logs), Function, Tuple{Symbol, Regex}})
205
+ precompile(Tuple{typeof(Test.match_logs), Function, Tuple{String, Regex}})
206
+ precompile(Tuple{typeof(Base.CoreLogging.shouldlog), Test.TestLogger, Base.CoreLogging.LogLevel, Module, Symbol, Symbol})
207
+ precompile(Tuple{typeof(Base.CoreLogging.handle_message), Test.TestLogger, Base.CoreLogging.LogLevel, String, Module, Symbol, Symbol, String, Int})
208
+ precompile(Tuple{typeof(Core.kwfunc(Base.CoreLogging.handle_message)), typeof((exception=nothing,)), typeof(Base.CoreLogging.handle_message), Test.TestLogger, Base.CoreLogging.LogLevel, String, Module, Symbol, Symbol, String, Int})
209
+ precompile(Tuple{typeof(Test.detect_ambiguities), Any})
210
+ precompile(Tuple{typeof(Test.collect_test_logs), Function})
211
+ precompile(Tuple{typeof(Test.do_broken_test), Test.ExecutionResult, Any})
212
+ precompile(Tuple{typeof(Test.record), Test.DefaultTestSet, Union{Test.Error, Test.Fail}})
213
+ precompile(Tuple{typeof(Test.filter_errors), Test.DefaultTestSet})
214
214
"""
215
215
end
216
216
@@ -219,7 +219,7 @@ Profile = get(Base.loaded_modules,
219
219
nothing )
220
220
if Profile != = nothing
221
221
hardcoded_precompile_statements *= """
222
- @assert precompile(Tuple{typeof(Profile.tree!), Profile.StackFrameTree{UInt64}, Vector{UInt64}, Dict{UInt64, Vector{Base.StackTraces.StackFrame}}, Bool, Symbol})
222
+ precompile(Tuple{typeof(Profile.tree!), Profile.StackFrameTree{UInt64}, Vector{UInt64}, Dict{UInt64, Vector{Base.StackTraces.StackFrame}}, Bool, Symbol})
223
223
"""
224
224
end
225
225
@@ -350,32 +350,49 @@ function generate_precompile_statements()
350
350
n_succeeded = 0
351
351
include_time = @elapsed for statement in sort! (collect (statements))
352
352
# println(statement)
353
- # The compiler has problem caching signatures with `Vararg{?, N}`. Replacing
354
- # N with a large number seems to work around it.
353
+ # XXX : skip some that are broken. these are caused by issue #39902
354
+ occursin (" Tuple{Artifacts.var\" #@artifact_str\" , LineNumberNode, Module, Any, Any}" , statement) && continue
355
+ occursin (" Tuple{Base.Cartesian.var\" #@ncall\" , LineNumberNode, Module, Int64, Any, Vararg{Any}}" , statement) && continue
356
+ occursin (" Tuple{Base.Cartesian.var\" #@ncall\" , LineNumberNode, Module, Int32, Any, Vararg{Any}}" , statement) && continue
357
+ occursin (" Tuple{Base.Cartesian.var\" #@nloops\" , LineNumberNode, Module, Any, Any, Any, Vararg{Any}}" , statement) && continue
358
+ occursin (" Tuple{Core.var\" #@doc\" , LineNumberNode, Module, Vararg{Any}}" , statement) && continue
359
+ # XXX : this is strange, as this isn't the correct representation of this
360
+ occursin (" typeof(Core.IntrinsicFunction)" , statement) && continue
361
+ # XXX : this is strange, as this method should not be getting compiled
362
+ occursin (" , Core.Compiler.AbstractInterpreter, " , statement) && continue
355
363
try
356
364
ps = Meta. parse (statement)
357
- if isexpr (ps, :call )
358
- if isexpr (ps. args[end ], :curly )
359
- l = ps. args[end ]
360
- if length (l. args) == 2 && l. args[1 ] == :Vararg
361
- push! (l. args, 100 )
362
- end
365
+ isexpr (ps, :call ) || continue
366
+ popfirst! (ps. args) # precompile(...)
367
+ ps. head = :tuple
368
+ l = ps. args[end ]
369
+ if (isexpr (l, :tuple ) || isexpr (l, :curly )) && length (l. args) > 0 # Tuple{...} or (...)
370
+ # XXX : precompile doesn't currently handle overloaded Vararg arguments very well.
371
+ # Replacing N with a large number works around it.
372
+ l = l. args[end ]
373
+ if isexpr (l, :curly ) && length (l. args) == 2 && l. args[1 ] == :Vararg # Vararg{T}
374
+ push! (l. args, 100 ) # form Vararg{T, 100} instead
363
375
end
364
376
end
365
377
# println(ps)
366
- Core. eval (PrecompileStagingArea, ps)
378
+ ps = Core. eval (PrecompileStagingArea, ps)
379
+ # XXX : precompile doesn't currently handle overloaded nospecialize arguments very well.
380
+ # Skipping them avoids the warning.
381
+ ms = length (ps) == 1 ? Base. _methods_by_ftype (ps[1 ], 1 , Base. get_world_counter ()) : Base. methods (ps... )
382
+ ms isa Vector || continue
383
+ precompile (ps... )
367
384
n_succeeded += 1
368
385
print (" \r Executing precompile statements... $n_succeeded /$(length (statements)) " )
369
- catch
386
+ catch ex
370
387
# See #28808
371
- # @error "Failed to precompile $statement"
388
+ @warn " Failed to precompile expression " form = statement exception = ex _module = nothing _file = nothing _line = 0
372
389
end
373
390
end
374
391
println ()
375
392
if have_repl
376
393
# Seems like a reasonable number right now, adjust as needed
377
394
# comment out if debugging script
378
- @assert n_succeeded > 1200
395
+ n_succeeded > 1200 || @warn " Only $n_succeeded precompile statements "
379
396
end
380
397
381
398
tot_time = time_ns () - start_time
0 commit comments