Skip to content

Commit 06b53b2

Browse files
Merge pull request swiftlang#20553 from aschwaighofer/dynamic_fixes
Dynamic fixes
2 parents eb147d9 + 893318c commit 06b53b2

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

lib/AST/Decl.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1416,7 +1416,7 @@ SourceRange IfConfigDecl::getSourceRange() const {
14161416
}
14171417

14181418
static bool isPolymorphic(const AbstractStorageDecl *storage) {
1419-
if (storage->isDynamic())
1419+
if (storage->isObjCDynamic())
14201420
return true;
14211421

14221422

@@ -1623,6 +1623,9 @@ AbstractStorageDecl::getAccessStrategy(AccessSemantics semantics,
16231623
if (isPolymorphic(this))
16241624
return getOpaqueAccessStrategy(this, accessKind, /*dispatch*/ true);
16251625

1626+
if (isDynamic())
1627+
return getOpaqueAccessStrategy(this, accessKind, /*dispatch*/ false);
1628+
16261629
// If the storage is resilient to the given use DC (perhaps because
16271630
// it's @_transparent and we have to be careful about it being inlined
16281631
// across module lines), we cannot use direct access.

lib/SILOptimizer/IPO/ClosureSpecializer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,8 @@ bool SILClosureSpecializerTransform::gatherCallSites(
10351035
// so continue...
10361036
auto AI = FullApplySite::isa(Use->getUser());
10371037
if (!AI || AI.hasSubstitutions() ||
1038-
!canSpecializeFullApplySite(AI.getKind()))
1038+
!canSpecializeFullApplySite(AI.getKind()) ||
1039+
!AI.canOptimize())
10391040
continue;
10401041

10411042
// Check if we have already associated this apply inst with a closure to

lib/SILOptimizer/Utils/SpecializationMangler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,12 @@ FunctionSignatureSpecializationMangler::mangleConstantProp(LiteralInst *LI) {
202202
switch (LI->getKind()) {
203203
default:
204204
llvm_unreachable("unknown literal");
205+
case SILInstructionKind::DynamicFunctionRefInst: {
206+
SILFunction *F = cast<DynamicFunctionRefInst>(LI)->getReferencedFunction();
207+
ArgOpBuffer << 'f';
208+
appendIdentifier(F->getName());
209+
break;
210+
}
205211
case SILInstructionKind::FunctionRefInst: {
206212
SILFunction *F = cast<FunctionRefInst>(LI)->getReferencedFunction();
207213
ArgOpBuffer << 'f';

test/SILGen/keypath_dynamic.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %target-swift-emit-silgen -enable-sil-ownership -module-name A %s | %FileCheck %s
2+
3+
struct Foo {
4+
var x : Int {
5+
get {
6+
return 1
7+
}
8+
set {
9+
}
10+
}
11+
12+
func foo(_ kp: WritableKeyPath<Foo, Int>) {
13+
}
14+
15+
func test() {
16+
// CHECK: keypath $WritableKeyPath<Foo, Int>, (root $Foo; settable_property $Int, id @$s1A3FooV1xSivg
17+
foo(\.x)
18+
}
19+
}

0 commit comments

Comments
 (0)