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

Change clone method of collections to consistently return iso^. #279

Closed
wants to merge 1 commit into from

Conversation

jemc
Copy link
Member

@jemc jemc commented Aug 8, 2015

This PR changes the clone method of Array, List, HashMap, and HashSet to return iso^.

This is a more flexible return type, allowing the calling code to take advantage of the fact that the return value is indeed the only reference to the new object that exists so far. This is also more consistent the clone method signature for String and Flags, which already do this.

@andymcn
Copy link
Contributor

andymcn commented Aug 9, 2015

Maybe I'm being dumb, but surely this isn't capability safe.

Array.clone() creates a shallow copy. So if you have an array of Foo refs then the new clone array will contain references to the same Foo objects, so the array itself is not isolated.

For String and Flags it's OK, because the contents is copied too.

@jemc
Copy link
Member Author

jemc commented Aug 9, 2015

You're right.

In my case it is a List of vals, so it's okay, but in other cases like the ones you mentioned, it won't be. For now, I guess I have to maintain my own method in the package that clones this kind of list and gives an iso^ return, unless there is some kind of guard for this that we could use in the standard library (under a different method name) that lets you clone a collection to iso^ if all the contents are of a capability such that it would be okay.

@jemc jemc closed this Aug 9, 2015
@jemc jemc deleted the feature/clone-as-iso-ephemeral branch August 9, 2015 15:59
@jemc jemc mentioned this pull request Nov 8, 2015
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