From 7baa73daa4222b75d567ca9e5cf9f453c05ebdc9 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Fri, 3 Jan 2025 06:41:26 -0600 Subject: [PATCH] Fix and test "DO NOT PARSE" (#879) --- Project.toml | 2 +- src/packagedef.jl | 6 ++++-- src/parsing.jl | 4 +++- src/pkgs.jl | 9 ++++++--- test/runtests.jl | 29 +++++++++++++++++++++++++++++ 5 files changed, 43 insertions(+), 7 deletions(-) diff --git a/Project.toml b/Project.toml index 3ba527ed..8286c8e0 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "Revise" uuid = "295af30f-e4ad-537b-8983-00126c2a3abe" -version = "3.7.0" +version = "3.7.1" [deps] CodeTracking = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2" diff --git a/src/packagedef.jl b/src/packagedef.jl index 3976c036..f64aa932 100644 --- a/src/packagedef.jl +++ b/src/packagedef.jl @@ -713,7 +713,7 @@ function handle_deletions(pkgdata, file) topmod = first(keys(mexsold)) fileok = file_exists(String(filep)::String) mexsnew = fileok ? parse_source(filep, topmod) : ModuleExprsSigs(topmod) - if mexsnew !== nothing + if mexsnew !== nothing && mexsnew !== DoNotParse() delete_missing!(mexsold, mexsnew) end if !fileok @@ -815,7 +815,9 @@ function revise(; throw=false) interrupt = false for (pkgdata, file) in queue try - push!(mexsnews, handle_deletions(pkgdata, file)[1]) + mexsnew, _ = handle_deletions(pkgdata, file) + mexsnew === DoNotParse() && continue + push!(mexsnews, mexsnew) push!(finished, (pkgdata, file)) catch err throw && Base.throw(err) diff --git a/src/parsing.jl b/src/parsing.jl index a2e0eb6c..275a8fba 100644 --- a/src/parsing.jl +++ b/src/parsing.jl @@ -1,3 +1,5 @@ +struct DoNotParse end + """ mexs = parse_source(filename::AbstractString, mod::Module) @@ -36,7 +38,7 @@ string. `pos` is the 1-based byte offset from which to begin parsing `src`. See also [`Revise.parse_source`](@ref). """ function parse_source!(mod_exprs_sigs::ModuleExprsSigs, src::AbstractString, filename::AbstractString, mod::Module; kwargs...) - startswith(src, "# REVISE: DO NOT PARSE") && return nothing + startswith(src, "# REVISE: DO NOT PARSE") && return DoNotParse() ex = Base.parse_input_line(src; filename=filename) ex === nothing && return mod_exprs_sigs if isexpr(ex, :error) || isexpr(ex, :incomplete) diff --git a/src/pkgs.jl b/src/pkgs.jl index 6909444a..80ca98f0 100644 --- a/src/pkgs.jl +++ b/src/pkgs.jl @@ -116,11 +116,14 @@ function maybe_parse_from_cache!(pkgdata::PkgData, file::AbstractString) filep = joinpath(basedir(pkgdata), file) filec = get(cache_file_key, filep, filep) topmod = first(keys(fi.modexsigs)) - if parse_source!(fi.modexsigs, src, filec, topmod) === nothing + ret = parse_source!(fi.modexsigs, src, filec, topmod) + if ret === nothing @error "failed to parse cache file source text for $file" end - add_modexs!(fi, fi.cacheexprs) - empty!(fi.cacheexprs) + if ret !== DoNotParse() + add_modexs!(fi, fi.cacheexprs) + empty!(fi.cacheexprs) + end fi.parsed[] = true end return fi diff --git a/test/runtests.jl b/test/runtests.jl index 2acdece1..1b56f5ca 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1722,6 +1722,35 @@ end rm_precompile("Timing") end + do_test("DO NOT PARSE") && @testset "DO NOT PARSE" begin + testdir = newtestdir() + dn = joinpath(testdir, "DoNotParse", "src") + mkpath(dn) + write(joinpath(dn, "DoNotParse.jl"), """ + # REVISE: DO NOT PARSE + module DoNotParse + f(x) = 1 + end + """) + sleep(mtimedelay) + @eval using DoNotParse + sleep(mtimedelay) + @test DoNotParse.f(1) == 1 + write(joinpath(dn, "DoNotParse.jl"), """ + # REVISE: DO NOT PARSE + module DoNotParse + f(x) = 2 + end + """) + logs, _ = Test.collect_test_logs() do + yry() + end + @test DoNotParse.f(1) == 1 + @test isempty(logs) + rm_precompile("DoNotParse") + pop!(LOAD_PATH) + end + do_test("Method deletion") && @testset "Method deletion" begin Core.eval(Base, :(revisefoo(x::Float64) = 1)) # to test cross-module method scoping testdir = newtestdir()