From 550cacd9a03c7f5c8828b272b7b7d2eaa88aca40 Mon Sep 17 00:00:00 2001 From: Simeon Schaub Date: Sun, 11 Oct 2020 13:13:04 +0200 Subject: [PATCH] wip --- Project.toml | 5 ++--- src/legacy_loading.jl | 2 +- src/loading.jl | 1 - src/lowered.jl | 2 +- src/packagedef.jl | 35 ++++++++++++++++++++++------------- src/pkgs.jl | 6 ++++-- test/runtests.jl | 6 ++---- 7 files changed, 32 insertions(+), 25 deletions(-) diff --git a/Project.toml b/Project.toml index d3e6c63f..79d0de56 100644 --- a/Project.toml +++ b/Project.toml @@ -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" @@ -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" @@ -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"] diff --git a/src/legacy_loading.jl b/src/legacy_loading.jl index e74b9bc2..725f3496 100644 --- a/src/legacy_loading.jl +++ b/src/legacy_loading.jl @@ -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 diff --git a/src/loading.jl b/src/loading.jl index c2c44a14..79b7b7d7 100644 --- a/src/loading.jl +++ b/src/loading.jl @@ -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 diff --git a/src/lowered.jl b/src/lowered.jl index d3812e63..bbc65010 100644 --- a/src/lowered.jl +++ b/src/lowered.jl @@ -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) diff --git a/src/packagedef.jl b/src/packagedef.jl index 2c9e9c0e..8526b067 100644 --- a/src/packagedef.jl +++ b/src/packagedef.jl @@ -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. @@ -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 @@ -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)[] @@ -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 @@ -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[], @@ -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 @@ -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() diff --git a/src/pkgs.jl b/src/pkgs.jl index fb515f16..540b9509 100644 --- a/src/pkgs.jl +++ b/src/pkgs.jl @@ -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 @@ -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) diff --git a/test/runtests.jl b/test/runtests.jl index 0ff759c9..0ac3bb9d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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 @@ -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)