From 69938284d6804dd30a24577397f52dfdedbd37e1 Mon Sep 17 00:00:00 2001 From: Cody Tapscott <84105208+topolarity@users.noreply.github.com> Date: Thu, 25 Jul 2024 23:14:44 -0400 Subject: [PATCH] Use `Base.TOML.Parser{Dates}` for TOML parsing w/ Dates support (#3938) * Use `Base.TOML.Parser{Dates}` for TOML parsing w/ Dates support This will allow us to delete the `.Dates` field upstream. * Use `Base.TOMLCache(p::TOML.Parser)` constructor These were relying on implicit `convert()` behavior in the previous constructor, which is harmless in this case but best not to depend upon. --------- Co-authored-by: Ian Butterworth (cherry picked from commit e4a6723bf3074764ff9266e5e13dfea501431b33) --- src/Registry/registry_instance.jl | 9 +++------ src/Types.jl | 5 +---- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/Registry/registry_instance.jl b/src/Registry/registry_instance.jl index 36b8ce13d2..c5743fed4f 100644 --- a/src/Registry/registry_instance.jl +++ b/src/Registry/registry_instance.jl @@ -1,5 +1,6 @@ using Base: UUID, SHA1 using TOML +using Dates using Tar using ..Versions: VersionSpec, VersionRange @@ -15,10 +16,7 @@ function to_tar_path_format(file::AbstractString) end # See loading.jl -const TOML_CACHE = let parser = Base.TOML.Parser() - parser.Dates = Dates - Base.TOMLCache(parser, Dict{String, Dict{String, Any}}()) -end +const TOML_CACHE = Base.TOMLCache(Base.TOML.Parser{Dates}()) const TOML_LOCK = ReentrantLock() _parsefile(toml_file::AbstractString) = Base.parsed_toml(toml_file, TOML_CACHE, TOML_LOCK) function parsefile(in_memory_registry::Union{Dict, Nothing}, folder::AbstractString, file::AbstractString) @@ -26,8 +24,7 @@ function parsefile(in_memory_registry::Union{Dict, Nothing}, folder::AbstractStr return _parsefile(joinpath(folder, file)) else content = in_memory_registry[to_tar_path_format(file)] - parser = Base.TOML.Parser(content; filepath=file) - parser.Dates = Dates + parser = Base.TOML.Parser{Dates}(content; filepath=file) return Base.TOML.parse(parser) end end diff --git a/src/Types.jl b/src/Types.jl index d6b31710c3..6bbdca5ad5 100644 --- a/src/Types.jl +++ b/src/Types.jl @@ -53,10 +53,7 @@ function deepcopy_toml(x::Dict{String, Any}) end # See loading.jl -const TOML_CACHE = let parser = Base.TOML.Parser() - parser.Dates = Dates - Base.TOMLCache(parser, Dict{String, Dict{String, Any}}()) -end +const TOML_CACHE = Base.TOMLCache(Base.TOML.Parser{Dates}()) const TOML_LOCK = ReentrantLock() # Some functions mutate the returning Dict so return a copy of the cached value here parse_toml(toml_file::AbstractString) =