Skip to content

Commit f5dd557

Browse files
authored
Merge pull request #79506 from drexin/wip-145095088
[SILOptimizer] Don't apply CMO to key paths that reference inaccessib…
2 parents e6639f1 + bde7daa commit f5dd557

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

lib/SILOptimizer/IPO/CrossModuleOptimization.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,21 @@ bool CrossModuleOptimization::canSerializeFieldsByInstructionKind(
651651
canUse = methodScope.isPublicOrPackage();
652652
}
653653
});
654+
auto pattern = KPI->getPattern();
655+
for (auto &component : pattern->getComponents()) {
656+
if (!canUse) {
657+
break;
658+
}
659+
switch (component.getKind()) {
660+
case KeyPathPatternComponent::Kind::StoredProperty: {
661+
auto property = component.getStoredPropertyDecl();
662+
canUse = isPackageOrPublic(property->getEffectiveAccess());
663+
break;
664+
}
665+
default:
666+
break;
667+
}
668+
}
654669
return canUse;
655670
}
656671
if (auto *MI = dyn_cast<MethodInst>(inst)) {

test/SILOptimizer/Inputs/cross-module/cross-module.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,3 +311,11 @@ public struct S<each T : Visitable> {
311311
_ = (repeat (each storage).visit())
312312
}
313313
}
314+
315+
public struct StructWithInternal {
316+
var internalVar: Int
317+
}
318+
319+
public func getKP() -> KeyPath<StructWithInternal, Int> {
320+
return \StructWithInternal.internalVar
321+
}

test/SILOptimizer/cross-module-optimization.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ func testPrivateVar() {
171171
print(getRandom())
172172
}
173173

174+
func testKeyPathAccess() -> KeyPath<StructWithInternal, Int> {
175+
return getKP()
176+
}
177+
174178
testNestedTypes()
175179
testClass()
176180
testError()
@@ -182,4 +186,4 @@ testMisc()
182186
testGlobal()
183187
testImplementationOnly()
184188
testPrivateVar()
185-
189+
testKeyPathAccess()

0 commit comments

Comments
 (0)