Skip to content

Commit 2911b1e

Browse files
authored
some more minor cleanups on the code base (#922)
Separated from the refactoring I'm working on locally.
1 parent 3ab981a commit 2911b1e

File tree

4 files changed

+23
-37
lines changed

4 files changed

+23
-37
lines changed

src/loading.jl

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ function pkg_fileinfo(id::PkgId)
3030
return nothing
3131
end
3232

33+
"""
34+
parse_pkg_files(id::PkgId)
35+
36+
This function gets called by `watch_package` and runs when a package is first loaded.
37+
Its job is to organize the files and expressions defining the module so that later we can
38+
detect and process revisions.
39+
"""
3340
function parse_pkg_files(id::PkgId)
3441
pkgdata = get!(()->PkgData(id), pkgdatas, id)
3542
if use_compiled_modules()
@@ -67,12 +74,21 @@ function parse_pkg_files(id::PkgId)
6774
return pkgdata
6875
end
6976

77+
"""
78+
parentfile, included_files = modulefiles(mod::Module)
79+
80+
Return the `parentfile` in which `mod` was defined, as well as a list of any
81+
other files that were `include`d to define `mod`. If this operation is unsuccessful,
82+
`(nothing, nothing)` is returned.
83+
84+
All files are returned as absolute paths.
85+
"""
7086
function modulefiles(mod::Module)
71-
function keypath(filename)
87+
function keypath(filename::AbstractString)
7288
filename = fixpath(filename)
7389
return get(src_file_key, filename, filename)
7490
end
75-
if isdefined(Base, :moduleloc)
91+
@static if isdefined(Base, :moduleloc)
7692
parentfile = String(Base.moduleloc(mod).file)
7793
else
7894
parentfile = String(first(methods(getfield(mod, :eval))).file)

src/packagedef.jl

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ include("types.jl")
8989
include("utils.jl")
9090
include("parsing.jl")
9191
include("lowered.jl")
92+
include("loading.jl")
9293
include("pkgs.jl")
9394
include("git.jl")
9495
include("recipes.jl")
@@ -200,23 +201,18 @@ function fallback_juliadir()
200201
normpath(candidate)
201202
end
202203

203-
Core.eval(@__MODULE__, :(global juliadir::String))
204-
205204
"""
206205
Revise.juliadir
207206
208207
Constant specifying full path to julia top-level source directory.
209208
This should be reliable even for local builds, cross-builds, and binary installs.
210209
"""
211-
juliadir
212-
213-
juliadir = normpath(
210+
global juliadir::String =
214211
if isdir(joinpath(basebuilddir, "base"))
215212
basebuilddir
216213
else
217214
fallback_juliadir() # Binaries probably end up here. We fall back on Sys.BINDIR
218-
end
219-
)
215+
end |> normpath
220216

221217
const cache_file_key = Dict{String,String}() # corrected=>uncorrected filenames
222218
const src_file_key = Dict{String,String}() # uncorrected=>corrected filenames
@@ -269,8 +265,6 @@ const silencefile = Ref(joinpath(depsdir, "silence.txt")) # Ref so that tests d
269265
## now this is the right strategy.) From the standpoint of CodeTracking, we should
270266
## link the signature to the actual method-defining expression (either :(f() = 1) or :(g() = 2)).
271267

272-
get_method_from_match(mm::Core.MethodMatch) = mm.method
273-
274268
function delete_missing!(exs_sigs_old::ExprsSigs, exs_sigs_new)
275269
with_logger(_debug_logger) do
276270
for (ex, sigs) in exs_sigs_old
@@ -281,7 +275,7 @@ function delete_missing!(exs_sigs_old::ExprsSigs, exs_sigs_new)
281275
ret = Base._methods_by_ftype(sig, -1, Base.get_world_counter())
282276
success = false
283277
if !isempty(ret)
284-
m = get_method_from_match(ret[end]) # the last method returned is the least-specific that matches, and thus most likely to be type-equal
278+
m = ret[end].method # the last method returned is the least-specific that matches, and thus most likely to be type-equal
285279
methsig = m.sig
286280
if sig <: methsig && methsig <: sig
287281
locdefs = get(CodeTracking.method_info, sig, nothing)

src/pkgs.jl

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,3 @@
1-
using Base: PkgId
2-
3-
include("loading.jl")
4-
5-
"""
6-
parse_pkg_files(id::PkgId)
7-
8-
This function gets called by `watch_package` and runs when a package is first loaded.
9-
Its job is to organize the files and expressions defining the module so that later we can
10-
detect and process revisions.
11-
"""
12-
parse_pkg_files(id::PkgId)
13-
14-
"""
15-
parentfile, included_files = modulefiles(mod::Module)
16-
17-
Return the `parentfile` in which `mod` was defined, as well as a list of any
18-
other files that were `include`d to define `mod`. If this operation is unsuccessful,
19-
`(nothing, nothing)` is returned.
20-
21-
All files are returned as absolute paths.
22-
"""
23-
modulefiles(mod::Module)
24-
251
# This is primarily used to parse non-precompilable packages.
262
# These lack a cache header that lists the files that constitute the package;
273
# they also lack the source cache, and so have to parsed immediately or

src/utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function unwrap_where(ex::Expr)
9393
while isexpr(ex, :where)
9494
ex = ex.args[1]
9595
end
96-
return ex
96+
return ex::Expr
9797
end
9898

9999
function pushex!(exsigs::ExprsSigs, ex::Expr)

0 commit comments

Comments
 (0)