Skip to content

Loosen platform requirements for Dependencies library #1466

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

Merged
merged 5 commits into from
Oct 11, 2022
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
3 changes: 0 additions & 3 deletions ComposableArchitecture.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 10 additions & 20 deletions Sources/ComposableArchitecture/Effect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,15 @@ extension Effect where Failure == Never {
#if DEBUG
var errorDump = ""
customDump(error, to: &errorDump, indent: 4)
runtimeWarning(
runtimeWarn(
"""
An 'Effect.task' returned from "%@:%d" threw an unhandled error. …
An "Effect.task" returned from "\(fileID):\(line)" threw an unhandled error. …

%@
\(errorDump)

All non-cancellation errors must be explicitly handled via the 'catch' parameter \
on 'Effect.task', or via a 'do' block.
All non-cancellation errors must be explicitly handled via the "catch" parameter \
on "Effect.task", or via a "do" block.
""",
[
"\(fileID)",
line,
errorDump,
],
file: file,
line: line
)
Expand Down Expand Up @@ -221,20 +216,15 @@ extension Effect where Failure == Never {
#if DEBUG
var errorDump = ""
customDump(error, to: &errorDump, indent: 4)
runtimeWarning(
runtimeWarn(
"""
An 'Effect.run' returned from "%@:%d" threw an unhandled error. …
An "Effect.run" returned from "\(fileID):\(line)" threw an unhandled error. …

%@
\(errorDump)

All non-cancellation errors must be explicitly handled via the 'catch' parameter \
on 'Effect.run', or via a 'do' block.
All non-cancellation errors must be explicitly handled via the "catch" parameter \
on "Effect.run", or via a "do" block.
""",
[
"\(fileID)",
line,
errorDump,
],
file: file,
line: line
)
Expand Down
35 changes: 16 additions & 19 deletions Sources/ComposableArchitecture/Effects/TaskResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -213,21 +213,20 @@ extension TaskResult: Equatable where Success: Equatable {
case let (.failure(lhs), .failure(rhs)):
return _isEqual(lhs, rhs) ?? {
#if DEBUG
if TaskResultDebugging.emitRuntimeWarnings, type(of: lhs) == type(of: rhs) {
runtimeWarning(
let lhsType = type(of: lhs)
if TaskResultDebugging.emitRuntimeWarnings, lhsType == type(of: rhs) {
let lhsTypeName = typeName(lhsType)
runtimeWarn(
"""
'%1$@' is not equatable. …
"\(lhsTypeName)" is not equatable. …

To test two values of this type, it must conform to the 'Equatable' protocol. For \
To test two values of this type, it must conform to the "Equatable" protocol. For \
example:

extension %1$@: Equatable {}
extension \(lhsTypeName): Equatable {}

See the documentation of 'TaskResult' for more information.
""",
[
"\(type(of: lhs))",
]
See the documentation of "TaskResult" for more information.
"""
)
}
#endif
Expand All @@ -252,19 +251,17 @@ extension TaskResult: Hashable where Success: Hashable {
} else {
#if DEBUG
if TaskResultDebugging.emitRuntimeWarnings {
runtimeWarning(
let errorType = typeName(type(of: error))
runtimeWarn(
"""
'%1$@' is not hashable. …
"\(errorType)" is not hashable. …

To hash a value of this type, it must conform to the 'Hashable' protocol. For example:
To hash a value of this type, it must conform to the "Hashable" protocol. For example:

extension %1$@: Hashable {}
extension \(errorType): Hashable {}

See the documentation of 'TaskResult' for more information.
""",
[
"\(type(of: error))",
]
See the documentation of "TaskResult" for more information.
"""
)
}
#endif
Expand Down
16 changes: 5 additions & 11 deletions Sources/ComposableArchitecture/Internal/Deprecations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1071,15 +1071,15 @@ extension AnyReducer {
return .none
}
if index >= parentState[keyPath: toElementsState].endIndex {
runtimeWarning(
runtimeWarn(
"""
A "forEach" reducer at "%@:%d" received an action when state contained no element at \
that index. …
A "forEach" reducer at "\(fileID):\(line)" received an action when state contained no \
element at that index. …

Action:
%@
\(debugCaseOutput(action))
Index:
%d
\(index)

This is generally considered an application logic error, and can happen for a few \
reasons:
Expand All @@ -1101,12 +1101,6 @@ extension AnyReducer {
when its state contains an element at this index. In SwiftUI applications, use \
"ForEachStore".
""",
[
"\(fileID)",
line,
debugCaseOutput(action),
index,
],
file: file,
line: line
)
Expand Down
91 changes: 54 additions & 37 deletions Sources/ComposableArchitecture/Internal/RuntimeWarnings.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,50 @@
@_transparent
@usableFromInline
@inline(__always)
func runtimeWarn(
_ message: @autoclosure () -> String,
category: String? = "ComposableArchitecture",
file: StaticString? = nil,
line: UInt? = nil
) {
#if DEBUG
let message = message()
let category = category ?? "Runtime Warning"
if _XCTIsTesting {
if let file = file, let line = line {
XCTFail(message, file: file, line: line)
} else {
XCTFail(message)
}
} else {
#if canImport(os)
os_log(
.fault,
dso: dso,
log: OSLog(subsystem: "com.apple.runtime-issues", category: category),
"%@",
message
)
#else
fputs("\(formatter.string(from: Date())) [\(category)] \(message)\n", stderr)
#endif
}
#endif
}

#if DEBUG
import os
import XCTestDynamicOverlay

// NB: Xcode runtime warnings offer a much better experience than traditional assertions and
// breakpoints, but Apple provides no means of creating custom runtime warnings ourselves.
// To work around this, we hook into SwiftUI's runtime issue delivery mechanism, instead.
//
// Feedback filed: https://gist.github.com/stephencelis/a8d06383ed6ccde3e5ef5d1b3ad52bbc
@usableFromInline
let rw = (
dso: { () -> UnsafeMutableRawPointer in
#if canImport(os)
import os

// NB: Xcode runtime warnings offer a much better experience than traditional assertions and
// breakpoints, but Apple provides no means of creating custom runtime warnings ourselves.
// To work around this, we hook into SwiftUI's runtime issue delivery mechanism, instead.
//
// Feedback filed: https://gist.github.com/stephencelis/a8d06383ed6ccde3e5ef5d1b3ad52bbc
@usableFromInline
let dso = { () -> UnsafeMutableRawPointer in
let count = _dyld_image_count()
for i in 0..<count {
if let name = _dyld_get_image_name(i) {
Expand All @@ -22,33 +57,15 @@
}
}
return UnsafeMutableRawPointer(mutating: #dsohandle)
}(),
log: OSLog(subsystem: "com.apple.runtime-issues", category: "ComposableArchitecture")
)
#endif
}()
#else
import Foundation

@_transparent
@usableFromInline
@inline(__always)
func runtimeWarning(
_ message: @autoclosure () -> StaticString,
_ args: @autoclosure () -> [CVarArg] = [],
file: StaticString? = nil,
line: UInt? = nil
) {
#if DEBUG
let message = message()
if _XCTIsTesting {
if let file = file, let line = line {
XCTFail(String(format: "\(message)", arguments: args()), file: file, line: line)
} else {
XCTFail(String(format: "\(message)", arguments: args()))
}
} else {
unsafeBitCast(
os_log as (OSLogType, UnsafeRawPointer, OSLog, StaticString, CVarArg...) -> Void,
to: ((OSLogType, UnsafeRawPointer, OSLog, StaticString, [CVarArg]) -> Void).self
)(.fault, rw.dso, rw.log, message, args())
}
@usableFromInline
let formatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd HH:MM:SS.sssZ"
return formatter
}()
#endif
}
#endif
Loading