Skip to content

Commit dbbf4b9

Browse files
committed
Merge remote-tracking branch 'origin/master' into master-next
2 parents b43ee54 + 44e4e14 commit dbbf4b9

File tree

3 files changed

+77
-5
lines changed

3 files changed

+77
-5
lines changed

lib/Sema/TypeCheckAttr.cpp

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

2709+
static bool shouldBlockImplicitDynamic(Decl *D) {
2710+
if (D->getAttrs().hasAttribute<NonObjCAttr>() ||
2711+
D->getAttrs().hasAttribute<SILGenNameAttr>() ||
2712+
D->getAttrs().hasAttribute<TransparentAttr>() ||
2713+
D->getAttrs().hasAttribute<InlinableAttr>())
2714+
return true;
2715+
return false;
2716+
}
27092717
void TypeChecker::addImplicitDynamicAttribute(Decl *D) {
27102718
if (!D->getModuleContext()->isImplicitDynamicEnabled())
27112719
return;
@@ -2716,10 +2724,9 @@ void TypeChecker::addImplicitDynamicAttribute(Decl *D) {
27162724
isa<AccessorDecl>(D))
27172725
return;
27182726

2719-
if (D->getAttrs().hasAttribute<NonObjCAttr>() ||
2720-
D->getAttrs().hasAttribute<TransparentAttr>() ||
2721-
D->getAttrs().hasAttribute<InlinableAttr>())
2722-
return;
2727+
// Don't add dynamic if decl is inlinable or tranparent.
2728+
if (shouldBlockImplicitDynamic(D))
2729+
return;
27232730

27242731
if (auto *FD = dyn_cast<FuncDecl>(D)) {
27252732
// Don't add dynamic to defer bodies.
@@ -2730,6 +2737,14 @@ void TypeChecker::addImplicitDynamicAttribute(Decl *D) {
27302737
return;
27312738
}
27322739

2740+
// Don't add dynamic if accessor is inlinable or tranparent.
2741+
if (auto *asd = dyn_cast<AbstractStorageDecl>(D)) {
2742+
for (auto *accessor : asd->getAllAccessors()) {
2743+
if (!accessor->isImplicit() && shouldBlockImplicitDynamic(accessor))
2744+
return;
2745+
}
2746+
}
2747+
27332748
if (auto *VD = dyn_cast<VarDecl>(D)) {
27342749
// Don't turn stored into computed properties. This could conflict with
27352750
// exclusivity checking.

test/ParseableInterface/ModuleCache/prebuilt-module-cache-forwarding.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// RUN: %{python} %S/Inputs/check-is-forwarding-module.py %t/MCP/Lib-*.swiftmodule
1515

1616
// Now invalidate a dependency of the prebuilt module, and make sure the forwarding file is replaced with a real module.
17-
// RUN: touch %t/Lib.swiftinterface
17+
// RUN: %{python} %S/Inputs/make-old.py %t/Lib.swiftinterface
1818
// RUN: not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP -sdk %S/Inputs -I %S/Inputs/prebuilt-module-cache/ -prebuilt-module-cache-path %t/prebuilt-cache %s 2>&1 | %FileCheck -check-prefix=FROM-INTERFACE %s
1919

2020
// Delete the cached module we just created, and create the forwarding module again

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)