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
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUI/App/FinishLaunchTestAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct FinishLaunchTestAction {
#if os(iOS) || os(visionOS)
UIApplication.shared.finishedTest(UIApplication.shared._launchTestName())
#else
preconditionFailure("Unimplemented for other platform")
_openSwiftUIPlatformUnimplementedWarning()
#endif
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,11 +621,11 @@ struct PlatformArchivedDisplayList<Content>: Rule where Content: PlatformViewRep
}

func makePlatformView() -> AnyObject? {
preconditionFailure("")
_openSwiftUIUnreachableCode()
}

func updatePlatformView(_ view: inout AnyObject) {
preconditionFailure("")
_openSwiftUIUnreachableCode()
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/OpenSwiftUI/View/Control/Link/OpenURLActionKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct OpenURLActionKey: EnvironmentKey {
completion(error != nil)
}
#else
preconditionFailure("Unimplemented")
_openSwiftUIPlatformUnimplementedWarning()
#endif
},
isDefault: true
Expand All @@ -51,7 +51,7 @@ struct OpenSensitiveURLActionKey: EnvironmentKey {
}
workspace.open(url, configuration: config, completionHandler: completion)
#else
preconditionFailure("Unimplemented")
_openSwiftUIPlatformUnimplementedWarning()
#endif
},
isDefault: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,10 @@ extension BodyAccessor {
inputs: inout _GraphInputs,
fields: DynamicPropertyCache.Fields
) -> (_GraphValue<Body>, _DynamicPropertyBuffer?) {
guard Body.self != Never.self else {
preconditionFailure("\(Container.self) may not have Body == Never")
}
precondition(
Body.self != Never.self,
"\(Container.self) may not have Body == Never"
)
return withUnsafePointer(to: inputs) { pointer in
func project<Flags>(flags _: Flags.Type) -> (_GraphValue<Body>, _DynamicPropertyBuffer?) where Flags: RuleThreadFlags {
let buffer = _DynamicPropertyBuffer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ extension ProtobufDecoder {
/// - Returns: The decodable value resulting from the plist data.
func value<T>(fromBinaryPlist data: Data, type: T.Type = T.self) throws -> T where T: Decodable {
#if os(WASI)
preconditionFailure("PropertyListDecoder is not avaiable on WASI")
_openSwiftUIPlatformUnimplementedFailure()
#else
let decoder = PropertyListDecoder()
decoder.userInfo = userInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ extension ProtobufEncoder {
/// - Returns: The encoded binary plist data.
func binaryPlistData<T>(for value: T) throws -> Data where T: Encodable {
#if os(WASI)
preconditionFailure("PropertyListEncoder is not avaiable on WASI")
_openSwiftUIPlatformUnimplementedFailure()
#else
let encoder = PropertyListEncoder()
encoder.outputFormat = .binary
Expand Down
15 changes: 8 additions & 7 deletions Sources/OpenSwiftUICore/Data/Update.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ package enum Update {
guard lockAssertionsAreEnabled else {
return
}
guard isOwner else {
preconditionFailure("OpenSwiftUI is active without having taken its own lock - missing Update.ensure()?")
}
precondition(
isOwner,
"OpenSwiftUI is active without having taken its own lock - missing Update.ensure()?"
)
}

package static func begin() {
Expand Down Expand Up @@ -184,10 +185,10 @@ package enum Update {
}
for action in actions {
action()
let newDepth = depth
guard newDepth == oldDepth else {
preconditionFailure("Action caused unbalanced updates.")
}
precondition(
depth == oldDepth,
"Action caused unbalanced updates."
)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/OpenSwiftUICore/Layout/Dynamic/DynamicContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ struct DynamicContainerInfo<Adapter>: StatefulRule, AsyncAttribute, ObservedAttr
}
switch phase {
case .willAppear:
preconditionFailure("")
_openSwiftUIUnreachableCode()
case .identity:
guard !disableTransitions, info.items[index].needsTransitions else {
eraseItem(at: index)
Expand Down Expand Up @@ -696,7 +696,7 @@ struct DynamicContainerInfo<Adapter>: StatefulRule, AsyncAttribute, ObservedAttr
let phase = info.items[index].phase
switch phase {
case .willAppear, nil:
preconditionFailure("")
_openSwiftUIUnreachableCode()
case .identity:
break
case .didDisappear:
Expand Down
13 changes: 5 additions & 8 deletions Sources/OpenSwiftUICore/Layout/Geometry/LayoutTraits.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,11 @@ public struct _LayoutTraits: Equatable {
}

private func _checkInvariant() {
guard min >= 0,
min.isFinite,
ideal < .infinity,
min <= ideal,
ideal <= max
else {
preconditionFailure("malformed dimension \(self)")
}
precondition(
min >= 0 && min.isFinite && ideal < .infinity &&
min <= ideal && ideal <= max,
"malformed dimension \(self)"
)
}
}

Expand Down
7 changes: 4 additions & 3 deletions Sources/OpenSwiftUICore/Layout/Layout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1700,9 +1700,10 @@ public struct LayoutSubview: Equatable {

package func place(at position: CGPoint, anchor: UnitPoint = .topLeading, dimensions: ViewDimensions) {
let origin = CGRect(position: position, size: dimensions.size.value, anchor: anchor).origin
guard !origin.isNaN else {
preconditionFailure("view origin is invalid: \(position), \(anchor), \(dimensions.size.value)")
}
precondition(
!origin.isNaN,
"view origin is invalid: \(position), \(anchor), \(dimensions.size.value)"
)
place(in: ViewGeometry(origin: origin, dimensions: dimensions))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ private class LayoutEngineBox<Engine>: AnyLayoutEngineBox where Engine: LayoutEn
}

override func mutateEngine<E, R>(as type: E.Type, do body: (inout E) -> R) -> R where E: LayoutEngine {
guard Engine.self == E.self else {
preconditionFailure("Mismatched engine type")
}
precondition(Engine.self == E.self, "Mismatched engine type")
return withUnsafePointer(to: &engine) { ptr in
body(&UnsafeMutableRawPointer(mutating: UnsafeRawPointer(ptr)).assumingMemoryBound(to: E.self).pointee)
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/OpenSwiftUICore/Layout/View/ViewTransform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public struct ViewTransform: Equatable, CustomStringConvertible {
rect = rect.applying(transform)
}
#else
preconditionFailure("CGAffineTransform+applying is not available on this platform")
_openSwiftUIPlatformUnimplementedWarning()
#endif
case .projectionTransform:
rect = nil
Expand Down Expand Up @@ -100,7 +100,7 @@ public struct ViewTransform: Equatable, CustomStringConvertible {
geometry.containerSize = geometry.containerSize.applying(transform)
}
#else
preconditionFailure("CGAffineTransform+applying is not available on this platform")
_openSwiftUIPlatformUnimplementedWarning()
#endif
case .projectionTransform:
geometry = nil
Expand Down Expand Up @@ -684,7 +684,7 @@ extension CGPoint: ApplyViewTransform, ViewTransformable {
self = applying(matrix)
}
#else
preconditionFailure("CGAffineTransform+applying is not available on this platform")
_openSwiftUIPlatformUnimplementedWarning()
#endif
case let .projectionTransform(matrix, inverse):
self = inverse ? unapplying(matrix) : applying(matrix)
Expand Down Expand Up @@ -712,7 +712,7 @@ extension [CGPoint]: ApplyViewTransform, ViewTransformable {
let tranform = inverse ? matrix.inverted() : matrix
self = map { $0.applying(tranform) }
#else
preconditionFailure("CGAffineTransform+applying is not available on this platform")
_openSwiftUIPlatformUnimplementedWarning()
#endif
case let .projectionTransform(matrix, inverse):
apply(matrix, inverse: inverse)
Expand Down
9 changes: 7 additions & 2 deletions Sources/OpenSwiftUICore/Log/Logging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@ extension os.OSLog {

// MARK: - OpenSwiftUI addition: abstract and stub call

@_transparent
package func _openSwiftUIUnreachableCode(_ function: String = #function, file: StaticString = #fileID, line: UInt = #line) -> Never {
preconditionFailure("", file: file, line: line)
}

@_transparent
package func _openSwiftUIBaseClassAbstractMethod(_ function: String = #function, file: StaticString = #fileID, line: UInt = #line) -> Never {
preconditionFailure("", file: file, line: line)
Expand All @@ -269,12 +274,12 @@ package func _openSwiftUIEmptyStub(_ function: String = #function, file: StaticS

@_transparent
package func _openSwiftUIUnimplementedFailure(_ function: String = #function, file: StaticString = #fileID, line: UInt = #line) -> Never {
preconditionFailure("TODO", file: file, line: line)
preconditionFailure("Unimplemented yet", file: file, line: line)
}

@_transparent
package func _openSwiftUIPlatformUnimplementedFailure(_ function: String = #function, file: StaticString = #fileID, line: UInt = #line) -> Never {
preconditionFailure("TODO", file: file, line: line)
preconditionFailure("Unimplemented for this platform yet", file: file, line: line)
}

@_transparent
Expand Down
7 changes: 4 additions & 3 deletions Sources/OpenSwiftUICore/Modifier/CustomViewModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,10 @@ extension ViewModifier {
inputs: inout _GraphInputs,
fields: DynamicPropertyCache.Fields
) -> (_GraphValue<Body>, _DynamicPropertyBuffer?) {
guard Metadata(Self.self).isValueType else {
preconditionFailure("view modifiers must be value types: \(Self.self)")
}
precondition(
Metadata(Self.self).isValueType,
"view modifiers must be value types: \(Self.self)"
)
let accessor = ModifierBodyAccessor<Self>()
return accessor.makeBody(container: modifier, inputs: &inputs, fields: fields)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ extension EnvironmentalModifier {
inputs: inout _GraphInputs,
fields: DynamicPropertyCache.Fields
) -> (_GraphValue<ResolvedModifier>, _DynamicPropertyBuffer?) {
guard Metadata(Self.self).isValueType else {
preconditionFailure("Environmental modifiers must be value types: \(Self.self)")
}
precondition(
Metadata(Self.self).isValueType,
"Environmental modifiers must be value types: \(Self.self)"
)
var fields = fields
if !fields.behaviors.contains(.requiresMainThread), !_requiresMainThread {
fields.behaviors.formUnion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ extension DisplayList.GraphicsRenderer {
layer.bounds = CGRect(origin: .zero, size: size)
layer.layoutIfNeeded()
}
preconditionFailure("Blocked by GraphicsContext")
// TODO: Blocked by GraphicsContext
_openSwiftUIUnimplementedFailure()
// ctx.drawLayer
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUICore/Util/ThreadUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final package class ThreadSpecific<T> {
}

deinit {
preconditionFailure("\(Self.self).deinit is unsafe and would leak", file: #file, line: #line)
preconditionFailure("\(Self.self).deinit is unsafe and would leak")
}

private final var box: UnsafeMutablePointer<Any> {
Expand Down
7 changes: 4 additions & 3 deletions Sources/OpenSwiftUICore/View/CustomView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ extension View {
inputs: inout _GraphInputs,
fields: DynamicPropertyCache.Fields
) -> (_GraphValue<Body>, _DynamicPropertyBuffer?) {
guard Metadata(Self.self).isValueType else {
preconditionFailure("views must be value types (either a struct or an enum); \(Self.self) is a class.")
}
precondition(
Metadata(Self.self).isValueType,
"views must be value types (either a struct or an enum); \(Self.self) is a class."
)
let accessor = ViewBodyAccessor<Self>()
return accessor.makeBody(container: view, inputs: &inputs, fields: fields)
}
Expand Down
7 changes: 4 additions & 3 deletions Sources/OpenSwiftUICore/View/Graph/ViewGraph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,10 @@ extension ViewGraph {
//package typealias SizeThatFitsObservers = ViewGraphGeometryObservers<SizeThatFitsMeasurer>
extension ViewGraph {
private var layoutComputer: LayoutComputer? {
guard requestedOutputs.contains(.layout) else {
preconditionFailure("Cannot fetch layout computer without layout output")
}
precondition(
requestedOutputs.contains(.layout),
"Cannot fetch layout computer without layout output"
)
instantiateIfNeeded()
return rootLayoutComputer
}
Expand Down
14 changes: 8 additions & 6 deletions Sources/OpenSwiftUICore/View/Graph/ViewRendererHost.swift
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,10 @@ extension ViewRendererHost {
}

package func advanceTimeForTest(interval: Double) {
guard interval >= 0 else {
preconditionFailure("Test render timestamps must monotonically increase.")
}
precondition(
interval >= 0,
"Test render timestamps must monotonically increase."
)
let advancedTime = currentTimestamp + interval
currentTimestamp = advancedTime == currentTimestamp ? Time(seconds: nextafter(advancedTime.seconds, Double.infinity)) : advancedTime
}
Expand Down Expand Up @@ -432,9 +433,10 @@ extension ViewRendererHost {
}
update()
for host in enclosingHosts {
guard host.externalUpdateCount >= 1 else {
preconditionFailure("Unbalanced will/did update functions.")
}
precondition(
host.externalUpdateCount >= 1,
"Unbalanced will/did update functions."
)
host.externalUpdateCount -= 1
}
}
Expand Down
7 changes: 4 additions & 3 deletions Sources/OpenSwiftUICore/View/Style/ViewStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,10 @@ private struct StyleModifierType<M>: AnyStyleModifierType where M: StyleModifier
fields: DynamicPropertyCache.Fields
) -> (_GraphValue<M.StyleBody>, _DynamicPropertyBuffer?) where V: StyleableView {
if Semantics.ViewStylesMustBeValueTypes.isEnabled {
guard Metadata(M.Style.self).isValueType else {
preconditionFailure("styles must be value types (either a struct or an enum); \(M.Style.self) is a class.")
}
precondition(
Metadata(M.Style.self).isValueType,
"styles must be value types (either a struct or an enum); \(M.Style.self) is a class."
)
}
let styleModifier = modifier.value.unsafeCast(to: M.self)
let accessor = StyleBodyAccessor<V, M>(
Expand Down
7 changes: 4 additions & 3 deletions Sources/OpenSwiftUICore/View/VariadicView/VariadicView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,10 @@ extension _VariadicView.ViewRoot {
inputs: inout _GraphInputs,
fields: DynamicPropertyCache.Fields
) -> (_GraphValue<Body>, _DynamicPropertyBuffer?) {
guard Metadata(Self.self).isValueType else {
preconditionFailure("views root must be value types (either a struct or an enum); \(Self.self) is a class.")
}
precondition(
Metadata(Self.self).isValueType,
"views root must be value types (either a struct or an enum); \(Self.self) is a class."
)
let accessor = ViewRootBodyAccessor<Self>(list: list, contentSubgraph: .current!)
return accessor.makeBody(container: root, inputs: &inputs, fields: fields)
}
Expand Down
Loading