Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
simeonschaub committed Oct 11, 2020
1 parent b8b4cef commit 550cacd
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 25 deletions.
5 changes: 2 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Revise"
uuid = "295af30f-e4ad-537b-8983-00126c2a3abe"
version = "3.1.3"
version = "3.1.4"

[deps]
CodeTracking = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2"
Expand Down Expand Up @@ -29,7 +29,6 @@ Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
CRC32c = "8bf52ea8-c179-5cab-976a-9e18b702a9bc"
CatIndices = "aafaddc9-749c-510e-ac4f-586e18779b91"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Debugger = "31a5f54b-26ea-5ae9-a837-f05ce5417438"
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
EndpointRanges = "340492b5-2a47-5f55-813d-aca7ddf97656"
EponymTuples = "97e2ac4a-e175-5f49-beb1-4d6866a6cdc3"
Expand Down Expand Up @@ -58,4 +57,4 @@ SuiteSparse = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "Base64", "CRC32c", "CatIndices", "Dates", "DelimitedFiles", "EndpointRanges", "EponymTuples", "Example", "Future", "IndirectArrays", "InteractiveUtils", "Libdl", "LinearAlgebra", "Logging", "MappedArrays", "Markdown", "Mmap", "Printf", "Profile", "Random", "Requires", "RoundingIntegers", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "SuiteSparse", "Debugger"]
test = ["Test", "Base64", "CRC32c", "CatIndices", "Dates", "DelimitedFiles", "EndpointRanges", "EponymTuples", "Example", "Future", "IndirectArrays", "InteractiveUtils", "Libdl", "LinearAlgebra", "Logging", "MappedArrays", "Markdown", "Mmap", "Printf", "Profile", "Random", "Requires", "RoundingIntegers", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "SuiteSparse"]
2 changes: 1 addition & 1 deletion src/legacy_loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function parse_pkg_files(id::PkgId)
# To reduce compiler latency, use runtime dispatch for `queue_includes!`.
# `queue_includes!` requires compilation of the whole parsing/expression-splitting infrastructure,
# and it's better to wait to compile it until we actually need it.
worldage[] = Base.get_world_counter()
#worldage[] = Base.get_world_counter()
invoke_revisefunc(queue_includes!, pkgdata, id)
return pkgdata
end
Expand Down
1 change: 0 additions & 1 deletion src/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ function parse_pkg_files(id::PkgId)
# To reduce compiler latency, use runtime dispatch for `queue_includes!`.
# `queue_includes!` requires compilation of the whole parsing/expression-splitting infrastructure,
# and it's better to wait to compile it until we actually need it.
worldage[] = Base.get_world_counter()
invoke_revisefunc(queue_includes!, pkgdata, id)
return pkgdata
end
Expand Down
2 changes: 1 addition & 1 deletion src/lowered.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ The other keyword arguments are more straightforward:
function methods_by_execution!(@nospecialize(recurse), methodinfo, docexprs, mod::Module, ex::Expr;
mode::Symbol=:eval, disablebp::Bool=true, always_rethrow::Bool=false, kwargs...)
mode (:sigs, :eval, :evalmeth, :evalassign) || error("unsupported mode ", mode)
lwr = _lower(mod, ex, worldage[])
lwr = lower_in_reviseworld(mod, ex)
isa(lwr, Expr) || return nothing, nothing
if lwr.head === :error || lwr.head === :incomplete
error("lowering returned an error, ", lwr)
Expand Down
35 changes: 22 additions & 13 deletions src/packagedef.jl
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,14 @@ const silence_pkgs = Set{Symbol}()
const depsdir = joinpath(dirname(@__DIR__), "deps")
const silencefile = Ref(joinpath(depsdir, "silence.txt")) # Ref so that tests don't clobber

#"""
# Revise.worldage
#
#The world age Revise was started in. Needed so that Revise doesn't delete methods
#from under itself.
#"""
#const worldage = Ref{Union{Nothing,UInt}}(nothing)
using CodeTracking: worldage
"""
Revise.worldage
The world age Revise was started in. Needed so that Revise doesn't delete methods
from under itself.
"""
const worldage = Ref{Union{Nothing,UInt}}(nothing)
#using CodeTracking: worldage

##
## The inputs are sets of expressions found in each file.
Expand Down Expand Up @@ -639,6 +639,7 @@ function handle_deletions(pkgdata, file)
topmod = first(keys(mexsold))
fileok = file_exists(filep)
mexsnew = fileok ? parse_source(filep, topmod) : ModuleExprsSigs(topmod)
worldage[] = Base.get_world_counter()
if mexsnew !== nothing
delete_missing!(mexsold, mexsnew)
end
Expand Down Expand Up @@ -732,6 +733,7 @@ function revise(; throw=false)

# Do all the deletion first. This ensures that a method that moved from one file to another
# won't get redefined first and deleted second.
@show worldage[] = Base.get_world_counter()
revision_errors = []
queue = sort!(collect(revision_queue); lt=pkgfileless)
finished = eltype(revision_queue)[]
Expand Down Expand Up @@ -764,6 +766,7 @@ function revise(; throw=false)
mode (:sigs, :eval, :evalmeth, :evalassign) || error("unsupported mode ", mode)
exsold = get(fi.modexsigs, mod, empty_exs_sigs)
for rex in keys(exsnew)
@show Base.get_world_counter()
sigs, includes = eval_rex(rex, exsold, mod; mode=mode)
if sigs !== nothing
exsnew[rex] = sigs
Expand Down Expand Up @@ -1191,13 +1194,17 @@ if VERSION < v"1.6.0-DEV.1162"
const lower_in_reviseworld = Meta.lower
else
function invoke_revisefunc(f, args...; kwargs...)
@show worldage[]
Base.show_backtrace(backtrace[1:2])
#@show worldage[]
#@show Base.get_world_counter()
#Base.show_backtrace(stdout, backtrace()[1:4])
#println()
return Base.invoke_in_world(worldage[], f, args...; kwargs...)
end
function lower_in_reviseworld(m::Module, @nospecialize(ex))
@show worldage[]
Base.show_backtrace(backtrace[1:2])
#@show worldage[]
#@show Base.get_world_counter()
#Base.show_backtrace(stdout, backtrace()[1:1])
#println()
return ccall(:jl_expand_in_world, Any,
(Any, Ref{Module}, Cstring, Cint, Csize_t),
ex, m, "none", 0, worldage[],
Expand All @@ -1209,7 +1216,7 @@ end
# This uses invokelatest not for reasons of world age but to ensure that the call is made at runtime.
# This allows `revise_first` to be compiled without compiling `revise` itself, and greatly
# reduces the overhead of using Revise.
revise_first(ex) = Expr(:toplevel, :(isempty($revision_queue) || (worldage[] = Base.get_world_counter(); invoke_revisefunc($revise))), ex)
revise_first(ex) = Expr(:toplevel, :(isempty($revision_queue) || (#=worldage[] = Base.get_world_counter(); =#invoke_revisefunc($revise))), ex)

@noinline function run_backend(backend)
while true
Expand Down Expand Up @@ -1362,6 +1369,8 @@ function __init__()
# Set the lookup callbacks
CodeTracking.method_lookup_callback[] = x -> (worldage[] = Base.get_world_counter(); invoke_revisefunc(get_def, x))
CodeTracking.expressions_callback[] = x -> (worldage[] = Base.get_world_counter(); invoke_revisefunc(get_expressions, x))
CodeTracking.method_lookup_callback[] = get_def
CodeTracking.expressions_callback[] = get_expressions

# Watch the manifest file for changes
mfile = manifest_file()
Expand Down
6 changes: 4 additions & 2 deletions src/pkgs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ function maybe_add_includes_to_pkgdata!(pkgdata::PkgData, file::AbstractString,
parse_source!(fi.modexsigs, fullfile, mod)
if eval_now
# Use runtime dispatch to reduce latency
Base.invoke_in_world(worldage[], instantiate_sigs!, fi.modexsigs; mode=:eval)
#Base.invoke_in_world(worldage[], instantiate_sigs!, fi.modexsigs; mode=:eval)
Base.invokelatest(instantiate_sigs!, fi.modexsigs; mode=:eval)
end
end
# Add to watchlist
Expand Down Expand Up @@ -237,7 +238,8 @@ function _add_require(sourcefile, modcaller, idmod, modname, expr)
end
end
if complex
Base.invoke_in_world(worldage[], eval_require_now, pkgdata, fileidx, filekey, sourcefile, modcaller, expr)
#Base.invoke_in_world(worldage[], eval_require_now, pkgdata, fileidx, filekey, sourcefile, modcaller, expr)
Base.invokelatest(eval_require_now, pkgdata, fileidx, filekey, sourcefile, modcaller, expr)
end
finally
unlock(requires_lock)
Expand Down
6 changes: 2 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ using Revise.CodeTracking
using Revise.JuliaInterpreter
using Test

@show VERSION

@test isempty(detect_ambiguities(Revise))

using Pkg, Unicode, Distributed, InteractiveUtils, REPL, UUIDs
Expand Down Expand Up @@ -473,8 +471,8 @@ end
@eval @test $(fn4)() == 4
@eval @test $(fn5)() == 5
@eval @test $(fn6)() == 6
m = @show @eval first(methods($fn1))
rex = Revise.RelocatableExpr(@show definition(m))
m = @eval first(methods($fn1))
rex = Revise.RelocatableExpr(definition(m))
@test rex == Revise.RelocatableExpr(:( $fn1() = 1 ))
# Check that definition returns copies
rex2 = deepcopy(rex)
Expand Down

0 comments on commit 550cacd

Please sign in to comment.