-
Notifications
You must be signed in to change notification settings - Fork 453
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
Improve obj dup using spread syntax #7043
Conversation
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.
The implementation looks great.
Not sure I understand the comments about FFI.
Changes in current tests seem harmless, but perhaps I'm not fully getting what the concern is.
When using |
And was that a desired behaviour in FFI or a programming mistake of mixing arrays and objects, that now will have different semantics? |
Well, the existing One case I found during experiments was In a real-world case, a pattern in JS like So yes, this PR will change the semantics. We have to choose whether to preserve the prototype of the array or preserve the data. |
Ok so it's a semantic change that removes a hack. |
I'm merging this to continue work at #6984 , but I have to revisit this to remove |
@cknitt @cristianoc Should we note this as a breaking change? |
It is only breaking in the unlikely case that people misused this using Thanks a lot for your work! |
Right. IMHO it's very rare that this change is a problem, in fact it often fixes (another) problem, like copying such |
This removes
Caml_obj.obj_dup
runtime primitive. The spread syntax can be a perfect alternative toobj_dup
, as it doesn't change the key order.However, this may change FFI's behavior since it no longer handles Arrays separately. it's mostly Arrays extended with additional fields, so upcasting to Object makes sense IMO.
It's not an ideal implementation, but I'd like to merge first to finish #6984. It should be integrated into
Caml_block
, notObject
.Currently, the output looks like:
But later: