mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Keep calm: remember that the standard library has many more public exports than the average target, and that this contains ALL of them at once. I also deliberately tried to tag nearly every top-level decl, even if that was just to explicitly mark things @internal, to make sure I didn't miss something. This does export more than we might want to, mostly for protocol conformance reasons, along with our simple-but-limiting typealias rule. I tried to also mark things private where possible, but it's really going to be up to the standard library owners to get this right. This is also only validated against top-level access control; I haven't fully tested against member-level access control yet, and none of our semantic restrictions are in place. Along the way I also noticed bits of stdlib cruft; to keep this patch understandable, I didn't change any of them. Swift SVN r19145
126 lines
4.4 KiB
Swift
126 lines
4.4 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See http://swift.org/LICENSE.txt for license information
|
|
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Implementation Note: this file intentionally uses very LOW-LEVEL
|
|
// CONSTRUCTS, so that assert and fatal may be used liberally in
|
|
// building library abstractions without fear of infinite recursion.
|
|
//
|
|
// FIXME: We could go farther with this simplification, e.g. avoiding
|
|
// UnsafePointer
|
|
|
|
@transparent @internal
|
|
func _isDebugAssertConfiguration() -> Bool {
|
|
// The values for the assert_configuration call are:
|
|
// 0: Debug
|
|
// 1: Release
|
|
// 2: Fast
|
|
return Int32(Builtin.assert_configuration()) == 0;
|
|
}
|
|
|
|
@transparent @internal
|
|
func _isReleaseAssertConfiguration() -> Bool {
|
|
// The values for the assert_configuration call are:
|
|
// 0: Debug
|
|
// 1: Release
|
|
// 2: Fast
|
|
return Int32(Builtin.assert_configuration()) == 1;
|
|
}
|
|
|
|
@transparent @internal
|
|
func _isFastAssertConfiguration() -> Bool {
|
|
// The values for the assert_configuration call are:
|
|
// 0: Debug
|
|
// 1: Release
|
|
// 2: Fast
|
|
return Int32(Builtin.assert_configuration()) == 2;
|
|
}
|
|
|
|
@asmname("swift_reportFatalErrorInFile")
|
|
func _reportFatalErrorInFile(
|
|
prefix: Builtin.RawPointer, prefixLength: Builtin.Word,
|
|
message: Builtin.RawPointer, messageLength: Builtin.Word,
|
|
file: Builtin.RawPointer, fileLength: Builtin.Word,
|
|
line: UWord)
|
|
|
|
@asmname("swift_reportFatalError")
|
|
func _reportFatalError(
|
|
prefix: Builtin.RawPointer, prefixLength: Builtin.Word,
|
|
message: Builtin.RawPointer, messageLength: Builtin.Word)
|
|
|
|
@asmname("swift_reportUnimplementedInitializerInFile")
|
|
func _reportUnimplementedInitializerInFile(
|
|
className: Builtin.RawPointer, classNameLength: Builtin.Word,
|
|
initName: Builtin.RawPointer, initNameLength: Builtin.Word,
|
|
file: Builtin.RawPointer, fileLength: Builtin.Word,
|
|
line: UWord, column: UWord)
|
|
|
|
@asmname("swift_reportUnimplementedInitializer")
|
|
func _reportUnimplementedInitializer(
|
|
className: Builtin.RawPointer, classNameLength: Builtin.Word,
|
|
initName: Builtin.RawPointer, initNameLength: Builtin.Word)
|
|
|
|
/// This function should be used only in the implementation of user-level
|
|
/// assertions.
|
|
@noreturn @internal
|
|
func _assertionFailed(prefix: StaticString, message: StaticString,
|
|
file: StaticString, line: UWord) {
|
|
_reportFatalErrorInFile(
|
|
prefix.start, prefix.byteSize, message.start, message.byteSize,
|
|
file.start, file.byteSize, line)
|
|
|
|
Builtin.int_trap()
|
|
}
|
|
|
|
/// This function should be used only in the implementation of stdlib
|
|
/// assertions.
|
|
@transparent @noreturn @internal
|
|
func _fatalErrorMessage(prefix: StaticString, message: StaticString,
|
|
file: StaticString, line: UWord) {
|
|
#if INTERNAL_CHECKS_ENABLED
|
|
_reportFatalErrorInFile(
|
|
prefix.start, prefix.byteSize, message.start, message.byteSize,
|
|
file.start, file.byteSize, line)
|
|
#else
|
|
_reportFatalError(prefix.start, prefix.byteSize,
|
|
message.start, message.byteSize)
|
|
#endif
|
|
|
|
Builtin.int_trap()
|
|
}
|
|
|
|
/// Prints a fatal error message when a unimplemented initializer gets
|
|
/// called by the Objective-C runtime.
|
|
@transparent @noreturn @internal
|
|
func _unimplemented_initializer(className: StaticString,
|
|
initName: StaticString = __FUNCTION__,
|
|
file: StaticString = __FILE__,
|
|
line: UWord = __LINE__,
|
|
column: UWord = __COLUMN__) {
|
|
// This function is marked @transparent so that it is inlined into the caller
|
|
// (the initializer stub), and, depending on the build configuration,
|
|
// redundant parameter values (__FILE__ etc.) are eliminated, and don't leak
|
|
// information about the user's source.
|
|
|
|
if _isDebugAssertConfiguration() {
|
|
_reportUnimplementedInitializerInFile(
|
|
className.start, className.byteSize,
|
|
initName.start, initName.byteSize,
|
|
file.start, file.byteSize, line, column)
|
|
} else {
|
|
_reportUnimplementedInitializer(
|
|
className.start, className.byteSize,
|
|
initName.start, initName.byteSize)
|
|
}
|
|
|
|
Builtin.int_trap()
|
|
}
|