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

fix _StrSlice == method linkage #139

Closed
wants to merge 1 commit into from
Closed
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
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
60 changes: 30 additions & 30 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 @@ -127,21 +127,21 @@ 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 }
public protocol _StrSlice: _PlatformStringable, Hashable, Codable {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@milseman this is the actual change

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
26 changes: 13 additions & 13 deletions Sources/System/FilePath/FilePathParsing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,30 @@
// manages (and hides) the null terminator

// The separator we use internally
private var genericSeparator: SystemChar { .slash }
private var genericSeparator: _SystemChar { .slash }

// The platform preferred separator
//
// TODO: Make private
internal var platformSeparator: SystemChar {
internal var platformSeparator: _SystemChar {
_windowsPaths ? .backslash : genericSeparator
}

// Whether the character is the canonical separator
// TODO: Make private
internal func isSeparator(_ c: SystemChar) -> Bool {
internal func isSeparator(_ c: _SystemChar) -> Bool {
c == platformSeparator
}

// Whether the character is a pre-normalized separator
internal func isPrenormalSeparator(_ c: SystemChar) -> Bool {
internal func isPrenormalSeparator(_ c: _SystemChar) -> Bool {
c == genericSeparator || c == platformSeparator
}

// Separator normalization, checking, and root parsing is internally hosted
// on SystemString for ease of unit testing.

extension SystemString {
extension _SystemString {
// For invariant enforcing/checking. Should always return false on
// a fully-formed path
fileprivate func _hasTrailingSeparator() -> Bool {
Expand Down Expand Up @@ -186,15 +186,15 @@ extension FilePath {
}
}

extension SystemString {
extension _SystemString {
internal var _relativePathStart: Index {
_parseRoot().relativeBegin
}
}

@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
extension FilePath {
internal var _relativeStart: SystemString.Index {
internal var _relativeStart: _SystemString.Index {
_storage._relativePathStart
}
internal var _hasRoot: Bool {
Expand All @@ -206,7 +206,7 @@ extension FilePath {

@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
extension FilePath {
internal typealias _Index = SystemString.Index
internal typealias _Index = _SystemString.Index

// Parse a component that starts at `i`. Returns the end
// of the component and the start of the next. Parsing terminates
Expand Down Expand Up @@ -271,12 +271,12 @@ extension FilePath {
@available(/*System 0.0.2: macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0*/iOS 8, *)
extension FilePath.ComponentView {
// TODO: Store this...
internal var _relativeStart: SystemString.Index {
internal var _relativeStart: _SystemString.Index {
_path._relativeStart
}
}

extension SystemString {
extension _SystemString {
internal func _parseRoot() -> (
rootEnd: Index, relativeBegin: Index
) {
Expand All @@ -303,7 +303,7 @@ extension FilePath.Root {
//
// TODO: public
internal var isAbsolute: Bool {
assert(FilePath(SystemString(self._slice)).root == self, "not a root")
assert(FilePath(_SystemString(self._slice)).root == self, "not a root")

guard _windowsPaths else { return true }

Expand Down Expand Up @@ -354,8 +354,8 @@ extension FilePath {

// Perform an append, inseting a separator if needed.
// Note that this will not check whether `content` is a root
internal mutating func _append(unchecked content: Slice<SystemString>) {
assert(FilePath(SystemString(content)).root == nil)
internal mutating func _append(unchecked content: Slice<_SystemString>) {
assert(FilePath(_SystemString(content)).root == nil)
if content.isEmpty { return }
if _needsSeparatorForAppend {
_storage.append(platformSeparator)
Expand Down
Loading