Skip to content

Commit

Permalink
Update precondition implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Ye committed Nov 24, 2024
1 parent 5954bc7 commit c7af959
Show file tree
Hide file tree
Showing 91 changed files with 316 additions and 308 deletions.
37 changes: 21 additions & 16 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,21 @@ func envEnable(_ key: String, default defaultValue: Bool = false) -> Bool {
}
}

let isXcodeEnv = Context.environment["__CFBundleIdentifier"] == "com.apple.dt.Xcode"
let development = envEnable("OPENSWIFTUI_DEVELOPMENT", default: false)

// Xcode use clang as linker which supports "-iframework" while SwiftPM use swiftc as linker which supports "-Fsystem"
let systemFrameworkSearchFlag = isXcodeEnv ? "-iframework" : "-Fsystem"
var sharedSwiftSettings: [SwiftSetting] = [
.enableUpcomingFeature("BareSlashRegexLiterals"),
.enableUpcomingFeature("InternalImportsByDefault"),
.define("OPENSWIFTUI_SUPPRESS_DEPRECATED_WARNINGS"),
.swiftLanguageMode(.v5),
]

let releaseVersion = Context.environment["OPENSWIFTUI_TARGET_RELEASE"].flatMap { Int($0) } ?? 2024
sharedSwiftSettings.append(.define("OPENSWIFTUI_RELEASE_\(releaseVersion)"))
if releaseVersion >= 2021 {
for year in 2021 ... releaseVersion {
sharedSwiftSettings.append(.define("OPENSWIFTUI_SUPPORT_\(year)_API"))
}
}

let platforms: [SupportedPlatform] = switch releaseVersion {
case 2024: // iOS 18.0
[
Expand Down Expand Up @@ -53,18 +61,15 @@ default:
]
}

var sharedSwiftSettings: [SwiftSetting] = [
.enableUpcomingFeature("BareSlashRegexLiterals"),
.enableUpcomingFeature("InternalImportsByDefault"),
.define("OPENSWIFTUI_SUPPRESS_DEPRECATED_WARNINGS"),
.define("OPENSWIFTUI_RELEASE_\(releaseVersion)"),
.swiftLanguageMode(.v5),
]
let isXcodeEnv = Context.environment["__CFBundleIdentifier"] == "com.apple.dt.Xcode"

if releaseVersion >= 2021 {
for year in 2021 ... releaseVersion {
sharedSwiftSettings.append(.define("OPENSWIFTUI_SUPPORT_\(year)_API"))
}
// Xcode use clang as linker which supports "-iframework" while SwiftPM use swiftc as linker which supports "-Fsystem"
let systemFrameworkSearchFlag = isXcodeEnv ? "-iframework" : "-Fsystem"

let development = envEnable("OPENSWIFTUI_DEVELOPMENT")

if development {
sharedSwiftSettings.append(.define("OPENSWIFTUI_DEVELOPMENT"))
}

let warningsAsErrorsCondition = envEnable("OPENSWIFTUI_WERROR", default: isXcodeEnv && development)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ protocol AccessibilityConfigurationModifier {
}

extension AccessibilityConfigurationModifier where Configuration == Never {
var configuration: Configuration { fatalError() }
var configuration: Configuration { preconditionFailure("") }
}
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)
UIApplication.shared.finishedTest(UIApplication.shared._launchTestName())
#else
fatalError("Unimplemented for other platform")
preconditionFailure("Unimplemented for other platform")
#endif
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUI/App/LegacyApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extension __App {
var rootView: V

init() {
fatalError("Not a standalone App.")
preconditionFailure("Not a standalone App.")
}

init(rootView: V) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUI/App/OpenSwiftUIApplication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private final class OpenSwiftUIApplication: NSApplication {
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
preconditionFailure("init(coder:) has not been implemented")
}
}
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ extension _SceneModifier {
extension _SceneModifier where Body == Never {
@inline(__always)
public func body(content _: SceneContent) -> Body {
fatalError("body() should not be called on \(Self.self)")
preconditionFailure("body() should not be called on \(Self.self)")
}
}
4 changes: 2 additions & 2 deletions Sources/OpenSwiftUI/Core/Render/DisplayLink.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ final class DisplayLink: NSObject {

#if os(iOS)
init(host: AnyUIHostingView, window: UIWindow) {
fatalError("TODO")
preconditionFailure("TODO")
}
#elseif os(macOS)
init(host: AnyUIHostingView, window: NSWindow) {
fatalError("TODO")
preconditionFailure("TODO")
}
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ class FocusStoreLocation<A: Hashable>: AnyLocation<A>, @unchecked Sendable {
}

override func get() -> A {
fatalError("TODO")
preconditionFailure("TODO")
}

override func set(_ value: A, transaction: Transaction) {
fatalError("TODO")
preconditionFailure("TODO")
}

typealias Value = A

override init() { fatalError() }
override init() { preconditionFailure("") }

var store: FocusStore
weak var host: GraphHost?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ extension UIViewRepresentable {
static func _modifyBridgedViewInputs(_ inputs: inout _ViewInputs) {}

public static func _makeView(view: _GraphValue<Self>, inputs: _ViewInputs) -> _ViewOutputs {
fatalError("TODO")
preconditionFailure("TODO")
}

public static func _makeViewList(view: _GraphValue<Self>, inputs: _ViewListInputs) -> _ViewListOutputs {
fatalError("TODO")
preconditionFailure("TODO")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ open class UIHostingController<Content> : UIViewController where Content : View
}

public required init?(coder: NSCoder) {
fatalError("init(coder:) must be implemented in a subclass and call super.init(coder:, rootView:)")
preconditionFailure("init(coder:) must be implemented in a subclass and call super.init(coder:, rootView:)")
}

func _commonInit() {
Expand Down
22 changes: 11 additions & 11 deletions Sources/OpenSwiftUI/Integration/UIKit/UIHostingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ open class _UIHostingView<Content>: UIView where Content: View {

@available(*, unavailable)
public required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
preconditionFailure("init(coder:) has not been implemented")
}

deinit {
Expand Down Expand Up @@ -156,40 +156,40 @@ open class _UIHostingView<Content>: UIView where Content: View {
extension _UIHostingView: ViewRendererHost {
package var renderingPhase: OpenSwiftUICore.ViewRenderingPhase {
get {
fatalError("TODO")
preconditionFailure("TODO")
}
set(newValue) {
fatalError("TODO")
preconditionFailure("TODO")
}
}

package var externalUpdateCount: Int {
get {
fatalError("TODO")
preconditionFailure("TODO")
}
set(newValue) {
fatalError("TODO")
preconditionFailure("TODO")
}
}

package func updateEnvironment() {
fatalError("TODO")
preconditionFailure("TODO")
}

package func updateSize() {
fatalError("TODO")
preconditionFailure("TODO")
}

package func updateSafeArea() {
fatalError("TODO")
preconditionFailure("TODO")
}

package func updateScrollableContainerSize() {
fatalError("TODO")
preconditionFailure("TODO")
}

package func renderDisplayList(_ list: DisplayList, asynchronously: Bool, time: Time, nextTime: Time, targetTimestamp: Time?, version: DisplayList.Version, maxVersion: DisplayList.Version) -> Time {
fatalError("TODO")
preconditionFailure("TODO")
}

package func addImplicitPropertiesNeedingUpdate(to _: inout ViewRendererHostProperties) {}
Expand All @@ -216,7 +216,7 @@ extension _UIHostingView: ViewRendererHost {
}

package func rootTransform() -> ViewTransform {
fatalError("TODO")
preconditionFailure("TODO")
}

public func graphDidChange() {
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUI/Scene/Core/Scene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ extension Never: Scene {}

extension Scene {
func sceneBodyError() -> Never {
fatalError("body() should not be called on \(Self.self)")
preconditionFailure("body() should not be called on \(Self.self)")
}
}
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUI/Scene/Core/SceneBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ extension SceneBuilder {
// if #available(iOS 16.1, macOS 13.0, watchOS 9.1, tvOS 16.1, *) {
// return LimitedAvailabilityScene(scene)
// } else {
// fatalError("Unavailable")
// preconditionFailure("Unavailable")
// }
// }
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUI/Scene/WindowGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public struct WindowGroup<Content>: Scene where Content: View {

// FIXME
public var body: some Scene {
fatalError()
preconditionFailure("")
}

var title: Text?
Expand Down
8 changes: 4 additions & 4 deletions Sources/OpenSwiftUI/Test/TestApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

public struct _TestApp {
public init() {
fatalError("TODO")
preconditionFailure("TODO")
}
public func run() -> Never {
fatalError("TODO")
preconditionFailure("TODO")
}
}

Expand All @@ -21,12 +21,12 @@ extension _TestApp {
var state: StateType

init() {
fatalError("TODO")
preconditionFailure("TODO")
}

var body: some View {
state.testView
fatalError("TODO")
preconditionFailure("TODO")
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUI/Test/TestIDView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct TestIDView<Content, ID>: PrimitiveView, UnaryView {

static func _makeView(view: _GraphValue<TestIDView<Content, ID>>, inputs: _ViewInputs) -> _ViewOutputs {
// Use IdentifiedView here
fatalError("TODO")
preconditionFailure("TODO")
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUI/Test/_Benchmark.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ public protocol _Benchmark: _Test {
extension _TestApp {
public func runBenchmarks(_ benchmarks: [_Benchmark]) -> Never {
let _ = RootView()
fatalError("TODO")
preconditionFailure("TODO")
}
}
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUI/Test/_BenchmarkHost.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ extension _BenchmarkHost {
}
return end - begin
#else
fatalError("Unsupported Platfrom")
preconditionFailure("Unsupported Platfrom")
#endif
}

Expand Down
8 changes: 4 additions & 4 deletions Sources/OpenSwiftUI/Test/_PerformanceTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extension __App {

extension _TestApp {
public func runPerformanceTests(_ tests: [_PerformanceTest]) -> Never {
fatalError("TODO")
preconditionFailure("TODO")
}
}

Expand All @@ -37,7 +37,7 @@ extension _BenchmarkHost {
#elseif os(macOS)
NSApplication.shared.startedTest(test.name)
#else
fatalError("Unimplemented for other platform")
preconditionFailure("Unimplemented for other platform")
#endif
}

Expand All @@ -47,7 +47,7 @@ extension _BenchmarkHost {
#elseif os(macOS)
NSApplication.shared.finishedTest(test.name)
#else
fatalError("Unimplemented for other platform")
preconditionFailure("Unimplemented for other platform")
#endif
}

Expand All @@ -57,7 +57,7 @@ extension _BenchmarkHost {
#elseif os(macOS)
NSApplication.shared.failedTest(test.name, withFailure: nil)
#else
fatalError("Unimplemented for other platform")
preconditionFailure("Unimplemented for other platform")
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public struct PlainButtonStyle: PrimitiveButtonStyle {
public func makeBody(configuration: Configuration) -> some View {
// Button(configuration)
// .buttonStyle(buttonStyleRepresentation)
fatalError()
preconditionFailure("")
}
}

Expand All @@ -35,6 +35,6 @@ private struct PlainButtonStyleBase: ButtonStyle {
// configuration.label
// }
// .opacity(isEnabled ? (configuration.isPressed ? 0.75 : 1.0) : 0.5)
fatalError()
preconditionFailure("")
}
}
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
fatalError("Unimplemented")
preconditionFailure("Unimplemented")
#endif
},
isDefault: true
Expand All @@ -51,7 +51,7 @@ struct OpenSensitiveURLActionKey: EnvironmentKey {
}
workspace.open(url, configuration: config, completionHandler: completion)
#else
fatalError("Unimplemented")
preconditionFailure("Unimplemented")
#endif
},
isDefault: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ protocol SliderStyle {

private class AnyStyleBox {
func body(configuration _: Slider<SliderStyleLabel, SliderStyleValueLabel>) -> AnyView {
fatalError("")
preconditionFailure("")
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUI/View/Control/Slider/Slider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ private struct Normalizing<Value>: Projection where Value: Strideable, Value: Ha
if let stride {
let result = (min.distance(to: max) / stride).rounded(.down)
guard result > 0 else {
fatalError("max stride must be positive")
preconditionFailure("max stride must be positive")
}
length = stride * result
maxStrides = result
Expand Down
Loading

0 comments on commit c7af959

Please sign in to comment.