ponylang / ponyc

Pony is an open-source, actor-model, capabilities-secure, high performance programming language
http://www.ponylang.io
BSD 2-Clause "Simplified" License
5.69k stars 410 forks source link

Collection clone methods should return iso when A is sharable. #1784

Open jemc opened 7 years ago

jemc commented 7 years ago

It's a quite common pain point in Pony that arrays of #shareable objects (val or tag) cannot be cloned to iso or val, as would be expected (and is the case with String.clone). This isn't possible because doing so would be unsafe when A is not #shareable.

This violates principle of least surprise for a lot of our users and we've received three PRs so far of users who were so surprised that they filed a PR to change it (including me, when I was first getting involved with the project). See #279, #1360, #1782.

However, once we have specialization (#1410) we can implement Array.clone so that it returns iso when A <: Any #share, or ref otherwise (as it does now). Doing so would seamlessly resolve the issue for users in the least surprising way.

jemc commented 7 years ago

Marking this a medium-priority bug, blocked until #1410 is implemented.

jemc commented 7 years ago

Changing the name of the ticket, since this applies not only to Array, but all other collections with a clone method as well (List, Map, Set, etc...). Noticed this because my original PR for this issue (#279) included them all.

SeanTAllen commented 4 years ago

This is currently blocked

jemc commented 3 years ago

I've written a somewhat lengthy explanation in Zulip about what's going on with the signature of Array.clone. Maybe it will be helpful to someone reading this ticket, so I'll link to it here: https://ponylang.zulipchat.com/#narrow/stream/189985-beginner-help/topic/Debug.28.29ing.20an.20iso.20passed.20through/near/236037204