Skip to content

Commit 109193f

Browse files
committed
Revert "[6.0] Reduce overhead of .expectationChecked event handling in #expect(). (swiftlang#657)"
This reverts commit 3e30663.
1 parent 3e30663 commit 109193f

File tree

5 files changed

+9
-64
lines changed

5 files changed

+9
-64
lines changed

Package.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ extension Array where Element == PackageDescription.SwiftSetting {
148148
.enableExperimentalFeature("AvailabilityMacro=_clockAPI:macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0"),
149149
.enableExperimentalFeature("AvailabilityMacro=_regexAPI:macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0"),
150150
.enableExperimentalFeature("AvailabilityMacro=_swiftVersionAPI:macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0"),
151-
.enableExperimentalFeature("AvailabilityMacro=_synchronizationAPI:macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0"),
152151

153152
.enableExperimentalFeature("AvailabilityMacro=_distantFuture:macOS 99.0, iOS 99.0, watchOS 99.0, tvOS 99.0, visionOS 99.0"),
154153
]

Sources/Testing/Expectations/ExpectationChecking+Macro.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,8 @@ public func __checkValue(
9595
// Post an event for the expectation regardless of whether or not it passed.
9696
// If the current event handler is not configured to handle events of this
9797
// kind, this event is discarded.
98-
lazy var expectation = Expectation(evaluatedExpression: expression, isPassing: condition, isRequired: isRequired, sourceLocation: sourceLocation)
99-
if Configuration.deliverExpectationCheckedEvents {
100-
Event.post(.expectationChecked(expectation))
101-
}
98+
var expectation = Expectation(evaluatedExpression: expression, isPassing: condition, isRequired: isRequired, sourceLocation: sourceLocation)
99+
Event.post(.expectationChecked(expectation))
102100

103101
// Early exit if the expectation passed.
104102
if condition {

Sources/Testing/Parameterization/TypeInfo.swift

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,6 @@ public struct TypeInfo: Sendable {
7474
// MARK: - Name
7575

7676
extension TypeInfo {
77-
/// An in-memory cache of fully-qualified type name components.
78-
private static let _fullyQualifiedNameComponentsCache = Locked<[ObjectIdentifier: [String]]>()
79-
8077
/// The complete name of this type, with the names of all referenced types
8178
/// fully-qualified by their module names when possible.
8279
///
@@ -95,10 +92,6 @@ extension TypeInfo {
9592
public var fullyQualifiedNameComponents: [String] {
9693
switch _kind {
9794
case let .type(type):
98-
if let cachedResult = Self._fullyQualifiedNameComponentsCache.rawValue[ObjectIdentifier(type)] {
99-
return cachedResult
100-
}
101-
10295
var result = String(reflecting: type)
10396
.split(separator: ".")
10497
.map(String.init)
@@ -116,10 +109,6 @@ extension TypeInfo {
116109
// those out as they're uninteresting to us.
117110
result = result.filter { !$0.starts(with: "(unknown context at") }
118111

119-
Self._fullyQualifiedNameComponentsCache.withLock { fullyQualifiedNameComponentsCache in
120-
fullyQualifiedNameComponentsCache[ObjectIdentifier(type)] = result
121-
}
122-
123112
return result
124113
case let .nameOnly(fullyQualifiedNameComponents, _, _):
125114
return fullyQualifiedNameComponents

Sources/Testing/Running/Runner.RuntimeState.swift

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
99
//
1010

11-
private import Synchronization
12-
1311
extension Runner {
1412
/// A type which collects the task-scoped runtime state for a running
1513
/// ``Runner`` instance, the tests it runs, and other objects it interacts
@@ -113,10 +111,7 @@ extension Configuration {
113111
/// - Returns: A unique number identifying `self` that can be
114112
/// passed to `_removeFromAll(identifiedBy:)`` to unregister it.
115113
private func _addToAll() -> UInt64 {
116-
if deliverExpectationCheckedEvents, #available(_synchronizationAPI, *) {
117-
Self._deliverExpectationCheckedEventsCount.add(1, ordering: .sequentiallyConsistent)
118-
}
119-
return Self._all.withLock { all in
114+
Self._all.withLock { all in
120115
let id = all.nextID
121116
all.nextID += 1
122117
all.instances[id] = self
@@ -128,37 +123,12 @@ extension Configuration {
128123
///
129124
/// - Parameters:
130125
/// - id: The unique identifier of this instance, as previously returned by
131-
/// `_addToAll()`.
132-
private func _removeFromAll(identifiedBy id: UInt64) {
133-
let configuration = Self._all.withLock { all in
134-
all.instances.removeValue(forKey: id)
135-
}
136-
if let configuration, configuration.deliverExpectationCheckedEvents, #available(_synchronizationAPI, *) {
137-
Self._deliverExpectationCheckedEventsCount.subtract(1, ordering: .sequentiallyConsistent)
138-
}
139-
}
140-
141-
/// An atomic counter that tracks the number of "current" configurations that
142-
/// have set ``deliverExpectationCheckedEvents`` to `true`.
143-
///
144-
/// On older Apple platforms, this property is not available and ``all`` is
145-
/// directly consulted instead (which is less efficient.)
146-
@available(_synchronizationAPI, *)
147-
private static let _deliverExpectationCheckedEventsCount = Atomic(0)
148-
149-
/// Whether or not events of the kind
150-
/// ``Event/Kind-swift.enum/expectationChecked(_:)`` should be delivered to
151-
/// the event handler of _any_ configuration set as current for a task in the
152-
/// current process.
153-
///
154-
/// To determine if an individual instance of ``Configuration`` is listening
155-
/// for these events, consult the per-instance
156-
/// ``Configuration/deliverExpectationCheckedEvents`` property.
157-
static var deliverExpectationCheckedEvents: Bool {
158-
if #available(_synchronizationAPI, *) {
159-
_deliverExpectationCheckedEventsCount.load(ordering: .sequentiallyConsistent) > 0
160-
} else {
161-
all.contains(where: \.deliverExpectationCheckedEvents)
126+
/// `_addToAll()`. If `nil`, this function has no effect.
127+
private func _removeFromAll(identifiedBy id: UInt64?) {
128+
if let id {
129+
Self._all.withLock { all in
130+
_ = all.instances.removeValue(forKey: id)
131+
}
162132
}
163133
}
164134
}

Tests/TestingTests/MiscellaneousTests.swift

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -532,15 +532,4 @@ struct MiscellaneousTests {
532532
failureBreakpoint()
533533
#expect(failureBreakpointValue == 1)
534534
}
535-
536-
@available(_clockAPI, *)
537-
@Test("Repeated calls to #expect() run in reasonable time", .disabled("time-sensitive"))
538-
func repeatedlyExpect() {
539-
let duration = Test.Clock().measure {
540-
for _ in 0 ..< 1_000_000 {
541-
#expect(true as Bool)
542-
}
543-
}
544-
#expect(duration < .seconds(1))
545-
}
546535
}

0 commit comments

Comments
 (0)