Skip to content

Commit 2d27db6

Browse files
Merge pull request #25011 from aschwaighofer/implicit_dynamic_fixes-5.1
[5.1] Don't use implicit dynamic on declarations if they are transpar…
2 parents 719a6d9 + a082987 commit 2d27db6

File tree

2 files changed

+76
-4
lines changed

2 files changed

+76
-4
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2608,6 +2608,14 @@ TypeChecker::diagnosticIfDeclCannotBePotentiallyUnavailable(const Decl *D) {
26082608
return None;
26092609
}
26102610

2611+
static bool shouldBlockImplicitDynamic(Decl *D) {
2612+
if (D->getAttrs().hasAttribute<NonObjCAttr>() ||
2613+
D->getAttrs().hasAttribute<SILGenNameAttr>() ||
2614+
D->getAttrs().hasAttribute<TransparentAttr>() ||
2615+
D->getAttrs().hasAttribute<InlinableAttr>())
2616+
return true;
2617+
return false;
2618+
}
26112619
void TypeChecker::addImplicitDynamicAttribute(Decl *D) {
26122620
if (!D->getModuleContext()->isImplicitDynamicEnabled())
26132621
return;
@@ -2618,10 +2626,9 @@ void TypeChecker::addImplicitDynamicAttribute(Decl *D) {
26182626
isa<AccessorDecl>(D))
26192627
return;
26202628

2621-
if (D->getAttrs().hasAttribute<NonObjCAttr>() ||
2622-
D->getAttrs().hasAttribute<TransparentAttr>() ||
2623-
D->getAttrs().hasAttribute<InlinableAttr>())
2624-
return;
2629+
// Don't add dynamic if decl is inlinable or tranparent.
2630+
if (shouldBlockImplicitDynamic(D))
2631+
return;
26252632

26262633
if (auto *FD = dyn_cast<FuncDecl>(D)) {
26272634
// Don't add dynamic to defer bodies.
@@ -2632,6 +2639,14 @@ void TypeChecker::addImplicitDynamicAttribute(Decl *D) {
26322639
return;
26332640
}
26342641

2642+
// Don't add dynamic if accessor is inlinable or tranparent.
2643+
if (auto *asd = dyn_cast<AbstractStorageDecl>(D)) {
2644+
for (auto *accessor : asd->getAllAccessors()) {
2645+
if (!accessor->isImplicit() && shouldBlockImplicitDynamic(accessor))
2646+
return;
2647+
}
2648+
}
2649+
26352650
if (auto *VD = dyn_cast<VarDecl>(D)) {
26362651
// Don't turn stored into computed properties. This could conflict with
26372652
// exclusivity checking.

test/attr/implicit_dynamic.swift

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// RUN: %target-swift-frontend -swift-version 5 -enable-implicit-dynamic -I %t -emit-silgen %s | %FileCheck %s
2+
3+
// Make sure that these functions are not implicitly marked dynamic.
4+
5+
public struct NotImplicitDynamic {
6+
@inlinable
7+
public var x : Int {
8+
// CHECK: sil [serialized] [ossa] @$s16implicit_dynamic18NotImplicitDynamicV1xSivg
9+
// CHECK: sil [serialized] [ossa] @$s16implicit_dynamic18NotImplicitDynamicV1xSivs
10+
get {
11+
return 1
12+
}
13+
set {
14+
}
15+
}
16+
17+
@inlinable
18+
public var y : Int {
19+
// CHECK: sil [serialized] [ossa] @$s16implicit_dynamic18NotImplicitDynamicV1ySivg
20+
return 1
21+
}
22+
23+
public var z : Int {
24+
// CHECK: sil [serialized] [ossa] @$s16implicit_dynamic18NotImplicitDynamicV1zSivg
25+
// CHECK: sil [ossa] @$s16implicit_dynamic18NotImplicitDynamicV1zSivs
26+
@inlinable
27+
get {
28+
return 1
29+
}
30+
set {
31+
}
32+
}
33+
34+
@_transparent
35+
public var x2 : Int {
36+
// CHECK: sil [transparent] [serialized] [ossa] @$s16implicit_dynamic18NotImplicitDynamicV2x2Sivg
37+
// CHECK: sil [transparent] [serialized] [ossa] @$s16implicit_dynamic18NotImplicitDynamicV2x2Sivs
38+
get {
39+
return 1
40+
}
41+
set {
42+
}
43+
}
44+
45+
public subscript() -> Int {
46+
// CHECK: sil [transparent] [serialized] [ossa] @$s16implicit_dynamic18NotImplicitDynamicVSiycig
47+
@_transparent
48+
get{
49+
return 1
50+
}
51+
}
52+
}
53+
54+
// CHECK: sil [ossa] @foobar
55+
@_silgen_name("foobar")
56+
public func noImplicitDynamicFunc() {
57+
}

0 commit comments

Comments
 (0)