swift
02e1f2ea - IRGen: Fix key path generic environment marshalling for external property descriptors.

Commit
1 year ago
IRGen: Fix key path generic environment marshalling for external property descriptors. The layout of a computed key path component carries an argument buffer for captures, which has the following layout: ``` --- captured values (subscript indices) --- generic arguments --- ``` When we reference an externally-defined public property or subscript from a key path, and the external declaration has a property descriptor, then the generic arguments for the external declaration get appended to the end of this buffer, giving: ``` --- captured values (subscript indices) --- generic arguments --- external property's generic arguments --- ``` The convention for key path accessors to bind their generic environment is thus to unpack them from the end of the argument buffer, so that the external keypath's accessors can find the arguments to bind the external generic environment while still allowing the enclosing key path to save the original captured generic environment (which may be necessary to capture the appropriate conditional and/or retroactive `Equatable` and `Hashable` conformances for subscript indices). However, our code generation for binding the generic arguments out of the argument buffer contained a flawed optimization: for a property, we know there are never any captured values, so I had assumed that the generic parameters could always be bound from the beginning of the argument buffer, assuming that the generic parameters make up the totality of the buffer. This falls over for external property descriptor references when the key path itself captures a generic environment, since the external property's expected generic environment appears after the key path's original generic environment. We can fix this by removing the conditional entirely, and always adjusting the offset we load the generic environment from to look at the end of the buffer. Fixes rdar://125886333.
Author
Parents
Loading