Uploaded image for project: 'Swift'
  1. Swift
  2. SR-263

Implement a general solution to prevent deadlocks when generic types rely on their own metadata recursively

    XMLWordPrintable

    Details

      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.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                rjmccall John McCall
                Reporter:
                slavapestov Slava Pestov
              • Votes:
                1 Vote for this issue
                Watchers:
                10 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: