Skip to content

Commit f44cbe4

Browse files
committed
[Foundation] Update & simplify class name stability check
Move the ObjC class name stability check logic to the Swift runtime, exposing it as a new SPI called _swift_isObjCTypeNameSerializable. Update the reporting logic. The ObjC names of generic classes are considered stable now, but private classes and classes defined in function bodies or other anonymous contexts are unstable by design. On the overlay side, rewrite the check’s implementation in Swift and considerably simplify it. rdar://57809977
1 parent 3e8166e commit f44cbe4

File tree

9 files changed

+324
-452
lines changed

9 files changed

+324
-452
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//===--- FoundationSupport.cpp - Support functions for Foundation ---------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2020 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// Helper functions for the Foundation framework.
14+
//
15+
//===----------------------------------------------------------------------===//
16+
17+
#ifndef SWIFT_RUNTIME_FOUNDATION_SUPPORT_H
18+
#define SWIFT_RUNTIME_FOUNDATION_SUPPORT_H
19+
20+
#include "swift/Runtime/Config.h"
21+
22+
#if SWIFT_OBJC_INTEROP
23+
#include <objc/runtime.h>
24+
25+
#ifdef __cplusplus
26+
namespace swift { extern "C" {
27+
#endif
28+
29+
/// Returns a boolean indicating whether the Objective-C name of a class type is
30+
/// stable across executions, i.e., if the class name is safe to serialize. (The
31+
/// names of private and local types are unstable.)
32+
SWIFT_RUNTIME_STDLIB_SPI
33+
bool _swift_isObjCTypeNameSerializable(Class theClass);
34+
35+
#ifdef __cplusplus
36+
}} // extern "C", namespace swift
37+
#endif
38+
39+
#endif // SWIFT_OBJC_INTEROP
40+
#endif // SWIFT_RUNTIME_FOUNDATION_SUPPORT_H

stdlib/public/Darwin/Foundation/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ add_swift_target_library(swiftFoundation ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES
77
BundleLookup.mm
88
Calendar.swift
99
CharacterSet.swift
10-
CheckClass.mm
10+
CheckClass.swift
1111
Codable.swift
1212
Collections+DataProtocol.swift
1313
CombineTypealiases.swift

stdlib/public/Darwin/Foundation/CheckClass.mm

Lines changed: 0 additions & 291 deletions
This file was deleted.

0 commit comments

Comments
 (0)