Skip to content

Commit 1e894cd

Browse files
author
Greg Parker
authored
[runtime] Clean up symbols in error machinery. (swiftlang#12853)
* [runtime] Clean up symbols in error machinery. * [runtime] Clean up symbols in Foundation overlay. * [runtime] Clean up symbols in collections and hashing. * [runtime] Remove symbol controls from the Linux definition of swift_allocError. * [tests] Add more stub functions for tests that link directly to the runtime.
1 parent b77374a commit 1e894cd

34 files changed

+407
-268
lines changed

include/swift/AST/KnownDecls.def

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ FUNC_DECL(ForceBridgeFromObjectiveC,
4949
"_forceBridgeFromObjectiveC")
5050
FUNC_DECL(ConditionallyBridgeFromObjectiveC,
5151
"_conditionallyBridgeFromObjectiveC")
52-
FUNC_DECL(BridgeErrorToNSError,
53-
"_bridgeErrorToNSError")
5452

5553
FUNC_DECL(ForceBridgeFromObjectiveCBridgeable,
5654
"_forceBridgeFromObjectiveC_bridgeable")
@@ -66,7 +64,7 @@ FUNC_DECL(ConvertToAnyHashable, "_convertToAnyHashable")
6664

6765
FUNC_DECL(DiagnoseUnexpectedNilOptional, "_diagnoseUnexpectedNilOptional")
6866

69-
FUNC_DECL(GetErrorEmbeddedNSError, "_stdlib_getErrorEmbeddedNSError")
67+
FUNC_DECL(GetErrorEmbeddedNSError, "_getErrorEmbeddedNSError")
7068

7169
FUNC_DECL(UnsafeBitCast, "unsafeBitCast")
7270

include/swift/Runtime/Debug.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,16 +210,12 @@ enum: uintptr_t {
210210
};
211211

212212
/// Debugger hook. Calling this stops the debugger with a message and details
213-
/// about the issues.
214-
///
215-
/// This is not considered a finalized runtime entry point at this time. Do not
216-
/// emit calls to it from arbitrary Swift code; it's only meant for libraries
217-
/// that ship with the runtime (i.e. the stdlib and overlays).
218-
SWIFT_RUNTIME_EXPORT
213+
/// about the issues. Called by overlays.
214+
SWIFT_RUNTIME_STDLIB_SPI
219215
void _swift_reportToDebugger(uintptr_t flags, const char *message,
220216
RuntimeErrorDetails *details = nullptr);
221217

222-
SWIFT_RUNTIME_EXPORT
218+
SWIFT_RUNTIME_STDLIB_SPI
223219
bool _swift_reportFatalErrorsToDebugger;
224220

225221
// namespace swift

lib/IRGen/Linking.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ std::string LinkEntity::mangleAsString() const {
166166
// entity ::= declaration // other declaration
167167
case Kind::Function:
168168
// As a special case, functions can have manually mangled names.
169-
if (auto AsmA = getDecl()->getAttrs().getAttribute<SILGenNameAttr>()) {
170-
return AsmA->Name;
171-
}
169+
if (auto AsmA = getDecl()->getAttrs().getAttribute<SILGenNameAttr>())
170+
if (!AsmA->Name.empty())
171+
return AsmA->Name;
172172

173173
// Otherwise, fall through into the 'other decl' case.
174174
LLVM_FALLTHROUGH;

lib/SIL/SILDeclRef.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,8 @@ std::string SILDeclRef::mangle(ManglingKind MKind) const {
701701
// Use the SILGen name only for the original non-thunked, non-curried entry
702702
// point.
703703
if (auto NameA = getDecl()->getAttrs().getAttribute<SILGenNameAttr>())
704-
if (!isForeignToNativeThunk() && !isNativeToForeignThunk()
704+
if (!NameA->Name.empty() &&
705+
!isForeignToNativeThunk() && !isNativeToForeignThunk()
705706
&& !isCurried) {
706707
return NameA->Name;
707708
}

lib/SILGen/SILGenGlobalVariable.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@ SILGlobalVariable *SILGenModule::getSILGlobalVariable(VarDecl *gDecl,
2626
// First, get a mangled name for the declaration.
2727
std::string mangledName;
2828

29-
if (auto SILGenName = gDecl->getAttrs().getAttribute<SILGenNameAttr>()) {
30-
mangledName = SILGenName->Name;
31-
} else {
32-
Mangle::ASTMangler NewMangler;
33-
mangledName = NewMangler.mangleGlobalVariableFull(gDecl);
29+
{
30+
auto SILGenName = gDecl->getAttrs().getAttribute<SILGenNameAttr>();
31+
if (SILGenName && !SILGenName->Name.empty()) {
32+
mangledName = SILGenName->Name;
33+
} else {
34+
Mangle::ASTMangler NewMangler;
35+
mangledName = NewMangler.mangleGlobalVariableFull(gDecl);
36+
}
3437
}
3538

3639
// Check if it is already created, and update linkage if necessary.

stdlib/public/SDK/Foundation/DataThunks.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ static NSInteger _NSWriteToFileDescriptor(int32_t fd, const void *buffer, NSUInt
111111
return error;
112112
}
113113

114-
SWIFT_CC(swift)
114+
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_INTERNAL
115115
BOOL __NSDataWriteToURL(NSData *NS_RELEASES_ARGUMENT data, NSURL *NS_RELEASES_ARGUMENT url, NSDataWritingOptions writingOptions, NSError **_Nullable errorPtr) {
116116
assert((writingOptions & NSDataWritingAtomic) == 0);
117117

stdlib/public/SDK/Foundation/NSError.swift

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public typealias ErrorPointer = NSErrorPointer
2727
public // COMPILER_INTRINSIC
2828
let _nilObjCError: Error = _GenericObjCError.nilError
2929

30-
@_silgen_name("swift_convertNSErrorToError")
3130
public // COMPILER_INTRINSIC
3231
func _convertNSErrorToError(_ error: NSError?) -> Error {
3332
if let error = error {
@@ -36,7 +35,6 @@ func _convertNSErrorToError(_ error: NSError?) -> Error {
3635
return _nilObjCError
3736
}
3837

39-
@_silgen_name("swift_convertErrorToNSError")
4038
public // COMPILER_INTRINSIC
4139
func _convertErrorToNSError(_ error: Error) -> NSError {
4240
return unsafeDowncast(_bridgeErrorToNSError(error), to: NSError.self)
@@ -147,7 +145,7 @@ public extension CustomNSError {
147145

148146
/// The error code within the given domain.
149147
var errorCode: Int {
150-
return _swift_getDefaultErrorCode(self)
148+
return _getDefaultErrorCode(self)
151149
}
152150

153151
/// The default user-info dictionary.
@@ -201,8 +199,7 @@ internal let _errorDomainUserInfoProviderQueue = DispatchQueue(
201199
label: "SwiftFoundation._errorDomainUserInfoProviderQueue")
202200

203201
/// Retrieve the default userInfo dictionary for a given error.
204-
@_silgen_name("swift_Foundation_getErrorDefaultUserInfo")
205-
public func _swift_Foundation_getErrorDefaultUserInfo<T: Error>(_ error: T)
202+
public func _getErrorDefaultUserInfo<T: Error>(_ error: T)
206203
-> AnyObject? {
207204
let hasUserInfoValueProvider: Bool
208205

@@ -358,8 +355,7 @@ public protocol _ObjectiveCBridgeableError : Error {
358355
/// If the bridge succeeds, the bridged value is written to the uninitialized
359356
/// memory pointed to by 'out', and true is returned. Otherwise, 'out' is
360357
/// left uninitialized, and false is returned.
361-
@_silgen_name("swift_stdlib_bridgeNSErrorToError")
362-
public func _stdlib_bridgeNSErrorToError<
358+
public func _bridgeNSErrorToError<
363359
T : _ObjectiveCBridgeableError
364360
>(_ error: NSError, out: UnsafeMutablePointer<T>) -> Bool {
365361
if let bridged = T(_bridgedNSError: error) {

stdlib/public/SDK/Foundation/NSString.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ public class NSSimpleCString {}
2222
@available(*, unavailable, message: "Please use String or NSString")
2323
public class NSConstantString {}
2424

25-
@_silgen_name("swift_convertStringToNSString")
26-
public // COMPILER_INTRINSIC
27-
func _convertStringToNSString(_ string: String) -> NSString {
25+
// Called by the SwiftObject implementation.
26+
public func _convertStringToNSString(_ string: String) -> NSString {
2827
return string._bridgeToObjectiveC()
2928
}
3029

stdlib/public/SDK/Foundation/NSUndoManager.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@
1313
@_exported import Foundation // Clang module
1414
import _SwiftFoundationOverlayShims
1515

16-
@_silgen_name("NS_Swift_NSUndoManager_registerUndoWithTargetHandler")
17-
internal func NS_Swift_NSUndoManager_registerUndoWithTargetHandler(
18-
_ self_: AnyObject,
19-
_ target: AnyObject,
20-
_ handler: @escaping @convention(block) (AnyObject) -> Void)
21-
2216
extension UndoManager {
2317
@available(*, unavailable, renamed: "registerUndo(withTarget:handler:)")
2418
public func registerUndoWithTarget<TargetType : AnyObject>(_ target: TargetType, handler: (TargetType) -> Void) {

stdlib/public/SwiftShims/Visibility.h

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,33 @@
109109
#define SWIFT_RUNTIME_EXPORT SWIFT_EXPORT_ATTRIBUTE
110110
#endif
111111

112-
/// Attribute for runtime-stdlib SPI interfaces.
112+
113+
/// Attributes for runtime-stdlib interfaces.
114+
/// Use these for C implementations that are imported into Swift via SwiftShims
115+
/// and for C implementations of Swift @_silgen_name declarations
116+
/// Note that @_silgen_name implementations must also be marked SWIFT_CC(swift).
117+
///
118+
/// SWIFT_RUNTIME_STDLIB_API functions are called by compiler-generated code
119+
/// or by @_inlineable Swift code.
120+
/// Such functions must be exported and must be supported forever as API.
121+
/// The function name should be prefixed with `swift_`.
122+
///
123+
/// SWIFT_RUNTIME_STDLIB_SPI functions are called by overlay code.
124+
/// Such functions must be exported, but are still SPI
125+
/// and may be changed at any time.
126+
/// The function name should be prefixed with `_swift_`.
113127
///
114-
/// Since the stdlib is currently fully fragile, runtime-stdlib SPI currently
115-
/// needs to be exported from the core dylib. When the stdlib admits more
116-
/// resilience we may be able to make this hidden.
117-
#define SWIFT_RUNTIME_STDLIB_INTERFACE SWIFT_RUNTIME_EXPORT
128+
/// SWIFT_RUNTIME_STDLIB_INTERNAL functions are called only by the stdlib.
129+
/// Such functions are internal and are not exported.
130+
/// FIXME(sil-serialize-all): _INTERNAL functions are also exported for now
131+
/// until the tide of @_inlineable is rolled back.
132+
/// They really should be LLVM_LIBRARY_VISIBILITY, not SWIFT_RUNTIME_EXPORT.
133+
#define SWIFT_RUNTIME_STDLIB_API SWIFT_RUNTIME_EXPORT
134+
#define SWIFT_RUNTIME_STDLIB_SPI SWIFT_RUNTIME_EXPORT
135+
#define SWIFT_RUNTIME_STDLIB_INTERNAL SWIFT_RUNTIME_EXPORT
136+
137+
/// Old marker for runtime-stdlib interfaces. This marker will go away soon.
138+
#define SWIFT_RUNTIME_STDLIB_INTERFACE SWIFT_RUNTIME_STDLIB_API
118139

119140
// SWIFT_STDLIB_SHIMS_VISIBILITY_H
120141
#endif

0 commit comments

Comments
 (0)