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

RFC: Copy Idiom #1138

Open
SeanTAllen opened this issue Aug 19, 2016 · 7 comments
Open

RFC: Copy Idiom #1138

SeanTAllen opened this issue Aug 19, 2016 · 7 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@SeanTAllen
Copy link
Member

see: https://github.com/ponylang/rfcs/blob/master/text/0009-copy-idiom.md

@Theodus
Copy link
Contributor

Theodus commented Aug 29, 2016

While trying to implement this I encountered the following error when changing the signature of List.from in list.pony#L21 to fun from(that: List[A^] box) =>:

/home/theodus/stuff/ponyc/packages/collections/list.pony:26:12: argument not a subtype of parameter
      push(consume value)
           ^
    Info:
    /home/theodus/stuff/ponyc/packages/collections/list.pony:26:7: A tag is not a subtype of A iso: the subtype has no constraint
          push(consume value)
          ^
    /home/theodus/stuff/ponyc/packages/collections/list.pony:26:7: A box is not a subtype of A trn: the subtype has no constraint
          push(consume value)
          ^
    /home/theodus/stuff/ponyc/packages/collections/list.pony:26:7: A box is not a subtype of A ref: the subtype has no constraint
          push(consume value)
          ^
    /home/theodus/stuff/ponyc/packages/collections/list.pony:529:37: (A tag, A box, A box, A val, A box, A tag) is not a pairwise subtype of (A iso, A trn, A ref, A val, A box, A tag)
      fun values(): ListValues[A, this->ListNode[A]]^ =>

I'm confused about what the problem is and how it can be solved, especially since it works fine when that is a ref instead of a box.

@SeanTAllen
Copy link
Member Author

Is that the only thing you changed @Theodus ?

@Theodus
Copy link
Contributor

Theodus commented Aug 30, 2016

It is the only change made to List.

@jemc
Copy link
Member

jemc commented Aug 31, 2016

We discussed on the call that there are compiler limitations that prevent this idiom from working as expected.

Action items (as I understand them):

  • Adjust the new from constructor to take a type parameter for the input type, constrained by #read instead of being Object box.
  • Use type parameter inference as described in Generic type inference rfcs#26 to make this less onerous.
  • Adjust the compiler and/or type system to allow constructors to have their cap affected by the type parameter.
  • Extend the compiler and/or type system to be able to loosen the requirement that iso, trn and val constructors have all sendable params, provided that we can prove some other points of safety, that @sylvanc can describe in more detail.

The idea is that the end result will be calling Foo.from(foo) where foo is a Foo ref will yield a Foo ref, and where foo is a Foo val will yield a Foo val, etc.

@SeanTAllen
Copy link
Member Author

@jemc should we have new issues for the above action items?

@SeanTAllen SeanTAllen added good first issue Good for newcomers enhancement New feature or request and removed complexity: beginner friendly labels May 12, 2020
@SeanTAllen SeanTAllen added the help wanted Extra attention is needed label Sep 5, 2020
@SeanTAllen
Copy link
Member Author

@jemc did we ever discuss how:

Adjust the compiler and/or type system to allow constructors to have their cap affected by the type parameter.

would work and what the impact on existing pony code would be? would this be something that should be a request for RFC?

@jemc
Copy link
Member

jemc commented Jan 28, 2022

I think this would need a new RFC of its own, yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants