Files
swift-mirror/stdlib/core/AssertCommon.swift
Arnold Schwaighofer ddb874e045 Rename _isDebug and friends to _isDebugAssertConfiguration
Really we want those nullary functions be computed properties using enums.

  var _assertConfiguration : _AssertConfiguration {
    let assertConfig = Int32(Builtin.assert_configuration())
    if assertConfig == 0 {
      return .Debug
    }
    if assertConfig == 1 {
      return .Release
    }
    return .Fast
  }

  if _assertConfiguration == .Debug {
    _fatal_error_message("assertion failed", message, file, line)
  }

In my tests the enums were not optimized away. So for the short term leave
these functions as nullary functions.

Swift SVN r18211
2014-05-16 20:49:50 +00:00

87 lines
2.9 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
func _isDebugAssertConfiguration() -> Bool {
// The values for the assert_configuration call are:
// 0 .. Debug
// 1 .. Release
// 2 .. Fast
return Int32(Builtin.assert_configuration()) == 0;
}
@transparent
func _isReleaseAssertConfiguration() -> Bool {
// The values for the assert_configuration call are:
// 0 .. Debug
// 1 .. Release
// 2 .. Fast
return Int32(Builtin.assert_configuration()) == 1;
}
@transparent
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_reportFatalError")
func _reportFatalError(
header: Builtin.RawPointer, headerLength: Builtin.Word,
message: Builtin.RawPointer, messageLength: Builtin.Word,
file: Builtin.RawPointer, fileLength: Builtin.Word,
line: UWord)
@asmname("swift_reportUnimplementedInitializer")
func _reportUnimplementedInitializer(
className: Builtin.RawPointer, classNameLength: Builtin.Word,
file: Builtin.RawPointer, fileLength: Builtin.Word,
line: UWord, column: UWord,
initName: Builtin.RawPointer, initNameLength: Builtin.Word)
@noreturn
func _fatal_error_message(header: StaticString, message: StaticString,
file: StaticString, line: UWord)
{
_reportFatalError(header.start, header.byteSize,
message.start, message.byteSize,
file.start, file.byteSize, line)
Builtin.int_trap()
}
/// Prints a fatal error message when a unimplemented initializer gets
/// called by the Objective-C runtime.
@noreturn
func _unimplemented_initializer(className: StaticString,
file: StaticString = __FILE__,
line: UWord = __LINE__,
column: UWord = __LINE__,
initName: StaticString = __FUNCTION__)
{
_reportUnimplementedInitializer(className.start, className.byteSize,
file.start, file.byteSize, line, column,
initName.start, initName.byteSize)
Builtin.int_trap()
}