Skip to content

Commit 52561b4

Browse files
committed
AST: Members of @_weakLinked types are implicitly @_weakLinked
1 parent 6832e68 commit 52561b4

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

include/swift/AST/Attr.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ DECL_ATTR(_clangImporterSynthesizedType, ClangImporterSynthesizedType,
362362
NotSerialized, 74)
363363
SIMPLE_DECL_ATTR(_weakLinked, WeakLinked,
364364
OnNominalType | OnAssociatedType | OnFunc | OnAccessor | OnVar |
365-
OnSubscript | OnConstructor | OnEnumElement | UserInaccessible,
365+
OnSubscript | OnConstructor | OnEnumElement | OnExtension | UserInaccessible,
366366
75)
367367
SIMPLE_DECL_ATTR(_frozen, Frozen,
368368
OnEnum |

lib/AST/Decl.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,12 @@ bool Decl::isWeakImported(ModuleDecl *fromModule) const {
557557
if (auto *dtor = dyn_cast<DestructorDecl>(this))
558558
return cast<ClassDecl>(dtor->getDeclContext())->isWeakImported(fromModule);
559559

560+
auto *dc = getDeclContext();
561+
if (auto *ext = dyn_cast<ExtensionDecl>(dc))
562+
return ext->isWeakImported(fromModule);
563+
if (auto *ntd = dyn_cast<NominalTypeDecl>(dc))
564+
return ntd->isWeakImported(fromModule);
565+
560566
// FIXME: Also check availability when containingModule is resilient.
561567
return false;
562568
}

test/IRGen/Inputs/weak_import_native_helper.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ public protocol P {
8383
}
8484

8585
@_weakLinked
86-
public struct WeakS {}
86+
public struct WeakS {
87+
public init() {}
88+
public func weakMember() {}
89+
}
8790

8891
@_weakLinked
8992
public enum WeakE {}

test/IRGen/weak_import_native.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ func testStruct() {
5555
let z = s[0]
5656
s[0] = z
5757
s[0] += 1
58+
59+
// CHECK-DAG: declare extern_weak {{.+}} @"$s25weak_import_native_helper5WeakSV0A6MemberyyF"
60+
let w = WeakS()
61+
w.weakMember()
5862
}
5963

6064
func testEnum() {

0 commit comments

Comments
 (0)