Skip to content

Commit

Permalink
Fix and test "DO NOT PARSE" (#879)
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy authored Jan 3, 2025
1 parent 41f735b commit 7baa73d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 7 deletions.
2 changes: 1 addition & 1 deletion 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.7.0"
version = "3.7.1"

[deps]
CodeTracking = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2"
Expand Down
6 changes: 4 additions & 2 deletions src/packagedef.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/parsing.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
struct DoNotParse end

"""
mexs = parse_source(filename::AbstractString, mod::Module)
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions src/pkgs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

2 comments on commit 7baa73d

@timholy
Copy link
Owner Author

@timholy timholy commented on 7baa73d Jan 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/122354

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v3.7.1 -m "<description of version>" 7baa73daa4222b75d567ca9e5cf9f453c05ebdc9
git push origin v3.7.1

Please sign in to comment.