Skip to content

Commit 804cc5b

Browse files
authored
Fix clear_module! world semantics (#2693)
1 parent 3ff554f commit 804cc5b

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
* Added anchor links to admonition blocks, making it possible to create direct links to specific admonitions. ([#2505], [#2676], [#2688])
1111
* Added different banners for dev and unreleased docs ([#2382], [#2682])
1212

13+
### Fixed
14+
15+
* In Julia v1.12, the queries used by `clear_module!` will now be versioned by world, allowing the deleting of bindings to work correctly. ([#2693])
16+
1317
## Version [v1.10.2] - 2025-04-25
1418

1519
### Fixed
@@ -2029,6 +2033,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
20292033
[#2676]: https://github.com/JuliaDocs/Documenter.jl/issues/2676
20302034
[#2682]: https://github.com/JuliaDocs/Documenter.jl/issues/2682
20312035
[#2685]: https://github.com/JuliaDocs/Documenter.jl/issues/2685
2036+
[#2693]: https://github.com/JuliaDocs/Documenter.jl/issues/2693
20322037
[JuliaLang/julia#36953]: https://github.com/JuliaLang/julia/issues/36953
20332038
[JuliaLang/julia#38054]: https://github.com/JuliaLang/julia/issues/38054
20342039
[JuliaLang/julia#39841]: https://github.com/JuliaLang/julia/issues/39841

src/expander_pipeline.jl

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
11
# Defines node "expanders" that transform nodes from the parsed markdown files.
22

3+
function clear_global!(M::Module, name::Symbol)
4+
isconst(M, name) && return
5+
if VERSION >= v"1.9"
6+
Nothing <: Core.get_binding_type(M, name) || return
7+
setglobal!(M, name, nothing)
8+
else
9+
Core.eval(M, :($name = $nothing))
10+
end
11+
return nothing
12+
end
13+
314
# helper for "cleaning up" content of modules to enable garbage collection.
415
# See also <https://github.com/JuliaDocs/Documenter.jl/issues/2640>.
516
function clear_module!(M::Module)
617
# we need `invokelatest` here for Julia >= 1.12 (or 1.13?)
7-
for name in Base.invokelatest(names, M, all = true)
8-
if !isconst(M, name)
9-
# see, e.g https://github.com/JuliaDocs/Documenter.jl/issues/2673
10-
# it is not possible to set `nothing` to variables, which are strongly typed
11-
# still attempt to set it, but ignore any errors
12-
try
13-
@eval M $name = $nothing
14-
catch err
15-
@debug "Could not clear variable `$name` by assigning `nothing`" err
16-
end
18+
for name in Base.invokelatest(names, M, all = true)::Vector{Symbol}
19+
# see, e.g https://github.com/JuliaDocs/Documenter.jl/issues/2673
20+
# it is not possible to set `nothing` to variables, which are strongly typed
21+
# still attempt to set it, but ignore any errors
22+
try
23+
Base.invokelatest(clear_global!, M, name::Symbol)
24+
catch err
25+
@debug "Could not clear variable `$name` by assigning `nothing`" err
1726
end
27+
VERSION >= v"1.12" && Base.delete_binding(M, name)
1828
end
1929
return
2030
end

0 commit comments

Comments
 (0)