Skip to content

Commit a03f5ec

Browse files
authored
Revert "Avoid hanging trying to diff Data and similar collections. (#1644)" (#1662)
This reverts the change recently made in #1644. It ended up causing slow type-checking of certain complex expressions passed to `#expect`, such as [this one](https://github.com/swiftlang/swift-build/blob/48e5c4ff4f37aa6ce2c85b5ff1e8600fe809b722/Tests/SWBBuildSystemTests/BuildTaskBehaviorTests.swift#L1079) in particular in the swift-build project: ```swift #expect(output.unsafeStringValue.split(separator: "\n").map({ $0.split("=").0 }).sorted().filter { $0 != "VCToolsInstallDir" && !$0.hasPrefix("ANDROID_") && !$0.hasPrefix("QNX_") } == [ "LLBUILD_BUILD_ID", "LLBUILD_CONTROL_FD", "LLBUILD_LANE_ID", "LLBUILD_TASK_ID" ]) ``` It appears the new `__checkBinaryOperation()` overload added in that PR caused type-checking to become more complex and slower for complex expressions such as this. It may be possible to implement an alternate approach for this which checks the type at runtime only, to avoid needing an additional overload. Related to: rdar://173002947 ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
1 parent 99dc231 commit a03f5ec

2 files changed

Lines changed: 0 additions & 48 deletions

File tree

Sources/Testing/Expectations/ExpectationChecking+Macro.swift

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -664,34 +664,6 @@ public func __checkBinaryOperation(
664664
)
665665
}
666666

667-
/// Check that an expectation has passed after a condition has been evaluated
668-
/// and throw an error if it failed.
669-
///
670-
/// This overload is necessary because collections whose elements are of type
671-
/// `UInt8` or `Int8` tend to be raw data and diffing them can be very slow
672-
/// while also not producing useful, readable output.
673-
///
674-
/// - Warning: This function is used to implement the `#expect()` and
675-
/// `#require()` macros. Do not call it directly.
676-
public func __checkBinaryOperation<T, U>(
677-
_ lhs: T, _ op: (T, () -> U) -> Bool, _ rhs: @autoclosure () -> U,
678-
expression: __Expression,
679-
comments: @autoclosure () -> [Comment],
680-
isRequired: Bool,
681-
sourceLocation: SourceLocation
682-
) -> Result<Void, any Error> where T: Collection, U: Collection, T.Element == U.Element, T.Element: BinaryInteger, T.Element.Magnitude == UInt8 {
683-
let (condition, rhs) = _callBinaryOperator(lhs, op, rhs)
684-
return __checkValue(
685-
condition,
686-
expression: expression,
687-
expressionWithCapturedRuntimeValues: expression.capturingRuntimeValues(condition, lhs, rhs),
688-
difference: nil,
689-
comments: comments(),
690-
isRequired: isRequired,
691-
sourceLocation: sourceLocation
692-
)
693-
}
694-
695667
/// Check that an expectation has passed after a condition has been evaluated
696668
/// and throw an error if it failed.
697669
///

Tests/TestingTests/IssueTests.swift

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,26 +1288,6 @@ final class IssueTests: XCTestCase {
12881288
}.run(configuration: configuration)
12891289
}
12901290

1291-
func testCollectionDifferenceSkippedForByteCollections() async {
1292-
var configuration = Configuration()
1293-
configuration.eventHandler = { event, _ in
1294-
guard case let .issueRecorded(issue) = event.kind else {
1295-
return
1296-
}
1297-
guard case let .expectationFailed(expectation) = issue.kind else {
1298-
XCTFail("Unexpected issue kind \(issue.kind)")
1299-
return
1300-
}
1301-
XCTAssertNil(expectation.differenceDescription)
1302-
}
1303-
1304-
await Test {
1305-
let lhs = [1, 2, 3] as [UInt8]
1306-
let rhs = [4, 5, 6] as [UInt8]
1307-
#expect(lhs == rhs)
1308-
}.run(configuration: configuration)
1309-
}
1310-
13111291
func testCollectionDifferenceSkippedForRanges() async {
13121292
var configuration = Configuration()
13131293
configuration.eventHandler = { event, _ in

0 commit comments

Comments
 (0)