-
-
Notifications
You must be signed in to change notification settings - Fork 418
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
Tuple allowed for unconstrained type param, but not Any #any type param. #1767
Comments
The result is that I can create a list of |
On the sync call, @sylvanc said that this is expected, given that In other words, an unconstrained type parameter is not equivalent to a type parameter constrained on There's currently no way to specify a reference capability for a type parameter that can include tuples, since tuples currently do not have a reference capability at all. On the sync call, I proposed a system of inferring a reference capability for tuples based on the ref caps of the elements, such that the ref cap of the tuple would be one whose viewpoint-adaptation set included the set of ref caps of the elements. |
This came up again in the context of #1931. On this week's call we talked about an alternative, fairly simple, solution. We can add a special case in the type checker to make tuple subtypes of empty interfaces, such as With this, tuples can now satisfy the |
I think we do still need to consider the cap of the tuple elements to determine if the tuple is a subtype of a given empty interface, due to the cap of the empty interface. One of the reasons for that is definitely sendability, as you suggested in your parenthetical, though there may also be other reasons. For example, consider the actor Promise[A: Any #share]
be apply(value: A) =>
// ... If we didn't consider the cap of the tuple, this would allow for unsound cases, such as I think the key as I mentioned in my previous comment is to consider the set of valid viewpoint-adapted caps for a given origin cap. Or in other words, to consider the tuple elements as viewpoint-adapted fields in an "object" with unknown cap, in order to determine what caps are possible for the unknown cap of the "object". Note that this doesn't require tuples to actually be objects in the runtime, but just to be treated like objects with fields for the purposes of determining what tuple cap(s) would be sound. For example, the set of valid viewpoint-adapted caps for a |
Because we never actually go through viewpoint adaptation, I think we can get away with saying This way This is stricter than your proposal, but I believe simpler to implement |
After this commit, a tuple is considered a subtype of `Any ${cap}` if all of the elements of the tuple are subcaps of the cap. This is a principle of least surprise issue, as it is surprising that a type param constraint of `Any #any` does not behave the same as an unconstrained type param, with the latter accepting tuple type args, and the latter not doing so. Previously, there was no way to allow tuples of any cardinality as a type argument, while restricting what caps were allowed to be in those tuples (such as for the concerns of aliasing or sendability). For example, `class List[A]` in the `collections` package allowed tuples as type args, but `class List[A: Any #share]` in the `collections/persistent` package did not. Now they both allow tuple type args, and the `Any #share` constrains the type arg so that all tuple elements must be shareable (`val` or `tag`). Resolves #1767.
After this commit, a tuple is considered a subtype of `Any ${cap}` if all of the elements of the tuple are subcaps of the cap. This is a principle of least surprise issue, as it is surprising that a type param constraint of `Any #any` does not behave the same as an unconstrained type param, with the latter accepting tuple type args, and the latter not doing so. Previously, there was no way to allow tuples of any cardinality as a type argument, while restricting what caps were allowed to be in those tuples (such as for the concerns of aliasing or sendability). For example, `class List[A]` in the `collections` package allowed tuples as type args, but `class List[A: Any #share]` in the `collections/persistent` package did not. Now they both allow tuple type args, and the `Any #share` constrains the type arg so that all tuple elements must be shareable (`val` or `tag`). Resolves #1767.
After this commit, a tuple is considered a subtype of `Any ${cap}` if all of the elements of the tuple are subcaps of the cap. This is a principle of least surprise issue, as it is surprising that a type param constraint of `Any #any` does not behave the same as an unconstrained type param, with the latter accepting tuple type args, and the latter not doing so. Previously, there was no way to allow tuples of any cardinality as a type argument, while restricting what caps were allowed to be in those tuples (such as for the concerns of aliasing or sendability). For example, `class List[A]` in the `collections` package allowed tuples as type args, but `class List[A: Any #share]` in the `collections/persistent` package did not. Now they both allow tuple type args, and the `Any #share` constrains the type arg so that all tuple elements must be shareable (`val` or `tag`). Resolves #1767.
After this commit, a tuple is considered a subtype of `Any ${cap}` if all of the elements of the tuple are subcaps of the cap. This is a principle of least surprise issue, as it is surprising that a type param constraint of `Any #any` does not behave the same as an unconstrained type param, with the latter accepting tuple type args, and the latter not doing so. Previously, there was no way to allow tuples of any cardinality as a type argument, while restricting what caps were allowed to be in those tuples (such as for the concerns of aliasing or sendability). For example, `class List[A]` in the `collections` package allowed tuples as type args, but `class List[A: Any #share]` in the `collections/persistent` package did not. Now they both allow tuple type args, and the `Any #share` constrains the type arg so that all tuple elements must be shareable (`val` or `tag`). Resolves #1767.
I'm finding that tuples are allowed as type args for type params with no constraints, but are not allowed for type params that are constrained on
Any #any
, or more useful constraints, likeAny #share
. For example:The text was updated successfully, but these errors were encountered: