diff --git a/Sources/SwiftDriver/IncrementalCompilation/Bitcode/Bitcode.swift b/Sources/SwiftDriver/IncrementalCompilation/Bitcode/Bitcode.swift index d983fd961..f66833e3a 100644 --- a/Sources/SwiftDriver/IncrementalCompilation/Bitcode/Bitcode.swift +++ b/Sources/SwiftDriver/IncrementalCompilation/Bitcode/Bitcode.swift @@ -12,14 +12,14 @@ import struct TSCBasic.ByteString -public struct Bitcode { +internal struct Bitcode { public let signature: Bitcode.Signature public let elements: [BitcodeElement] public let blockInfo: [UInt64:BlockInfo] } extension Bitcode { - public struct Signature: Equatable { + internal struct Signature: Equatable { private var value: UInt32 public init(value: UInt32) { @@ -41,7 +41,7 @@ extension Bitcode { extension Bitcode { /// Traverse a bitstream using the specified `visitor`, which will receive /// callbacks when blocks and records are encountered. - public static func read(bytes: ByteString, using visitor: inout Visitor) throws { + internal static func read(bytes: ByteString, using visitor: inout Visitor) throws { precondition(bytes.count > 4) var reader = BitstreamReader(buffer: bytes) try visitor.validate(signature: reader.readSignature()) diff --git a/Sources/SwiftDriver/IncrementalCompilation/Bitcode/BitcodeElement.swift b/Sources/SwiftDriver/IncrementalCompilation/Bitcode/BitcodeElement.swift index d29addcd3..a65bea6cb 100644 --- a/Sources/SwiftDriver/IncrementalCompilation/Bitcode/BitcodeElement.swift +++ b/Sources/SwiftDriver/IncrementalCompilation/Bitcode/BitcodeElement.swift @@ -10,8 +10,8 @@ // //===----------------------------------------------------------------------===// -public enum BitcodeElement { - public struct Block { +internal enum BitcodeElement { + internal struct Block { public var id: UInt64 public var elements: [BitcodeElement] } @@ -21,8 +21,8 @@ public enum BitcodeElement { /// - Warning: A `Record` element's fields and payload only live as long as /// the `visit` function that provides them is called. To persist /// a record, always make a copy of it. - public struct Record { - public enum Payload { + internal struct Record { + internal enum Payload { case none case array([UInt64]) case char6String(String) @@ -39,7 +39,7 @@ public enum BitcodeElement { } extension BitcodeElement.Record.Payload: CustomStringConvertible { - public var description: String { + internal var description: String { switch self { case .none: return "none" diff --git a/Sources/SwiftDriver/IncrementalCompilation/Bitcode/Bits.swift b/Sources/SwiftDriver/IncrementalCompilation/Bitcode/Bits.swift index 68bedd0d4..0495db292 100644 --- a/Sources/SwiftDriver/IncrementalCompilation/Bitcode/Bits.swift +++ b/Sources/SwiftDriver/IncrementalCompilation/Bitcode/Bits.swift @@ -12,7 +12,7 @@ import struct TSCBasic.ByteString -struct Bits: RandomAccessCollection { +internal struct Bits: RandomAccessCollection { var buffer: ByteString var startIndex: Int { return 0 } @@ -50,7 +50,7 @@ struct Bits: RandomAccessCollection { } extension Bits { - struct Cursor { + internal struct Cursor { enum Error: Swift.Error { case bufferOverflow } let buffer: Bits diff --git a/Sources/SwiftDriver/IncrementalCompilation/Bitcode/Bitstream.swift b/Sources/SwiftDriver/IncrementalCompilation/Bitcode/Bitstream.swift index f85fb2f61..83e6b49c7 100644 --- a/Sources/SwiftDriver/IncrementalCompilation/Bitcode/Bitstream.swift +++ b/Sources/SwiftDriver/IncrementalCompilation/Bitcode/Bitstream.swift @@ -11,14 +11,14 @@ //===----------------------------------------------------------------------===// /// A top-level namespace for all bitstream-related structures. -public enum Bitstream {} +internal enum Bitstream {} extension Bitstream { /// An `Abbreviation` represents the encoding definition for a user-defined /// record. An `Abbreviation` is the primary form of compression available in /// a bitstream file. - public struct Abbreviation { - public enum Operand { + internal struct Abbreviation { + internal enum Operand { /// A literal value (emitted as a VBR8 field). case literal(UInt64) @@ -91,7 +91,7 @@ extension Bitstream { /// abbreviation defined by `BitstreamWriter`. Always use /// `BitstreamWriter.defineBlockInfoAbbreviation(_:_:)` /// to register abbreviations. - public struct AbbreviationID: RawRepresentable, Equatable, Hashable, Comparable, Identifiable { + internal struct AbbreviationID: RawRepresentable, Equatable, Hashable, Comparable, Identifiable { public var rawValue: UInt64 public init(rawValue: UInt64) { @@ -136,7 +136,7 @@ extension Bitstream { /// static let diagnostics = Self.firstApplicationID + 1 /// } /// ``` - public struct BlockID: RawRepresentable, Equatable, Hashable, Comparable, Identifiable { + internal struct BlockID: RawRepresentable, Equatable, Hashable, Comparable, Identifiable { public var rawValue: UInt8 public init(rawValue: UInt8) { @@ -166,7 +166,7 @@ extension Bitstream { /// a name is given to a block or record with `blockName` or /// `setRecordName`, debugging tools like `llvm-bcanalyzer` can be used to /// introspect the structure of blocks and records in the bitstream file. - public enum BlockInfoCode: UInt8 { + internal enum BlockInfoCode: UInt8 { /// Indicates which block ID is being described. case setBID = 1 /// An optional element that records which bytes of the record are the diff --git a/Sources/SwiftDriver/IncrementalCompilation/Bitcode/BitstreamVisitor.swift b/Sources/SwiftDriver/IncrementalCompilation/Bitcode/BitstreamVisitor.swift index 4c966d2b3..33714884f 100644 --- a/Sources/SwiftDriver/IncrementalCompilation/Bitcode/BitstreamVisitor.swift +++ b/Sources/SwiftDriver/IncrementalCompilation/Bitcode/BitstreamVisitor.swift @@ -10,7 +10,7 @@ // //===----------------------------------------------------------------------===// -public protocol BitstreamVisitor { +internal protocol BitstreamVisitor { /// Customization point to validate a bitstream's signature or "magic number". func validate(signature: Bitcode.Signature) throws /// Called when a new block is encountered. Return `true` to enter the block diff --git a/Sources/SwiftDriver/IncrementalCompilation/Bitcode/BitstreamWriter.swift b/Sources/SwiftDriver/IncrementalCompilation/Bitcode/BitstreamWriter.swift index bd995d8fc..99c389773 100644 --- a/Sources/SwiftDriver/IncrementalCompilation/Bitcode/BitstreamWriter.swift +++ b/Sources/SwiftDriver/IncrementalCompilation/Bitcode/BitstreamWriter.swift @@ -92,7 +92,7 @@ /// /// The higher-level APIs will automatically ensure that `BitstreamWriter.data` /// is valid. Once serialization has completed, simply emit this data to a file. -public final class BitstreamWriter { +internal final class BitstreamWriter { /// The buffer of data being written to. private(set) public var data: [UInt8] @@ -161,7 +161,7 @@ public final class BitstreamWriter { extension BitstreamWriter { /// Writes the provided UInt32 to the data stream directly. - public func write(_ int: UInt32) { + internal func write(_ int: UInt32) { let index = data.count // Add 4 bytes of zeroes to be overwritten. @@ -179,7 +179,7 @@ extension BitstreamWriter { /// - int: The integer containing the bits you'd like to write /// - width: The number of low-bits of the integer you're writing to the /// buffer - public func writeVBR(_ int: IntType, width: UInt8) + internal func writeVBR(_ int: IntType, width: UInt8) where IntType: UnsignedInteger & ExpressibleByIntegerLiteral { let threshold = UInt64(1) << (UInt64(width) - 1) @@ -201,7 +201,7 @@ extension BitstreamWriter { /// - int: The integer containing the bits you'd like to write /// - width: The number of low-bits of the integer you're writing to the /// buffer - public func write(_ int: IntType, width: UInt8) + internal func write(_ int: IntType, width: UInt8) where IntType: UnsignedInteger & ExpressibleByIntegerLiteral { precondition(width > 0, "cannot emit 0 bits") @@ -247,7 +247,7 @@ extension BitstreamWriter { currentBit = (currentBit + width) & 31 } - public func alignIfNeeded() { + internal func alignIfNeeded() { guard currentBit > 0 else { return } write(currentValue) assert(bufferOffset % 4 == 0, "buffer must be 32-bit aligned") @@ -256,12 +256,12 @@ extension BitstreamWriter { } /// Writes a Bool as a 1-bit integer value. - public func write(_ bool: Bool) { + internal func write(_ bool: Bool) { write(bool ? 1 as UInt : 0, width: 1) } /// Writes the provided BitCode Abbrev operand to the stream. - public func write(_ abbrevOp: Bitstream.Abbreviation.Operand) { + internal func write(_ abbrevOp: Bitstream.Abbreviation.Operand) { write(abbrevOp.isLiteral) // the Literal bit. switch abbrevOp { case .literal(let value): @@ -290,19 +290,19 @@ extension BitstreamWriter { } /// Writes the specified abbreviaion value to the stream, as a 32-bit quantity. - public func writeCode(_ code: Bitstream.AbbreviationID) { + internal func writeCode(_ code: Bitstream.AbbreviationID) { writeCode(code.rawValue) } /// Writes the specified Code value to the stream, as a 32-bit quantity. - public func writeCode(_ code: IntType) + internal func writeCode(_ code: IntType) where IntType: UnsignedInteger & ExpressibleByIntegerLiteral { write(code, width: codeBitWidth) } /// Writes an ASCII character to the stream, as an 8-bit ascii value. - public func writeASCII(_ character: Character) { + internal func writeASCII(_ character: Character) { precondition(character.unicodeScalars.count == 1, "character is not ASCII") let c = UInt8(ascii: character.unicodeScalars.first!) write(c, width: 8) @@ -314,7 +314,7 @@ extension BitstreamWriter { extension BitstreamWriter { /// Defines an abbreviation and returns the unique identifier for that /// abbreviation. - public func defineAbbreviation(_ abbrev: Bitstream.Abbreviation) -> Bitstream.AbbreviationID { + internal func defineAbbreviation(_ abbrev: Bitstream.Abbreviation) -> Bitstream.AbbreviationID { encodeAbbreviation(abbrev) currentAbbreviations.append(abbrev) let rawValue = UInt64(currentAbbreviations.count - 1) + @@ -335,7 +335,7 @@ extension BitstreamWriter { // MARK: Writing Records extension BitstreamWriter { - public struct RecordBuffer { + internal struct RecordBuffer { private(set) var values = [UInt32]() fileprivate init() { @@ -378,7 +378,7 @@ extension BitstreamWriter { } /// Writes an unabbreviated record to the stream. - public func writeRecord(_ code: CodeType, _ composeRecord: (inout RecordBuffer) -> Void) + internal func writeRecord(_ code: CodeType, _ composeRecord: (inout RecordBuffer) -> Void) where CodeType: RawRepresentable, CodeType.RawValue == UInt8 { writeCode(.unabbreviatedRecord) @@ -394,7 +394,7 @@ extension BitstreamWriter { /// Writes a record with the provided abbreviation ID and record contents. /// Optionally, emits the provided blob if the abbreviation referenced /// by that ID requires it. - public func writeRecord( + internal func writeRecord( _ abbrevID: Bitstream.AbbreviationID, _ composeRecord: (inout RecordBuffer) -> Void, blob: String? = nil @@ -463,7 +463,7 @@ extension BitstreamWriter { "0123456789._", (0 as UInt)...)) /// Writes a char6-encoded value. - public func writeChar6(_ value: IntType) + internal func writeChar6(_ value: IntType) where IntType: UnsignedInteger & ExpressibleByIntegerLiteral { guard (0..<64).contains(value) else { @@ -474,7 +474,7 @@ extension BitstreamWriter { } /// Writes a value with the provided abbreviation encoding. - public func writeAbbrevField(_ op: Bitstream.Abbreviation.Operand, value: UInt32) { + internal func writeAbbrevField(_ op: Bitstream.Abbreviation.Operand, value: UInt32) { switch op { case .literal(let literalValue): // Do not write anything @@ -494,7 +494,7 @@ extension BitstreamWriter { /// Writes a block, beginning with the provided block code and the /// abbreviation width - public func writeBlock( + internal func writeBlock( _ blockID: Bitstream.BlockID, newAbbrevWidth: UInt8? = nil, emitRecords: () -> Void @@ -504,7 +504,7 @@ extension BitstreamWriter { endBlock() } - public func writeBlob(_ bytes: S, includeSize: Bool = true) + internal func writeBlob(_ bytes: S, includeSize: Bool = true) where S: Collection, S.Element == UInt8 { if includeSize { @@ -529,7 +529,7 @@ extension BitstreamWriter { /// Writes the blockinfo block and allows emitting abbreviations /// and records in it. - public func writeBlockInfoBlock(emitRecords: () -> Void) { + internal func writeBlockInfoBlock(emitRecords: () -> Void) { writeBlock(.blockInfo, newAbbrevWidth: 2) { currentBlockID = nil blockInfoRecords = [:] @@ -547,7 +547,7 @@ extension BitstreamWriter { /// - blockID: The ID of the block to emit. /// - abbreviationBitWidth: The width of the largest abbreviation ID in this block. /// - defineSubBlock: A closure that is called to define the contents of the new block. - public func withSubBlock( + internal func withSubBlock( _ blockID: Bitstream.BlockID, abbreviationBitWidth: UInt8? = nil, defineSubBlock: () -> Void @@ -568,7 +568,7 @@ extension BitstreamWriter { /// - Parameters: /// - blockID: The ID of the block to emit. /// - abbreviationBitWidth: The width of the largest abbreviation ID in this block. - public func enterSubblock( + internal func enterSubblock( _ blockID: Bitstream.BlockID, abbreviationBitWidth: UInt8? = nil ) { @@ -601,7 +601,7 @@ extension BitstreamWriter { } /// Marks the end of a new block record. - public func endBlock() { + internal func endBlock() { guard let block = blockScope.popLast() else { fatalError("endBlock() called with no block registered") } @@ -623,7 +623,7 @@ extension BitstreamWriter { /// Defines an abbreviation within the blockinfo block for the provided /// block ID. - public func defineBlockInfoAbbreviation( + internal func defineBlockInfoAbbreviation( _ blockID: Bitstream.BlockID, _ abbrev: Bitstream.Abbreviation ) -> Bitstream.AbbreviationID { diff --git a/Sources/SwiftDriver/IncrementalCompilation/Bitcode/BlockInfo.swift b/Sources/SwiftDriver/IncrementalCompilation/Bitcode/BlockInfo.swift index ac8057c44..fa10562ab 100644 --- a/Sources/SwiftDriver/IncrementalCompilation/Bitcode/BlockInfo.swift +++ b/Sources/SwiftDriver/IncrementalCompilation/Bitcode/BlockInfo.swift @@ -10,7 +10,7 @@ // //===----------------------------------------------------------------------===// -public struct BlockInfo { +internal struct BlockInfo { public var name: String = "" public var recordNames: [UInt64:String] = [:] }