Skip to content

Commit fa01b95

Browse files
committed
More 1.12 compat
With this and the LCU fixes, Revise should pass tests again on 1.12.
1 parent 4ad68c2 commit fa01b95

File tree

4 files changed

+47
-16
lines changed

4 files changed

+47
-16
lines changed

src/loading.jl

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
1+
const badfile = (nothing, nothing, nothing, UInt128(0))
12
function pkg_fileinfo(id::PkgId)
23
origin = get(Base.pkgorigins, id, nothing)
3-
origin === nothing && return nothing, nothing, nothing
4+
origin === nothing && return badfile
45
cachepath = origin.cachepath
5-
cachepath === nothing && return nothing, nothing, nothing
6+
cachepath === nothing && return badfile
7+
local checksum
68
provides, includes_requires, required_modules = try
7-
@static if VERSION v"1.11.0-DEV.683" # https://github.com/JuliaLang/julia/pull/49866
9+
ret = @static if VERSION v"1.11.0-DEV.683" # https://github.com/JuliaLang/julia/pull/49866
10+
io = open(cachepath, "r")
11+
checksum = Base.isvalid_cache_header(io)
12+
iszero(checksum) && (close(io); return badfile)
813
provides, (_, includes_srcfiles_only, requires), required_modules, _... =
9-
Base.parse_cache_header(cachepath)
14+
Base.parse_cache_header(io, cachepath)
15+
close(io)
1016
provides, (includes_srcfiles_only, requires), required_modules
1117
else
18+
checksum = UInt64(0) # Buildid prior to v"1.12.0-DEV.764", and the `srcfiles_only` API does not take `io`
1219
Base.parse_cache_header(cachepath, srcfiles_only = true)
1320
end
14-
catch
15-
return nothing, nothing, nothing
21+
ret
22+
catch err
23+
return badfile
1624
end
1725
includes, _ = includes_requires
1826
for (pkgid, buildid) in provides
1927
if pkgid.uuid === id.uuid && pkgid.name == id.name
20-
return cachepath, includes, first.(required_modules)
28+
return cachepath, includes, first.(required_modules), (UInt128(checksum) << 64 | buildid)
2129
end
2230
end
2331
end
@@ -29,13 +37,17 @@ function parse_pkg_files(id::PkgId)
2937
end
3038
modsym = Symbol(id.name)
3139
if use_compiled_modules()
32-
cachefile, includes, reqs = pkg_fileinfo(id)
40+
cachefile, includes, reqs, buildid = pkg_fileinfo(id)
3341
if cachefile !== nothing
3442
@assert includes !== nothing
3543
@assert reqs !== nothing
3644
pkgdata.requirements = reqs
3745
for chi in includes
38-
mod = Base.root_module(id)
46+
if VERSION >= v"1.12.0-DEV.764" && haskey(Base.loaded_precompiles, id => buildid)
47+
mod = Base.loaded_precompiles[id => buildid]
48+
else
49+
mod = Base.root_module(id)
50+
end
3951
for mpath in chi.modpath
4052
mod = getfield(mod, Symbol(mpath))::Module
4153
end

src/lowered.jl

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,23 @@ pop_expr!(methodinfo::MethodInfo) = methodinfo
2323
add_dependencies!(methodinfo::MethodInfo, be::CodeEdges, src, isrequired) = methodinfo
2424
add_includes!(methodinfo::MethodInfo, mod::Module, filename) = methodinfo
2525

26+
function is_some_include(@nospecialize(f))
27+
if isa(f, GlobalRef)
28+
return f.name === :include
29+
elseif isa(f, Symbol)
30+
return f === :include
31+
else
32+
if isa(f, QuoteNode)
33+
f = f.value
34+
end
35+
if isa(f, Function)
36+
mod = Base.typename(typeof(f)).module
37+
return isdefined(mod, :include) && f === (@isdefined(getglobal) ? getglobal(mod, :include) : getfield(mod, :include))
38+
end
39+
end
40+
return false
41+
end
42+
2643
# This is not generally used, see `is_method_or_eval` instead
2744
function hastrackedexpr(stmt; heads=LoweredCodeUtils.trackedheads)
2845
haseval = false
@@ -32,7 +49,7 @@ function hastrackedexpr(stmt; heads=LoweredCodeUtils.trackedheads)
3249
f = stmt.args[1]
3350
callee_matches(f, Core, :_typebody!) && return true, haseval
3451
callee_matches(f, Core, :_setsuper!) && return true, haseval
35-
f === :include && return true, haseval
52+
is_some_include(f) && return true, haseval
3653
elseif stmt.head === :thunk
3754
any(s->any(hastrackedexpr(s; heads=heads)), (stmt.args[1]::Core.CodeInfo).code) && return true, haseval
3855
elseif stmt.head heads
@@ -57,7 +74,7 @@ function categorize_stmt(@nospecialize(stmt))
5774
ismeth = stmt.head === :method || (stmt.head === :thunk && defines_function(only(stmt.args)))
5875
istoplevel = stmt.head === :toplevel
5976
isnamespace = stmt.head === :export || stmt.head === :import || stmt.head === :using
60-
isinclude = stmt.head === :call && stmt.args[1] === :include
77+
isinclude = stmt.head === :call && is_some_include(stmt.args[1])
6178
end
6279
return ismeth, haseval, isinclude, isnamespace, istoplevel
6380
end

src/packagedef.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ function revise(mod::Module)
862862
for def in keys(exsigs)
863863
ex = def.ex
864864
exuw = unwrap(ex)
865-
isexpr(exuw, :call) && exuw.args[1] === :include && continue
865+
isexpr(exuw, :call) && is_some_include(exuw.args[1]) && continue
866866
try
867867
Core.eval(mod, ex)
868868
catch err
@@ -1264,6 +1264,8 @@ function init_worker(p)
12641264
end)
12651265
end
12661266

1267+
active_repl_backend_available() = isdefined(Base, :active_repl_backend) && Base.active_repl_backend !== nothing
1268+
12671269
function __init__()
12681270
ccall(:jl_generating_output, Cint, ()) == 1 && return nothing
12691271
run_on_worker = get(ENV, "JULIA_REVISE_WORKER_ONLY", "0")
@@ -1330,18 +1332,18 @@ function __init__()
13301332
else
13311333
pushfirst!(REPL.repl_ast_transforms, revise_first)
13321334
# #664: once a REPL is started, it no longer interacts with REPL.repl_ast_transforms
1333-
if isdefined(Base, :active_repl_backend)
1335+
if active_repl_backend_available()
13341336
push!(Base.active_repl_backend.ast_transforms, revise_first)
13351337
else
13361338
# wait for active_repl_backend to exist
13371339
# #719: do this async in case Revise is being loaded from startup.jl
13381340
t = @async begin
13391341
iter = 0
1340-
while !isdefined(Base, :active_repl_backend) && iter < 20
1342+
while !active_repl_backend_available() && iter < 20
13411343
sleep(0.05)
13421344
iter += 1
13431345
end
1344-
if isdefined(Base, :active_repl_backend)
1346+
if active_repl_backend_available()
13451347
push!(Base.active_repl_backend.ast_transforms, revise_first)
13461348
end
13471349
end

src/pkgs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ end
241241
function deferrable_require!(includes, expr::Expr)
242242
if expr.head === :call
243243
callee = expr.args[1]
244-
if callee === :include
244+
if is_some_include(callee)
245245
if isa(expr.args[2], AbstractString)
246246
push!(includes, expr.args[2])
247247
else

0 commit comments

Comments
 (0)