Skip to content

Commit f09463a

Browse files
committed
Use singleton instances, not just singleton type.
This is crucial to avoid creating a huge number of invalidations in Base code. Using SnoopCompile (on Julia master ~v1.6): ```julia-repl julia> using SnoopCompileCore julia> invs = @Snoopr using HDF5; julia> using SnoopCompile ``` **Before:** ```julia-repl julia> trees = invalidation_trees(invs) 1-element Vector{SnoopCompile.MethodInvalidations}: inserting getproperty(::Type{H5E}, sym::Symbol) in HDF5 invalidated: backedges: 1: superseding getproperty(x::Type, f::Symbol) in Base at Base.jl:28 with MethodInstance for getproperty(::DataType, ::Symbol) (1220 children) 3 mt_cache ``` **After:** ```julia-repl julia> trees = invalidation_trees(invs) SnoopCompile.MethodInvalidations[] ```
1 parent b6ab18b commit f09463a

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/deprecated.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ end
226226
@deprecate exists(parent::Union{File,Group,Dataset,Datatype,Attributes}, path::String) Base.haskey(parent, path) false
227227

228228
for pseudomod in (H5, H5D, H5E, H5F, H5FD, H5I, H5L, H5O, H5P, H5R, H5S, H5T, H5Z)
229-
modsym = nameof(pseudomod)
229+
modsym = nameof(typeof(pseudomod))
230230
for C in propertynames(pseudomod)
231231
constname = Symbol(modsym, :_, C)
232232
@eval @deprecate_binding($constname, $modsym.$C, false)

src/macros.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,26 +89,26 @@ macro defconstants(prefix::Symbol, expr::Expr)
8989
# Push the imports into the definition body
9090
pushfirst!(defbody, Expr(:import, imports...))
9191

92-
prefix = esc(prefix)
93-
innermod = esc(innermod)
92+
eprefix = esc(prefix)
93+
einnermod = esc(innermod)
94+
qprefix = QuoteNode(prefix)
9495
block = quote
95-
Base.@__doc__(struct $prefix end)
96-
baremodule $innermod
96+
baremodule $einnermod
97+
struct $eprefix end
9798
$(defbody...)
9899
end
99-
function Base.propertynames(::Type{$prefix})
100+
const $eprefix = $einnermod.$prefix()
101+
function Base.propertynames(::$einnermod.$prefix)
100102
return $((symbols...,))
101103
end
102-
function Base.getproperty(::Type{$prefix}, sym::Symbol)
104+
function Base.getproperty(::$einnermod.$prefix, sym::Symbol)
103105
$(getbody...)
104-
return getfield($prefix, sym)
105106
end
106107
end
107108
if !isempty(setbody)
108109
setfn = quote
109-
function Base.setproperty!(::Type{$prefix}, sym::Symbol, value)
110+
function Base.setproperty!(::$einnermod.$prefix, sym::Symbol, value)
110111
$(setbody...)
111-
return setfield!($prefix, sym, value)
112112
end
113113
end
114114
append!(block.args, Base.remove_linenums!(setfn).args)

0 commit comments

Comments
 (0)