# Pitch #2: Protocol-based Actor Isolation

**URL:** <https://forums.swift.org/t/pitch-2-protocol-based-actor-isolation/42123>\
**Category:** Pitches\
**Created:** [November 19, 2020, 6:23am UTC](https://forums.swift.org/t/pitch-2-protocol-based-actor-isolation/42123 "2020-11-19T06:23:53Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![Chris\_Lattner3](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/chris_lattner3/32/348_2.png) [@Chris\_Lattner3](https://forums.swift.org/u/Chris_Lattner3)\
**Post date:** [November 21, 2020, 5:20am UTC](https://forums.swift.org/t/pitch-2-protocol-based-actor-isolation/42123/12 "2020-11-21T05:20:39Z")

</div>

> [@gribozavr](#):
>
> We could also borrow a page from Rust, specifically the [`PhantomData` type](https://doc.rust-lang.org/std/marker/struct.PhantomData.html). The type that wants to opt out can add a `PhantomData<AnyObject>` property -- the authosynthesis would see a non-value type stored var and would avoid synthesizing the conformance (but since the property is zero-size it does not cost anything at runtime). That way we can keep synthesis rules uniform (no opt-out processing).

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 🙂):

```swift
@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](https://github.com/tensorflow/swift-apis/blob/master/Sources/TensorFlow/Core/TensorHandle.swift#L39), 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

---

_[View the full topic](https://forums.swift.org/t/pitch-2-protocol-based-actor-isolation/42123)._
