Skip to content

Commit cfebd83

Browse files
authored
Merge pull request swiftlang#14681 from eeckstein/nested-classes-md
2 parents 10eae68 + 2a7c958 commit cfebd83

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4173,8 +4173,7 @@ static void inferStaticInitializeObjCMetadata(TypeChecker &tc,
41734173

41744174
// If we know that the Objective-C metadata will be statically registered,
41754175
// there's nothing to do.
4176-
if (!hasGenericAncestry(classDecl) &&
4177-
classDecl->getDeclContext()->isModuleScopeContext()) {
4176+
if (!hasGenericAncestry(classDecl)) {
41784177
return;
41794178
}
41804179

test/Interpreter/SDK/archive_attributes.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-build-swift %s -module-name=test -DENCODE -o %t/encode
33
// RUN: %target-build-swift %s -module-name=test -o %t/decode
4+
// RUN: %target-build-swift %s -module-name=test -Xfrontend -disable-llvm-optzns -emit-ir | %FileCheck -check-prefix=CHECK-IR %s
45
// RUN: %target-run %t/encode %t/test.arc
56
// RUN: plutil -p %t/test.arc | %FileCheck -check-prefix=CHECK-ARCHIVE %s
67
// RUN: %target-run %t/decode %t/test.arc | %FileCheck %s
@@ -176,3 +177,13 @@ func main() {
176177

177178
main()
178179

180+
// Check that we eagerly create metadata of generic classes, but not for nested classes.
181+
182+
// CHECK-IR-LABEL: define {{.*}} @_swift_eager_class_initialization
183+
// CHECK-IR-NEXT: entry:
184+
// CHECK-IR-NEXT: call {{.*}}IntClassCMa
185+
// CHECK-IR-NEXT: call void asm
186+
// CHECK-IR-NEXT: call {{.*}}DoubleClassCMa
187+
// CHECK-IR-NEXT: call void asm
188+
// CHECK-IR-NEXT: ret
189+

test/decl/protocol/conforms/nscoding.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class CodingA : NSObject, NSCoding {
2121

2222
// Nested classes
2323
extension CodingA {
24-
// CHECK: class_decl "NestedA"{{.*}}@_staticInitializeObjCMetadata
24+
// CHECK-NOT: class_decl "NestedA"{{.*}}@_staticInitializeObjCMetadata
2525
class NestedA : NSObject, NSCoding { // expected-error{{nested class 'CodingA.NestedA' has an unstable name when archiving via 'NSCoding'}}
2626
// expected-note@-1{{for compatibility with existing archives, use '@objc' to record the Swift 3 runtime name}}{{3-3=@objc(_TtCC8nscoding7CodingA7NestedA)}}
2727
// expected-note@-2{{for new classes, use '@objc' to specify a unique, prefixed Objective-C runtime name}}{{3-3=@objc(<#prefixed Objective-C class name#>)}}
@@ -36,14 +36,14 @@ extension CodingA {
3636
func encode(coder: NSCoder) { }
3737
}
3838

39-
// CHECK: class_decl "NestedC"{{.*}}@_staticInitializeObjCMetadata
39+
// CHECK-NOT: class_decl "NestedC"{{.*}}@_staticInitializeObjCMetadata
4040
@objc(CodingA_NestedC)
4141
class NestedC : NSObject, NSCoding {
4242
required init(coder: NSCoder) { }
4343
func encode(coder: NSCoder) { }
4444
}
4545

46-
// CHECK: class_decl "NestedD"{{.*}}@_staticInitializeObjCMetadata
46+
// CHECK-NOT: class_decl "NestedD"{{.*}}@_staticInitializeObjCMetadata
4747
@objc(CodingA_NestedD)
4848
class NestedD : NSObject {
4949
required init(coder: NSCoder) { }

0 commit comments

Comments
 (0)