Skip to content
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
4 changes: 2 additions & 2 deletions benchmark/single-source/StringTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import TestsUtils
@_spi(_Unicode)
import Swift

public var benchmarks: [BenchmarkInfo] {
public let benchmarks: [BenchmarkInfo] = {
var result = [
BenchmarkInfo(
name: "StringEqualPointerComparison",
Expand Down Expand Up @@ -50,7 +50,7 @@ public var benchmarks: [BenchmarkInfo] {
tags: [.validation, .String]))
}
return result
}
}()

// FIXME(string)
public func run_StringHasPrefixAscii(_ n: Int) {
Expand Down
5 changes: 5 additions & 0 deletions include/swift/AST/RuntimeVersions.def
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ RUNTIME_VERSION(
FUTURE
)

RUNTIME_VERSION(
(6, 4),
FUTURE
)

END_MAJOR_VERSION(6)

// .......................................................................... //
Expand Down
4 changes: 3 additions & 1 deletion stdlib/public/core/Availability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,10 @@ extension _SwiftStdlibVersion {
public static var v6_2_0: Self { Self(_value: 0x060200) }
@_alwaysEmitIntoClient
public static var v6_3_0: Self { Self(_value: 0x060300) }
@_alwaysEmitIntoClient
public static var v6_4_0: Self { Self(_value: 0x060400) }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

[2025-12-09T04:52:54.512Z] FAIL: Swift(macosx-x86_64) :: abi/macOS/x86_64/stdlib-asserts.swift (10622 of 20420, 6 of 6 attempts)
[2025-12-09T04:52:54.512Z] ******************** TEST 'Swift(macosx-x86_64) :: abi/macOS/x86_64/stdlib-asserts.swift' FAILED ********************
[2025-12-09T04:52:54.512Z] Exit Code: 1
[2025-12-09T04:52:54.512Z] 
[2025-12-09T04:52:54.512Z] Command Output (stdout):
[2025-12-09T04:52:54.512Z] --
[2025-12-09T04:52:54.512Z] --- /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/swift/test/abi/macOS/x86_64/../../Inputs/macOS/x86_64/stdlib/baseline-asserts	2025-12-09 02:24:28
[2025-12-09T04:52:54.512Z] +++ /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/test-macosx-x86_64/abi/macOS/x86_64/Output/stdlib-asserts.swift.tmp/symbols	2025-12-09 04:52:54
[2025-12-09T04:52:54.512Z] @@ -3385,6 +3385,7 @@
[2025-12-09T04:52:54.512Z]  _$sSo19_SwiftStdlibVersionas23CustomStringConvertiblesWP
[2025-12-09T04:52:54.512Z]  _$sSo19_SwiftStdlibVersionasE11descriptionSSvg
[2025-12-09T04:52:54.512Z]  _$sSo19_SwiftStdlibVersionasE11descriptionSSvpMV
[2025-12-09T04:52:54.512Z] +_$sSo19_SwiftStdlibVersionasE6v6_4_0ABvpZMV
[2025-12-09T04:52:54.512Z]  _$sSo19_SwiftStdlibVersionasE7currentABvgZ
[2025-12-09T04:52:54.512Z]  _$sSp10deallocate8capacityySi_tF
[2025-12-09T04:52:54.512Z]  _$sSp10deallocateyyF

@lorentey I think this one led to a failure from the stdlib-asserts.swift… but I thought aeic did not trigger the ABI tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found 58dec75 and 1434440. So I think we also need to add the 6.4 here?

Copy link
Member

Choose a reason for hiding this comment

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

@lorentey I think this one led to a failure from the stdlib-asserts.swift… but I thought aeic did not trigger the ABI tests?

This is a property descriptor to support reflection; its export is somewhat questionable, but it's expected! It should be added to the expectation files (for both arm64 and Intel), just like the others.

The property itself is backdeployable; do not add an availability declaration to it.


private static var _current: Self { .v6_3_0 }
private static var _current: Self { .v6_4_0 }

#if hasFeature(Macros)
@available(SwiftStdlib 5.7, *)
Expand Down
39 changes: 38 additions & 1 deletion stdlib/public/core/String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1112,4 +1112,41 @@ extension String {
}
}


extension String {
/// Returns a boolean value indicating whether this string is identical to
/// `other`.
///
/// Two string values are identical if there is no way to distinguish between
/// them.
///
/// For any values `a`, `b`, and `c`:
///
/// - `a.isTriviallyIdentical(to: a)` is always `true`. (Reflexivity)
/// - `a.isTriviallyIdentical(to: b)` implies `b.isTriviallyIdentical(to: a)`.
/// (Symmetry)
/// - If `a.isTriviallyIdentical(to: b)` and `b.isTriviallyIdentical(to: c)`
/// are both `true`, then `a.isTriviallyIdentical(to: c)` is also `true`.
/// (Transitivity)
/// - `a.isTriviallyIdentical(b)` implies `a == b`. `a == b` does not imply `a.isTriviallyIdentical(b)`
///
/// Values produced by copying the same value, with no intervening mutations,
/// will compare identical:
///
/// ```swift
/// let d = c
/// print(c.isTriviallyIdentical(to: d))
/// // Prints true
/// ```
///
/// Comparing strings this way includes comparing (normally) hidden
/// implementation details such as the memory location of any underlying
/// string storage object. Therefore, identical strings are guaranteed to
/// compare equal with `==`, but not all equal strings are considered
/// identical.
///
/// - Complexity: O(1)
@available(StdlibDeploymentTarget 6.4, *)
public func isTriviallyIdentical(to other: Self) -> Bool {
self._guts.isTriviallyIdentical(to: other._guts)
}
}
7 changes: 7 additions & 0 deletions stdlib/public/core/StringGuts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,13 @@ extension _StringGuts {
}
}

extension _StringGuts {
@inline(__always) // Performance
internal func isTriviallyIdentical(to other: Self) -> Bool {
self.rawBits == other.rawBits
}
}

#if _runtime(_ObjC)
extension _StringGuts {

Expand Down
11 changes: 11 additions & 0 deletions stdlib/public/core/StringUTF16View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1056,3 +1056,14 @@ extension String.UTF16View {
}
}
}

extension String.UTF16View {
/// Returns a boolean value indicating whether this UTF16 view
/// is trivially identical to `other`.
///
/// - Complexity: O(1)
@available(StdlibDeploymentTarget 6.4, *)
public func isTriviallyIdentical(to other: Self) -> Bool {
self._guts.isTriviallyIdentical(to: other._guts)
}
}
11 changes: 11 additions & 0 deletions stdlib/public/core/StringUTF8View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -684,3 +684,14 @@ extension String.UTF8View {
return unsafe try _guts.withFastUTF8(body)
}
}

extension String.UTF8View {
/// Returns a boolean value indicating whether this UTF8 view
/// is trivially identical to `other`.
///
/// - Complexity: O(1)
@available(StdlibDeploymentTarget 6.4, *)
public func isTriviallyIdentical(to other: Self) -> Bool {
self._guts.isTriviallyIdentical(to: other._guts)
}
}
11 changes: 11 additions & 0 deletions stdlib/public/core/StringUnicodeScalarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -527,3 +527,14 @@ extension String.UnicodeScalarView {
return r._knownUTF16
}
}

extension String.UnicodeScalarView {
/// Returns a boolean value indicating whether this unicode scalar view
/// is trivially identical to `other`.
///
/// - Complexity: O(1)
@available(StdlibDeploymentTarget 6.4, *)
public func isTriviallyIdentical(to other: Self) -> Bool {
self._guts.isTriviallyIdentical(to: other._guts)
}
}
76 changes: 76 additions & 0 deletions stdlib/public/core/Substring.swift
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,18 @@ extension Substring.UTF8View {
#endif // !(os(watchOS) && _pointerBitWidth(_32))
}

extension Substring.UTF8View {
/// Returns a boolean value indicating whether this UTF8 view
/// is trivially identical to `other`.
///
/// - Complexity: O(1)
@available(StdlibDeploymentTarget 6.4, *)
public func isTriviallyIdentical(to other: Self) -> Bool {
self._base.isTriviallyIdentical(to: other._base)
&& self._bounds == other._bounds
}
}

extension Substring {
@inlinable
public var utf8: UTF8View {
Expand Down Expand Up @@ -1037,6 +1049,18 @@ extension Substring.UTF16View: BidirectionalCollection {
}
}

extension Substring.UTF16View {
/// Returns a boolean value indicating whether this UTF16 view
/// is trivially identical to `other`.
///
/// - Complexity: O(1)
@available(StdlibDeploymentTarget 6.4, *)
public func isTriviallyIdentical(to other: Self) -> Bool {
self._base.isTriviallyIdentical(to: other._base)
&& self._bounds == other._bounds
}
}

extension Substring {
@inlinable
public var utf16: UTF16View {
Expand Down Expand Up @@ -1281,6 +1305,18 @@ extension Substring.UnicodeScalarView: RangeReplaceableCollection {
}
}

extension Substring.UnicodeScalarView {
/// Returns a boolean value indicating whether this unicode scalar view
/// is trivially identical to `other`.
///
/// - Complexity: O(1)
@available(StdlibDeploymentTarget 6.4, *)
public func isTriviallyIdentical(to other: Self) -> Bool {
self._slice._base.isTriviallyIdentical(to: other._slice._base)
&& self._bounds == other._bounds
}
}

extension Substring: RangeReplaceableCollection {
@_specialize(where S == String)
@_specialize(where S == Substring)
Expand Down Expand Up @@ -1385,3 +1421,43 @@ extension Substring {
return Substring(_unchecked: Slice(base: base, bounds: r))
}
}

extension Substring {
/// Returns a boolean value indicating whether this substring is identical to
/// `other`.
///
/// Two substring values are identical if there is no way to distinguish
/// between them.
///
/// For any values `a`, `b`, and `c`:
///
/// - `a.isTriviallyIdentical(to: a)` is always `true`. (Reflexivity)
/// - `a.isTriviallyIdentical(to: b)` implies `b.isTriviallyIdentical(to: a)`.
/// (Symmetry)
/// - If `a.isTriviallyIdentical(to: b)` and `b.isTriviallyIdentical(to: c)`
/// are both `true`, then `a.isTriviallyIdentical(to: c)` is also `true`.
/// (Transitivity)
/// - `a.isTriviallyIdentical(b)` implies `a == b`. `a == b` does not imply `a.isTriviallyIdentical(b)`
///
/// Values produced by copying the same value, with no intervening mutations,
/// will compare identical:
///
/// ```swift
/// let d = c
/// print(c.isTriviallyIdentical(to: d))
/// // Prints true
/// ```
///
/// Comparing substrings this way includes comparing (normally) hidden
/// implementation details such as the memory location of any underlying
/// substring storage object. Therefore, identical substrings are guaranteed
/// to compare equal with `==`, but not all equal substrings are considered
/// identical.
///
/// - Complexity: O(1)
@available(StdlibDeploymentTarget 6.4, *)
public func isTriviallyIdentical(to other: Self) -> Bool {
self._wholeGuts.isTriviallyIdentical(to: other._wholeGuts) &&
self._offsetRange == other._offsetRange
}
}
1 change: 1 addition & 0 deletions test/Interop/SwiftToCxx/stdlib/swift-stdlib-in-cxx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
// CHECK: SWIFT_INLINE_THUNK uint8_t operator [](const __StringNested::Index& i) const SWIFT_SYMBOL({{.*}});
// CHECK: SWIFT_INLINE_THUNK String getDescription() const SWIFT_SYMBOL({{.*}});
// CHECK: SWIFT_INLINE_THUNK swift::Int getCount() const SWIFT_SYMBOL({{.*}});
// CHECK: SWIFT_INLINE_THUNK bool isTriviallyIdenticalTo(const __StringNested::UTF8View& other) const SWIFT_SYMBOL({{.*}}) {{.*}};
// CHECK-NEXT: private:

// CHECK: class AnyKeyPath { } SWIFT_UNAVAILABLE_MSG("class 'AnyKeyPath' is not yet exposed to C++");
Expand Down
11 changes: 11 additions & 0 deletions test/abi/macOS/arm64/stdlib.swift
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ Added: _$ss7UnicodeO5UTF32O27encodedReplacementCharacters15CollectionOfOneVys6UI
Added: _$sSo19_SwiftStdlibVersionasE6v6_1_0ABvpZMV
Added: _$sSo19_SwiftStdlibVersionasE6v6_2_0ABvpZMV
Added: _$sSo19_SwiftStdlibVersionasE6v6_3_0ABvpZMV
Added: _$sSo19_SwiftStdlibVersionasE6v6_4_0ABvpZMV
Added: _$sSBsE5radixSivpZMV
Added: _$sSFsE8ulpOfOnexvpZMV
Added: _$sSUsE8isSignedSbvpZMV
Expand Down Expand Up @@ -1161,3 +1162,13 @@ Added: _$ss13EncodingErrorO16debugDescriptionSSvg
Added: _$ss13EncodingErrorO16debugDescriptionSSvpMV
Added: _$ss13EncodingErrorOs28CustomDebugStringConvertiblesMc
Added: _$ss13EncodingErrorOs28CustomDebugStringConvertiblesWP

// SE-0494 Add isTriviallyIdentical(to:) Methods to String and Substring
Added: _$sSS20isTriviallyIdentical2toSbSS_tF
Added: _$sSs20isTriviallyIdentical2toSbSs_tF
Added: _$sSS17UnicodeScalarViewV20isTriviallyIdentical2toSbAB_tF
Added: _$sSS8UTF8ViewV20isTriviallyIdentical2toSbAB_tF
Added: _$sSS9UTF16ViewV20isTriviallyIdentical2toSbAB_tF
Added: _$sSs17UnicodeScalarViewV20isTriviallyIdentical2toSbAB_tF
Added: _$sSs8UTF8ViewV20isTriviallyIdentical2toSbAB_tF
Added: _$sSs9UTF16ViewV20isTriviallyIdentical2toSbAB_tF
11 changes: 11 additions & 0 deletions test/abi/macOS/x86_64/stdlib.swift
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@ Added: _$ss8SIMDMaskVss6SIMD64Vys5Int64VGRszrlE7allTrueAByAGGvpZMV
Added: _$sSo19_SwiftStdlibVersionasE6v6_1_0ABvpZMV
Added: _$sSo19_SwiftStdlibVersionasE6v6_2_0ABvpZMV
Added: _$sSo19_SwiftStdlibVersionasE6v6_3_0ABvpZMV
Added: _$sSo19_SwiftStdlibVersionasE6v6_4_0ABvpZMV
Added: _$ss7Float80V12signalingNaNABvpZMV
Added: _$ss7Float80V13_exponentBiasSuvpZMV
Added: _$ss7Float80V13_quietNaNMasks6UInt64VvpZMV
Expand Down Expand Up @@ -1156,3 +1157,13 @@ Added: _$ss13EncodingErrorO16debugDescriptionSSvg
Added: _$ss13EncodingErrorO16debugDescriptionSSvpMV
Added: _$ss13EncodingErrorOs28CustomDebugStringConvertiblesMc
Added: _$ss13EncodingErrorOs28CustomDebugStringConvertiblesWP

// SE-0494 Add isTriviallyIdentical(to:) Methods to String and Substring
Added: _$sSS20isTriviallyIdentical2toSbSS_tF
Added: _$sSs20isTriviallyIdentical2toSbSs_tF
Added: _$sSS17UnicodeScalarViewV20isTriviallyIdentical2toSbAB_tF
Added: _$sSS8UTF8ViewV20isTriviallyIdentical2toSbAB_tF
Added: _$sSS9UTF16ViewV20isTriviallyIdentical2toSbAB_tF
Added: _$sSs17UnicodeScalarViewV20isTriviallyIdentical2toSbAB_tF
Added: _$sSs8UTF8ViewV20isTriviallyIdentical2toSbAB_tF
Added: _$sSs9UTF16ViewV20isTriviallyIdentical2toSbAB_tF
Loading