Skip to content

Commit

Permalink
Merge pull request #26165 from JuliaLang/sk/load_cache_path_begone
Browse files Browse the repository at this point in the history
loading: delete LOAD_CACHE_PATH
  • Loading branch information
StefanKarpinski authored Feb 23, 2018
2 parents f32a9ce + 675e66d commit 33ca610
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 51 deletions.
1 change: 0 additions & 1 deletion base/initdefs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ function and `using` and `import` statements to consider when loading
code.
"""
const LOAD_PATH = Any[]
const LOAD_CACHE_PATH = String[]

function parse_load_path(str::String)
envs = Any[split(str, Sys.iswindows() ? ';' : ':');]
Expand Down
24 changes: 11 additions & 13 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -638,15 +638,17 @@ function find_source_file(path::AbstractString)
return isfile(base_path) ? base_path : nothing
end

cache_file_entry(pkg::PkgId) =
pkg.uuid === nothing ? "$(pkg.name).ji" :
joinpath(pkg.name, "$(package_slug(pkg.uuid)).ji")
cache_file_entry(pkg::PkgId) = joinpath(
"compiled",
"v$(VERSION.major).$(VERSION.minor)",
pkg.uuid === nothing ? "$(pkg.name).ji" : joinpath(pkg.name, "$(package_slug(pkg.uuid)).ji")
)

function find_all_in_cache_path(pkg::PkgId)
paths = String[]
suffix = cache_file_entry(pkg)
for prefix in LOAD_CACHE_PATH
path = joinpath(prefix, suffix)
entry = cache_file_entry(pkg)
for depot in DEPOT_PATH
path = joinpath(depot, entry)
isfile_casesensitive(path) && push!(paths, path)
end
return paths
Expand Down Expand Up @@ -1133,8 +1135,6 @@ function create_expr_cache(input::String, output::String, concrete_deps::typeof(
append!(Base.LOAD_PATH, $(repr(LOAD_PATH, context=:module=>nothing)))
empty!(Base.DEPOT_PATH)
append!(Base.DEPOT_PATH, $(repr(DEPOT_PATH)))
empty!(Base.LOAD_CACHE_PATH)
append!(Base.LOAD_CACHE_PATH, $(repr(LOAD_CACHE_PATH)))
empty!(Base.DL_LOAD_PATH)
append!(Base.DL_LOAD_PATH, $(repr(DL_LOAD_PATH)))
Base._track_dependencies[] = true
Expand Down Expand Up @@ -1173,11 +1173,9 @@ end
"""
Base.compilecache(module::PkgId)
Creates a precompiled cache file for
a module and all of its dependencies.
Creates a precompiled cache file for a module and all of its dependencies.
This can be used to reduce package load times. Cache files are stored in
`LOAD_CACHE_PATH[1]`, which defaults to `~/.julia/lib/VERSION`. See
[Module initialization and precompilation](@ref)
`DEPOT_PATH[1]/compiled`. See [Module initialization and precompilation](@ref)
for important notes.
"""
function compilecache(pkg::PkgId)
Expand All @@ -1186,7 +1184,7 @@ function compilecache(pkg::PkgId)
path = locate_package(pkg)
path === nothing && throw(ArgumentError("$name not found in path"))
# decide where to put the resulting cache file
cachefile = abspath(LOAD_CACHE_PATH[1], cache_file_entry(pkg))
cachefile = abspath(DEPOT_PATH[1], cache_file_entry(pkg))
cachepath = dirname(cachefile)
isdir(cachepath) || mkpath(cachepath)
# build up the list of modules that we want the precompile process to preserve
Expand Down
2 changes: 1 addition & 1 deletion doc/src/manual/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ versions of modules to reduce this time.
To create an incremental precompiled module file, add `__precompile__()` at the top of your module
file (before the `module` starts). This will cause it to be automatically compiled the first time
it is imported. Alternatively, you can manually call `Base.compilecache(modulename)`. The resulting
cache files will be stored in `Base.LOAD_CACHE_PATH[1]`. Subsequently, the module is automatically
cache files will be stored in `DEPOT_PATH[1]/compiled/`. Subsequently, the module is automatically
recompiled upon `import` whenever any of its dependencies change; dependencies are modules it
imports, the Julia build, files it includes, or explicit dependencies declared by `include_dependency(path)`
in the module file(s).
Expand Down
1 change: 0 additions & 1 deletion stdlib/Pkg/src/Pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ init(meta::AbstractString=DEFAULT_META, branch::AbstractString=META_BRANCH) = Di
function __init__()
vers = "v$(VERSION.major).$(VERSION.minor)"
push!(Base.LOAD_PATH, dir)
pushfirst!(Base.LOAD_CACHE_PATH, abspath(Dir._pkgroot(), "lib", vers))
end

"""
Expand Down
2 changes: 0 additions & 2 deletions stdlib/Pkg/src/entry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,6 @@ function build(pkg::AbstractString, build_file::AbstractString, errfile::Abstrac
append!(Base.LOAD_PATH, $(repr(LOAD_PATH, context=:module=>nothing)))
empty!(Base.DEPOT_PATH)
append!(Base.DEPOT_PATH, $(repr(DEPOT_PATH)))
empty!(Base.LOAD_CACHE_PATH)
append!(Base.LOAD_CACHE_PATH, $(repr(Base.LOAD_CACHE_PATH)))
empty!(Base.DL_LOAD_PATH)
append!(Base.DL_LOAD_PATH, $(repr(Base.DL_LOAD_PATH)))
open("$(escape_string(errfile))", "a") do f
Expand Down
60 changes: 31 additions & 29 deletions test/compile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ using .ConflictingBindings
dir = mktempdir()
dir2 = mktempdir()
insert!(LOAD_PATH, 1, dir)
insert!(Base.LOAD_CACHE_PATH, 1, dir)
insert!(DEPOT_PATH, 1, dir)
try
Foo_file = joinpath(dir, "$Foo_module.jl")
Foo2_file = joinpath(dir, "$Foo2_module.jl")
Expand Down Expand Up @@ -166,7 +166,9 @@ try
@test Foo.override(UInt(1)) == 2
end

cachefile = joinpath(dir, "$Foo_module.ji")
cachedir = joinpath(dir, "compiled", "v$(VERSION.major).$(VERSION.minor)")
cachedir2 = joinpath(dir2, "compiled", "v$(VERSION.major).$(VERSION.minor)")
cachefile = joinpath(cachedir, "$Foo_module.ji")
# use _require_from_serialized to ensure that the test fails if
# the module doesn't reload from the image:
@test_logs (:warn, "Replacing module `$Foo_module`") begin
Expand Down Expand Up @@ -293,36 +295,36 @@ try
""")

Base.compilecache(Base.PkgId("FooBar"))
@test isfile(joinpath(dir, "FooBar.ji"))
@test Base.stale_cachefile(FooBar_file, joinpath(dir, "FooBar.ji")) isa Vector
@test isfile(joinpath(cachedir, "FooBar.ji"))
@test Base.stale_cachefile(FooBar_file, joinpath(cachedir, "FooBar.ji")) isa Vector
@test !isdefined(Main, :FooBar)
@test !isdefined(Main, :FooBar1)

relFooBar_file = joinpath(dir, "subfolder", "..", "FooBar.jl")
@test Base.stale_cachefile(relFooBar_file, joinpath(dir, "FooBar.ji")) isa (Sys.iswindows() ? Vector : Bool) # `..` is not a symlink on Windows
@test Base.stale_cachefile(relFooBar_file, joinpath(cachedir, "FooBar.ji")) isa (Sys.iswindows() ? Vector : Bool) # `..` is not a symlink on Windows
mkdir(joinpath(dir, "subfolder"))
@test Base.stale_cachefile(relFooBar_file, joinpath(dir, "FooBar.ji")) isa Vector
@test Base.stale_cachefile(relFooBar_file, joinpath(cachedir, "FooBar.ji")) isa Vector

@eval using FooBar
fb_uuid = Base.module_build_id(FooBar)
sleep(2); touch(FooBar_file)
insert!(Base.LOAD_CACHE_PATH, 1, dir2)
@test Base.stale_cachefile(FooBar_file, joinpath(dir, "FooBar.ji")) === true
insert!(DEPOT_PATH, 1, dir2)
@test Base.stale_cachefile(FooBar_file, joinpath(cachedir, "FooBar.ji")) === true
@eval using FooBar1
@test !isfile(joinpath(dir2, "FooBar.ji"))
@test !isfile(joinpath(dir, "FooBar1.ji"))
@test isfile(joinpath(dir2, "FooBar1.ji"))
@test Base.stale_cachefile(FooBar_file, joinpath(dir, "FooBar.ji")) === true
@test Base.stale_cachefile(FooBar1_file, joinpath(dir2, "FooBar1.ji")) isa Vector
@test !isfile(joinpath(cachedir2, "FooBar.ji"))
@test !isfile(joinpath(cachedir, "FooBar1.ji"))
@test isfile(joinpath(cachedir2, "FooBar1.ji"))
@test Base.stale_cachefile(FooBar_file, joinpath(cachedir, "FooBar.ji")) === true
@test Base.stale_cachefile(FooBar1_file, joinpath(cachedir2, "FooBar1.ji")) isa Vector
@test fb_uuid == Base.module_build_id(FooBar)
fb_uuid1 = Base.module_build_id(FooBar1)
@test fb_uuid != fb_uuid1

# test checksum
open(joinpath(dir2, "FooBar1.ji"), "a") do f
open(joinpath(cachedir2, "FooBar1.ji"), "a") do f
write(f, 0x076cac96) # append 4 random bytes
end
@test Base.stale_cachefile(FooBar1_file, joinpath(dir2, "FooBar1.ji")) === true
@test Base.stale_cachefile(FooBar1_file, joinpath(cachedir2, "FooBar1.ji")) === true

# test behavior of precompile modules that throw errors
FooBar2_file = joinpath(dir, "FooBar2.jl")
Expand Down Expand Up @@ -373,10 +375,10 @@ try
end
""")
rm(FooBarT_file)
@test Base.stale_cachefile(FooBarT2_file, joinpath(dir2, "FooBarT2.ji")) === true
@test Base.stale_cachefile(FooBarT2_file, joinpath(cachedir2, "FooBarT2.ji")) === true
@test Base.require(Main, :FooBarT2) isa Module
finally
splice!(Base.LOAD_CACHE_PATH, 1:2)
splice!(DEPOT_PATH, 1:2)
splice!(LOAD_PATH, 1)
rm(dir, recursive=true)
rm(dir2, recursive=true)
Expand All @@ -398,15 +400,15 @@ let dir = mktempdir(),

eval(quote
insert!(LOAD_PATH, 1, $(dir))
insert!(Base.LOAD_CACHE_PATH, 1, $(dir))
insert!(DEPOT_PATH, 1, $(dir))
Base.compilecache(Base.PkgId("Time4b3a94a1a081a8cb"))
end)

exename = `$(Base.julia_cmd()) --compiled-modules=yes --startup-file=no`

testcode = """
insert!(LOAD_PATH, 1, $(repr(dir)))
insert!(Base.LOAD_CACHE_PATH, 1, $(repr(dir)))
insert!(DEPOT_PATH, 1, $(repr(dir)))
using $Time_module
getfield($Time_module, :time)
"""
Expand All @@ -421,7 +423,7 @@ let dir = mktempdir(),
@test parse(Float64, t1_no) < parse(Float64, t2_no)

finally
splice!(Base.LOAD_CACHE_PATH, 1)
splice!(DEPOT_PATH, 1)
splice!(LOAD_PATH, 1)
rm(dir, recursive=true)
end
Expand All @@ -448,7 +450,7 @@ let dir = mktempdir()

testcode = """
insert!(LOAD_PATH, 1, $(repr(dir)))
insert!(Base.LOAD_CACHE_PATH, 1, $(repr(dir)))
insert!(DEPOT_PATH, 1, $(repr(dir)))
using $Test_module
"""

Expand Down Expand Up @@ -481,7 +483,7 @@ end
let dir = mktempdir()
try
insert!(LOAD_PATH, 1, dir)
insert!(Base.LOAD_CACHE_PATH, 1, dir)
insert!(DEPOT_PATH, 1, dir)

loaded_modules = Channel{Symbol}(32)
callback = (mod::Base.PkgId) -> put!(loaded_modules, Symbol(mod.name))
Expand Down Expand Up @@ -521,7 +523,7 @@ let dir = mktempdir()
@test take!(loaded_modules) == Test3_module
finally
pop!(Base.package_callbacks)
splice!(Base.LOAD_CACHE_PATH, 1)
splice!(DEPOT_PATH, 1)
splice!(LOAD_PATH, 1)
rm(dir, recursive=true)
end
Expand Down Expand Up @@ -563,7 +565,7 @@ end

@everywhere test_workers begin
pushfirst!(LOAD_PATH, $load_path)
pushfirst!(Base.LOAD_CACHE_PATH, $load_cache_path)
pushfirst!(DEPOT_PATH, $load_cache_path)
end
try
@eval using $ModuleB
Expand All @@ -579,7 +581,7 @@ end
finally
@everywhere test_workers begin
popfirst!(LOAD_PATH)
popfirst!(Base.LOAD_CACHE_PATH)
popfirst!(DEPOT_PATH)
end
end
finally
Expand All @@ -594,7 +596,7 @@ end
(f -> f())() do # wrap in function scope, so we can test world errors
dir = mktempdir()
insert!(LOAD_PATH, 1, dir)
insert!(Base.LOAD_CACHE_PATH, 1, dir)
insert!(DEPOT_PATH, 1, dir)
try
A_module = :Aedb164bd3a126418
B_module = :Bedb164bd3a126418
Expand Down Expand Up @@ -642,7 +644,7 @@ try
@test Base.invokelatest(B.bnopc, 1) == Base.invokelatest(B.bnopc, 1.0) == 2
finally
popfirst!(LOAD_PATH)
popfirst!(Base.LOAD_CACHE_PATH)
popfirst!(DEPOT_PATH)
rm(dir, recursive=true)
end

Expand All @@ -662,7 +664,7 @@ let
""")

pushfirst!(LOAD_PATH, load_path)
pushfirst!(Base.LOAD_CACHE_PATH, load_cache_path)
pushfirst!(DEPOT_PATH, load_cache_path)

l0 = length(Base.package_callbacks)
@eval using $ModuleA
Expand Down Expand Up @@ -700,7 +702,7 @@ let
""")

pushfirst!(LOAD_PATH, load_path)
pushfirst!(Base.LOAD_CACHE_PATH, load_cache_path)
pushfirst!(DEPOT_PATH, load_cache_path)

Base.compilecache(Base.PkgId("A25604"))
@test_nowarn @eval using A25604
Expand Down
4 changes: 0 additions & 4 deletions test/embedding/embedding.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,6 @@ int main()
// locate files relative to the "embedding" executable
" stdlib = filter(env -> startswith(Base.find_package(Base, \"Distributed\"), env), Base.load_path())[end]\n"
" push!(empty!(LOAD_PATH), dir, stdlib)\n"
// this directory needs to be writable for the example,
// although in real code it usually wouldn't necessarily be used that way
" empty!(Base.LOAD_CACHE_PATH)\n"
" push!(Base.LOAD_CACHE_PATH, tempdir())\n"
"end"
);
checked_eval_string("import LocalModule");
Expand Down

1 comment on commit 33ca610

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Executing the daily benchmark build, I will reply here when finished:

@nanosoldier runbenchmarks(ALL, isdaily = true)

Please sign in to comment.