Question about _enclosingInstance function in property wrappers

Swift has the following undocumented feature, which was added as part of @Douglas_Gregor and @Joe_Groff 's original proposal to add property wrappers, and was something discussed in the "future direction" section which got implemented as an undocumented feature of property wrappers:

    public static subscript<Root>(
        _enclosingInstance instance: Root,
        wrapped rootKeyPath: ReferenceWritableKeyPath<Root, Value>,
        storage wrapperKeyPath: ReferenceWritableKeyPath<Root, Self>
    ) -> Value

When we asked about this a few years ago, someone said they were probably waiting until this could be updated to just a WritableKeyPath (allowing for an inout struct) before making it an official language feature.

So... where are we at with this now in mid-2022? Is anyone aware of any plans or proposals to make this API official anytime soon, or are we still blocked by a lack of inout structs? Would it be worthwhile to make a follow-up pitch to get this made official at this point? Thanks.

6 Likes

I did hit a situation where I wanted this feature: getting the enclosing self would have saved one object allocation per wrapped property.

In my case, this hypothetical feature would only have been useful when Root is an object type, so the WritableKeyPath approach wouldn’t have been necessary — but that approach presumably also would not have prevented me from solving my problem.