Skip to content

Commit 59368a6

Browse files
authored
Merge pull request swiftlang#30766 from eeckstein/fix-keypath-opt
SILOptimizer: fix a crash in the keypath optimization
2 parents 6434890 + 5406a81 commit 59368a6

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

lib/SILOptimizer/Utils/KeyPathProjector.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@ class GettablePropertyProjector : public ComponentProjector {
225225
auto &function = builder.getFunction();
226226
auto substType = component.getComponentType().subst(keyPath->getSubstitutions(),
227227
None);
228-
SILType type = function.getLoweredType(substType);
228+
SILType type = function.getLoweredType(
229+
Lowering::AbstractionPattern::getOpaque(), substType);
229230
auto addr = builder.createAllocStack(loc, type);
230231

231232
assertHasNoContext();
@@ -302,7 +303,8 @@ class SettablePropertyProjector : public GettablePropertyProjector {
302303
auto &function = builder.getFunction();
303304
auto substType = component.getComponentType().subst(keyPath->getSubstitutions(),
304305
None);
305-
SILType type = function.getLoweredType(substType);
306+
SILType type = function.getLoweredType(
307+
Lowering::AbstractionPattern::getOpaque(), substType);
306308
auto addr = builder.createAllocStack(loc, type);
307309

308310
assertHasNoContext();
@@ -351,7 +353,8 @@ class OptionalWrapProjector : public ComponentProjector {
351353
auto &function = builder.getFunction();
352354
auto substType = component.getComponentType().subst(keyPath->getSubstitutions(),
353355
None);
354-
SILType optType = function.getLoweredType(substType);
356+
SILType optType = function.getLoweredType(
357+
Lowering::AbstractionPattern::getOpaque(), substType);
355358
SILType objType = optType.getOptionalObjectType().getAddressType();
356359

357360
assert(objType && "optional wrap must return an optional");
@@ -557,7 +560,8 @@ class CompleteKeyPathProjector : public KeyPathProjector {
557560
auto resultCanType = components.back().getComponentType();
558561
auto &function = builder.getFunction();
559562
auto substType = resultCanType.subst(keyPath->getSubstitutions(), None);
560-
auto optType = function.getLoweredType(substType);
563+
auto optType = function.getLoweredType(
564+
Lowering::AbstractionPattern::getOpaque(), substType);
561565

562566
assert(optType.getOptionalObjectType() &&
563567
"Optional-chained key path should result in an optional");
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %target-swift-frontend -O -emit-sil %s | %FileCheck %s
2+
3+
// REQUIRES: objc_interop
4+
5+
// Check if the optimizer does not crash.
6+
7+
import Foundation
8+
9+
@dynamicMemberLookup
10+
public struct S {
11+
private let x: NSXPCConnection
12+
13+
subscript<T>(dynamicMember property: ReferenceWritableKeyPath<NSXPCConnection, T>) -> T {
14+
get {
15+
x[keyPath: property]
16+
}
17+
nonmutating set {
18+
x[keyPath: property] = newValue
19+
}
20+
}
21+
22+
}
23+
24+
// CHECK: sil {{.*}}test_set
25+
public func test_set(s: S) {
26+
s.invalidationHandler = {}
27+
}
28+
29+
// CHECK: sil {{.*}}test_get
30+
public func test_get(s: S) -> (() -> ())? {
31+
return s.invalidationHandler
32+
}
33+
34+

0 commit comments

Comments
 (0)