Skip to content
Draft
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
9 changes: 9 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ let swiftSettings = swiftSettingsAvailability + swiftSettingsCI + [
.define("SYSTEM_PACKAGE"),
.define("ENABLE_MOCKING", .when(configuration: .debug)),
.enableExperimentalFeature("Lifetimes"),
// FilePath port: select the SE-0529 sources' package-mode branch (provides
// _internalInvariant etc.) and define the SwiftStdlib availability macro their
// @available annotations reference. Mirrors ../SE-0529-FilePath/Package.swift;
// that package's strictMemorySafety/-Werror are enforcement, not source seam,
// so are intentionally not brought over.
.define("FILEPATH_PACKAGE"),
.enableExperimentalFeature(
"AvailabilityMacro=SwiftStdlib 9999:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, visionOS 9999"),
.unsafeFlags(["-Xfrontend", "-disable-availability-checking"]),
]

let cSettings: [CSetting] = [
Expand Down
Empty file.
90 changes: 0 additions & 90 deletions Sources/System/FilePath/FilePath.swift

This file was deleted.

89 changes: 89 additions & 0 deletions Sources/System/FilePath/FilePathCompatInternals.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
This source file is part of the Swift System open source project

Copyright (c) 2026 Apple Inc. and the Swift System project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See https://swift.org/LICENSE.txt for license information
*/

// PORT SHIM: re-plumbs the internal `FilePath` helpers that the old package
// API (FilePathSyntax.swift, FilePathString.swift, …) still calls onto the
// SE-0529 stdlib copy's internals. These names used to live in the old
// FilePath implementation files that were emptied during the port; the
// bodies below are reimplemented on the copy's `_storage: _SystemString`,
// its `_parseRoot()` boundaries, and the `_normalizing` construction funnel.
//
// Temporary by design: once the call sites move to the copy's own API
// (`anchor`, `hasTrailingSeparator`, `components`, …) these compat members
// and their call sites are the mechanical removal list. Do not grow API here.

@available(SwiftStdlib 9999, *)
extension FilePath {
/// Old debug invariant hook. The stdlib copy has no whole-path recheck
/// method (it asserts inline via `_internalInvariant` and establishes
/// invariants at construction), so this checks the invariant directly:
/// storage must be a fixed point of the `_normalizing` funnel.
internal func _invariantCheck() {
#if DEBUG
// The copy's storage invariant, stated as a property: normal form is a
// fixed point of the normalizing funnel. Catches any old-API code path
// that mutates _storage directly and leaves it non-normal.
let renormalized = FilePath(_normalizing: _storage)
precondition(
renormalized._storage == self._storage,
"FilePath storage not in stdlib normal form")
#endif
}

/// Whether the path begins with an anchor/root.
///
/// Mirrors the copy's `anchor != nil`: the root is non-empty iff parsing
/// finds an anchor that ends past the start of storage.
internal var _hasRoot: Bool {
_storage._parseRoot().rootEnd != _storage.startIndex
}

/// The index in `_storage` where the relative portion begins, i.e. just
/// past the anchor and any gap separator. Equivalent to the copy's
/// `_parseRoot().relativeBegin`.
internal var _relativeStart: _SystemString.Index {
_storage._parseRoot().relativeBegin
}

/// Append raw path bytes, inserting a platform separator between existing
/// content and the new bytes when the current storage does not already end
/// in one. Routes the result through the copy's `_normalizing` funnel so
/// storage keeps the copy's invariants (coalesced separators, dot rules).
internal mutating func _append(
unchecked newElements: some Collection<FilePath.CodeUnit>
) {
guard !newElements.isEmpty else { return }
var storage = _storage
if !storage.isEmpty, !_isSeparator(storage.last!) {
storage.append(_platformSeparator)
}
storage.append(contentsOf: newElements)
self = FilePath(_normalizing: storage)
}

/// Drop a trailing directory separator, if the path has a non-structural
/// one. Delegates to the copy's `hasTrailingSeparator` setter, which
/// preserves separators that belong to the anchor (e.g. `\\server\share\`).
internal mutating func _removeTrailingSeparator() {
hasTrailingSeparator = false
}

/// Lexically collapse `.` and `..` components in place.
internal mutating func _normalizeSpecialDirectories() {
// PORT-TODO: no stdlib-copy equivalent. The copy normalizes at
// construction (`_SystemString._normalizeDots`) but deliberately
// PRESERVES `..`, whereas the old `_normalizeSpecialDirectories`
// lexically resolved `..` against preceding components (this is what
// `lexicallyNormalize()` relied on). The copy exposes no lexical-collapse
// primitive, so this needs a real port; left unimplemented rather than
// inventing semantics.
fatalError(
"PORT-TODO: _normalizeSpecialDirectories has no stdlib-copy equivalent")
}
}
51 changes: 51 additions & 0 deletions Sources/System/FilePath/FilePathComponentCompat.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
This source file is part of the Swift System open source project

Copyright (c) 2026 Apple Inc. and the Swift System project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See https://swift.org/LICENSE.txt for license information
*/

// PORT SHIM: internal helpers for FilePath.Component that the old package
// API (Component.extension / Component.stem in FilePathSyntax.swift) relies
// on. The SE-0529 copy has no stem/extension notion, so these are the old
// swift-system algorithms retyped from the old substrate (SystemChar,
// Slice<SystemString>) onto the copy's (FilePath.CodeUnit,
// Slice<_SystemString>). Algorithm bodies are unchanged from the originals
// in FilePathComponents.swift (now PORT-CLOBBERED there).

@available(SwiftStdlib 9999, *)
extension Slice where Base == _SystemString {
/// Decode this slice's code units as a String. Mirrors
/// `_SystemString.string` in the stdlib copy.
internal var string: String {
withCodeUnits { codeUnits in
codeUnits.withMemoryRebound(to: FilePath._Encoding.CodeUnit.self) {
String(decoding: $0, as: FilePath._Encoding.self)
}
}
}
}

@available(SwiftStdlib 9999, *)
extension FilePath.Component {
// The index of the `.` denoting an extension
internal func _extensionIndex() -> _SystemString.Index? {
guard kind == .regular,
let idx = _slice.lastIndex(of: ._dot),
idx != _slice.startIndex
else { return nil }

return idx
}

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> {
_slice.startIndex ..< (_extensionIndex() ?? _slice.endIndex)
}
}
Empty file.
Loading
Loading