diff --git a/Sources/OpenSwiftUI/App/FinishLaunchTestAction.swift b/Sources/OpenSwiftUI/App/FinishLaunchTestAction.swift index fa525bb62..eba252132 100644 --- a/Sources/OpenSwiftUI/App/FinishLaunchTestAction.swift +++ b/Sources/OpenSwiftUI/App/FinishLaunchTestAction.swift @@ -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 } } diff --git a/Sources/OpenSwiftUI/Integration/Representable/Platform/PlatformViewRepresentable.swift b/Sources/OpenSwiftUI/Integration/Representable/Platform/PlatformViewRepresentable.swift index bf694439b..e9066e406 100644 --- a/Sources/OpenSwiftUI/Integration/Representable/Platform/PlatformViewRepresentable.swift +++ b/Sources/OpenSwiftUI/Integration/Representable/Platform/PlatformViewRepresentable.swift @@ -621,11 +621,11 @@ struct PlatformArchivedDisplayList: Rule where Content: PlatformViewRep } func makePlatformView() -> AnyObject? { - preconditionFailure("") + _openSwiftUIUnreachableCode() } func updatePlatformView(_ view: inout AnyObject) { - preconditionFailure("") + _openSwiftUIUnreachableCode() } } } diff --git a/Sources/OpenSwiftUI/View/Control/Link/OpenURLActionKey.swift b/Sources/OpenSwiftUI/View/Control/Link/OpenURLActionKey.swift index 228e7ba3d..e83d27677 100644 --- a/Sources/OpenSwiftUI/View/Control/Link/OpenURLActionKey.swift +++ b/Sources/OpenSwiftUI/View/Control/Link/OpenURLActionKey.swift @@ -26,7 +26,7 @@ struct OpenURLActionKey: EnvironmentKey { completion(error != nil) } #else - preconditionFailure("Unimplemented") + _openSwiftUIPlatformUnimplementedWarning() #endif }, isDefault: true @@ -51,7 +51,7 @@ struct OpenSensitiveURLActionKey: EnvironmentKey { } workspace.open(url, configuration: config, completionHandler: completion) #else - preconditionFailure("Unimplemented") + _openSwiftUIPlatformUnimplementedWarning() #endif }, isDefault: true diff --git a/Sources/OpenSwiftUICore/Data/DynamicProperty/DynamicProperty.swift b/Sources/OpenSwiftUICore/Data/DynamicProperty/DynamicProperty.swift index 08c82f6ae..2ac036bc6 100644 --- a/Sources/OpenSwiftUICore/Data/DynamicProperty/DynamicProperty.swift +++ b/Sources/OpenSwiftUICore/Data/DynamicProperty/DynamicProperty.swift @@ -324,9 +324,10 @@ extension BodyAccessor { inputs: inout _GraphInputs, fields: DynamicPropertyCache.Fields ) -> (_GraphValue, _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.Type) -> (_GraphValue, _DynamicPropertyBuffer?) where Flags: RuleThreadFlags { let buffer = _DynamicPropertyBuffer( diff --git a/Sources/OpenSwiftUICore/Data/Protobuf/ProtobufDecoder.swift b/Sources/OpenSwiftUICore/Data/Protobuf/ProtobufDecoder.swift index d77e4e9a9..7655f2add 100644 --- a/Sources/OpenSwiftUICore/Data/Protobuf/ProtobufDecoder.swift +++ b/Sources/OpenSwiftUICore/Data/Protobuf/ProtobufDecoder.swift @@ -473,7 +473,7 @@ extension ProtobufDecoder { /// - Returns: The decodable value resulting from the plist data. func value(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 diff --git a/Sources/OpenSwiftUICore/Data/Protobuf/ProtobufEncoder.swift b/Sources/OpenSwiftUICore/Data/Protobuf/ProtobufEncoder.swift index 0c4c11965..dda2ce72a 100644 --- a/Sources/OpenSwiftUICore/Data/Protobuf/ProtobufEncoder.swift +++ b/Sources/OpenSwiftUICore/Data/Protobuf/ProtobufEncoder.swift @@ -415,7 +415,7 @@ extension ProtobufEncoder { /// - Returns: The encoded binary plist data. func binaryPlistData(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 diff --git a/Sources/OpenSwiftUICore/Data/Update.swift b/Sources/OpenSwiftUICore/Data/Update.swift index af3ee3d30..c57c1bd7a 100644 --- a/Sources/OpenSwiftUICore/Data/Update.swift +++ b/Sources/OpenSwiftUICore/Data/Update.swift @@ -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() { @@ -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." + ) } } } diff --git a/Sources/OpenSwiftUICore/Layout/Dynamic/DynamicContainer.swift b/Sources/OpenSwiftUICore/Layout/Dynamic/DynamicContainer.swift index fda7c2159..953e0316a 100644 --- a/Sources/OpenSwiftUICore/Layout/Dynamic/DynamicContainer.swift +++ b/Sources/OpenSwiftUICore/Layout/Dynamic/DynamicContainer.swift @@ -629,7 +629,7 @@ struct DynamicContainerInfo: StatefulRule, AsyncAttribute, ObservedAttr } switch phase { case .willAppear: - preconditionFailure("") + _openSwiftUIUnreachableCode() case .identity: guard !disableTransitions, info.items[index].needsTransitions else { eraseItem(at: index) @@ -696,7 +696,7 @@ struct DynamicContainerInfo: StatefulRule, AsyncAttribute, ObservedAttr let phase = info.items[index].phase switch phase { case .willAppear, nil: - preconditionFailure("") + _openSwiftUIUnreachableCode() case .identity: break case .didDisappear: diff --git a/Sources/OpenSwiftUICore/Layout/Geometry/LayoutTraits.swift b/Sources/OpenSwiftUICore/Layout/Geometry/LayoutTraits.swift index 565369b9d..d79cd75b2 100644 --- a/Sources/OpenSwiftUICore/Layout/Geometry/LayoutTraits.swift +++ b/Sources/OpenSwiftUICore/Layout/Geometry/LayoutTraits.swift @@ -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)" + ) } } diff --git a/Sources/OpenSwiftUICore/Layout/Layout.swift b/Sources/OpenSwiftUICore/Layout/Layout.swift index d8ec10ee3..aa1247418 100644 --- a/Sources/OpenSwiftUICore/Layout/Layout.swift +++ b/Sources/OpenSwiftUICore/Layout/Layout.swift @@ -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)) } diff --git a/Sources/OpenSwiftUICore/Layout/LayoutComputer/LayoutComputer.swift b/Sources/OpenSwiftUICore/Layout/LayoutComputer/LayoutComputer.swift index 3ed5329a8..9842d82be 100644 --- a/Sources/OpenSwiftUICore/Layout/LayoutComputer/LayoutComputer.swift +++ b/Sources/OpenSwiftUICore/Layout/LayoutComputer/LayoutComputer.swift @@ -101,9 +101,7 @@ private class LayoutEngineBox: AnyLayoutEngineBox where Engine: LayoutEn } override func mutateEngine(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) } diff --git a/Sources/OpenSwiftUICore/Layout/View/ViewTransform.swift b/Sources/OpenSwiftUICore/Layout/View/ViewTransform.swift index 83635fbac..baf5d324b 100644 --- a/Sources/OpenSwiftUICore/Layout/View/ViewTransform.swift +++ b/Sources/OpenSwiftUICore/Layout/View/ViewTransform.swift @@ -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 @@ -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 @@ -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) @@ -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) diff --git a/Sources/OpenSwiftUICore/Log/Logging.swift b/Sources/OpenSwiftUICore/Log/Logging.swift index 8d3453dd7..09fc27e32 100644 --- a/Sources/OpenSwiftUICore/Log/Logging.swift +++ b/Sources/OpenSwiftUICore/Log/Logging.swift @@ -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) @@ -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 diff --git a/Sources/OpenSwiftUICore/Modifier/CustomViewModifier.swift b/Sources/OpenSwiftUICore/Modifier/CustomViewModifier.swift index 91fd7f47f..9af33628b 100644 --- a/Sources/OpenSwiftUICore/Modifier/CustomViewModifier.swift +++ b/Sources/OpenSwiftUICore/Modifier/CustomViewModifier.swift @@ -161,9 +161,10 @@ extension ViewModifier { inputs: inout _GraphInputs, fields: DynamicPropertyCache.Fields ) -> (_GraphValue, _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() return accessor.makeBody(container: modifier, inputs: &inputs, fields: fields) } diff --git a/Sources/OpenSwiftUICore/Modifier/ViewModifier/EnvironmentalModifier.swift b/Sources/OpenSwiftUICore/Modifier/ViewModifier/EnvironmentalModifier.swift index d8da4c589..53edbec88 100644 --- a/Sources/OpenSwiftUICore/Modifier/ViewModifier/EnvironmentalModifier.swift +++ b/Sources/OpenSwiftUICore/Modifier/ViewModifier/EnvironmentalModifier.swift @@ -74,9 +74,10 @@ extension EnvironmentalModifier { inputs: inout _GraphInputs, fields: DynamicPropertyCache.Fields ) -> (_GraphValue, _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( diff --git a/Sources/OpenSwiftUICore/Render/DisplayList/DisplayListViewPlatform.swift b/Sources/OpenSwiftUICore/Render/DisplayList/DisplayListViewPlatform.swift index 569513c4d..015a9ad22 100644 --- a/Sources/OpenSwiftUICore/Render/DisplayList/DisplayListViewPlatform.swift +++ b/Sources/OpenSwiftUICore/Render/DisplayList/DisplayListViewPlatform.swift @@ -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 diff --git a/Sources/OpenSwiftUICore/Util/ThreadUtils.swift b/Sources/OpenSwiftUICore/Util/ThreadUtils.swift index 8d2819423..346926d31 100644 --- a/Sources/OpenSwiftUICore/Util/ThreadUtils.swift +++ b/Sources/OpenSwiftUICore/Util/ThreadUtils.swift @@ -29,7 +29,7 @@ final package class ThreadSpecific { } 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 { diff --git a/Sources/OpenSwiftUICore/View/CustomView.swift b/Sources/OpenSwiftUICore/View/CustomView.swift index 92a57b6ed..a40e960a7 100644 --- a/Sources/OpenSwiftUICore/View/CustomView.swift +++ b/Sources/OpenSwiftUICore/View/CustomView.swift @@ -52,9 +52,10 @@ extension View { inputs: inout _GraphInputs, fields: DynamicPropertyCache.Fields ) -> (_GraphValue, _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() return accessor.makeBody(container: view, inputs: &inputs, fields: fields) } diff --git a/Sources/OpenSwiftUICore/View/Graph/ViewGraph.swift b/Sources/OpenSwiftUICore/View/Graph/ViewGraph.swift index 00a0d9707..15c5fd535 100644 --- a/Sources/OpenSwiftUICore/View/Graph/ViewGraph.swift +++ b/Sources/OpenSwiftUICore/View/Graph/ViewGraph.swift @@ -468,9 +468,10 @@ extension ViewGraph { //package typealias SizeThatFitsObservers = ViewGraphGeometryObservers 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 } diff --git a/Sources/OpenSwiftUICore/View/Graph/ViewRendererHost.swift b/Sources/OpenSwiftUICore/View/Graph/ViewRendererHost.swift index 475df51c4..d4b4fb963 100644 --- a/Sources/OpenSwiftUICore/View/Graph/ViewRendererHost.swift +++ b/Sources/OpenSwiftUICore/View/Graph/ViewRendererHost.swift @@ -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 } @@ -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 } } diff --git a/Sources/OpenSwiftUICore/View/Style/ViewStyle.swift b/Sources/OpenSwiftUICore/View/Style/ViewStyle.swift index 35468489f..69a9cec17 100644 --- a/Sources/OpenSwiftUICore/View/Style/ViewStyle.swift +++ b/Sources/OpenSwiftUICore/View/Style/ViewStyle.swift @@ -278,9 +278,10 @@ private struct StyleModifierType: AnyStyleModifierType where M: StyleModifier fields: DynamicPropertyCache.Fields ) -> (_GraphValue, _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( diff --git a/Sources/OpenSwiftUICore/View/VariadicView/VariadicView.swift b/Sources/OpenSwiftUICore/View/VariadicView/VariadicView.swift index b3aeaa61f..6cb06de62 100644 --- a/Sources/OpenSwiftUICore/View/VariadicView/VariadicView.swift +++ b/Sources/OpenSwiftUICore/View/VariadicView/VariadicView.swift @@ -348,9 +348,10 @@ extension _VariadicView.ViewRoot { inputs: inout _GraphInputs, fields: DynamicPropertyCache.Fields ) -> (_GraphValue, _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(list: list, contentSubgraph: .current!) return accessor.makeBody(container: root, inputs: &inputs, fields: fields) }