Skip to content

Commit c8e3c84

Browse files
authored
Merge pull request #1376 from compnerd/internal
SwiftDriver: mark bitcode interfaces as `internal`
2 parents f0ca4cb + 7819bd0 commit c8e3c84

File tree

7 files changed

+41
-41
lines changed

7 files changed

+41
-41
lines changed

Sources/SwiftDriver/IncrementalCompilation/Bitcode/Bitcode.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212

1313
import struct TSCBasic.ByteString
1414

15-
public struct Bitcode {
15+
internal struct Bitcode {
1616
public let signature: Bitcode.Signature
1717
public let elements: [BitcodeElement]
1818
public let blockInfo: [UInt64:BlockInfo]
1919
}
2020

2121
extension Bitcode {
22-
public struct Signature: Equatable {
22+
internal struct Signature: Equatable {
2323
private var value: UInt32
2424

2525
public init(value: UInt32) {
@@ -41,7 +41,7 @@ extension Bitcode {
4141
extension Bitcode {
4242
/// Traverse a bitstream using the specified `visitor`, which will receive
4343
/// callbacks when blocks and records are encountered.
44-
public static func read<Visitor: BitstreamVisitor>(bytes: ByteString, using visitor: inout Visitor) throws {
44+
internal static func read<Visitor: BitstreamVisitor>(bytes: ByteString, using visitor: inout Visitor) throws {
4545
precondition(bytes.count > 4)
4646
var reader = BitstreamReader(buffer: bytes)
4747
try visitor.validate(signature: reader.readSignature())

Sources/SwiftDriver/IncrementalCompilation/Bitcode/BitcodeElement.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
public enum BitcodeElement {
14-
public struct Block {
13+
internal enum BitcodeElement {
14+
internal struct Block {
1515
public var id: UInt64
1616
public var elements: [BitcodeElement]
1717
}
@@ -21,8 +21,8 @@ public enum BitcodeElement {
2121
/// - Warning: A `Record` element's fields and payload only live as long as
2222
/// the `visit` function that provides them is called. To persist
2323
/// a record, always make a copy of it.
24-
public struct Record {
25-
public enum Payload {
24+
internal struct Record {
25+
internal enum Payload {
2626
case none
2727
case array([UInt64])
2828
case char6String(String)
@@ -39,7 +39,7 @@ public enum BitcodeElement {
3939
}
4040

4141
extension BitcodeElement.Record.Payload: CustomStringConvertible {
42-
public var description: String {
42+
internal var description: String {
4343
switch self {
4444
case .none:
4545
return "none"

Sources/SwiftDriver/IncrementalCompilation/Bitcode/Bits.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import struct TSCBasic.ByteString
1414

15-
struct Bits: RandomAccessCollection {
15+
internal struct Bits: RandomAccessCollection {
1616
var buffer: ByteString
1717

1818
var startIndex: Int { return 0 }
@@ -50,7 +50,7 @@ struct Bits: RandomAccessCollection {
5050
}
5151

5252
extension Bits {
53-
struct Cursor {
53+
internal struct Cursor {
5454
enum Error: Swift.Error { case bufferOverflow }
5555

5656
let buffer: Bits

Sources/SwiftDriver/IncrementalCompilation/Bitcode/Bitstream.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
/// A top-level namespace for all bitstream-related structures.
14-
public enum Bitstream {}
14+
internal enum Bitstream {}
1515

1616
extension Bitstream {
1717
/// An `Abbreviation` represents the encoding definition for a user-defined
1818
/// record. An `Abbreviation` is the primary form of compression available in
1919
/// a bitstream file.
20-
public struct Abbreviation {
21-
public enum Operand {
20+
internal struct Abbreviation {
21+
internal enum Operand {
2222
/// A literal value (emitted as a VBR8 field).
2323
case literal(UInt64)
2424

@@ -91,7 +91,7 @@ extension Bitstream {
9191
/// abbreviation defined by `BitstreamWriter`. Always use
9292
/// `BitstreamWriter.defineBlockInfoAbbreviation(_:_:)`
9393
/// to register abbreviations.
94-
public struct AbbreviationID: RawRepresentable, Equatable, Hashable, Comparable, Identifiable {
94+
internal struct AbbreviationID: RawRepresentable, Equatable, Hashable, Comparable, Identifiable {
9595
public var rawValue: UInt64
9696

9797
public init(rawValue: UInt64) {
@@ -136,7 +136,7 @@ extension Bitstream {
136136
/// static let diagnostics = Self.firstApplicationID + 1
137137
/// }
138138
/// ```
139-
public struct BlockID: RawRepresentable, Equatable, Hashable, Comparable, Identifiable {
139+
internal struct BlockID: RawRepresentable, Equatable, Hashable, Comparable, Identifiable {
140140
public var rawValue: UInt8
141141

142142
public init(rawValue: UInt8) {
@@ -166,7 +166,7 @@ extension Bitstream {
166166
/// a name is given to a block or record with `blockName` or
167167
/// `setRecordName`, debugging tools like `llvm-bcanalyzer` can be used to
168168
/// introspect the structure of blocks and records in the bitstream file.
169-
public enum BlockInfoCode: UInt8 {
169+
internal enum BlockInfoCode: UInt8 {
170170
/// Indicates which block ID is being described.
171171
case setBID = 1
172172
/// An optional element that records which bytes of the record are the

Sources/SwiftDriver/IncrementalCompilation/Bitcode/BitstreamVisitor.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
public protocol BitstreamVisitor {
13+
internal protocol BitstreamVisitor {
1414
/// Customization point to validate a bitstream's signature or "magic number".
1515
func validate(signature: Bitcode.Signature) throws
1616
/// Called when a new block is encountered. Return `true` to enter the block

Sources/SwiftDriver/IncrementalCompilation/Bitcode/BitstreamWriter.swift

+23-23
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
///
9393
/// The higher-level APIs will automatically ensure that `BitstreamWriter.data`
9494
/// is valid. Once serialization has completed, simply emit this data to a file.
95-
public final class BitstreamWriter {
95+
internal final class BitstreamWriter {
9696
/// The buffer of data being written to.
9797
private(set) public var data: [UInt8]
9898

@@ -161,7 +161,7 @@ public final class BitstreamWriter {
161161

162162
extension BitstreamWriter {
163163
/// Writes the provided UInt32 to the data stream directly.
164-
public func write(_ int: UInt32) {
164+
internal func write(_ int: UInt32) {
165165
let index = data.count
166166

167167
// Add 4 bytes of zeroes to be overwritten.
@@ -179,7 +179,7 @@ extension BitstreamWriter {
179179
/// - int: The integer containing the bits you'd like to write
180180
/// - width: The number of low-bits of the integer you're writing to the
181181
/// buffer
182-
public func writeVBR<IntType>(_ int: IntType, width: UInt8)
182+
internal func writeVBR<IntType>(_ int: IntType, width: UInt8)
183183
where IntType: UnsignedInteger & ExpressibleByIntegerLiteral
184184
{
185185
let threshold = UInt64(1) << (UInt64(width) - 1)
@@ -201,7 +201,7 @@ extension BitstreamWriter {
201201
/// - int: The integer containing the bits you'd like to write
202202
/// - width: The number of low-bits of the integer you're writing to the
203203
/// buffer
204-
public func write<IntType>(_ int: IntType, width: UInt8)
204+
internal func write<IntType>(_ int: IntType, width: UInt8)
205205
where IntType: UnsignedInteger & ExpressibleByIntegerLiteral
206206
{
207207
precondition(width > 0, "cannot emit 0 bits")
@@ -247,7 +247,7 @@ extension BitstreamWriter {
247247
currentBit = (currentBit + width) & 31
248248
}
249249

250-
public func alignIfNeeded() {
250+
internal func alignIfNeeded() {
251251
guard currentBit > 0 else { return }
252252
write(currentValue)
253253
assert(bufferOffset % 4 == 0, "buffer must be 32-bit aligned")
@@ -256,12 +256,12 @@ extension BitstreamWriter {
256256
}
257257

258258
/// Writes a Bool as a 1-bit integer value.
259-
public func write(_ bool: Bool) {
259+
internal func write(_ bool: Bool) {
260260
write(bool ? 1 as UInt : 0, width: 1)
261261
}
262262

263263
/// Writes the provided BitCode Abbrev operand to the stream.
264-
public func write(_ abbrevOp: Bitstream.Abbreviation.Operand) {
264+
internal func write(_ abbrevOp: Bitstream.Abbreviation.Operand) {
265265
write(abbrevOp.isLiteral) // the Literal bit.
266266
switch abbrevOp {
267267
case .literal(let value):
@@ -290,19 +290,19 @@ extension BitstreamWriter {
290290
}
291291

292292
/// Writes the specified abbreviaion value to the stream, as a 32-bit quantity.
293-
public func writeCode(_ code: Bitstream.AbbreviationID) {
293+
internal func writeCode(_ code: Bitstream.AbbreviationID) {
294294
writeCode(code.rawValue)
295295
}
296296

297297
/// Writes the specified Code value to the stream, as a 32-bit quantity.
298-
public func writeCode<IntType>(_ code: IntType)
298+
internal func writeCode<IntType>(_ code: IntType)
299299
where IntType: UnsignedInteger & ExpressibleByIntegerLiteral
300300
{
301301
write(code, width: codeBitWidth)
302302
}
303303

304304
/// Writes an ASCII character to the stream, as an 8-bit ascii value.
305-
public func writeASCII(_ character: Character) {
305+
internal func writeASCII(_ character: Character) {
306306
precondition(character.unicodeScalars.count == 1, "character is not ASCII")
307307
let c = UInt8(ascii: character.unicodeScalars.first!)
308308
write(c, width: 8)
@@ -314,7 +314,7 @@ extension BitstreamWriter {
314314
extension BitstreamWriter {
315315
/// Defines an abbreviation and returns the unique identifier for that
316316
/// abbreviation.
317-
public func defineAbbreviation(_ abbrev: Bitstream.Abbreviation) -> Bitstream.AbbreviationID {
317+
internal func defineAbbreviation(_ abbrev: Bitstream.Abbreviation) -> Bitstream.AbbreviationID {
318318
encodeAbbreviation(abbrev)
319319
currentAbbreviations.append(abbrev)
320320
let rawValue = UInt64(currentAbbreviations.count - 1) +
@@ -335,7 +335,7 @@ extension BitstreamWriter {
335335
// MARK: Writing Records
336336

337337
extension BitstreamWriter {
338-
public struct RecordBuffer {
338+
internal struct RecordBuffer {
339339
private(set) var values = [UInt32]()
340340

341341
fileprivate init() {
@@ -378,7 +378,7 @@ extension BitstreamWriter {
378378
}
379379

380380
/// Writes an unabbreviated record to the stream.
381-
public func writeRecord<CodeType>(_ code: CodeType, _ composeRecord: (inout RecordBuffer) -> Void)
381+
internal func writeRecord<CodeType>(_ code: CodeType, _ composeRecord: (inout RecordBuffer) -> Void)
382382
where CodeType: RawRepresentable, CodeType.RawValue == UInt8
383383
{
384384
writeCode(.unabbreviatedRecord)
@@ -394,7 +394,7 @@ extension BitstreamWriter {
394394
/// Writes a record with the provided abbreviation ID and record contents.
395395
/// Optionally, emits the provided blob if the abbreviation referenced
396396
/// by that ID requires it.
397-
public func writeRecord(
397+
internal func writeRecord(
398398
_ abbrevID: Bitstream.AbbreviationID,
399399
_ composeRecord: (inout RecordBuffer) -> Void,
400400
blob: String? = nil
@@ -463,7 +463,7 @@ extension BitstreamWriter {
463463
"0123456789._", (0 as UInt)...))
464464

465465
/// Writes a char6-encoded value.
466-
public func writeChar6<IntType>(_ value: IntType)
466+
internal func writeChar6<IntType>(_ value: IntType)
467467
where IntType: UnsignedInteger & ExpressibleByIntegerLiteral
468468
{
469469
guard (0..<64).contains(value) else {
@@ -474,7 +474,7 @@ extension BitstreamWriter {
474474
}
475475

476476
/// Writes a value with the provided abbreviation encoding.
477-
public func writeAbbrevField(_ op: Bitstream.Abbreviation.Operand, value: UInt32) {
477+
internal func writeAbbrevField(_ op: Bitstream.Abbreviation.Operand, value: UInt32) {
478478
switch op {
479479
case .literal(let literalValue):
480480
// Do not write anything
@@ -494,7 +494,7 @@ extension BitstreamWriter {
494494

495495
/// Writes a block, beginning with the provided block code and the
496496
/// abbreviation width
497-
public func writeBlock(
497+
internal func writeBlock(
498498
_ blockID: Bitstream.BlockID,
499499
newAbbrevWidth: UInt8? = nil,
500500
emitRecords: () -> Void
@@ -504,7 +504,7 @@ extension BitstreamWriter {
504504
endBlock()
505505
}
506506

507-
public func writeBlob<S>(_ bytes: S, includeSize: Bool = true)
507+
internal func writeBlob<S>(_ bytes: S, includeSize: Bool = true)
508508
where S: Collection, S.Element == UInt8
509509
{
510510
if includeSize {
@@ -529,7 +529,7 @@ extension BitstreamWriter {
529529

530530
/// Writes the blockinfo block and allows emitting abbreviations
531531
/// and records in it.
532-
public func writeBlockInfoBlock(emitRecords: () -> Void) {
532+
internal func writeBlockInfoBlock(emitRecords: () -> Void) {
533533
writeBlock(.blockInfo, newAbbrevWidth: 2) {
534534
currentBlockID = nil
535535
blockInfoRecords = [:]
@@ -547,7 +547,7 @@ extension BitstreamWriter {
547547
/// - blockID: The ID of the block to emit.
548548
/// - abbreviationBitWidth: The width of the largest abbreviation ID in this block.
549549
/// - defineSubBlock: A closure that is called to define the contents of the new block.
550-
public func withSubBlock(
550+
internal func withSubBlock(
551551
_ blockID: Bitstream.BlockID,
552552
abbreviationBitWidth: UInt8? = nil,
553553
defineSubBlock: () -> Void
@@ -568,7 +568,7 @@ extension BitstreamWriter {
568568
/// - Parameters:
569569
/// - blockID: The ID of the block to emit.
570570
/// - abbreviationBitWidth: The width of the largest abbreviation ID in this block.
571-
public func enterSubblock(
571+
internal func enterSubblock(
572572
_ blockID: Bitstream.BlockID,
573573
abbreviationBitWidth: UInt8? = nil
574574
) {
@@ -601,7 +601,7 @@ extension BitstreamWriter {
601601
}
602602

603603
/// Marks the end of a new block record.
604-
public func endBlock() {
604+
internal func endBlock() {
605605
guard let block = blockScope.popLast() else {
606606
fatalError("endBlock() called with no block registered")
607607
}
@@ -623,7 +623,7 @@ extension BitstreamWriter {
623623

624624
/// Defines an abbreviation within the blockinfo block for the provided
625625
/// block ID.
626-
public func defineBlockInfoAbbreviation(
626+
internal func defineBlockInfoAbbreviation(
627627
_ blockID: Bitstream.BlockID,
628628
_ abbrev: Bitstream.Abbreviation
629629
) -> Bitstream.AbbreviationID {

Sources/SwiftDriver/IncrementalCompilation/Bitcode/BlockInfo.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
public struct BlockInfo {
13+
internal struct BlockInfo {
1414
public var name: String = ""
1515
public var recordNames: [UInt64:String] = [:]
1616
}

0 commit comments

Comments
 (0)