Completing Property Wrappers

Well, perhaps there does not have to be a single, "final" way to access self. Maybe we can have multiple approaches.

I'm working on a project where this currently-hidden API is a hugely useful game-changer. The use case is for a very simplified kind of binding that relies on keypaths.

At first I was passing in the keypath like @Wrap(\Foo.bar) var bar: Bar however this no longer compiles due to a bug in Swift 5.2, and there is no guarantee that you passed in the right keypath—@Wrap(\Foo.baz) var bar would compile but then fail at runtime since \Foo.baz != \Foo.bar.

To me, the main problem with the current hidden feature is that the wrapper does not know the enclosing instance's type at init-time, so I'm having to resort to passing an extra argument into the wrapper just to make sure our wrapper is specialized on the correct root type. That could easily be remedied if the compiler synthesized this extra param.

Speaking of synthesizing params, maybe there is a way to add a general ability to add auto-synthesized params for wrappers based on keypaths and protocols, something like:

protocol AFoo {
   var bar: Bar
}

@propertyWrapper 
struct Wrap<Root: AFoo, Value> {
    // normal stuff
    // ...
    
    /// Inits the wrapper with a Bar, 
    /// uses Root instance's bar as default
    init(bar: Bar = \Root.bar) {
        self.bar = bar
    }

Especially with wrappers in protocols this would be super awesome since you'd be able to:

protocol AFoo {
   @Bind var bar: Bar
}

@propertyWrapper 
struct Wrap<Root: AFoo, Value> {
    // normal stuff
    // ...
    
    /// Inits the wrapper with a Bar, 
    /// uses Root instance's bar binder as default
    init(bar: Bar = \Root.bar) {
        self.bar = $bar
    }