Skip to content

replace constructorof with something not UB #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/ConstructionBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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) = Base.typename(T).wrapper
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
constructorof(T::Type) = Base.typename(T).wrapper
constructorof(::Type{T}) where T = Base.typename(T).wrapper

Is there a reason why the where T was dropped as well?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In practice, the where just reduces the information inference is permitted to use about the argument during inlining

Copy link
Member

@rafaqz rafaqz Mar 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I guess I don't understand the scope of consequences of that.

From practical experience using where on types and functions like this often fixes type stability bugs.

(The reason for my concern is a small loss of type stability in constructorof could break the performance of 100s of packages)

constructorof(::Type{<:Tuple}) = tuple
constructorof(::Type{<:NamedTuple{names}}) where names =
NamedTupleConstructor{names}()
Expand Down
Loading