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

SwiftDriver: mark bitcode interfaces as internal #1376

Merged
merged 1 commit into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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<Visitor: BitstreamVisitor>(bytes: ByteString, using visitor: inout Visitor) throws {
internal static func read<Visitor: BitstreamVisitor>(bytes: ByteString, using visitor: inout Visitor) throws {
precondition(bytes.count > 4)
var reader = BitstreamReader(buffer: bytes)
try visitor.validate(signature: reader.readSignature())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
//
//===----------------------------------------------------------------------===//

public enum BitcodeElement {
public struct Block {
internal enum BitcodeElement {
internal struct Block {
public var id: UInt64
public var elements: [BitcodeElement]
}
Expand All @@ -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)
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftDriver/IncrementalCompilation/Bitcode/Bits.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import struct TSCBasic.ByteString

struct Bits: RandomAccessCollection {
internal struct Bits: RandomAccessCollection {
var buffer: ByteString

var startIndex: Int { return 0 }
Expand Down Expand Up @@ -50,7 +50,7 @@ struct Bits: RandomAccessCollection {
}

extension Bits {
struct Cursor {
internal struct Cursor {
enum Error: Swift.Error { case bufferOverflow }

let buffer: Bits
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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.
Expand All @@ -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<IntType>(_ int: IntType, width: UInt8)
internal func writeVBR<IntType>(_ int: IntType, width: UInt8)
where IntType: UnsignedInteger & ExpressibleByIntegerLiteral
{
let threshold = UInt64(1) << (UInt64(width) - 1)
Expand All @@ -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<IntType>(_ int: IntType, width: UInt8)
internal func write<IntType>(_ int: IntType, width: UInt8)
where IntType: UnsignedInteger & ExpressibleByIntegerLiteral
{
precondition(width > 0, "cannot emit 0 bits")
Expand Down Expand Up @@ -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")
Expand All @@ -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):
Expand Down Expand Up @@ -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<IntType>(_ code: IntType)
internal func writeCode<IntType>(_ 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)
Expand All @@ -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) +
Expand All @@ -335,7 +335,7 @@ extension BitstreamWriter {
// MARK: Writing Records

extension BitstreamWriter {
public struct RecordBuffer {
internal struct RecordBuffer {
private(set) var values = [UInt32]()

fileprivate init() {
Expand Down Expand Up @@ -378,7 +378,7 @@ extension BitstreamWriter {
}

/// Writes an unabbreviated record to the stream.
public func writeRecord<CodeType>(_ code: CodeType, _ composeRecord: (inout RecordBuffer) -> Void)
internal func writeRecord<CodeType>(_ code: CodeType, _ composeRecord: (inout RecordBuffer) -> Void)
where CodeType: RawRepresentable, CodeType.RawValue == UInt8
{
writeCode(.unabbreviatedRecord)
Expand All @@ -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
Expand Down Expand Up @@ -463,7 +463,7 @@ extension BitstreamWriter {
"0123456789._", (0 as UInt)...))

/// Writes a char6-encoded value.
public func writeChar6<IntType>(_ value: IntType)
internal func writeChar6<IntType>(_ value: IntType)
where IntType: UnsignedInteger & ExpressibleByIntegerLiteral
{
guard (0..<64).contains(value) else {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -504,7 +504,7 @@ extension BitstreamWriter {
endBlock()
}

public func writeBlob<S>(_ bytes: S, includeSize: Bool = true)
internal func writeBlob<S>(_ bytes: S, includeSize: Bool = true)
where S: Collection, S.Element == UInt8
{
if includeSize {
Expand All @@ -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 = [:]
Expand All @@ -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
Expand All @@ -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
) {
Expand Down Expand Up @@ -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")
}
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//
//===----------------------------------------------------------------------===//

public struct BlockInfo {
internal struct BlockInfo {
public var name: String = ""
public var recordNames: [UInt64:String] = [:]
}