-
Notifications
You must be signed in to change notification settings - Fork 784
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
Created a builder for creating types, allowing for more flexibility #2553
Conversation
In general, a function taking a raw pointer as an argument has to be unsafe, because it has no way to check that the pointer is correct. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm really happy to have a builder for this. It has gotten quite messy so thanks for the cleanup :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks very much for working on the enums and for kicking off with a much-needed refactor!
Using a builder is a great idea. For a bit of context why we had create_type_object
and create_type_object_impl
, the motivation was to keep the codgen cost of this code as low as possible by having minimal generic wrapper create_type_object
around concrete create_type_object_impl
. We had some severe compile-time regressions reported in the past by users in this code.
I think with a builder we could actually cut the codegen cost further. I wonder if we could have a trait like the following, shifting the builder creation to const eval and meaning we only need concrete runtime code to be generated:
trait HasPyClassBuilder {
const BUILDER: PyClassBuilder;
}
I think it should be possible to give HasPyClassBuilder
a blanket impl for T: PyClassImpl
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, cleaned up that last clippy warning, and all other comments don't seem to be actionable. Let me know the next steps from here!
The builder currently allocates a Vec to store all of the slots, so can't be const. |
Ok fair, instead I pushed vultix#1 which captures all of the arguments we feed to the builder as a constant in the same fashion. I checked |
As discussed in vultix#1 we've shown that there is a compile performance regression, but it doesn't appear to be so significant that it should be a blocker for merging. So I think #2553 (comment) is the last tweak proposed here, and then let's merge this. |
I'm not sure why CI is failing now - is this on my end? |
No, it isnt anything you did - Bumpalo bumped its msrv, so we need to use an older version. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll rebase this on main; that should then go through. Thanks!
EDIT: looks like you didn't check the box to give me permission to push to your branch - you'll need to do the rebase :) |
Actually I just pushed the rebase to my own fork, opened as #2565; will close this one. Thanks! |
…more flexibility (#2565) * Rewrote `create_type_object_impl` to use a builder, allowing for more flexibility. * Fixed clippy warning about complex type * Removed `with_` prefix from `PyTypeBuilder` * Fixed misnamed function call Co-authored-by: Aidan Grant <[email protected]>
This is the first in a series of pull requests as I implement issues #417 and #906. This seemed like a relatively easy piece to review separately.
Creating metaclasses and custom types for different enum variants required more flexibility than our current
create_type_object_impl
allowed for. I originally had lots of near-duplicates of the function, but found a builder like what I have here covers my use cases better.Question regarding unsafe
I'm not entirely sure which methods should / shouldn't be considered unsafe to use. The approach I've taken here is to assume pushing a c pointer to a slot is always unsafe, but that functions doing so are considered safe if we've verified the slot type is correct. For example, is
PyTypeBuilder::build
always safe to call if the earlier safety invariants are met? I believe so, but am not positive.