Skip to content

Commit 830de99

Browse files
authored
some minor code cleanups (#918)
1 parent d9aecc2 commit 830de99

File tree

7 files changed

+38
-44
lines changed

7 files changed

+38
-44
lines changed

src/loading.jl

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
const badfile = (nothing, nothing, nothing, UInt128(0))
21
function pkg_fileinfo(id::PkgId)
32
origin = get(Base.pkgorigins, id, nothing)
4-
origin === nothing && return badfile
3+
origin === nothing && return nothing
54
cachepath = origin.cachepath
6-
cachepath === nothing && return badfile
5+
cachepath === nothing && return nothing
76
local checksum
87
provides, includes_requires, required_modules = try
98
ret = @static if VERSION v"1.11.0-DEV.683" # https://github.com/JuliaLang/julia/pull/49866
@@ -16,42 +15,38 @@ function pkg_fileinfo(id::PkgId)
1615
provides, (includes_srcfiles_only, requires), required_modules
1716
else
1817
checksum = UInt64(0) # Buildid prior to v"1.12.0-DEV.764", and the `srcfiles_only` API does not take `io`
19-
Base.parse_cache_header(cachepath, srcfiles_only = true)
18+
Base.parse_cache_header(cachepath; srcfiles_only = true)
2019
end
2120
ret
2221
catch err
23-
return badfile
22+
return nothing
2423
end
2524
includes, _ = includes_requires
2625
for (pkgid, buildid) in provides
2726
if pkgid.uuid === id.uuid && pkgid.name == id.name
2827
return cachepath, includes, first.(required_modules), (UInt128(checksum) << 64 | buildid)
2928
end
3029
end
30+
return nothing
3131
end
3232

3333
function parse_pkg_files(id::PkgId)
34-
pkgdata = get(pkgdatas, id, nothing)
35-
if pkgdata === nothing
36-
pkgdata = PkgData(id)
37-
end
38-
modsym = Symbol(id.name)
34+
pkgdata = get!(()->PkgData(id), pkgdatas, id)
3935
if use_compiled_modules()
40-
cachefile, includes, reqs, buildid = pkg_fileinfo(id)
41-
if cachefile !== nothing
42-
@assert includes !== nothing
43-
@assert reqs !== nothing
36+
cachefile_includes_reqs_buildid = pkg_fileinfo(id)
37+
if cachefile_includes_reqs_buildid !== nothing
38+
cachefile, includes, reqs, buildid = cachefile_includes_reqs_buildid
4439
pkgdata.requirements = reqs
4540
for chi in includes
46-
if isdefined(Base, :maybe_loaded_precompile) && Base.maybe_loaded_precompile(id, buildid) isa Module
47-
mod = Base.maybe_loaded_precompile(id, buildid)
41+
if isdefined(Base, :maybe_loaded_precompile) && (mod′ = Base.maybe_loaded_precompile(id, buildid); mod′ isa Module)
42+
mod = mod′
4843
elseif isdefined(Base, :loaded_precompiles) && haskey(Base.loaded_precompiles, id => buildid)
4944
mod = Base.loaded_precompiles[id => buildid]
5045
else
5146
mod = Base.root_module(id)
5247
end
5348
for mpath in chi.modpath
54-
mod = getfield(mod, Symbol(mpath))::Module
49+
mod = getglobal(mod, Symbol(mpath))::Module
5550
end
5651
fname = relpath(chi.filename, pkgdata)
5752
# For precompiled packages, we can read the source later (whenever we need it)
@@ -68,7 +63,7 @@ function parse_pkg_files(id::PkgId)
6863
# To reduce compiler latency, use runtime dispatch for `queue_includes!`.
6964
# `queue_includes!` requires compilation of the whole parsing/expression-splitting infrastructure,
7065
# and it's better to wait to compile it until we actually need it.
71-
Base.invokelatest(queue_includes!, pkgdata, id)
66+
@invokelatest queue_includes!(pkgdata, id)
7267
return pkgdata
7368
end
7469

@@ -93,8 +88,9 @@ function modulefiles(mod::Module)
9388
return keypath(parentfile), [keypath(mf[2]) for mf in included_files]
9489
end
9590
use_compiled_modules() || return nothing, nothing # FIXME: support non-precompiled packages
96-
_, filedata, reqs = pkg_fileinfo(id)
97-
filedata === nothing && return nothing, nothing
98-
included_files = filter(mf->mf.id == id, filedata)
91+
cachefile_includes_reqs_buildid = pkg_fileinfo(id)
92+
cachefile_includes_reqs_buildid === nothing && return nothing, nothing
93+
_, includes, _, _ = cachefile_includes_reqs_buildid
94+
included_files = filter(mf->mf.id == id, includes)
9995
return keypath(parentfile), [keypath(mf.filename) for mf in included_files]
10096
end

src/packagedef.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
@eval Base.Experimental.@optlevel 1
22

33
using FileWatching, REPL, UUIDs
4-
import LibGit2
4+
using LibGit2: LibGit2
55
using Base: PkgId
66
using Base.Meta: isexpr
77
using Core: CodeInfo
88

99
export revise, includet, entr, MethodSummary
1010

11-
1211
# Abstract type to represent a single worker
1312
abstract type AbstractWorker end
1413

@@ -1177,7 +1176,11 @@ function update_stacktrace_lineno!(trace)
11771176
linfo = t.linfo
11781177
if linfo isa Core.CodeInstance
11791178
linfo = linfo.def
1180-
(isdefined(Core, :ABIOverride) && isa(linfo, Core.ABIOverride)) && (linfo = linfo.def)
1179+
@static if isdefined(Core, :ABIOverride)
1180+
if isa(linfo, Core.ABIOverride)
1181+
linfo = linfo.def
1182+
end
1183+
end
11811184
end
11821185
if linfo isa Core.MethodInstance
11831186
m = linfo.def
@@ -1313,10 +1316,7 @@ function __init__()
13131316
if polling == "1"
13141317
polling_files[] = watching_files[] = true
13151318
end
1316-
rev_include = get(ENV, "JULIA_REVISE_INCLUDE", "0")
1317-
if rev_include == "1"
1318-
tracking_Main_includes[] = true
1319-
end
1319+
tracking_Main_includes[] = Base.get_bool_env("JULIA_REVISE_INCLUDE", false)
13201320
# Correct line numbers for code moving around
13211321
Base.update_stackframes_callback[] = update_stacktrace_lineno!
13221322
if isdefined(Base, :methodloc_callback)

src/parsing.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,7 @@ function process_source!(mod_exprs_sigs::ModuleExprsSigs, ex, filename, mod::Mod
5959
throw(ReviseEvalException(loc, err, Any[(sf, 1) for sf in stacktrace(bt)]))
6060
end
6161
end
62-
exprs_sigs = get(mod_exprs_sigs, mod, nothing)
63-
if exprs_sigs === nothing
64-
mod_exprs_sigs[mod] = exprs_sigs = ExprsSigs()
65-
end
62+
exprs_sigs = get!(ExprsSigs, mod_exprs_sigs, mod)
6663
if ex.head === :toplevel
6764
lnn = nothing
6865
for a in ex.args

src/utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
relpath_safe(path, startpath) = isempty(startpath) ? path : relpath(path, startpath)
22

3-
function Base.relpath(filename, pkgdata::PkgData)
3+
function Base.relpath(filename::AbstractString, pkgdata::PkgData)
44
if isabspath(filename)
55
# `Base.locate_package`, which is how `pkgdata` gets initialized, might strip pieces of the path.
66
# For example, on Travis macOS the paths returned by `abspath`

test/common.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ else
2323
const mtimedelay = 0.1
2424
end
2525

26+
if isdefined(Core, :var"@latestworld")
27+
using Core: @latestworld
28+
else
29+
# In older Julia versions, there were more implicit
30+
# world age increments, so the macro is generally not
31+
# required.
32+
macro latestworld()
33+
nothing
34+
end
35+
end
36+
2637
yry() = (sleep(mtimedelay); revise(); sleep(mtimedelay))
2738
macro yry()
2839
esc(quote

test/non_jl_test.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ using Test
77
struct MyFile
88
file::String
99
end
10+
Base.relpath(file::MyFile, args...) = MyFile(Base.relpath(file.file, args...))
1011
Base.abspath(file::MyFile) = MyFile(Base.abspath(file.file))
1112
Base.isabspath(file::MyFile) = Base.isabspath(file.file)
1213
Base.joinpath(str::String, file::MyFile) = MyFile(Base.joinpath(str, file.file))

test/runtests.jl

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,6 @@ end
7272

7373
const issue639report = []
7474

75-
if isdefined(Core, :var"@latestworld")
76-
import Core: @latestworld
77-
else
78-
# In older Julia versions, there were more implicit
79-
# world age increments, so the macro is generally not
80-
# required.
81-
macro latestworld()
82-
nothing
83-
end
84-
end
85-
8675
@testset "Revise" begin
8776
do_test("PkgData") && @testset "PkgData" begin
8877
# Related to #358

0 commit comments

Comments
 (0)