-
Notifications
You must be signed in to change notification settings - Fork 5.5k
[Ruby 4.1] Declare legacy RData as TypedData #15455
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
base: master
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
| struct rb_legacy_rdata { | ||
| void *data; /* must be first for RDATA(obj)->data compatibility */ | ||
| RUBY_DATA_FUNC dmark; | ||
| RUBY_DATA_FUNC dfree; | ||
| }; |
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.
It is possible to keep the order as previous and make extra embed size 0.
You can obtain the container pointer from the member pointer with ccan_container_of.
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.
We need somewhere to store dmark and dfree and RTypedData needs the location those used to be in for RData
| a = @s.untyped_wrap_struct(1024) | ||
| @s.RTYPEDDATA_P(a).should == false | ||
| end | ||
| end |
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.
Should enclose in ruby_version_is ""..."4.0" do / end.
|
Apart from this PR, Always treat encoding as TYPEDDATA should be merged, I think. |
byroot
left a comment
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've been meaning to retrofit RData as RTypedData since about two years, but your solution is much better than the one I was toying with.
I believe this is very valuable as RData is very rare now, officially deprecated, and removing many conditionals in hotspots should help with performance (as demonstrated in #15387). And I think you now can remove the RTYPEDDATA_P(obj) condition in rbimpl_check_typeddata.
My only worry is that we're perhaps a bit late in the release cycle for such a change, but I'd really really like that change for 4.0 though.
| STATIC_ASSERT(rdata_data, offsetof(struct RData, data) == offsetof(struct RTypedData, data) + offsetof(struct rb_legacy_rdata, data)); | ||
| STATIC_ASSERT(rdata_dmark, offsetof(struct RData, dmark) == offsetof(struct RTypedData, data) + offsetof(struct rb_legacy_rdata, dmark)); | ||
| STATIC_ASSERT(rdata_dfree, offsetof(struct RData, dfree) == offsetof(struct RTypedData, data) + offsetof(struct rb_legacy_rdata, dfree)); |
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.
Do we even need this anymore? If legacy RData is retrofitted inside RTypedData, we don't care about offsets. AFAIK these were only necessary to be able to distinguish the two.
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.
Or do you want to keep supporting RDATA(obj)->dmark and RDATA(obj)->dfree ? I can't imagine how an extension would legitimately need to do that, to me that always was private API.
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 had intended to keep dmark/dfree just in case they were in use, but if we're aiming for Ruby 4.1 I can see removing them. We should probably keep RDATA(obj)->data for now
| } | ||
|
|
||
| static const rb_data_type_t rb_legacy_rdata_type = { | ||
| .wrap_struct_name = "legacy RData", |
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.
| .wrap_struct_name = "legacy RData", | |
| .wrap_struct_name = "deprecated RData", |
I think after this change, RTYPEDDATA_TYPE(obj) != &deprecated_rdata_typeBut we probably deprecate this as well as part of https://bugs.ruby-lang.org/issues/19998 |
|
You should also be able to get rid of |
jeremyevans
left a comment
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.
Overall, I think this is good change. I worry it may be a little late in the dev cycle to introduce this change, though. We are only a little over two weeks from release.
I think we may want a developer with more GC knowledge that I have to review the commented out code in gc.c. We may want to wait to commit this until we have a better understanding about why the existing code was wrong, and what the correct code would be. If we already have that understanding, we should remove or replace the commented out code and include the reasoning in the commit message.
|
I agree it's probably too late in the cycle for this. I'll wait until January.
The There's no reason to test this. |
I was realizing with the new
TYPED_DATA_EMBEDDEDit should be possible to store an RData as a proper valid RTypedData. We do this by marking the T_DATA as embedded, and havingvoid *databe the first element of the struct (so that it's in the same location) after that pointer we can store dmark and dfree.I think there is still usage of the old API in the wild and this should remove most of our maintenance burden internally.
cc @byroot @nobu What do you think? Is this worth doing? I can do more testing and clean this up for merging if you think so.
There is one potential incompatibility with this: RTYPEDDATA_P will return true for all T_DATA. (I suppose we could remove all references to
RTYPEDDATA_Pinternally and add a new method to check whether it's this special type of TypedData, but that seems unnecessary)