matsuda
7/30/2015 - 4:41 PM

0 Conformances and Associated Types

/*
    http://ericasadun.com
*/

import Foundation

extension String {
    public var first: String? {return isEmpty ? nil : self[startIndex..<startIndex.successor()]}
    public var last: String? {return isEmpty ? nil : self[endIndex.predecessor()..<endIndex]}
    public var butFirst: String? {return isEmpty ? nil : String(dropFirst(self.characters))}
    public var butLast: String? {return isEmpty ? nil : String(dropLast(self.characters))}
    public var trimmed: String {return stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())}
    public static func pattern(count: Int, _ s: String) -> String {
        if let c = s.characters.first {
            return String(count: count, repeatedValue: c)
        } else { fatalError("Character not supplied to String.pattern")}
    }
}

/// Returns an optional range where a regular expression is first matched within a string
public func RexRange(s: String, _ rex: String) -> Range<String.Index>? {
    return s.rangeOfString(rex,
        options: [.RegularExpressionSearch],
        range: s.startIndex..<s.endIndex,
        locale: nil)
}

/// Extract an entire scope from a match point by pairing braces
public func FetchScope(contents: String, prefixRex: String) -> Range<String.Index>? {
    if let matchRange = RexRange(contents, prefixRex) {
        var index = matchRange.endIndex; var count = 1; var ii = 0
        let chars = Array(contents.substringFromIndex(index).characters)
        while count > 0 {
            if ii < chars.count {
                let testChar = chars[ii++]
                if testChar == "{" {count++}
                if testChar == "}" {count--}
                index = advance(index, 1)
            } else {
                print("Ran out of characters")
                return nil
            }
        }
        return matchRange.startIndex..<index
    }
    return nil
}

/// Substring from start of Rex
public func SubstringFromStartOfRex(string: String, rex: String) -> String {
    if let matchRange = RexRange(string, rex) {
        return string.substringFromIndex(matchRange.startIndex)
    } else {fatalError()}
    //    } else {return string} // previously fatal
}

/// Substring to start of Rex
public func SubstringToStartOfRex(string: String, rex: String) -> String {
    if let matchRange = RexRange(string, rex) {
        return string.substringToIndex(matchRange.startIndex)
    } else {fatalError()}
    //    } else {return string} // previously fatal
}

/// Substring from end of Rex
public func SubstringFromEndOfRex(string: String, rex: String) -> String {
    if let matchRange = RexRange(string, rex) {
        return string.substringFromIndex(matchRange.endIndex)
    } else {fatalError()}
    //    } else {return string} // previously fatal
}

/// Substring to end of Rex
public func SubstringToEndOfRex(string: String, rex: String) -> String {
    if let matchRange = RexRange(string, rex) {
        return string.substringToIndex(matchRange.endIndex)
    } else {fatalError()}
    //    } else {return string} // previously fatal
}

/// Extract string between starting.end and ending.start rexes
public func ExtractStringContent(string: String, startRex: String, endRex: String) -> String {
    var s = string
    s = SubstringFromEndOfRex(s, rex: startRex)
    s = SubstringToStartOfRex(s, rex: endRex)
    return s
}

/// Transform comma-delineated string to trimmed string array
public func ArrayFromCommaDelineatedString(string: String) -> [String] {
    let members = string.componentsSeparatedByString(",")
    return members.map({$0.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())})
}
/*
    http://ericasadun.com
*/

import Foundation

/// Remove duplicate elements from an array
/// There are better ways to do this (see Chapter 5) but this will do for now
public func uniq<S: SequenceType, T: Hashable where S.Generator.Element == T>(source: S) -> [T] {
    var uniqueItems = Set<T>()
    for element in source {uniqueItems.insert(element)}
    return Array(uniqueItems)
}

/// Print a heading for a section
public func PrintHeading(string: String, first: Bool = false) {
    let highlightCharacter = Character("-")
    if !first {print("")}
    print(String(count:string.characters.count, repeatedValue:highlightCharacter))
    print(string)
    print(String(count:string.characters.count, repeatedValue:highlightCharacter))
    print("")
}
/*
    http://ericasadun.com
*/

import Foundation

// Replace this with a path to the standard library on your system
//public let stdlpath = NSBundle.mainBundle().pathForResource("stdl", ofType: "txt")!
public let stdlpath = "/Users/ericasadun/Desktop/Playgrounds/Cookbook Playgrounds/0 - C05/FetchProtocolTypes/FetchProtocolTypes/stdl.txt"
public let contents = try! String(contentsOfFile: stdlpath)

// Storage for the items of interest
var conformanceDictionary = [String:[String]]()
var associatedConformanceDictionary = [String:[String]]()
var typeDictionary = [String:[String]]()
var fullAssociatedTypes = [String:[String]]()
var objc = Set<String>()

func ProtocolReport() {
    /// Fetch a full protocol declaration from the library
    func FetchProtocol(contents: String) -> Range<String.Index>? {
        return FetchScope(contents, prefixRex: "\n(@objc\\s)?protocol[^\\{]*\\{")
    }
    
    /// Return the name of a protocol
    func FetchProtocolName(protocolString: String) -> String {
        return ExtractStringContent(protocolString, startRex: "\n(@objc\\s+)?protocol\\s*", endRex: "[\\s:]")
    }
    
    /// Return a list of ancestor protocols that are conformed to
    func FetchProtocolConformance(protocolString: String) -> [String] {
        var p = protocolString
        p = SubstringToEndOfRex(p, rex:"protocol[^\\{]*\\{")
        if RexRange(p, ":") == nil {return []}
        p = SubstringToEndOfRex(p, rex: ":.*\\{")
        p = SubstringFromStartOfRex(p, rex: ":.*\\{")
        p = (p.butFirst?.butLast)!
        return ArrayFromCommaDelineatedString(p)
    }
    
    /// Locate associated types for the protocol
    func FetchAssociatedTypes(protocolString: String) -> [String] {
        var p = protocolString
        var types = [String]()
        repeat {
            if var typealiasRange = RexRange(p, "typealias .*\n") {
                typealiasRange.startIndex = advance(typealiasRange.startIndex, "typealias ".characters.count)
                types.append(p.substringWithRange(typealiasRange).trimmed)
                p = p.substringFromIndex(typealiasRange.endIndex)
            } else {
                p = ""
            }
        } while !p.isEmpty
        return types
    }
    
    /// Find conformances for associated types
    func FetchAssociatedConformances(associatedString: String) -> [String] {
        var a = associatedString
        if let matchRange = RexRange(a, ":") {
            a = a.substringFromIndex(matchRange.endIndex)
        } else {
            return [String]()
        }
        if let matchRange = RexRange(a, "=") {
            a = a.substringToIndex(matchRange.startIndex)
        }
        return ArrayFromCommaDelineatedString(a)
    }

    PrintHeading("Conformances", first: true)
    
    // Iteratively fetch each protocol, log the conformances, types, and objc-compliance
    var c = contents
    repeat {
        if let protocolRange = FetchProtocol(c) {
            
            // Consume a protocol
            let protocolString = c.substringWithRange(protocolRange)
            c = c.substringFromIndex(protocolRange.endIndex)
            
            // Fetch the protocol's name
            let name = FetchProtocolName(protocolString)
            
            // Is it objc-conformant?
            if protocolString.hasPrefix("\n@objc") {objc.insert(name)}
            
            // Fetch direct conformances
            let conformants = FetchProtocolConformance(protocolString)
            conformanceDictionary[name] = conformants
            
            // Fetch associated types
            let associatedTypes = FetchAssociatedTypes(protocolString)
            typeDictionary[name] = associatedTypes
            
            // Fetch associated conformances and add to associated dictionary
            for associatedType in associatedTypes {
                let associatedConformances = FetchAssociatedConformances(associatedType)
                associatedConformanceDictionary[name] = conformanceDictionary[name]! + associatedConformances
            }
        } else {
            c = ""
        }
    } while !c.isEmpty
    
    // Integrate ancestor details into child protocol lists until stable
    var unchanged = true
    repeat {
        unchanged = true
        for (key, conformances) in conformanceDictionary {
            let current = conformances // fetch current conformances
            for item in current {
                if let inheritedConformances = conformanceDictionary[item] {
                    for inherited in inheritedConformances {
                        if !current.contains(inherited) {
                            unchanged = false
                            conformanceDictionary[key]!.append(inherited)
                        }
                    }
                }
            }
        }
    } while unchanged
    
    // Repeat for associated conformances (from associated types)
    unchanged = true
    repeat {
        unchanged = true
        for (key, conformances) in associatedConformanceDictionary {
            let current = conformances
            for item in current {
                if let inheritedConformances = associatedConformanceDictionary[item] {
                    for inherited in inheritedConformances {
                        if !current.contains(inherited) {
                            unchanged = false
                            associatedConformanceDictionary[key]!.append(inherited)
                        }
                    }
                }
            }
        }
    } while unchanged
    
    
    // Unique and sort the protocol names
    var keys = Array(conformanceDictionary.keys)
    keys = uniq(keys)
    keys.sortInPlace()
    
    // List protocols
    for key in keys {
        var conformances = conformanceDictionary[key]!
        print("protocol \(key)", appendNewline:false)
        if objc.contains(key) {
            print(" <ObjC>", appendNewline:false)
        }
        print("")
        
        // List conformances
        if !conformances.isEmpty {
            conformances = uniq(conformances)
            conformances.sortInPlace()
            print(String.pattern(4, " ")+"Conformances:")
            for conformance in conformances {
                print(String.pattern(8, " ") + "\(conformance)")
            }
        }
        
        // Find associated types both directly and for ancestors
        var aTypes = [String]()
        if let types = typeDictionary[key] {
            for associatedType in types {
                aTypes.append(associatedType)
            }
        }
        
        // Now uses associated conformances over conformances
        if let conformances = associatedConformanceDictionary[key] {
            for conformance in conformances {
                if let types = typeDictionary[conformance] {
                    for associatedType in types {
                        aTypes.append(associatedType + " [\(conformance)]")
                    }
                }
            }
        }
        
        // List associated types
        if !aTypes.isEmpty {
            aTypes = uniq(aTypes)
            aTypes.sortInPlace()
            fullAssociatedTypes[key] = aTypes
            print(String.pattern(4, " ") + "Associated types:")
            for aType in aTypes {
                print(String.pattern(8, " ") + "\(aType)")
            }
        }
        
        // Add space between protocol listings
        print("")
    }
}

func TypeParameterReport() {
    /// Fetch a full construct declaration from the library
    func FetchConstruct(contents: String) -> Range<String.Index>? {
        return FetchScope(contents, prefixRex: "\n(@objc\\s)?(class|struct|enum)[^\\{]*\\{")
    }
    
    /// Return the name of a construct
    func FetchConstructName(constructString: String) -> String {
        return ExtractStringContent(constructString, startRex: "\n(@objc\\s+)?(class|struct|enum)\\s*", endRex: "[<\\s:]")
    }
    
    /// Return a list of ancestor protocols that are conformed to
    func FetchConstructConformance(constructString: String) -> [String] {
        var c = constructString
        c = SubstringToEndOfRex(c, rex:"(class|struct|enum)[^\\{]*\\{")
        if RexRange(c, ">\\s*:\\s*") != nil {
            c = SubstringFromEndOfRex(c, rex: ">\\s*:\\s*")
        } else if RexRange(c, ":") == nil {
            return []
        }
        c = (c.butLast)!
        return ArrayFromCommaDelineatedString(c)
    }
    
    /// Find type parameters for structs, enums, classes
    PrintHeading("Type Parameters")
    var c = contents
    repeat {
        if let range = FetchConstruct(c) {
            
            // Consume a construct
            let constructString = c.substringWithRange(range)
            c = c.substringFromIndex(range.endIndex)
            
            // Fetch the construct's name
            let name = FetchConstructName(constructString)
            
            // Anything to report?
            let conformances = FetchConstructConformance(constructString)
            let usesParameters = RexRange(constructString, "\(name)<") != nil
            var associatedTypes = Set<String>()
            for conformance in conformances {
                if let t = fullAssociatedTypes[conformance] {
                    associatedTypes = associatedTypes.union(t)
                }
            }
    
            if conformances.isEmpty && associatedTypes.isEmpty && !usesParameters {continue}
    
            if let typeRange = RexRange(constructString, "(class|struct|enum)") {
                let typeString = constructString.substringWithRange(typeRange)
                print("\(typeString) ", appendNewline: false)
            }
            print(name)
            // Does the type use parameters?
            if usesParameters {
                // Fetch the construct's type parameters
                let typeParameterString = ExtractStringContent(constructString, startRex: "<", endRex: ">")
                let items = ArrayFromCommaDelineatedString(typeParameterString)
                print(String.pattern(4, " ") + "Type Parameters")
                for item in items {print(String.pattern(8, " "), appendNewline: false); print(item)}
                print("")
            }
            
            // Type Aliases...
            if !associatedTypes.isEmpty {
                print(String.pattern(4, " ") + "Inherited Type Parameters:")
                for associatedType in Array(associatedTypes).sort() {
                    print(String.pattern(8, " "), appendNewline: false)
                    print(associatedType)
                }
                print("")
            }

            // Conforms to...
            if !conformances.isEmpty {
                print(String.pattern(4, " ") + "Conformances:")
                for conformance in conformances {
                    print(String.pattern(8, " "), appendNewline: false)
                    print(conformance)
                }
            }
        } else {
            c = ""
        }
        print("")
    } while !c.isEmpty
}

/// MARK: Main
ProtocolReport()
TypeParameterReport()
---------------
Type Parameters
---------------

struct AnyBidirectionalCollection
    Type Parameters
        Element

    Inherited Type Parameters:
        Distance : _SignedIntegerType = Int [ForwardIndexType]
        Element [GeneratorType]
        Generator : GeneratorType
        Generator : GeneratorType = IndexingGenerator<Self>
        Generator : GeneratorType [SequenceType]
        Index : ForwardIndexType
        Index : ForwardIndexType [Indexable]
        SubSequence : Indexable, SequenceType = Slice<Self>

    Conformances:
        AnyCollectionType
        CollectionType
        Indexable
        SequenceType

struct AnyBidirectionalIndex
    Conformances:
        struct AnyBidirectionalIndex : ForwardIndexType
        _Incrementable
        Equatable
        BidirectionalIndexType

struct AnyForwardCollection
    Type Parameters
        Element

    Inherited Type Parameters:
        Distance : _SignedIntegerType = Int [ForwardIndexType]
        Element [GeneratorType]
        Generator : GeneratorType
        Generator : GeneratorType = IndexingGenerator<Self>
        Generator : GeneratorType [SequenceType]
        Index : ForwardIndexType
        Index : ForwardIndexType [Indexable]
        SubSequence : Indexable, SequenceType = Slice<Self>

    Conformances:
        AnyCollectionType
        CollectionType
        Indexable
        SequenceType

struct AnyForwardIndex
    Conformances:
        struct AnyForwardIndex : ForwardIndexType
        _Incrementable
        Equatable

class AnyGenerator
    Type Parameters
        Element

    Inherited Type Parameters:
        Element

    Conformances:
        GeneratorType

struct AnyRandomAccessCollection
    Type Parameters
        Element

    Inherited Type Parameters:
        Distance : _SignedIntegerType = Int [ForwardIndexType]
        Element [GeneratorType]
        Generator : GeneratorType
        Generator : GeneratorType = IndexingGenerator<Self>
        Generator : GeneratorType [SequenceType]
        Index : ForwardIndexType
        Index : ForwardIndexType [Indexable]
        SubSequence : Indexable, SequenceType = Slice<Self>

    Conformances:
        AnyCollectionType
        CollectionType
        Indexable
        SequenceType

struct AnyRandomAccessIndex
    Inherited Type Parameters:
        Stride : SignedNumberType
        Stride : SignedNumberType [_Strideable]

    Conformances:
        struct AnyRandomAccessIndex : ForwardIndexType
        _Incrementable
        Equatable
        RandomAccessIndexType
        BidirectionalIndexType
        Strideable
        Comparable
        _Strideable

struct AnySequence
    Type Parameters
        Element

    Inherited Type Parameters:
        Element [GeneratorType]
        Generator : GeneratorType

    Conformances:
        SequenceType

struct Array
    Type Parameters
        Element

    Inherited Type Parameters:
        Distance : _SignedIntegerType = Int [ForwardIndexType]
        Element [GeneratorType]
        Generator : GeneratorType
        Generator : GeneratorType = IndexingGenerator<Self>
        Generator : GeneratorType [SequenceType]
        Index : ForwardIndexType
        Index : ForwardIndexType [Indexable]
        SubSequence : Indexable, SequenceType = Slice<Self>

    Conformances:
        CollectionType
        Indexable
        SequenceType
        MutableCollectionType
        _DestructorSafeContainer

struct ArraySlice
    Type Parameters
        Element

    Inherited Type Parameters:
        Distance : _SignedIntegerType = Int [ForwardIndexType]
        Element [GeneratorType]
        Generator : GeneratorType
        Generator : GeneratorType = IndexingGenerator<Self>
        Generator : GeneratorType [SequenceType]
        Index : ForwardIndexType
        Index : ForwardIndexType [Indexable]
        SubSequence : Indexable, SequenceType = Slice<Self>

    Conformances:
        Indexable
        SequenceType
        CollectionType
        MutableCollectionType
        _DestructorSafeContainer

struct AutoreleasingUnsafeMutablePointer
    Type Parameters
        Memory

    Conformances:
        Equatable
        NilLiteralConvertible
        _PointerType

enum Bit
    Inherited Type Parameters:
        Distance : _SignedIntegerType = Int
        Stride : SignedNumberType
        Stride : SignedNumberType [_Strideable]

    Conformances:
        enum Bit : Int
        Comparable
        RandomAccessIndexType
        BidirectionalIndexType
        ForwardIndexType
        _Incrementable
        Strideable
        _Strideable
        _Reflectable

struct COpaquePointer
    Conformances:
        struct COpaquePointer : Equatable
        Hashable
        NilLiteralConvertible

struct Character
    Inherited Type Parameters:
        UnicodeScalarLiteralType

    Conformances:
        struct Character : ExtendedGraphemeClusterLiteralConvertible
        UnicodeScalarLiteralConvertible
        Equatable
        Hashable
        Comparable

struct ClosedInterval
    Type Parameters
        Bound : Comparable

    Inherited Type Parameters:
        Bound : Comparable

    Conformances:
        IntervalType
        Equatable
        CustomStringConvertible
        CustomDebugStringConvertible
        _Reflectable

struct CollectionOfOne
    Type Parameters
        Element

    Inherited Type Parameters:
        Distance : _SignedIntegerType = Int [ForwardIndexType]
        Element [GeneratorType]
        Generator : GeneratorType
        Generator : GeneratorType = IndexingGenerator<Self>
        Generator : GeneratorType [SequenceType]
        Index : ForwardIndexType
        Index : ForwardIndexType [Indexable]
        SubSequence : Indexable, SequenceType = Slice<Self>

    Conformances:
        CollectionType
        Indexable
        SequenceType

struct ContiguousArray
    Type Parameters
        Element

    Inherited Type Parameters:
        Distance : _SignedIntegerType = Int [ForwardIndexType]
        Element [GeneratorType]
        Generator : GeneratorType
        Generator : GeneratorType = IndexingGenerator<Self>
        Generator : GeneratorType [SequenceType]
        Index : ForwardIndexType
        Index : ForwardIndexType [Indexable]
        SubSequence : Indexable, SequenceType = Slice<Self>

    Conformances:
        CollectionType
        Indexable
        SequenceType
        MutableCollectionType
        _DestructorSafeContainer

struct Dictionary
    Type Parameters
        Key : Hashable
        Value

    Inherited Type Parameters:
        Distance : _SignedIntegerType = Int [ForwardIndexType]
        Element [GeneratorType]
        Generator : GeneratorType
        Generator : GeneratorType = IndexingGenerator<Self>
        Generator : GeneratorType [SequenceType]
        Index : ForwardIndexType
        Index : ForwardIndexType [Indexable]
        Key
        SubSequence : Indexable, SequenceType = Slice<Self>
        Value

    Conformances:
        CollectionType
        Indexable
        SequenceType
        DictionaryLiteralConvertible

struct DictionaryGenerator
    Type Parameters
        Key : Hashable
        Value

    Inherited Type Parameters:
        Element

    Conformances:
        GeneratorType

struct DictionaryIndex
    Type Parameters
        Key : Hashable
        Value

    Inherited Type Parameters:
        Distance : _SignedIntegerType = Int

    Conformances:
        ForwardIndexType
        _Incrementable
        Equatable
        Comparable

struct DictionaryLiteral
    Type Parameters
        Key
        Value

    Inherited Type Parameters:
        Key
        Value

    Conformances:
        DictionaryLiteralConvertible

struct EmptyCollection
    Type Parameters
        Element

    Inherited Type Parameters:
        Distance : _SignedIntegerType = Int [ForwardIndexType]
        Element [GeneratorType]
        Generator : GeneratorType
        Generator : GeneratorType = IndexingGenerator<Self>
        Generator : GeneratorType [SequenceType]
        Index : ForwardIndexType
        Index : ForwardIndexType [Indexable]
        SubSequence : Indexable, SequenceType = Slice<Self>

    Conformances:
        CollectionType
        Indexable
        SequenceType

struct EmptyGenerator
    Type Parameters
        Element

    Inherited Type Parameters:
        Element
        Element [GeneratorType]
        Generator : GeneratorType

    Conformances:
        GeneratorType
        SequenceType

struct EnumerateGenerator
    Type Parameters
        Base : GeneratorType

    Inherited Type Parameters:
        Element
        Element [GeneratorType]
        Generator : GeneratorType

    Conformances:
        GeneratorType
        SequenceType

struct EnumerateSequence
    Type Parameters
        Base : SequenceType

    Inherited Type Parameters:
        Element [GeneratorType]
        Generator : GeneratorType

    Conformances:
        SequenceType

struct FilterCollection
    Type Parameters
        Base : CollectionType

    Inherited Type Parameters:
        Distance : _SignedIntegerType = Int [ForwardIndexType]
        Element [GeneratorType]
        Generator : GeneratorType
        Generator : GeneratorType = IndexingGenerator<Self>
        Generator : GeneratorType [SequenceType]
        Index : ForwardIndexType
        Index : ForwardIndexType [Indexable]
        SubSequence : Indexable, SequenceType = Slice<Self>

    Conformances:
        CollectionType
        Indexable
        SequenceType

struct FilterCollectionIndex
    Type Parameters
        Base : CollectionType

    Inherited Type Parameters:
        Distance : _SignedIntegerType = Int

    Conformances:
        ForwardIndexType
        _Incrementable
        Equatable

struct FilterGenerator
    Type Parameters
        Base : GeneratorType

    Inherited Type Parameters:
        Element
        Element [GeneratorType]
        Generator : GeneratorType

    Conformances:
        GeneratorType
        SequenceType

struct FilterSequence
    Type Parameters
        Base : SequenceType

    Inherited Type Parameters:
        Element [GeneratorType]
        Generator : GeneratorType

    Conformances:
        SequenceType

struct GeneratorOfOne
    Type Parameters
        Element

    Inherited Type Parameters:
        Element
        Element [GeneratorType]
        Generator : GeneratorType

    Conformances:
        GeneratorType
        SequenceType

struct GeneratorSequence
    Type Parameters
        Base : GeneratorType

    Inherited Type Parameters:
        Element
        Element [GeneratorType]
        Generator : GeneratorType

    Conformances:
        GeneratorType
        SequenceType

struct HalfOpenInterval
    Type Parameters
        Bound : Comparable

    Inherited Type Parameters:
        Bound : Comparable

    Conformances:
        IntervalType
        Equatable
        CustomStringConvertible
        CustomDebugStringConvertible
        _Reflectable

enum ImplicitlyUnwrappedOptional
    Type Parameters
        T

    Conformances:
        _Reflectable
        NilLiteralConvertible

struct IndexingGenerator
    Type Parameters
        Elements : Indexable

    Inherited Type Parameters:
        Element
        Element [GeneratorType]
        Generator : GeneratorType

    Conformances:
        GeneratorType
        SequenceType

struct Int
    Conformances:
        struct Int : Equatable
        _SignedIntegerType
        Comparable
        _IntegerType
        IntegerArithmeticType
        _IntegerArithmeticType
        SignedIntegerType
        IntegerType

struct Int16
    Conformances:
        struct Int16 : SignedIntegerType
        IntegerType
        Equatable
        Comparable
        _IntegerType
        IntegerArithmeticType
        _IntegerArithmeticType
        _SignedIntegerType

struct Int32
    Conformances:
        struct Int32 : SignedIntegerType
        IntegerType
        Equatable
        Comparable
        _IntegerType
        IntegerArithmeticType
        _IntegerArithmeticType
        _SignedIntegerType

struct Int64
    Conformances:
        struct Int64 : _SignedIntegerType
        Comparable
        Equatable
        _IntegerType
        IntegerArithmeticType
        _IntegerArithmeticType
        SignedIntegerType
        IntegerType

struct Int8
    Conformances:
        struct Int8 : SignedIntegerType
        IntegerType
        Equatable
        Comparable
        _IntegerType
        IntegerArithmeticType
        _IntegerArithmeticType
        _SignedIntegerType

struct LazyBidirectionalCollection
    Type Parameters
        Base : CollectionType where Base.Index : BidirectionalIndexType

    Inherited Type Parameters:
        Distance : _SignedIntegerType = Int [ForwardIndexType]
        Element [GeneratorType]
        Generator : GeneratorType
        Generator : GeneratorType = IndexingGenerator<Self>
        Generator : GeneratorType [SequenceType]
        Index : ForwardIndexType
        Index : ForwardIndexType [Indexable]
        SubSequence : Indexable, SequenceType = Slice<Self>

    Conformances:
        CollectionType
        Indexable
        SequenceType

struct LazyForwardCollection
    Type Parameters
        Base : CollectionType where Base.Index : ForwardIndexType

    Inherited Type Parameters:
        Distance : _SignedIntegerType = Int [ForwardIndexType]
        Element [GeneratorType]
        Generator : GeneratorType
        Generator : GeneratorType = IndexingGenerator<Self>
        Generator : GeneratorType [SequenceType]
        Index : ForwardIndexType
        Index : ForwardIndexType [Indexable]
        SubSequence : Indexable, SequenceType = Slice<Self>

    Conformances:
        CollectionType
        Indexable
        SequenceType

struct LazyRandomAccessCollection
    Type Parameters
        Base : CollectionType where Base.Index : RandomAccessIndexType

    Inherited Type Parameters:
        Distance : _SignedIntegerType = Int [ForwardIndexType]
        Element [GeneratorType]
        Generator : GeneratorType
        Generator : GeneratorType = IndexingGenerator<Self>
        Generator : GeneratorType [SequenceType]
        Index : ForwardIndexType
        Index : ForwardIndexType [Indexable]
        SubSequence : Indexable, SequenceType = Slice<Self>

    Conformances:
        CollectionType
        Indexable
        SequenceType

struct LazySequence
    Type Parameters
        Base : SequenceType

    Inherited Type Parameters:
        Element [GeneratorType]
        Generator : GeneratorType

    Conformances:
        SequenceType

class ManagedBuffer
    Type Parameters
        Value
        Element

    Conformances:
        ManagedProtoBuffer<Value
        Element>

struct ManagedBufferPointer
    Type Parameters
        Value
        Element

    Conformances:
        Equatable

class ManagedProtoBuffer
    Type Parameters
        Value
        Element

    Conformances:
        NonObjectiveCBase

struct MapCollection
    Type Parameters
        Base : CollectionType
        Element

    Inherited Type Parameters:
        Distance : _SignedIntegerType = Int [ForwardIndexType]
        Element [GeneratorType]
        Generator : GeneratorType
        Generator : GeneratorType = IndexingGenerator<Self>
        Generator : GeneratorType [SequenceType]
        Index : ForwardIndexType
        Index : ForwardIndexType [Indexable]
        SubSequence : Indexable, SequenceType = Slice<Self>

    Conformances:
        CollectionType
        Indexable
        SequenceType

struct MapGenerator
    Type Parameters
        Base : GeneratorType
        Element

    Inherited Type Parameters:
        Element
        Element [GeneratorType]
        Generator : GeneratorType

    Conformances:
        GeneratorType
        SequenceType

struct MapSequence
    Type Parameters
        Base : SequenceType
        Element

    Inherited Type Parameters:
        Element [GeneratorType]
        Generator : GeneratorType

    Conformances:
        SequenceType

struct ObjectIdentifier
    Conformances:
        struct ObjectIdentifier : Hashable
        Equatable
        Comparable

enum Optional
    Type Parameters
        T

    Conformances:
        _Reflectable
        NilLiteralConvertible

struct PermutationGenerator
    Type Parameters
        C : CollectionType
        Indices : SequenceType where C.Index == Indices.Generator.Element

    Inherited Type Parameters:
        Element
        Element [GeneratorType]
        Generator : GeneratorType

    Conformances:
        GeneratorType
        SequenceType

struct Range
    Type Parameters
        Element : ForwardIndexType

    Inherited Type Parameters:
        Distance : _SignedIntegerType = Int [ForwardIndexType]
        Element [GeneratorType]
        Generator : GeneratorType
        Generator : GeneratorType = IndexingGenerator<Self>
        Generator : GeneratorType [SequenceType]
        Index : ForwardIndexType
        Index : ForwardIndexType [Indexable]
        SubSequence : Indexable, SequenceType = Slice<Self>

    Conformances:
        Equatable
        CollectionType
        Indexable
        SequenceType
        CustomStringConvertible
        CustomDebugStringConvertible

struct RangeGenerator
    Type Parameters
        Element : ForwardIndexType

    Inherited Type Parameters:
        Element
        Element [GeneratorType]
        Generator : GeneratorType

    Conformances:
        GeneratorType
        SequenceType

struct Repeat
    Type Parameters
        Element

    Inherited Type Parameters:
        Distance : _SignedIntegerType = Int [ForwardIndexType]
        Element [GeneratorType]
        Generator : GeneratorType
        Generator : GeneratorType = IndexingGenerator<Self>
        Generator : GeneratorType [SequenceType]
        Index : ForwardIndexType
        Index : ForwardIndexType [Indexable]
        SubSequence : Indexable, SequenceType = Slice<Self>

    Conformances:
        CollectionType
        Indexable
        SequenceType

struct ReverseCollection
    Type Parameters
        Base : CollectionType where Base.Index : BidirectionalIndexType

    Inherited Type Parameters:
        Distance : _SignedIntegerType = Int [ForwardIndexType]
        Element [GeneratorType]
        Generator : GeneratorType
        Generator : GeneratorType = IndexingGenerator<Self>
        Generator : GeneratorType [SequenceType]
        Index : ForwardIndexType
        Index : ForwardIndexType [Indexable]
        SubSequence : Indexable, SequenceType = Slice<Self>

    Conformances:
        CollectionType
        Indexable
        SequenceType

struct ReverseIndex
    Type Parameters
        Base : BidirectionalIndexType

    Inherited Type Parameters:
        Distance : _SignedIntegerType = Int

    Conformances:
        ForwardIndexType
        _Incrementable
        Equatable
        BidirectionalIndexType

struct ReverseRandomAccessCollection
    Type Parameters
        Base : CollectionType where Base.Index : RandomAccessIndexType

    Inherited Type Parameters:
        Distance : _SignedIntegerType = Int [ForwardIndexType]
        Element [GeneratorType]
        Generator : GeneratorType
        Generator : GeneratorType = IndexingGenerator<Self>
        Generator : GeneratorType [SequenceType]
        Index : ForwardIndexType
        Index : ForwardIndexType [Indexable]
        SubSequence : Indexable, SequenceType = Slice<Self>

    Conformances:
        CollectionType
        Indexable
        SequenceType

struct ReverseRandomAccessIndex
    Type Parameters
        Base : RandomAccessIndexType

    Inherited Type Parameters:
        Distance : _SignedIntegerType = Int
        Stride : SignedNumberType
        Stride : SignedNumberType [_Strideable]

    Conformances:
        ForwardIndexType
        _Incrementable
        Equatable
        RandomAccessIndexType
        BidirectionalIndexType
        Strideable
        Comparable
        _Strideable

struct Set
    Type Parameters
        Element : Hashable

    Inherited Type Parameters:
        Distance : _SignedIntegerType = Int [ForwardIndexType]
        Element
        Element [GeneratorType]
        Generator : GeneratorType
        Generator : GeneratorType = IndexingGenerator<Self>
        Generator : GeneratorType [SequenceType]
        Index : ForwardIndexType
        Index : ForwardIndexType [Indexable]
        SubSequence : Indexable, SequenceType = Slice<Self>

    Conformances:
        Hashable
        Equatable
        CollectionType
        Indexable
        SequenceType
        ArrayLiteralConvertible

struct SetGenerator
    Type Parameters
        Element : Hashable

    Inherited Type Parameters:
        Element

    Conformances:
        GeneratorType

struct SetIndex
    Type Parameters
        Element : Hashable

    Inherited Type Parameters:
        Distance : _SignedIntegerType = Int

    Conformances:
        ForwardIndexType
        _Incrementable
        Equatable
        Comparable

struct Slice
    Type Parameters
        Base : Indexable

    Inherited Type Parameters:
        Distance : _SignedIntegerType = Int [ForwardIndexType]
        Element [GeneratorType]
        Generator : GeneratorType
        Generator : GeneratorType = IndexingGenerator<Self>
        Generator : GeneratorType [SequenceType]
        Index : ForwardIndexType
        Index : ForwardIndexType [Indexable]
        SubSequence : Indexable, SequenceType = Slice<Self>

    Conformances:
        Indexable
        SequenceType
        CollectionType

struct StaticString
    Inherited Type Parameters:
        ExtendedGraphemeClusterLiteralType
        ExtendedGraphemeClusterLiteralType [ExtendedGraphemeClusterLiteralConvertible]
        StringLiteralType
        UnicodeScalarLiteralType [UnicodeScalarLiteralConvertible]

    Conformances:
        struct StaticString : UnicodeScalarLiteralConvertible
        ExtendedGraphemeClusterLiteralConvertible
        StringLiteralConvertible
        CustomStringConvertible
        CustomDebugStringConvertible
        _Reflectable

struct StrideThrough
    Type Parameters
        Element : Strideable

    Inherited Type Parameters:
        Element [GeneratorType]
        Generator : GeneratorType

    Conformances:
        SequenceType

struct StrideThroughGenerator
    Type Parameters
        Element : Strideable

    Inherited Type Parameters:
        Element

    Conformances:
        GeneratorType

struct StrideTo
    Type Parameters
        Element : Strideable

    Inherited Type Parameters:
        Element [GeneratorType]
        Generator : GeneratorType

    Conformances:
        SequenceType

struct StrideToGenerator
    Type Parameters
        Element : Strideable

    Inherited Type Parameters:
        Element

    Conformances:
        GeneratorType

struct UInt
    Inherited Type Parameters:
        IntegerLiteralType

    Conformances:
        struct UInt : UnsignedIntegerType
        IntegerType
        Equatable
        Comparable
        _IntegerType
        IntegerArithmeticType
        _IntegerArithmeticType
        IntegerLiteralConvertible
        _DisallowMixedSignArithmetic

struct UInt16
    Inherited Type Parameters:
        IntegerLiteralType

    Conformances:
        struct UInt16 : UnsignedIntegerType
        IntegerType
        Equatable
        Comparable
        _IntegerType
        IntegerArithmeticType
        _IntegerArithmeticType
        IntegerLiteralConvertible
        _DisallowMixedSignArithmetic

struct UInt32
    Inherited Type Parameters:
        IntegerLiteralType

    Conformances:
        struct UInt32 : UnsignedIntegerType
        IntegerType
        Equatable
        Comparable
        _IntegerType
        IntegerArithmeticType
        _IntegerArithmeticType
        IntegerLiteralConvertible
        _DisallowMixedSignArithmetic

struct UInt64
    Inherited Type Parameters:
        IntegerLiteralType

    Conformances:
        struct UInt64 : UnsignedIntegerType
        IntegerType
        Equatable
        Comparable
        _IntegerType
        IntegerArithmeticType
        _IntegerArithmeticType
        IntegerLiteralConvertible
        _DisallowMixedSignArithmetic

struct UInt8
    Inherited Type Parameters:
        IntegerLiteralType

    Conformances:
        struct UInt8 : UnsignedIntegerType
        IntegerType
        Equatable
        Comparable
        _IntegerType
        IntegerArithmeticType
        _IntegerArithmeticType
        IntegerLiteralConvertible
        _DisallowMixedSignArithmetic

struct UTF16
    Conformances:
        struct UTF16 : UnicodeCodecType

struct UTF32
    Conformances:
        struct UTF32 : UnicodeCodecType

struct UTF8
    Conformances:
        struct UTF8 : UnicodeCodecType

struct UnicodeScalar
    Conformances:
        struct UnicodeScalar : UnicodeScalarLiteralConvertible

struct Unmanaged
    Type Parameters
        Instance


struct UnsafeBufferPointer
    Type Parameters
        Element

    Inherited Type Parameters:
        Distance : _SignedIntegerType = Int [ForwardIndexType]
        Element [GeneratorType]
        Generator : GeneratorType
        Generator : GeneratorType = IndexingGenerator<Self>
        Generator : GeneratorType [SequenceType]
        Index : ForwardIndexType
        Index : ForwardIndexType [Indexable]
        SubSequence : Indexable, SequenceType = Slice<Self>

    Conformances:
        CollectionType
        Indexable
        SequenceType

struct UnsafeBufferPointerGenerator
    Type Parameters
        Element

    Inherited Type Parameters:
        Element
        Element [GeneratorType]
        Generator : GeneratorType

    Conformances:
        GeneratorType
        SequenceType

struct UnsafeMutableBufferPointer
    Type Parameters
        Element

    Inherited Type Parameters:
        Distance : _SignedIntegerType = Int [ForwardIndexType]
        Element [GeneratorType]
        Generator : GeneratorType
        Generator : GeneratorType = IndexingGenerator<Self>
        Generator : GeneratorType [SequenceType]
        Index : ForwardIndexType
        Index : ForwardIndexType [Indexable]
        SubSequence : Indexable, SequenceType = Slice<Self>

    Conformances:
        MutableCollectionType
        CollectionType
        Indexable
        SequenceType

struct UnsafeMutablePointer
    Type Parameters
        Memory

    Inherited Type Parameters:
        Distance : _SignedIntegerType = Int
        Stride : SignedNumberType
        Stride : SignedNumberType [_Strideable]

    Conformances:
        RandomAccessIndexType
        BidirectionalIndexType
        ForwardIndexType
        _Incrementable
        Equatable
        Strideable
        Comparable
        _Strideable
        Hashable
        NilLiteralConvertible
        _PointerType

struct UnsafePointer
    Type Parameters
        Memory

    Inherited Type Parameters:
        Distance : _SignedIntegerType = Int
        Stride : SignedNumberType
        Stride : SignedNumberType [_Strideable]

    Conformances:
        RandomAccessIndexType
        BidirectionalIndexType
        ForwardIndexType
        _Incrementable
        Equatable
        Strideable
        Comparable
        _Strideable
        Hashable
        NilLiteralConvertible
        _PointerType

struct Zip2Generator
    Type Parameters
        Generator1 : GeneratorType
        Generator2 : GeneratorType

    Inherited Type Parameters:
        Element

    Conformances:
        GeneratorType

struct Zip2Sequence
    Type Parameters
        Sequence1 : SequenceType
        Sequence2 : SequenceType

    Inherited Type Parameters:
        Element [GeneratorType]
        Generator : GeneratorType

    Conformances:
        SequenceType
------------
Conformances
------------

protocol AbsoluteValuable
    Conformances:
        Comparable
        IntegerLiteralConvertible
        SignedNumberType

protocol AnyCollectionType
    Conformances:
        CollectionType
        Indexable
        SequenceType

protocol AnyObject <ObjC>

protocol ArrayLiteralConvertible
    Associated types:
        Element

protocol BidirectionalIndexType
    Conformances:
        ForwardIndexType
        _Incrementable

protocol BitwiseOperationsType

protocol BooleanLiteralConvertible
    Associated types:
        BooleanLiteralType

protocol BooleanType

protocol CVarArgType

protocol CollectionType
    Conformances:
        Indexable
        SequenceType
    Associated types:
        Distance : _SignedIntegerType = Int [ForwardIndexType]
        Element [GeneratorType]
        Generator : GeneratorType = IndexingGenerator<Self>
        Generator : GeneratorType [SequenceType]
        Index : ForwardIndexType [Indexable]
        SubSequence : Indexable, SequenceType = Slice<Self>

protocol Comparable
    Conformances:
        Equatable

protocol CustomDebugStringConvertible

protocol CustomLeafReflectable
    Conformances:
        CustomReflectable

protocol CustomPlaygroundQuickLookable

protocol CustomReflectable

protocol CustomStringConvertible

protocol DictionaryLiteralConvertible
    Associated types:
        Key
        Value

protocol Equatable

protocol ErrorType

protocol ExtendedGraphemeClusterLiteralConvertible
    Conformances:
        UnicodeScalarLiteralConvertible
    Associated types:
        ExtendedGraphemeClusterLiteralType
        UnicodeScalarLiteralType [UnicodeScalarLiteralConvertible]

protocol FloatLiteralConvertible
    Associated types:
        FloatLiteralType

protocol FloatingPointType
    Conformances:
        Comparable
        Equatable
        Strideable
        _Strideable

protocol ForwardIndexType
    Conformances:
        Equatable
        _Incrementable
    Associated types:
        Distance : _SignedIntegerType = Int

protocol GeneratorType
    Associated types:
        Element

protocol Hashable
    Conformances:
        Equatable

protocol Indexable
    Associated types:
        Distance : _SignedIntegerType = Int [ForwardIndexType]
        Index : ForwardIndexType

protocol IntegerArithmeticType
    Conformances:
        Comparable
        Equatable
        _IntegerArithmeticType

protocol IntegerLiteralConvertible
    Associated types:
        IntegerLiteralType

protocol IntegerType
    Conformances:
        BidirectionalIndexType
        BitwiseOperationsType
        Comparable
        CustomStringConvertible
        ForwardIndexType
        Hashable
        IntegerArithmeticType
        IntegerLiteralConvertible
        RandomAccessIndexType
        Strideable
        _Incrementable
        _IntegerType
        _Strideable

protocol IntervalType
    Associated types:
        Bound : Comparable

protocol MirrorPathType

protocol MutableCollectionType
    Conformances:
        CollectionType
        Indexable
        SequenceType

protocol MutableSliceable
    Conformances:
        CollectionType
        Indexable
        MutableCollectionType
        SequenceType

protocol NilLiteralConvertible

protocol OptionSetType
    Conformances:
        ArrayLiteralConvertible
        Equatable
        RawRepresentable
        SetAlgebraType
    Associated types:
        Element = Self
        Element [ArrayLiteralConvertible]
        Element [SetAlgebraType]
        RawValue [RawRepresentable]

protocol OutputStreamType

protocol RandomAccessIndexType
    Conformances:
        BidirectionalIndexType
        Comparable
        ForwardIndexType
        Strideable
        _Incrementable
        _Strideable

protocol RangeReplaceableCollectionType
    Conformances:
        CollectionType
        Indexable
        SequenceType

protocol RawRepresentable
    Associated types:
        RawValue

protocol SequenceType
    Associated types:
        Element [GeneratorType]
        Generator : GeneratorType

protocol SetAlgebraType
    Conformances:
        ArrayLiteralConvertible
        Equatable
    Associated types:
        Element
        Element [ArrayLiteralConvertible]

protocol SignedIntegerType
    Conformances:
        BidirectionalIndexType
        BitwiseOperationsType
        Comparable
        CustomStringConvertible
        Equatable
        ForwardIndexType
        Hashable
        IntegerArithmeticType
        IntegerLiteralConvertible
        IntegerType
        RandomAccessIndexType
        SignedNumberType
        Strideable
        _Incrementable
        _IntegerType
        _SignedIntegerType
        _Strideable

protocol SignedNumberType
    Conformances:
        Comparable
        Equatable
        IntegerLiteralConvertible

protocol Streamable

protocol Strideable
    Conformances:
        Comparable
        Equatable
        _Strideable
    Associated types:
        Stride : SignedNumberType
        Stride : SignedNumberType [_Strideable]

protocol StringInterpolationConvertible

protocol StringLiteralConvertible
    Conformances:
        ExtendedGraphemeClusterLiteralConvertible
        UnicodeScalarLiteralConvertible
    Associated types:
        ExtendedGraphemeClusterLiteralType [ExtendedGraphemeClusterLiteralConvertible]
        StringLiteralType
        UnicodeScalarLiteralType [UnicodeScalarLiteralConvertible]

protocol UnicodeCodecType
    Associated types:
        CodeUnit

protocol UnicodeScalarLiteralConvertible
    Associated types:
        UnicodeScalarLiteralType

protocol UnsignedIntegerType
    Conformances:
        BidirectionalIndexType
        BitwiseOperationsType
        Comparable
        CustomStringConvertible
        ForwardIndexType
        Hashable
        IntegerArithmeticType
        IntegerLiteralConvertible
        IntegerType
        RandomAccessIndexType
        Strideable
        _DisallowMixedSignArithmetic
        _Incrementable
        _IntegerType
        _Strideable

protocol _ArrayBufferType
    Conformances:
        CollectionType
        MutableCollectionType
    Associated types:
        Element

protocol _ArrayType
    Conformances:
        ArrayLiteralConvertible
        CollectionType
        Indexable
        MutableCollectionType
        MutableSliceable
        RangeReplaceableCollectionType
        SequenceType

protocol _CVarArgAlignedType
    Conformances:
        CVarArgType

protocol _CVarArgPassedAsDouble
    Conformances:
        CVarArgType

protocol _CocoaStringType <ObjC>

protocol _CollectionWrapperType
    Conformances:
        _SequenceWrapperType
    Associated types:
        Base : CollectionType, SequenceType
        Base : SequenceType [_SequenceWrapperType]
        Distance : _SignedIntegerType = Int [ForwardIndexType]
        Element [GeneratorType]
        Generator : GeneratorType = Self.Base.Generator [_SequenceWrapperType]
        Index : ForwardIndexType = Self.Base.Index

protocol _ColorLiteralConvertible

protocol _DestructorSafeContainer

protocol _DisallowMixedSignArithmetic
    Conformances:
        BitwiseOperationsType
        CustomStringConvertible
        Hashable
        IntegerArithmeticType
        IntegerLiteralConvertible
        _Incrementable
        _IntegerType

protocol _ImageLiteralConvertible

protocol _Incrementable
    Conformances:
        Equatable

protocol _IntegerArithmeticType

protocol _IntegerType
    Conformances:
        BitwiseOperationsType
        Comparable
        CustomStringConvertible
        Equatable
        Hashable
        IntegerArithmeticType
        IntegerLiteralConvertible
        _Incrementable
        _IntegerArithmeticType

protocol _MirrorType

protocol _NSArrayCoreType <ObjC>
    Conformances:
        _NSCopyingType
        _NSFastEnumerationType
        _ShadowProtocol

protocol _NSCopyingType <ObjC>
    Conformances:
        _ShadowProtocol

protocol _NSDictionaryCoreType <ObjC>
    Conformances:
        _NSCopyingType
        _NSFastEnumerationType
        _ShadowProtocol

protocol _NSDictionaryType <ObjC>
    Conformances:
        _NSCopyingType
        _NSDictionaryCoreType
        _NSFastEnumerationType

protocol _NSEnumeratorType <ObjC>
    Conformances:
        _ShadowProtocol

protocol _NSFastEnumerationType <ObjC>
    Conformances:
        _ShadowProtocol

protocol _NSSetCoreType <ObjC>
    Conformances:
        _NSCopyingType
        _NSFastEnumerationType
        _ShadowProtocol

protocol _NSSetType <ObjC>
    Conformances:
        _NSCopyingType
        _NSFastEnumerationType
        _NSSetCoreType

protocol _NSStringCoreType <ObjC>
    Conformances:
        _NSCopyingType
        _NSFastEnumerationType
        _ShadowProtocol

protocol _ObjectiveCBridgeable

protocol _PointerType

protocol _Reflectable

protocol _SequenceWrapperType
    Associated types:
        Base : SequenceType
        Element [GeneratorType]
        Generator : GeneratorType = Self.Base.Generator

protocol _ShadowProtocol <ObjC>

protocol _SignedIntegerType
    Conformances:
        BitwiseOperationsType
        Comparable
        CustomStringConvertible
        Equatable
        Hashable
        IntegerArithmeticType
        IntegerLiteralConvertible
        SignedNumberType
        _Incrementable
        _IntegerType

protocol _SinkType

protocol _Strideable
    Associated types:
        Stride : SignedNumberType

protocol _StringElementType