Skip to content

Commit

Permalink
fix _StrSlice == method linkage
Browse files Browse the repository at this point in the history
  • Loading branch information
weissi committed Aug 7, 2023
1 parent 164fe8c commit a766fb6
Show file tree
Hide file tree
Showing 14 changed files with 171 additions and 170 deletions.
6 changes: 3 additions & 3 deletions Sources/System/FilePath/FilePath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@
public struct FilePath {
// TODO(docs): Section on all the new syntactic operations, lexical normalization, decomposition,
// components, etc.
internal var _storage: SystemString
internal var _storage: _SystemString

/// Creates an empty, null-terminated path.
public init() {
self._storage = SystemString()
self._storage = _SystemString()
_invariantCheck()
}

// In addition to the empty init, this init will properly normalize
// separators. All other initializers should be implemented by
// ultimately deferring to a normalizing init.
internal init(_ str: SystemString) {
internal init(_ str: _SystemString) {
self._storage = str
self._normalizeSeparators()
_invariantCheck()
Expand Down
20 changes: 10 additions & 10 deletions Sources/System/FilePath/FilePathComponentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extension FilePath {
/// // path is "/home/username/bin/scripts/tree"
public struct ComponentView {
internal var _path: FilePath
internal var _start: SystemString.Index
internal var _start: _SystemString.Index

internal init(_ path: FilePath) {
self._path = path
Expand All @@ -50,7 +50,7 @@ extension FilePath {
// TODO(perf): Small-form root (especially on Unix). Have Root
// always copy out (not worth ref counting). Make sure that we're
// not needlessly sliding values around or triggering a COW
let rootStr = self.root?._systemString ?? SystemString()
let rootStr = self.root?._systemString ?? _SystemString()
var comp = ComponentView(self)
self = FilePath()
defer {
Expand All @@ -73,7 +73,7 @@ extension FilePath {
// TODO(perf): Small-form root (especially on Unix). Have Root
// always copy out (not worth ref counting). Make sure that we're
// not needlessly sliding values around or triggering a COW
let rootStr = self.root?._systemString ?? SystemString()
let rootStr = self.root?._systemString ?? _SystemString()
var comp = ComponentView(self)
self = FilePath()
defer {
Expand All @@ -92,7 +92,7 @@ extension FilePath {
extension FilePath.ComponentView: BidirectionalCollection {
public typealias Element = FilePath.Component
public struct Index: Comparable, Hashable {
internal typealias Storage = SystemString.Index
internal typealias Storage = _SystemString.Index

internal var _storage: Storage

Expand Down Expand Up @@ -159,7 +159,7 @@ extension FilePath.ComponentView: RangeReplaceableCollection {
// filling in the bytes ourselves.

// If we're inserting at the end, we need a leading separator.
var str = SystemString()
var str = _SystemString()
let atEnd = subrange.lowerBound == endIndex
if atEnd {
str.append(platformSeparator)
Expand All @@ -178,7 +178,7 @@ extension FilePath {
public init<C: Collection>(
root: Root?, _ components: C
) where C.Element == Component {
var str = root?._systemString ?? SystemString()
var str = root?._systemString ?? _SystemString()
str.appendComponents(components: components)
self.init(str)
}
Expand All @@ -191,7 +191,7 @@ extension FilePath {
/// Create a file path from an optional root and a slice of another path's
/// components.
public init(root: Root?, _ components: ComponentView.SubSequence) {
var str = root?._systemString ?? SystemString()
var str = root?._systemString ?? _SystemString()
let (start, end) =
(components.startIndex._storage, components.endIndex._storage)
str.append(contentsOf: components.base._slice[start..<end])
Expand All @@ -203,11 +203,11 @@ extension FilePath {

@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
extension FilePath.ComponentView: _PathSlice {
internal var _range: Range<SystemString.Index> {
public var _range: Range<_SystemString.Index> {
_start ..< _path._storage.endIndex
}

internal init(_ str: SystemString) {
public init(_ str: _SystemString) {
fatalError("TODO: consider dropping proto req")
}
}
Expand All @@ -216,7 +216,7 @@ extension FilePath.ComponentView: _PathSlice {

@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
extension FilePath.ComponentView {
internal func _invariantCheck() {
public func _invariantCheck() {
#if DEBUG
if isEmpty {
precondition(_path.isEmpty == (_path.root == nil))
Expand Down
62 changes: 31 additions & 31 deletions Sources/System/FilePath/FilePathComponents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ extension FilePath {
/// * `\\?\Volume{12345678-abcd-1111-2222-123445789abc}\`
public struct Root {
internal var _path: FilePath
internal var _rootEnd: SystemString.Index
internal var _rootEnd: _SystemString.Index

internal init(_ path: FilePath, rootEnd: SystemString.Index) {
internal init(_ path: FilePath, rootEnd: _SystemString.Index) {
self._path = path
self._rootEnd = rootEnd
_invariantCheck()
Expand All @@ -56,14 +56,14 @@ extension FilePath {
/// path.append(file) // path is "/tmp/foo.txt"
public struct Component {
internal var _path: FilePath
internal var _range: Range<SystemString.Index>
public var _range: Range<_SystemString.Index>

// TODO: Make a small-component form to save on ARC overhead when
// extracted from a path, and especially to save on allocation overhead
// when constructing one from a String literal.

internal init<RE: RangeExpression>(_ path: FilePath, _ range: RE)
where RE.Bound == SystemString.Index {
where RE.Bound == _SystemString.Index {
self._path = path
self._range = range.relative(to: path._storage)
precondition(!self._range.isEmpty, "FilePath components cannot be empty")
Expand Down Expand Up @@ -104,7 +104,7 @@ extension FilePath.Root {

// MARK: - Internals

extension SystemString {
extension _SystemString {
// TODO: take insertLeadingSlash: Bool
// TODO: turn into an insert operation with slide
internal mutating func appendComponents<C: Collection>(
Expand All @@ -126,22 +126,22 @@ extension SystemString {
}

// Unifying protocol for common functionality between roots, components,
// and views onto SystemString and FilePath.
internal protocol _StrSlice: _PlatformStringable, Hashable, Codable {
var _storage: SystemString { get }
var _range: Range<SystemString.Index> { get }
// and views onto_SystemString and FilePath.
public protocol _StrSlice: _PlatformStringable, Hashable, Codable {
var _storage: _SystemString { get }
var _range: Range<_SystemString.Index> { get }

init?(_ str: SystemString)
init?(_ str: _SystemString)

func _invariantCheck()
}
extension _StrSlice {
internal var _slice: Slice<SystemString> {
internal var _slice: Slice<_SystemString> {
Slice(base: _storage, bounds: _range)
}

internal func _withSystemChars<T>(
_ f: (UnsafeBufferPointer<SystemChar>) throws -> T
_ f: (UnsafeBufferPointer<_SystemChar>) throws -> T
) rethrows -> T {
try _storage.withSystemChars {
try f(UnsafeBufferPointer(rebasing: $0[_range]))
Expand All @@ -153,17 +153,17 @@ extension _StrSlice {
try _slice.withCodeUnits(f)
}

internal init?(_platformString s: UnsafePointer<CInterop.PlatformChar>) {
self.init(SystemString(platformString: s))
public init?(_platformString s: UnsafePointer<CInterop.PlatformChar>) {
self.init(_SystemString(platformString: s))
}

internal func _withPlatformString<Result>(
public func _withPlatformString<Result>(
_ body: (UnsafePointer<CInterop.PlatformChar>) throws -> Result
) rethrows -> Result {
try _slice.withPlatformString(body)
}

internal var _systemString: SystemString { SystemString(_slice) }
internal var _systemString: _SystemString {_SystemString(_slice) }
}
extension _StrSlice {
public static func == (lhs: Self, rhs: Self) -> Bool {
Expand All @@ -180,35 +180,35 @@ internal protocol _PathSlice: _StrSlice {
var _path: FilePath { get }
}
extension _PathSlice {
internal var _storage: SystemString { _path._storage }
public var _storage: _SystemString { _path._storage }
}

@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
extension FilePath.Component: _PathSlice {
}
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
extension FilePath.Root: _PathSlice {
internal var _range: Range<SystemString.Index> {
public var _range: Range<_SystemString.Index> {
(..<_rootEnd).relative(to: _path._storage)
}
}

@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
extension FilePath: _PlatformStringable {
func _withPlatformString<Result>(_ body: (UnsafePointer<CInterop.PlatformChar>) throws -> Result) rethrows -> Result {
public func _withPlatformString<Result>(_ body: (UnsafePointer<CInterop.PlatformChar>) throws -> Result) rethrows -> Result {
try _storage.withPlatformString(body)
}

init(_platformString: UnsafePointer<CInterop.PlatformChar>) {
self.init(SystemString(platformString: _platformString))
public init(_platformString: UnsafePointer<CInterop.PlatformChar>) {
self.init(_SystemString(platformString: _platformString))
}

}

@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
extension FilePath.Component {
// The index of the `.` denoting an extension
internal func _extensionIndex() -> SystemString.Index? {
internal func _extensionIndex() ->_SystemString.Index? {
guard kind == .regular,
let idx = _slice.lastIndex(of: .dot),
idx != _slice.startIndex
Expand All @@ -217,26 +217,26 @@ extension FilePath.Component {
return idx
}

internal func _extensionRange() -> Range<SystemString.Index>? {
internal func _extensionRange() -> Range<_SystemString.Index>? {
guard let idx = _extensionIndex() else { return nil }
return _slice.index(after: idx) ..< _slice.endIndex
}

internal func _stemRange() -> Range<SystemString.Index> {
internal func _stemRange() -> Range<_SystemString.Index> {
_slice.startIndex ..< (_extensionIndex() ?? _slice.endIndex)
}
}

internal func _makeExtension(_ ext: String) -> SystemString {
var result = SystemString()
internal func _makeExtension(_ ext: String) ->_SystemString {
var result = _SystemString()
result.append(.dot)
result.append(contentsOf: ext.unicodeScalars.lazy.map(SystemChar.init))
result.append(contentsOf: ext.unicodeScalars.lazy.map(_SystemChar.init))
return result
}

@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
extension FilePath.Component {
internal init?(_ str: SystemString) {
public init?(_ str: _SystemString) {
// FIXME: explicit null root? Or something else?
let path = FilePath(str)
guard path.root == nil, path.components.count == 1 else {
Expand All @@ -249,7 +249,7 @@ extension FilePath.Component {

@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
extension FilePath.Root {
internal init?(_ str: SystemString) {
public init?(_ str: _SystemString) {
// FIXME: explicit null root? Or something else?
let path = FilePath(str)
guard path.root != nil, path.components.isEmpty else {
Expand All @@ -265,7 +265,7 @@ extension FilePath.Root {
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
extension FilePath.Component {
// TODO: ensure this all gets easily optimized away in release...
internal func _invariantCheck() {
public func _invariantCheck() {
#if DEBUG
precondition(!_slice.isEmpty)
precondition(_slice.last != .null)
Expand All @@ -277,7 +277,7 @@ extension FilePath.Component {

@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
extension FilePath.Root {
internal func _invariantCheck() {
public func _invariantCheck() {
#if DEBUG
precondition(self._rootEnd > _path._storage.startIndex)

Expand Down
Loading

0 comments on commit a766fb6

Please sign in to comment.