From 9aa57065b2e5dca040e5093bdd17653044acaca7 Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Fri, 17 Oct 2025 12:26:42 +1300 Subject: [PATCH 1/3] Fix serialization of BenchmarkGroup with JSON@1 --- src/serialization.jl | 14 ++++++++++++++ test/SerializationTests.jl | 7 +++++++ 2 files changed, 21 insertions(+) diff --git a/src/serialization.jl b/src/serialization.jl index 5aa7cced..c4d7145a 100644 --- a/src/serialization.jl +++ b/src/serialization.jl @@ -29,6 +29,20 @@ function JSON.lower(x::Union{values(SUPPORTED_TYPES)...}) return [string(nameof(typeof(x))), d] end +# Special support is needed for JSON@1, because it doesn't know how to support +# NTuple{N,String} as a dictionary key. +# +# Upstream issue: https://github.com/JuliaIO/JSON.jl/issues/399 +# +# This method may be removed if the upstream issue is fixed. +function JSON.lower(x::BenchmarkGroup) + d = Dict{String,Any}( + "data" => Dict(string(k) => v for (k, v) in x.data), + "tags" => x.tags, + ) + return ["BenchmarkGroup", d] +end + # a minimal 'eval' function, mirroring KeyTypes, but being slightly more lenient safeeval(@nospecialize x) = x safeeval(x::QuoteNode) = x.value diff --git a/test/SerializationTests.jl b/test/SerializationTests.jl index e24314a1..3d4ab165 100644 --- a/test/SerializationTests.jl +++ b/test/SerializationTests.jl @@ -124,4 +124,11 @@ end @test BenchmarkTools.load(json_io) == [params] end +@testset "issue_400_tuple_as_dict_key" begin + grp = BenchmarkTools.BenchmarkGroup() + grp["a", "b"] = BenchmarkTools.BenchmarkGroup() + contents = sprint(io -> BenchmarkTools.save(io, grp)) + @test occursin(""""data":{"(\\\"a\\", \\"b\\")":[""", contents) +end + end # module From 09333f1a770acdb0b71e86aa30b102bb0eec49fe Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Fri, 17 Oct 2025 02:58:49 +0200 Subject: [PATCH 2/3] Apply suggestion --- src/serialization.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/serialization.jl b/src/serialization.jl index c4d7145a..c3358018 100644 --- a/src/serialization.jl +++ b/src/serialization.jl @@ -37,8 +37,7 @@ end # This method may be removed if the upstream issue is fixed. function JSON.lower(x::BenchmarkGroup) d = Dict{String,Any}( - "data" => Dict(string(k) => v for (k, v) in x.data), - "tags" => x.tags, + "data" => Dict(string(k) => v for (k, v) in x.data), "tags" => x.tags ) return ["BenchmarkGroup", d] end From 71d0cf8cbf9fa3ac4f6d49d60d138b2f8a92e383 Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Thu, 16 Oct 2025 21:01:09 -0400 Subject: [PATCH 3/3] bump version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index a28cb5a8..9ef95106 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "BenchmarkTools" uuid = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" -version = "1.6.1" +version = "1.6.2" [deps] Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"