[SR-263] Implement a general solution to prevent deadlocks when generic types rely on their own metadata recursively #42885
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
compiler
The Swift compiler itself
runtime
The Swift Runtime
standard library
Area: Standard library umbrella
Additional Detail from JIRA
md5: f708bd18dd8ca57bb3b0279f9380be5e
blocks:
is duplicated by:
relates to:
Issue Description:
[Description by John McCall]
Recent changes taught the compiler to avoid emitting references to the type metadata for an ivar that the compiler can statically compute a fixed size of. This permits a large number of recursive class structures to be defined; however, there are some missing cases:
1. It does not suffice when the recursive metadata reference is an incidental aspect of a dependently-sized type expression. For example:
class Foo<T> {
var x: (T, Foo<T>)
}
Tuples, and fragile types in general, could be special cased; however:
2. It does not suffice when the recursive metadata reference is used in a type argument of a resilient type. For example:
class Foo<T> {
var x: ResilientStruct<Foo<T>>
}
This will provably not be an infinite type at runtime because Foo is a class. If Foo were a struct, it could still quite easily be finite, depending on how the type parameter is used.
3. It does not suffice when the recursive metadata reference appears somewhere other than an ivar's layout. For example:
class Bar<T> : Base<Bar<T>> {}
The correct fix is to develop a more complicated model that permits runtime type metadata to be briefly "incomplete" during instantiation.
The text was updated successfully, but these errors were encountered: