Skip to content

Commit

Permalink
Update some underscore public API doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Ye committed May 6, 2024
1 parent 25e716d commit ff8fa94
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 0 deletions.
1 change: 1 addition & 0 deletions Sources/OpenSwiftUI/Core/Graph/Graph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
// Audited for RELEASE_2021
// Status: Complete

/// A transient reference to a view graph.
public struct _Graph {}
1 change: 1 addition & 0 deletions Sources/OpenSwiftUI/Core/Graph/GraphInputsModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Audited for RELEASE_2021
// Status: Complete

/// Protocol for modifiers that only modify their children's inputs.
public protocol _GraphInputsModifier {
static func _makeInputs(modifier: _GraphValue<Self>, inputs: inout _GraphInputs)
}
5 changes: 5 additions & 0 deletions Sources/OpenSwiftUI/Core/Graph/GraphValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

internal import OpenGraphShims

/// A transient reference to a value in the view hierarchy's dataflow
/// graph. "Transient" means that these values must never be stored,
/// only passed around while initializing views.
public struct _GraphValue<Value>: Equatable {
var value: Attribute<Value>

Expand All @@ -26,6 +29,8 @@ public struct _GraphValue<Value>: Equatable {
_GraphValue<V>(value.unsafeBitCast(to: type))
}

/// Returns the value created by fetching the property at `keyPath`
/// of `self`.
public subscript<Member>(keyPath: KeyPath<Value, Member>) -> _GraphValue<Member> {
_GraphValue<Member>(value[keyPath: keyPath])
}
Expand Down
2 changes: 2 additions & 0 deletions Sources/OpenSwiftUI/Core/Modifier/ModifiedContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ extension ModifiedContent: ViewModifier where Content: ViewModifier, Modifier: V
}

extension ViewModifier {
/// Returns a new modifier that is the result of concatenating
/// `self` with `modifier`.
@inlinable
@inline(__always)
public func concat<T>(_ modifier: T) -> ModifiedContent<Self, T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@
/// caption in blue text surrounded by a rounded
/// rectangle.](OpenSwiftUI-View-ViewModifier.png)
public protocol ViewModifier {
/// The type of view representing the body.
associatedtype Body: View

/// Makes a new view using the view modifier and inputs that you provide.
static func _makeView(
modifier: _GraphValue<Self>,
inputs: _ViewInputs,
Expand All @@ -63,11 +65,14 @@ public protocol ViewModifier {
body: @escaping (_Graph, _ViewListInputs) -> _ViewListOutputs
) -> _ViewListOutputs

/// The number of views that `_makeViewList()` would produce, or
/// nil if unknown.
static func _viewListCount(
inputs: _ViewListCountInputs,
body: (_ViewListCountInputs) -> Int?
) -> Int?

/// The content view type passed to `body()`.
typealias Content = _ViewModifier_Content<Self>

/// Gets the current body of the caller.
Expand Down
1 change: 1 addition & 0 deletions Sources/OpenSwiftUI/Core/View/ConditionalContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

internal import OpenGraphShims

/// View content that shows one of two possible children.
@frozen
public struct _ConditionalContent<TrueContent, FalseContent> {
@usableFromInline
Expand Down
4 changes: 4 additions & 0 deletions Sources/OpenSwiftUI/Core/View/View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ public protocol View {
}

extension View {
/// Instantiates the view using `view` as its source value, and
/// `inputs` as its input values. Returns the view's output values.
/// This should never be called directly, instead use the
/// makeDebuggableView() shim function.
public static func _makeView(view: _GraphValue<Self>, inputs: _ViewInputs) -> _ViewOutputs {
makeView(view: view, inputs: inputs)
}
Expand Down
4 changes: 4 additions & 0 deletions Sources/OpenSwiftUI/Core/View/View/ViewInputs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

internal import OpenGraphShims

/// The input (aka inherited) attributes supplied to each view. Most
/// view types will only actually wire a small number of these into
/// their node. Doesn't include the view itself, which is passed
/// separately.
public struct _ViewInputs {
private var base: _GraphInputs
var preferences: PreferencesInputs
Expand Down
1 change: 1 addition & 0 deletions Sources/OpenSwiftUI/Core/View/View/ViewOutputs.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
internal import OpenGraphShims

/// The output (aka synthesized) attributes returned by each view.
public struct _ViewOutputs {
private var preferences = PreferencesOutputs()
@OptionalAttribute var layoutComputer: LayoutComputer?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Audited for RELEASE_2021
// Status: WIP

/// Input values to `View._viewListCount()`.
public struct _ViewListCountInputs {
var customInputs : PropertyList
var options : _ViewListInputs.Options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

internal import OpenGraphShims

/// Input values to `View._makeViewList()`.
public struct _ViewListInputs {
private var base: _GraphInputs
var implicitID: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

internal import OpenGraphShims

/// Output values from `View._makeViewList()`.
public struct _ViewListOutputs {
var views: Views
var nextImplicitID: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ internal import OpenGraphShims
/// The view gives values to these properties prior to recomputing the view's
/// ``View/body-swift.property``.
public protocol DynamicProperty {
/// Creates an instance of the dynamic `View` property
/// represented by `self`.
static func _makeProperty<Value>(
in buffer: inout _DynamicPropertyBuffer,
container: _GraphValue<Value>,
Expand Down
50 changes: 50 additions & 0 deletions Sources/OpenSwiftUI/View/Debug/ChangedBodyProperty.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,29 @@ import Foundation
// MARK: - printChanges

extension View {
/// When called within an invocation of `body` of a view of this
/// type, prints the names of the changed dynamic properties that
/// caused the result of `body` to need to be refreshed. As well as
/// the physical property names, "@self" is used to mark that the
/// view value itself has changed, and "@identity" to mark that the
/// identity of the view has changed (i.e. that the persistent data
/// associated with the view has been recycled for a new instance
/// of the same type).
public static func _printChanges() {
printChangedBodyProperties(of: Self.self)
}
}

extension ViewModifier {
/// When called within an invocation of `body()` of a view modifier
/// of this type, prints the names of the changed dynamic
/// properties that caused the result of `body()` to need to be
/// refreshed. As well as the physical property names, "@self" is
/// used to mark that the modifier value itself has changed, and
/// "@identity" to mark that the identity of the modifier has
/// changed (i.e. that the persistent data associated with the
/// modifier has been recycled for a new instance of the same
/// type).
public static func _printChanges() {
printChangedBodyProperties(of: Self.self)
}
Expand Down Expand Up @@ -58,12 +75,45 @@ extension OSLog {
#endif

extension View {
/// When called within an invocation of `body` of a view of this type, logs
/// the names of the changed dynamic properties that caused the result of
/// `body` to need to be refreshed.
///
/// var body: some View {
/// let _ = Self._logChanges()
/// ... view content ...
/// }
///
/// As well as the physical property names, "@self" is used to mark that the
/// view value itself has changed, and "@identity" to mark that the identity
/// of the view has changed (i.e. that the persistent data associated with
/// the view has been recycled for a new instance of the same type).
///
/// The information is logged at the info level to the "org.OpenSwiftUIProject.OpenSwiftUI"
/// subsystem with the category "Changed Body Properties".
public static func _logChanges() {
logChangedBodyProperties(of: Self.self)
}
}

extension ViewModifier {
/// When called within an invocation of `body` of a view modifier of this
/// type, logs the names of the changed dynamic properties that caused the
/// result of `body` to need to be refreshed.
///
/// func body(content: Self.Content): Self.Body {
/// let _ = Self._logChanges()
/// ... view modifier content ...
/// }
///
/// As well as the physical property names, "@self" is used to mark that the
/// modifier value itself has changed, and "@identity" to mark that the
/// identity of the modifier has changed (i.e. that the persistent data
/// associated with the modifier has been recycled for a new instance of the
/// same type).
///
/// The information is logged at the info level to the "org.OpenSwiftUIProject.OpenSwiftUI"
/// subsystem with the category "Changed Body Properties".
public static func _logChanges() {
logChangedBodyProperties(of: Self.self)
}
Expand Down

0 comments on commit ff8fa94

Please sign in to comment.