From b82459a081c4b8925da3c0d97a6dc61687648ed3 Mon Sep 17 00:00:00 2001 From: Tor Erlend Fjelde Date: Sun, 18 Jul 2021 21:56:46 +0100 Subject: [PATCH] Removal of redundant backwards compat `to_namedtuple_expr` (#280) * improved leftover to_namedtuple_expr, fixing a bug when used with Zygote * bumped patch version Co-authored-by: Hong Ge --- Project.toml | 2 +- src/utils.jl | 37 +++++-------------------------------- 2 files changed, 6 insertions(+), 33 deletions(-) diff --git a/Project.toml b/Project.toml index e17343312..e2c1dd29e 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "DynamicPPL" uuid = "366bfd00-2699-11ea-058f-f148b4cae6d8" -version = "0.12.2" +version = "0.12.3" [deps] AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001" diff --git a/src/utils.jl b/src/utils.jl index e77a4ecdd..db7faabbd 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -44,39 +44,12 @@ function getargs_tilde(expr::Expr) end end -############################################ -# Julia 1.2 temporary fix - Julia PR 33303 # -############################################ function to_namedtuple_expr(syms, vals=syms) - if length(syms) == 0 - nt = :(NamedTuple()) - else - nt_type = Expr( - :curly, - :NamedTuple, - Expr(:tuple, QuoteNode.(syms)...), - Expr(:curly, :Tuple, [:(Core.Typeof($x)) for x in vals]...), - ) - nt = Expr(:call, :($(DynamicPPL.namedtuple)), nt_type, Expr(:tuple, vals...)) - end - return nt -end - -if VERSION == v"1.2" - @eval function namedtuple( - ::Type{NamedTuple{names,T}}, args::Tuple - ) where {names,T<:Tuple} - if length(args) != length(names) - throw(ArgumentError("Wrong number of arguments to named tuple constructor.")) - end - # Note T(args) might not return something of type T; e.g. - # Tuple{Type{Float64}}((Float64,)) returns a Tuple{DataType} - return $(Expr(:splatnew, :(NamedTuple{names,T}), :(T(args)))) - end -else - function namedtuple(::Type{NamedTuple{names,T}}, args::Tuple) where {names,T<:Tuple} - return NamedTuple{names,T}(args) - end + length(syms) == 0 && return :(NamedTuple()) + + names_expr = Expr(:tuple, QuoteNode.(syms)...) + vals_expr = Expr(:tuple, vals...) + return :(NamedTuple{$names_expr}($vals_expr)) end #####################################################