Pitch #2: Protocol-based Actor Isolation

Interesting idea. It isn't really related to this proposal, but something that I would like to explore in the future is an attribute that turns off all autogenerated members -- including the default assignment operator, destructor for structs, and move/moveinit hooks in the basic type witness table. Swift internally supports arbitrary logic here, but we don't allow advanced users to write their own types with their own implementation of these hooks. I'd love to be able to write something like (disclaimer: I made no attempt to pick good names here :slight_smile:):

@explicit
struct MySmartPointer {
   init(_ x: MySmartPointer) { 
     // custom copy ctor 
   }

  init(_ x: ^MySmartPointer) { 
     // move constructor.
  }

  operator=(_ x: MySmartPointer) { 
     // custom copy reassign operator
  }

  operator=(_ x: ^MySmartPointer) { 
     // custom move reassign.
  }

  deinit {
     // custom destructor
  }
}

In addition to being valuable for advanced pure-swift APIs, such a thing is useful when you need to write a C API in Swift that has init/copyctor/dtor hooks. Currently the least-bad thing to do is use a class for this, which adds an extra level of indirection and a memory allocation.

This could also be way to handle move only types and other weird things that C++ can express that Swift can't.

-Chris

10 Likes