Skip to content

Commit fa7a092

Browse files
authored
Merge pull request #193 from OpenSwiftUIProject/feature/view_list
[Feature] Update ViewList
2 parents 9ead128 + 81a9c28 commit fa7a092

File tree

14 files changed

+2243
-518
lines changed

14 files changed

+2243
-518
lines changed

.swiftformat

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@
55
--asynccapturing
66
--beforemarks
77
--binarygrouping 4,8
8+
--callsiteparen default
89
--categorymark "MARK: %c"
910
--classthreshold 0
1011
--closingparen balanced
1112
--closurevoid remove
1213
--commas always
14+
--complexattrs preserve
15+
--computedvarattrs preserve
16+
--condassignment after-property
1317
--conflictmarkers reject
18+
--dateformat system
1419
--decimalgrouping 3,6
20+
--doccomments before-declarations
1521
--elseposition same-line
1622
--emptybraces no-space
1723
--enumnamespaces always
@@ -30,46 +36,51 @@
3036
--header ignore
3137
--hexgrouping 4,8
3238
--hexliteralcase uppercase
33-
--ifdef no-indent
39+
--ifdef indent
3440
--importgrouping alpha
3541
--indent 4
3642
--indentcase false
3743
--indentstrings false
44+
--initcodernil false
3845
--lifecycle
3946
--lineaftermarks true
4047
--linebreaks lf
4148
--markcategories true
4249
--markextensions always
4350
--marktypes always
4451
--maxwidth none
45-
--modifierorder
52+
--modifierorder nonisolated,public
4653
--nevertrailing
54+
--nilinit remove
55+
--noncomplexattrs
4756
--nospaceoperators
4857
--nowrapoperators
4958
--octalgrouping 4,8
5059
--onelineforeach ignore
5160
--operatorfunc spaced
61+
--organizationmode visibility
5262
--organizetypes actor,class,enum,struct
5363
--patternlet hoist
5464
--ranges spaced
55-
--redundanttype inferred
65+
--redundanttype infer-locals-only
5666
--self remove
5767
--selfrequired
5868
--semicolons inline
59-
--shortoptionals always
69+
--shortoptionals except-properties
6070
--smarttabs enabled
61-
--someany false
71+
--someany true
72+
--storedvarattrs preserve
6273
--stripunusedargs always
6374
--structthreshold 0
64-
--swiftversion 5.10
6575
--tabwidth unspecified
6676
--throwcapturing
77+
--timezone system
6778
--trailingclosures
68-
--trimwhitespace nonblank-lines
79+
--trimwhitespace always
6980
--typeattributes preserve
7081
--typeblanklines remove
82+
--typedelimiter space-after
7183
--typemark "MARK: - %t"
72-
--varattributes preserve
7384
--voidtype void
7485
--wraparguments preserve
7586
--wrapcollections preserve
@@ -82,5 +93,4 @@
8293
--wraptypealiases preserve
8394
--xcodeindentation disabled
8495
--yodaswap always
85-
--disable blankLineAfterImports,wrapMultilineStatementBraces
86-
--enable acronyms,blankLinesBetweenImports
96+
--disable unusedArguments
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// TransitionTraitKey.swift
3+
// OpenSwiftUICore
4+
//
5+
// Audited for iOS 18.0
6+
// Status: WIP
7+
8+
@usableFromInline
9+
struct CanTransitionTraitKey: _ViewTraitKey {
10+
@inlinable
11+
static var defaultValue: Bool { false }
12+
}
13+
14+
@available(*, unavailable)
15+
extension CanTransitionTraitKey: Sendable {}
16+
17+
extension ViewTraitCollection {
18+
package var canTransition: Bool {
19+
get { self[CanTransitionTraitKey.self] }
20+
set { self[CanTransitionTraitKey.self] = newValue }
21+
}
22+
}

Sources/OpenSwiftUICore/Graph/GraphInputs.swift

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,13 @@ public struct _GraphInputs {
199199
package struct Phase: Equatable {
200200
var value: UInt32
201201

202+
@inline(__always)
203+
static var isBeingRemovedBitCount: Int { 1 }
204+
@inline(__always)
205+
static var isBeingRemovedMask: UInt32 { (1 << isBeingRemovedBitCount) - 1}
206+
@inline(__always)
207+
static var resetSeedMask: UInt32 { ~isBeingRemovedMask }
208+
202209
@inlinable
203210
package init(value: UInt32) {
204211
self.value = value
@@ -211,19 +218,17 @@ public struct _GraphInputs {
211218

212219
@inlinable
213220
package var resetSeed: UInt32 {
214-
get { value >> 1 }
215-
set { value = (newValue << 1) | (value & 1) }
221+
get { value >> Self.isBeingRemovedBitCount }
222+
set { value = (newValue << Self.isBeingRemovedBitCount) | (value & Self.isBeingRemovedMask) }
216223
}
217224

218225
package var isBeingRemoved: Bool {
219-
get { value & 1 != 0 }
220-
set { value = (newValue ? 1 : 0) | (value & 0xFFFF_FFFE) }
226+
get { (value & Self.isBeingRemovedMask) != 0 }
227+
set { value = (newValue ? 1 : 0) | (value & Self.resetSeedMask) }
221228
}
222229

223230
@inlinable
224-
package var isInserted: Bool {
225-
value & 1 == 0
226-
}
231+
package var isInserted: Bool { !isBeingRemoved }
227232

228233
@inlinable
229234
package mutating func merge(_ other: _GraphInputs.Phase) {

Sources/OpenSwiftUICore/Graph/GraphReuse.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ package import OpenGraphShims
1212
package typealias Subgraph = OGSubgraph
1313
package typealias Graph = OGGraph
1414

15-
package final class IndirectAttributeMap {
15+
public final class IndirectAttributeMap {
1616
#if canImport(Darwin)
1717
package final let subgraph: Subgraph
1818
package final var map: [AnyAttribute: AnyAttribute]

Sources/OpenSwiftUICore/Graph/ReuseTrace.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,23 @@ package struct ReuseTrace {
3434
package static func traceReuseViewInputsDifferentFailure() {
3535
traceReuseFailure("reuse_inputsDifferent")
3636
}
37-
37+
38+
@inline(__always)
39+
package static func traceReuseUnaryElementExpectedFailure(_ elementType: any Any.Type) {
40+
traceReuseFailure("reuse_unaryElement")
41+
}
42+
43+
@inline(__always)
44+
package static func traceReuseInvalidSubgraphFailure(_ typeFoundInvalid: any Any.Type) {
45+
// FIXME: ReuseTraceInternal.InvalidSubgraphFailure
46+
traceReuseFailure("reuse_invalidSubgraph")
47+
}
48+
49+
@inline(__always)
50+
package static func traceReuseBodyMismatchedFailure() {
51+
traceReuseFailure("reuse_bodyMismatched")
52+
}
53+
3854
// TODO
3955

4056
final package class Recorder {

Sources/OpenSwiftUICore/Modifier/ViewModifier/CustomViewModifier.swift

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,56 @@ extension _ViewModifier_Content {
139139
}
140140
}
141141
}
142+
143+
// MARK: - BodyInput
144+
145+
// FIXME
146+
private struct BodyInput<Input> {}
147+
148+
private enum BodyInputElement: GraphReusable, Equatable {
149+
typealias MakeViewBody = (_Graph, _ViewInputs) -> _ViewOutputs
150+
typealias MakeViewListBody = (_Graph, _ViewListInputs) -> _ViewListOutputs
151+
152+
case view(MakeViewBody)
153+
case list(MakeViewListBody)
154+
155+
static func == (lhs: BodyInputElement, rhs: BodyInputElement) -> Bool {
156+
if case let .view(lhsBody) = lhs, case let .view(rhsBody) = rhs {
157+
compareValues(lhsBody, rhsBody, options: .init(rawValue: 0x103))
158+
} else if case let .list(lhsBody) = lhs, case let .list(rhsBody) = rhs{
159+
compareValues(lhsBody, rhsBody, options: .init(rawValue: 0x103))
160+
} else {
161+
false
162+
}
163+
}
164+
165+
static var isTriviallyReusable: Bool {
166+
_SemanticFeature_v5.isEnabled
167+
}
168+
169+
func makeReusable(indirectMap: IndirectAttributeMap) {
170+
return
171+
}
172+
173+
func tryToReuse(by other: BodyInputElement, indirectMap: IndirectAttributeMap, testOnly: Bool) -> Bool {
174+
switch self {
175+
case let .view(makeViewBody):
176+
guard case let .view(otherMakeViewBody) = other else {
177+
ReuseTrace.traceReuseInternalFailure()
178+
return false
179+
}
180+
return Self.isTriviallyReusable || compareValues(makeViewBody, otherMakeViewBody, options: .init(rawValue: 0x103))
181+
case let .list(makeViewListBody):
182+
guard case let .list(otherMakeViewListBody) = other else {
183+
ReuseTrace.traceReuseInternalFailure()
184+
return false
185+
}
186+
return Self.isTriviallyReusable || compareValues(makeViewListBody, otherMakeViewListBody, options: .init(rawValue: 0x103))
187+
}
188+
}
189+
}
190+
191+
192+
private struct BodyCountInput<V>: ViewInput {
193+
static var defaultValue: Stack<_ViewListCountInputs> { .init() }
194+
}

Sources/OpenSwiftUICore/Modifier/ViewModifier/ViewModifier.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ extension ViewModifier where Self: _GraphInputsModifier, Body == Never {
120120
body: @escaping (_Graph, _ViewListInputs) -> _ViewListOutputs
121121
) -> _ViewListOutputs {
122122
var inputs = inputs
123-
inputs.withMutateGraphInputs { inputs in
124-
_makeInputs(modifier: modifier, inputs: &inputs)
125-
}
123+
_makeInputs(modifier: modifier, inputs: &inputs.base)
126124
let outputs = body(_Graph(), inputs)
127125
return outputs
128126
}

Sources/OpenSwiftUICore/Render/DisplayList/DisplayList_StableIdentity.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ extension _GraphInputs {
134134
pushScope(id: makeStableTypeData(type))
135135
}
136136

137-
package var stableIDScope: WeakAttribute<_DisplayList_StableIdentityScope>? {
137+
package var stableIDScope: WeakAttribute<DisplayList.StableIdentityScope>? {
138138
guard !options.contains(.needsStableDisplayListIDs) else {
139139
return nil
140140
}

Sources/OpenSwiftUICore/View/AnyView.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,10 @@ private struct AnyViewList: StatefulRule, AsyncAttribute {
323323
}
324324

325325
struct Transform: _ViewList_SublistTransform_Item {
326+
func bindID(_ id: inout _ViewList_ID) {
327+
// TODO
328+
}
329+
326330
func apply(sublist: inout _ViewList_Sublist) {
327331
item.bindID(&sublist.id)
328332
sublist.elements = item.wrapping(sublist.elements)

Sources/OpenSwiftUICore/View/CustomView.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ extension View {
4444
nonisolated package static func makeViewList(view: _GraphValue<Self>, inputs: _ViewListInputs) -> _ViewListOutputs {
4545
let fields = DynamicPropertyCache.fields(of: Self.self)
4646
var inputs = inputs
47-
let (body, buffer) = inputs.withMutateGraphInputs { inputs in
48-
makeBody(view: view, inputs: &inputs, fields: fields)
49-
}
47+
let (body, buffer) = makeBody(view: view, inputs: &inputs.base, fields: fields)
5048
let outputs = Body.makeDebuggableViewList(view: body, inputs: inputs)
5149
if let buffer {
5250
buffer.traceMountedProperties(to: body, fields: fields)

Sources/OpenSwiftUICore/View/EmptyView.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ public struct EmptyView: PrimitiveView {
3636
}
3737

3838
public static func _makeViewList(view: _GraphValue<EmptyView>, inputs: _ViewListInputs) -> _ViewListOutputs {
39-
guard inputs.options.contains(.isNonEmptyParent) else {
40-
return _ViewListOutputs.emptyParentViewList(inputs: inputs)
41-
}
42-
return _ViewListOutputs.nonEmptyParentViewList(inputs: inputs)
39+
.emptyViewList(inputs: inputs)
4340
}
4441

4542
public static func _viewListCount(inputs: _ViewListCountInputs) -> Int? {

0 commit comments

Comments
 (0)