Skip to content

Commit 21f175a

Browse files
Added missing instances of pureStruct information propagation.
This means we no longer need to check for empty KeyPath Walker results.
1 parent a6a2f50 commit 21f175a

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

stdlib/public/core/KeyPath.swift

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3753,7 +3753,7 @@ internal struct ValidatingInstantiateKeyPathBuffer: KeyPathPatternVisitor {
37533753
offset: offset)
37543754
checkSizeConsistency()
37553755
structOffset = instantiateVisitor.structOffset
3756-
isPureStruct = instantiateVisitor.isPureStruct
3756+
isPureStruct.append(contentsOf: instantiateVisitor.isPureStruct)
37573757
}
37583758
mutating func visitComputedComponent(mutating: Bool,
37593759
idKind: KeyPathComputedIDKind,
@@ -3782,32 +3782,41 @@ internal struct ValidatingInstantiateKeyPathBuffer: KeyPathPatternVisitor {
37823782
setter: setter,
37833783
arguments: arguments,
37843784
externalArgs: externalArgs)
3785+
// Note: For this function and the ones below, modification of structOffset
3786+
// is omitted since these types of KeyPaths won't have a pureStruct
3787+
// offset anyway.
3788+
isPureStruct.append(contentsOf: instantiateVisitor.isPureStruct)
37853789
checkSizeConsistency()
37863790
}
37873791
mutating func visitOptionalChainComponent() {
37883792
sizeVisitor.visitOptionalChainComponent()
37893793
instantiateVisitor.visitOptionalChainComponent()
3794+
isPureStruct.append(contentsOf: instantiateVisitor.isPureStruct)
37903795
checkSizeConsistency()
37913796
}
37923797
mutating func visitOptionalWrapComponent() {
37933798
sizeVisitor.visitOptionalWrapComponent()
37943799
instantiateVisitor.visitOptionalWrapComponent()
3800+
isPureStruct.append(contentsOf: instantiateVisitor.isPureStruct)
37953801
checkSizeConsistency()
37963802
}
37973803
mutating func visitOptionalForceComponent() {
37983804
sizeVisitor.visitOptionalForceComponent()
37993805
instantiateVisitor.visitOptionalForceComponent()
3806+
isPureStruct.append(contentsOf: instantiateVisitor.isPureStruct)
38003807
checkSizeConsistency()
38013808
}
38023809
mutating func visitIntermediateComponentType(metadataRef: MetadataReference) {
38033810
sizeVisitor.visitIntermediateComponentType(metadataRef: metadataRef)
38043811
instantiateVisitor.visitIntermediateComponentType(metadataRef: metadataRef)
3812+
isPureStruct.append(contentsOf: instantiateVisitor.isPureStruct)
38053813
checkSizeConsistency()
38063814
}
38073815

38083816
mutating func finish() {
38093817
sizeVisitor.finish()
38103818
instantiateVisitor.finish()
3819+
isPureStruct.append(contentsOf: instantiateVisitor.isPureStruct)
38113820
checkSizeConsistency()
38123821
}
38133822

@@ -3885,14 +3894,6 @@ internal func _instantiateKeyPathBuffer(
38853894
isPureStruct = isPureStruct && value
38863895
}
38873896

3888-
// Disable the optimization in the general case of 0 components.
3889-
// Note that a KeyPath such as \SomeStruct.self would still technically
3890-
// have a valid offset of 0.
3891-
// TODO: Add the logic to distinguish pure struct
3892-
// 0-component KeyPaths (tuples too?) from others.
3893-
if walker.isPureStruct.count == 0 {
3894-
isPureStruct = false
3895-
}
38963897
if isPureStruct {
38973898
offset = walker.structOffset
38983899
}

0 commit comments

Comments
 (0)