Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a global cache to the toml parsing in loading and propagate that to precompile processes #37906

Merged
merged 1 commit into from
Oct 11, 2020
Merged
Show file tree
Hide file tree
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
262 changes: 159 additions & 103 deletions base/loading.jl

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions base/sysimg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ let
empty!(DEPOT_PATH)
end

empty!(Base.TOML_CACHE.d)
Base.TOML.reinit!(Base.TOML_CACHE.p, "")
@eval Sys begin
BINDIR = ""
STDLIB = ""
Expand Down
2 changes: 1 addition & 1 deletion base/toml_parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function Parser(str::String; filepath=nothing)
IdSet{TOMLDict}(), # defined_tables
root,
filepath,
get(Base.loaded_modules, DATES_PKGID, nothing),
isdefined(Base, :loaded_modules) ? get(Base.loaded_modules, DATES_PKGID, nothing) : nothing,
)
startup(l)
return l
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Profile/src/Profile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ function short_path(spath::Symbol, filenamecache::Dict{Symbol, String})
for proj in Base.project_names
project_file = joinpath(root, proj)
if Base.isfile_casesensitive(project_file)
pkgid = Base.project_file_name_uuid(project_file, "", Base.TOMLCache())
pkgid = Base.project_file_name_uuid(project_file, "")
isempty(pkgid.name) && return path # bad Project file
# return the joined the module name prefix and path suffix
path = path[nextind(path, sizeof(root)):end]
Expand Down
13 changes: 7 additions & 6 deletions stdlib/REPL/src/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -583,15 +583,16 @@ end

function project_deps_get_completion_candidates(pkgstarts::String, project_file::String)
loading_candidates = String[]
p = Base.TOML.Parser()
Base.TOML.reinit!(p, read(project_file, String); filepath=project_file)
d = Base.TOML.parse(p)
pkg = get(d, "name", nothing)
d = Base.parsed_toml(project_file)
pkg = get(d, "name", nothing)::Union{String, Nothing}
if pkg !== nothing && startswith(pkg, pkgstarts)
push!(loading_candidates, pkg)
end
for (pkg, _) in get(d, "deps", [])
startswith(pkg, pkgstarts) && push!(loading_candidates, pkg)
deps = get(d, "deps", nothing)::Union{Dict{String, Any}, Nothing}
if deps !== nothing
for (pkg, _) in deps
startswith(pkg, pkgstarts) && push!(loading_candidates, pkg)
end
end
return Completion[PackageCompletion(name) for name in loading_candidates]
end
Expand Down
11 changes: 5 additions & 6 deletions test/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,9 @@ end
d = findfirst(line -> line == "[deps]", p)
t = findfirst(line -> startswith(line, "This"), p)
# look up various packages by name
cache = Base.TOMLCache()
root = Base.explicit_project_deps_get(project_file, "Root", cache)
this = Base.explicit_project_deps_get(project_file, "This", cache)
that = Base.explicit_project_deps_get(project_file, "That", cache)
root = Base.explicit_project_deps_get(project_file, "Root")
this = Base.explicit_project_deps_get(project_file, "This")
that = Base.explicit_project_deps_get(project_file, "That")
# test that the correct answers are given
@test root == (something(n, N+1) ≥ something(d, N+1) ? nothing :
something(u, N+1) < something(d, N+1) ? root_uuid : proj_uuid)
Expand All @@ -205,13 +204,13 @@ Base.ACTIVE_PROJECT[] = nothing

# locate `tail(names)` package by following the search path graph through `names` starting from `where`
function recurse_package(where::PkgId, name::String, names::String...)
pkg = identify_package(where, name, Base.TOMLCache())
pkg = identify_package(where, name)
pkg === nothing && return nothing
return recurse_package(pkg, names...)
end

recurse_package(pkg::String) = identify_package(pkg)
recurse_package(where::PkgId, pkg::String) = identify_package(where, pkg, Base.TOMLCache())
recurse_package(where::PkgId, pkg::String) = identify_package(where, pkg)

function recurse_package(name::String, names::String...)
pkg = identify_package(name)
Expand Down
4 changes: 2 additions & 2 deletions test/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ try
# 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
ms = Base._require_from_serialized(cachefile, Base.TOMLCache())
ms = Base._require_from_serialized(cachefile)
@test isa(ms, Array{Any,1})
end

Expand Down Expand Up @@ -417,7 +417,7 @@ try
""")

cachefile = Base.compilecache(Base.PkgId("FooBar"))
@test cachefile == Base.compilecache_path(Base.PkgId("FooBar"), Base.TOMLCache())
@test cachefile == Base.compilecache_path(Base.PkgId("FooBar"))
@test isfile(joinpath(cachedir, "FooBar.ji"))
@test Base.stale_cachefile(FooBar_file, joinpath(cachedir, "FooBar.ji")) isa Vector
@test !isdefined(Main, :FooBar)
Expand Down