Skip to content

Commit 736c469

Browse files
committed
add a global cache to the toml parsing in loading and propagate that to precompile processes
1 parent be1f3ab commit 736c469

File tree

7 files changed

+173
-119
lines changed

7 files changed

+173
-119
lines changed

base/loading.jl

Lines changed: 155 additions & 103 deletions
Large diffs are not rendered by default.

base/sysimg.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ let
110110
empty!(DEPOT_PATH)
111111
end
112112

113+
empty!(Base.TOML_CACHE.d)
114+
Base.TOML.reinit!(Base.TOML_CACHE.p, "")
113115
@eval Sys begin
114116
BINDIR = ""
115117
STDLIB = ""

base/toml_parser.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function Parser(str::String; filepath=nothing)
102102
IdSet{TOMLDict}(), # defined_tables
103103
root,
104104
filepath,
105-
get(Base.loaded_modules, DATES_PKGID, nothing),
105+
isdefined(Base, :loaded_modules) ? get(Base.loaded_modules, DATES_PKGID, nothing) : nothing,
106106
)
107107
startup(l)
108108
return l

stdlib/Profile/src/Profile.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ function short_path(spath::Symbol, filenamecache::Dict{Symbol, String})
271271
for proj in Base.project_names
272272
project_file = joinpath(root, proj)
273273
if Base.isfile_casesensitive(project_file)
274-
pkgid = Base.project_file_name_uuid(project_file, "", Base.TOMLCache())
274+
pkgid = Base.project_file_name_uuid(project_file, "")
275275
isempty(pkgid.name) && return path # bad Project file
276276
# return the joined the module name prefix and path suffix
277277
path = path[nextind(path, sizeof(root)):end]

stdlib/REPL/src/REPLCompletions.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -583,15 +583,16 @@ end
583583

584584
function project_deps_get_completion_candidates(pkgstarts::String, project_file::String)
585585
loading_candidates = String[]
586-
p = Base.TOML.Parser()
587-
Base.TOML.reinit!(p, read(project_file, String); filepath=project_file)
588-
d = Base.TOML.parse(p)
589-
pkg = get(d, "name", nothing)
586+
d = Base.parsed_toml(project_file)
587+
pkg = get(d, "name", nothing)::Union{String, Nothing}
590588
if pkg !== nothing && startswith(pkg, pkgstarts)
591589
push!(loading_candidates, pkg)
592590
end
593-
for (pkg, _) in get(d, "deps", [])
594-
startswith(pkg, pkgstarts) && push!(loading_candidates, pkg)
591+
deps = get(d, "deps", nothing)::Union{Dict{String, Any}, Nothing}
592+
if deps !== nothing
593+
for (pkg, _) in deps
594+
startswith(pkg, pkgstarts) && push!(loading_candidates, pkg)
595+
end
595596
end
596597
return Completion[PackageCompletion(name) for name in loading_candidates]
597598
end

test/loading.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,9 @@ end
176176
d = findfirst(line -> line == "[deps]", p)
177177
t = findfirst(line -> startswith(line, "This"), p)
178178
# look up various packages by name
179-
cache = Base.TOMLCache()
180-
root = Base.explicit_project_deps_get(project_file, "Root", cache)
181-
this = Base.explicit_project_deps_get(project_file, "This", cache)
182-
that = Base.explicit_project_deps_get(project_file, "That", cache)
179+
root = Base.explicit_project_deps_get(project_file, "Root")
180+
this = Base.explicit_project_deps_get(project_file, "This")
181+
that = Base.explicit_project_deps_get(project_file, "That")
183182
# test that the correct answers are given
184183
@test root == (something(n, N+1) something(d, N+1) ? nothing :
185184
something(u, N+1) < something(d, N+1) ? root_uuid : proj_uuid)
@@ -205,13 +204,13 @@ Base.ACTIVE_PROJECT[] = nothing
205204

206205
# locate `tail(names)` package by following the search path graph through `names` starting from `where`
207206
function recurse_package(where::PkgId, name::String, names::String...)
208-
pkg = identify_package(where, name, Base.TOMLCache())
207+
pkg = identify_package(where, name)
209208
pkg === nothing && return nothing
210209
return recurse_package(pkg, names...)
211210
end
212211

213212
recurse_package(pkg::String) = identify_package(pkg)
214-
recurse_package(where::PkgId, pkg::String) = identify_package(where, pkg, Base.TOMLCache())
213+
recurse_package(where::PkgId, pkg::String) = identify_package(where, pkg)
215214

216215
function recurse_package(name::String, names::String...)
217216
pkg = identify_package(name)

test/precompile.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ try
244244
# use _require_from_serialized to ensure that the test fails if
245245
# the module doesn't reload from the image:
246246
@test_logs (:warn, "Replacing module `$Foo_module`") begin
247-
ms = Base._require_from_serialized(cachefile, Base.TOMLCache())
247+
ms = Base._require_from_serialized(cachefile)
248248
@test isa(ms, Array{Any,1})
249249
end
250250

@@ -417,7 +417,7 @@ try
417417
""")
418418

419419
cachefile = Base.compilecache(Base.PkgId("FooBar"))
420-
@test cachefile == Base.compilecache_path(Base.PkgId("FooBar"), Base.TOMLCache())
420+
@test cachefile == Base.compilecache_path(Base.PkgId("FooBar"))
421421
@test isfile(joinpath(cachedir, "FooBar.ji"))
422422
@test Base.stale_cachefile(FooBar_file, joinpath(cachedir, "FooBar.ji")) isa Vector
423423
@test !isdefined(Main, :FooBar)

0 commit comments

Comments
 (0)