mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Add a distinct hook for `swift_willThrowTypedImpl()`. This PR adds a hook for `swift_willThrowTypedImpl()` that is distinct from `swift_willThrow()`. The current implementation of `swift_willThrowTypedImpl()` creates a temporary existential box for the thrown error and calls the `_swift_willThrow` hook that is set by XCTest and swift-testing. Unfortunately, this temporary existential box isn't very useful because its address is not expected to be stable. Instead, expose a separate hook, `_swift_willThrowTypedImpl`, whose signature matches that of the new ABI function. This hook can then be used by XCTest and swift-testing to distinguish between typed throws and untyped throws and avoids creating a temporary existential box when it won't be useful. As implemented, if `_swift_willThrowTypedImpl` is not set but `_swift_willThrow` is, the `swift_willThrowTypedImpl()` will fall back to calling `_swift_willThrow` with a temporary existential box. We might decide this is unnecessary, but I figured it would allow us more time to stage adoption of the new hook in the testing libraries. Resolves rdar://122824443.
42 lines
1.3 KiB
C++
42 lines
1.3 KiB
C++
//===--- ErrorObjectTestSupport.h - Support for Instruments.app -*- C++ -*-===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Swift runtime support for tests involving errors.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SWIFT_RUNTIME_ERROROBJECT_TEST_SUPPORT_H
|
|
#define SWIFT_RUNTIME_ERROROBJECT_TEST_SUPPORT_H
|
|
|
|
#include <atomic>
|
|
|
|
namespace swift {
|
|
|
|
#if defined(__cplusplus)
|
|
SWIFT_RUNTIME_EXPORT std::atomic<void (*)(SwiftError *error)> _swift_willThrow;
|
|
SWIFT_RUNTIME_EXPORT std::atomic<void (*)(
|
|
OpaqueValue *value,
|
|
const Metadata *type,
|
|
const WitnessTable *errorConformance
|
|
)> _swift_willThrowTypedImpl;
|
|
#endif
|
|
|
|
/// Set the value of @c _swift_willThrow atomically.
|
|
///
|
|
/// This function is present for use by the standard library's test suite only.
|
|
SWIFT_CC(swift)
|
|
SWIFT_RUNTIME_STDLIB_SPI
|
|
void _swift_setWillThrowHandler(void (* handler)(SwiftError *error));
|
|
}
|
|
|
|
#endif
|