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

Swift 5 Metadata documentation is out of date

    XMLWordPrintable

    Details

      Description

      The documentation on the type metadata layout for Swift 5 needs to be updated.

      If I run the following code:

      func printFromMemory (_ ty: Any.Type) {

          let p = unsafeBitCast(ty, to: UnsafePointer<Int>.self)

          let s = String (p.pointee, radix: 16)

          print (s)

      }

      public enum OnIt {

          case ItsOff, ItsOn

      }

      public struct Foo {

          public var x: Int

      } 

      public class Bar {

      {{    public init () { }}}

      } 

      public protocol Proto {

          func nothing()

      } 

      print ("class")

      printFromMemory (Bar.self)

      print ("struct")

      printFromMemory (Foo.self)

      print ("optional")

      printFromMemory(Int?.self)

      print ("enum")

      printFromMemory (OnIt.self)

      print ("tuple")

      printFromMemory(type(of:(3, false)))

      print ("function")printFromMemory((()->()).self)

      print ("protocol")printFromMemory(Proto.self)

      I get the following output :

      class

      1d8001000032c9

      struct

      200

      optional

      202

      enum

      201

      tuple

      301

      function

      302

      protocol

      303

       

      This is clearly not the Kind field as described in the document but appears to have the bits spread out over the bottom 2 bytes? What is the layout now?

       

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            plinth666 Steve Hawley
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: