ponyc icon indicating copy to clipboard operation
ponyc copied to clipboard

RFC: Copy Idiom

Open SeanTAllen opened this issue 9 years ago • 7 comments

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

SeanTAllen avatar Aug 19 '16 13:08 SeanTAllen

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.

Theodus avatar Aug 29 '16 17:08 Theodus

Is that the only thing you changed @Theodus ?

SeanTAllen avatar Aug 30 '16 12:08 SeanTAllen

It is the only change made to List.

Theodus avatar Aug 30 '16 12:08 Theodus

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 https://github.com/ponylang/rfcs/pull/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.

jemc avatar Aug 31 '16 20:08 jemc

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

SeanTAllen avatar Sep 28 '16 11:09 SeanTAllen

@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?

SeanTAllen avatar Jan 27 '22 03:01 SeanTAllen

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

jemc avatar Jan 28 '22 16:01 jemc