Skip to content
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

implement ConstructionBase interface #1086

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aplavin
Copy link
Member

@aplavin aplavin commented Aug 26, 2022

Brief motivation: ConstructionBase is the foundational package for (re)constructing and modifying immutable and mutable objects, see https://github.com/JuliaObjects/ConstructionBase.jl.
constructorof(T)(args) is the main interface of that package, it works with lots of types by default. However, it needs to be overloaded when some type parameters cannot be determined purely from arguments passed to the constructor. Clearly, this is the case for SArray.
This PR implements that interface, making StaticArrays immediately compatible with all those packages and user codes that use ConstructionBase.

A similar PR was proposed 1.5 years ago: #901. See for more discussion and more details on the motivation.
Several things have changed since that PR that make me believe there are more reasons for this to be accepted now.

First, the implementation here is definitely cleaner and shorter than in #901. It just forwards constructorof to already existing S/MArray constructors, keeping only those type parameters that are necessary for reconstruction. So, it automatically supports all S/MArray constructor variations.
In partucular, this addresses a concern made for #901:

In generic code I might want to change the size or element type - so I'm a little curious how you handle this in practice with constructorof?

Second, more and more packages are using ConstructionBase: already more than 1k in General (transitively) depend on it, and this number is growing. ConstructionBase has stayed stable and there are no plans for breaking changes or "feature creep". It's an extremely lightweight package with no dependencies and negligible load time.

@rafaqz @jw3126 @andyferris

@mateuszbaran
Copy link
Collaborator

I think it would make sense to have this as a package extension: JuliaLang/julia#47695 when a stable version of Julia is released with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants