Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-10286] Swift 5 Metadata documentation is out of date #52686

Open
swift-ci opened this issue Apr 3, 2019 · 2 comments
Open

[SR-10286] Swift 5 Metadata documentation is out of date #52686

swift-ci opened this issue Apr 3, 2019 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself documentation runtime The Swift Runtime

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Apr 3, 2019

Previous ID SR-10286
Radar None
Original Reporter plinth666 (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, Documentation, Runtime
Assignee None
Priority Medium

md5: dab758796316c8ab4c094a6309ade70a

Issue 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?

@belkadan
Copy link
Contributor

belkadan commented Apr 3, 2019

cc @mikeash, @jckarter

@jckarter
Copy link
Member

jckarter commented Apr 3, 2019

In the meantime, until we update the docs, the definitive source of the layouts is the runtime headers in include/swift/ABI. For a higher-level example of what's available, you can look at the swift-reflection-dump tool's implementation.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself documentation runtime The Swift Runtime
Projects
None yet
Development

No branches or pull requests

3 participants