Skip to content

Commit

Permalink
Remove GlobalMetadata
Browse files Browse the repository at this point in the history
This originated from feedback from others a while back but isn't
terribly useful, and now that we can set variables in modules it's
nearly completely useless.
  • Loading branch information
Tokazama committed Apr 11, 2022
1 parent 316a284 commit e88941c
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 292 deletions.
33 changes: 0 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,39 +77,6 @@ julia> mr.den
Here we attached the same metadata to a rational number.
Again, our metadata is now considered the properties of `mr`, but we can still access the parent's properties.

If the type you want to attach metadata to is mutable then each instance has a unique global identifier and you may attach metadata to a global dictionary.
```julia
julia> x = ones(2, 2);

julia> @attach_metadata(x, meta);

julia> @metadata!(x, :z, 3);

julia> @metadata(x, :z)
3

julia> Pair(:x, 1) in @metadata(x)
true
```

If users want to access all of the metadata from one structure and attach it to another they should instead use `share_metadata(src, dst)` or `copy_metadata(src, dst)`.
```julia
julia> mx = attach_metadata(ones(2, 2), @metadata(x));

julia> mx2 = share_metadata(mx, ones(2, 2));

julia> metadata(mx2) === metadata(mx)
true

julia> mx3 = copy_metadata(mx2, ones(2, 2));

julia> metadata(mx3) === metadata(mx2)
false

julia> metadata(mx3) == metadata(mx2)
true
```

# Creating New Metadata Types

This package creates a very minimal number of dedicated structures and creating new dedicated structures that use this interface is encouraged.
Expand Down
206 changes: 0 additions & 206 deletions src/GlobalMetadata.jl

This file was deleted.

7 changes: 0 additions & 7 deletions src/Metadata.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ using Statistics
using Test

export
@attach_metadata,
@metadata,
@metadata!,
@has_metadata,
@copy_metadata,
@share_metadata,
attach_metadata,
copy_metadata,
getmeta,
Expand All @@ -29,7 +23,6 @@ export

include("MetaStruct.jl")
include("interface.jl")
include("GlobalMetadata.jl")
include("MetaDict.jl")
include("MetaTuple.jl")
include("MetaIO.jl")
Expand Down
48 changes: 2 additions & 46 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,16 @@ using Metadata
using Test

using ArrayInterface: parent_type, StaticInt
using Metadata: MetaArray, no_data, GlobalMetadata

using Metadata: MetaArray, no_data

Aqua.test_all(Metadata)

@test isempty(detect_ambiguities(Metadata, Base))

@testset "methods" begin
@testset "interface" begin
io = IOBuffer()
show(io, Metadata.no_data)
@test String(take!(io)) == "no_data"
@test Metadata.MetadataPropagation(Metadata.NoData) == Metadata.DropMetadata()
@test @inferred(metadata(Main)) isa GlobalMetadata
x = rand(4)
m = metadata(Main)
@test isempty(m)
get!(m, objectid(x), Dict{Symbol,Any}())
@test !isempty(m)
@test first(keys(m)) == objectid(x)
@test m[objectid(x)] == Dict{Symbol,Any}()
@test length(m) == 1
p, state = iterate(m)
@test p == (objectid(x) => Dict{Symbol,Any}())
@test iterate(m, state) === nothing
end

#=
Expand Down Expand Up @@ -105,36 +91,6 @@ end
include("MetaIO.jl")
end

@testset "GlobalMetadata" begin
x = ones(2, 2)
meta = (x = 1, y = 2)
@attach_metadata(x, meta)
@test @metadata(x, :x) == 1
@test @metadata(x, :y) == 2

struct MyType{X}
x::X
end

x = MyType(ones(2,2))
GC.gc()
@test @metadata(x) == Metadata.no_data # test finalizer

@test metadata_type(Main) <: Metadata.GlobalMetadata
@attach_metadata(x, meta)
@test @metadata(x, :x) == 1
@test @metadata(x, :y) == 2
x = MyType(1)
GC.gc()
@test @metadata(x) == Metadata.no_data # test finalizer on nested mutables
@test_logs(
(:warn, "Cannot create finalizer for MyType{$Int}. Global dictionary must be manually deleted."),
@attach_metadata(x, meta)
)
@test @metadata(x, :x) == 1
@test @metadata(x, :y) == 2
end

m = (x = 1, y = 2, suppress= [:x])
io = IOBuffer()
Metadata.metadata_summary(io, m)
Expand Down

0 comments on commit e88941c

Please sign in to comment.