From 8a4339e80b11fd0806c82379f3ea12230007a9bc Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Fri, 14 Mar 2025 15:10:19 -0400 Subject: [PATCH 1/4] replace constructorof with something not UB It is confusing that `constructorof` is documented as returning the constructor of `T`, which is normally defined to be `T`, and then typically does not return `T`, and so does not usually construct `T`. However, this PR is intended just to remove the undefined behavior here of using an unsound generated function (examining mutable state with getfield). --- src/ConstructionBase.jl | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/ConstructionBase.jl b/src/ConstructionBase.jl index 4c4871a..c3a2bbe 100644 --- a/src/ConstructionBase.jl +++ b/src/ConstructionBase.jl @@ -26,10 +26,7 @@ for (name, path) in [ end end -@generated function constructorof(::Type{T}) where T - getfield(parentmodule(T), nameof(T)) -end - +constructorof(T::Type) where {T} = nameof(T).wrapper constructorof(::Type{<:Tuple}) = tuple constructorof(::Type{<:NamedTuple{names}}) where names = NamedTupleConstructor{names}() From cf26ce7588cb3263e14a74a247c81dfda43f1978 Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Fri, 14 Mar 2025 15:18:27 -0400 Subject: [PATCH 2/4] Update ConstructionBase.jl --- src/ConstructionBase.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ConstructionBase.jl b/src/ConstructionBase.jl index c3a2bbe..f5ec90c 100644 --- a/src/ConstructionBase.jl +++ b/src/ConstructionBase.jl @@ -26,7 +26,7 @@ for (name, path) in [ end end -constructorof(T::Type) where {T} = nameof(T).wrapper +constructorof(T::Type) = nameof(T).wrapper constructorof(::Type{<:Tuple}) = tuple constructorof(::Type{<:NamedTuple{names}}) where names = NamedTupleConstructor{names}() From 1ecf0b241fb25636dfd34f3575a5113daefd61fb Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Fri, 14 Mar 2025 17:12:09 -0400 Subject: [PATCH 3/4] Update ConstructionBase.jl --- src/ConstructionBase.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ConstructionBase.jl b/src/ConstructionBase.jl index f5ec90c..caa9939 100644 --- a/src/ConstructionBase.jl +++ b/src/ConstructionBase.jl @@ -26,7 +26,7 @@ for (name, path) in [ end end -constructorof(T::Type) = nameof(T).wrapper +constructorof(T::Type) = typename(T).wrapper constructorof(::Type{<:Tuple}) = tuple constructorof(::Type{<:NamedTuple{names}}) where names = NamedTupleConstructor{names}() From 0bf093cac405e9cc28ffd9a484828830f1ea2661 Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Fri, 14 Mar 2025 17:18:31 -0400 Subject: [PATCH 4/4] Update ConstructionBase.jl --- src/ConstructionBase.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ConstructionBase.jl b/src/ConstructionBase.jl index caa9939..4f66e87 100644 --- a/src/ConstructionBase.jl +++ b/src/ConstructionBase.jl @@ -26,7 +26,7 @@ for (name, path) in [ end end -constructorof(T::Type) = typename(T).wrapper +constructorof(T::Type) = Base.typename(T).wrapper constructorof(::Type{<:Tuple}) = tuple constructorof(::Type{<:NamedTuple{names}}) where names = NamedTupleConstructor{names}()