@@ -118,58 +118,22 @@ end
118
118
119
119
# these return either the array of modules loaded from the path / content given
120
120
# or an Exception that describes why it couldn't be loaded
121
- function _include_from_serialized (content:: Vector{UInt8} , depmods :: Vector{Module} )
122
- return ccall (:jl_restore_incremental_from_buf , Any, (Ptr{UInt8}, Int, Any ), content, sizeof (content), depmods )
121
+ function _include_from_serialized (content:: Vector{UInt8} )
122
+ return ccall (:jl_restore_incremental_from_buf , Any, (Ptr{UInt8}, Int), content, sizeof (content))
123
123
end
124
- function _include_from_serialized (path:: String , depmods :: Vector{Module} )
125
- return ccall (:jl_restore_incremental , Any, (Cstring, Any ), path, depmods )
124
+ function _include_from_serialized (path:: String )
125
+ return ccall (:jl_restore_incremental , Any, (Cstring,), path)
126
126
end
127
127
128
128
# returns an array of modules loaded, or an Exception that describes why it failed
129
129
# and it reconnects the Base.Docs.META
130
130
function _require_from_serialized (mod:: Symbol , path_to_try:: String )
131
- return _require_from_serialized (mod, path_to_try, parse_cache_header (path_to_try)[3 ])
132
- end
133
- function _require_from_serialized (mod:: Symbol , path_to_try:: String , depmodnames:: Vector{Pair{Symbol, UInt64}} )
134
- # load all of the dependent modules
135
- ndeps = length (depmodnames)
136
- depmods = Vector {Module} (uninitialized, ndeps)
137
- for i in 1 : ndeps
138
- modname, uuid = depmodnames[i]
139
- if root_module_exists (modname)
140
- M = root_module (modname)
141
- if module_name (M) === modname && module_uuid (M) === uuid
142
- depmods[i] = M
143
- end
144
- else
145
- modpath = find_package (string (modname))
146
- modpath === nothing && return ErrorException (" Required dependency $modname not found in current path." )
147
- mod = _require_search_from_serialized (modname, String (modpath))
148
- if ! isa (mod, Bool)
149
- for M in mod:: Vector{Any}
150
- if module_name (M) === modname && module_uuid (M) === uuid
151
- depmods[i] = M
152
- break
153
- end
154
- end
155
- for callback in package_callbacks
156
- invokelatest (callback, modname)
157
- end
158
- end
159
- end
160
- isassigned (depmods, i) || return ErrorException (" Required dependency $modname failed to load from a cache file." )
161
- end
162
- # now load the path_to_try.ji file
163
- restored = _include_from_serialized (path_to_try, depmods)
131
+ restored = _include_from_serialized (path_to_try)
164
132
if ! isa (restored, Exception)
165
133
for M in restored:: Vector{Any}
166
- M = M:: Module
167
134
if isdefined (M, Base. Docs. META)
168
135
push! (Base. Docs. modules, M)
169
136
end
170
- if module_parent (M) === M
171
- register_root_module (module_name (M), M)
172
- end
173
137
end
174
138
end
175
139
return restored
@@ -181,13 +145,12 @@ end
181
145
function _require_search_from_serialized (mod:: Symbol , sourcepath:: String )
182
146
paths = find_all_in_cache_path (mod)
183
147
for path_to_try in paths:: Vector{String}
184
- deps = stale_cachefile (sourcepath, path_to_try)
185
- if deps === true
148
+ if stale_cachefile (sourcepath, path_to_try)
186
149
continue
187
150
end
188
- restored = _require_from_serialized (mod, path_to_try, deps )
151
+ restored = _require_from_serialized (mod, path_to_try)
189
152
if isa (restored, Exception)
190
- if isa (restored, ErrorException)
153
+ if isa (restored, ErrorException) && endswith (restored . msg, " uuid did not match cache file. " )
191
154
# can't use this cache due to a module uuid mismatch,
192
155
# defer reporting error until after trying all of the possible matches
193
156
DEBUG_LOADING[] && info (" JL_DEBUG_LOADING: Failed to load $path_to_try because $(restored. msg) " )
@@ -220,7 +183,7 @@ const package_callbacks = Any[]
220
183
const include_callbacks = Any[]
221
184
222
185
# used to optionally track dependencies when requiring a module:
223
- const _concrete_dependencies = Pair{Symbol, UInt64} [] # these dependency versions are "set in stone", and the process should try to avoid invalidating them
186
+ const _concrete_dependencies = Any [] # these dependency versions are "set in stone", and the process should try to avoid invalidating them
224
187
const _require_dependencies = Any[] # a list of (mod, path, mtime) tuples that are the file dependencies of the module currently being precompiled
225
188
const _track_dependencies = Ref (false ) # set this to true to track the list of file dependencies
226
189
function _include_dependency (modstring:: AbstractString , _path:: AbstractString )
@@ -400,6 +363,14 @@ function unreference_module(key)
400
363
end
401
364
end
402
365
366
+ function register_all (a)
367
+ for m in a
368
+ if module_parent (m) === m
369
+ register_root_module (module_name (m), m)
370
+ end
371
+ end
372
+ end
373
+
403
374
function _require (mod:: Symbol )
404
375
# dependency-tracking is only used for one top-level include(path),
405
376
# and is not applied recursively to imported modules:
@@ -425,13 +396,13 @@ function _require(mod::Symbol)
425
396
if path === nothing
426
397
throw (ArgumentError (" Module $name not found in current path.\n Run `Pkg.add(\" $name \" )` to install the $name package." ))
427
398
end
428
- path = String (path)
429
399
430
400
# attempt to load the module file via the precompile cache locations
431
401
doneprecompile = false
432
402
if JLOptions (). use_compiled_modules != 0
433
403
doneprecompile = _require_search_from_serialized (mod, path)
434
404
if ! isa (doneprecompile, Bool)
405
+ register_all (doneprecompile)
435
406
return
436
407
end
437
408
end
@@ -459,6 +430,7 @@ function _require(mod::Symbol)
459
430
warn (m, prefix= " WARNING: " )
460
431
# fall-through, TODO : disable __precompile__(true) error so that the normal include will succeed
461
432
else
433
+ register_all (m)
462
434
return
463
435
end
464
436
end
@@ -480,6 +452,7 @@ function _require(mod::Symbol)
480
452
# TODO : disable __precompile__(true) error and do normal include instead of error
481
453
error (" Module $mod declares __precompile__(true) but require failed to create a usable precompiled cache file." )
482
454
end
455
+ register_all (m)
483
456
end
484
457
finally
485
458
toplevel_load[] = last
@@ -572,7 +545,7 @@ function evalfile(path::AbstractString, args::Vector{String}=String[])
572
545
end
573
546
evalfile (path:: AbstractString , args:: Vector ) = evalfile (path, String[args... ])
574
547
575
- function create_expr_cache (input:: String , output:: String , concrete_deps:: typeof (_concrete_dependencies) )
548
+ function create_expr_cache (input:: String , output:: String , concrete_deps:: Vector{Any} )
576
549
rm (output, force= true ) # Remove file if it exists
577
550
code_object = """
578
551
while !eof(STDIN)
@@ -639,12 +612,12 @@ function compilecache(name::String)
639
612
if ! isdir (cachepath)
640
613
mkpath (cachepath)
641
614
end
642
- cachefile:: String = abspath (cachepath, " $ name .ji" )
615
+ cachefile:: String = abspath (cachepath, name* " .ji" )
643
616
# build up the list of modules that we want the precompile process to preserve
644
617
concrete_deps = copy (_concrete_dependencies)
645
- for (key, mod) in loaded_modules
618
+ for (key,mod) in loaded_modules
646
619
if ! (mod === Main || mod === Core || mod === Base)
647
- push! (concrete_deps, key => module_uuid (mod))
620
+ push! (concrete_deps, ( key, module_uuid (mod) ))
648
621
end
649
622
end
650
623
# run the expression and cache the result
@@ -671,13 +644,13 @@ module_uuid(m::Module) = ccall(:jl_module_uuid, UInt64, (Any,), m)
671
644
isvalid_cache_header (f:: IOStream ) = 0 != ccall (:jl_read_verify_header , Cint, (Ptr{Void},), f. ios)
672
645
673
646
function parse_cache_header (f:: IO )
674
- modules = Vector {Pair{ Symbol, UInt64} } ()
647
+ modules = Dict { Symbol,UInt64} ()
675
648
while true
676
649
n = ntoh (read (f, Int32))
677
650
n == 0 && break
678
651
sym = Symbol (read (f, n)) # module symbol
679
652
uuid = ntoh (read (f, UInt64)) # module UUID (mostly just a timestamp)
680
- push! ( modules, sym => uuid)
653
+ modules[ sym] = uuid
681
654
end
682
655
totbytes = ntoh (read (f, Int64)) # total bytes for file dependencies
683
656
# read the list of files
@@ -696,13 +669,13 @@ function parse_cache_header(f::IO)
696
669
@assert totbytes == 12 " header of cache file appears to be corrupt"
697
670
srctextpos = ntoh (read (f, Int64))
698
671
# read the list of modules that are required to be present during loading
699
- required_modules = Vector {Pair{ Symbol, UInt64} } ()
672
+ required_modules = Dict { Symbol,UInt64} ()
700
673
while true
701
674
n = ntoh (read (f, Int32))
702
675
n == 0 && break
703
676
sym = Symbol (read (f, n)) # module symbol
704
677
uuid = ntoh (read (f, UInt64)) # module UUID
705
- push! ( required_modules, sym => uuid)
678
+ required_modules[ sym] = uuid
706
679
end
707
680
return modules, files, required_modules, srctextpos
708
681
end
@@ -763,8 +736,6 @@ function read_dependency_src(cachefile::String, filename::AbstractString)
763
736
end
764
737
end
765
738
766
- # returns true if it "cachefile.ji" is stale relative to "modpath.jl"
767
- # otherwise returns the list of dependencies to also check
768
739
function stale_cachefile (modpath:: String , cachefile:: String )
769
740
io = open (cachefile, " r" )
770
741
try
@@ -773,12 +744,13 @@ function stale_cachefile(modpath::String, cachefile::String)
773
744
return true # invalid cache file
774
745
end
775
746
modules, files, required_modules = parse_cache_header (io)
776
- modules = Dict {Symbol, UInt64} (modules)
777
747
778
748
# Check if transitive dependencies can be fullfilled
779
- for (mod, uuid_req) in required_modules
749
+ for mod in keys (required_modules)
750
+ if mod == :Main || mod == :Core || mod == :Base
751
+ continue
780
752
# Module is already loaded
781
- if root_module_exists (mod)
753
+ elseif root_module_exists (mod)
782
754
continue
783
755
end
784
756
name = string (mod)
@@ -796,7 +768,7 @@ function stale_cachefile(modpath::String, cachefile::String)
796
768
uuid = get (modules, mod, UInt64 (0 ))
797
769
if uuid != = UInt64 (0 )
798
770
if uuid === uuid_req
799
- return required_modules # this is the file we want
771
+ return false # this is the file we want
800
772
end
801
773
DEBUG_LOADING[] && info (" JL_DEBUG_LOADING: Rejecting cache file $cachefile because it provides the wrong uuid (got $uuid ) for $mod (want $uuid_req )." )
802
774
return true # cachefile doesn't provide the required version of the dependency
@@ -825,7 +797,7 @@ function stale_cachefile(modpath::String, cachefile::String)
825
797
return true
826
798
end
827
799
828
- return required_modules # fresh cachefile
800
+ return false # fresh cachefile
829
801
finally
830
802
close (io)
831
803
end
0 commit comments