Skip to content

Commit 0fb4079

Browse files
committed
[NFC] Rename swift_runtime_unreachable to swift_unreachable and make it use LLVM's support when available.
1 parent 66a42d8 commit 0fb4079

38 files changed

+112
-73
lines changed

include/swift/ABI/Metadata.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#include "swift/Basic/RelativePointer.h"
3939
#include "swift/Demangling/Demangle.h"
4040
#include "swift/Demangling/ManglingMacros.h"
41-
#include "swift/Runtime/Unreachable.h"
41+
#include "swift/Basic/Unreachable.h"
4242
#include "../../../stdlib/public/SwiftShims/HeapObject.h"
4343
#if SWIFT_OBJC_INTEROP
4444
#include <objc/runtime.h>
@@ -4664,7 +4664,7 @@ int32_t TargetTypeContextDescriptor<Runtime>::getGenericArgumentOffset() const {
46644664
return llvm::cast<TargetStructDescriptor<Runtime>>(this)
46654665
->getGenericArgumentOffset();
46664666
default:
4667-
swift_runtime_unreachable("Not a type context descriptor.");
4667+
swift_unreachable("Not a type context descriptor.");
46684668
}
46694669
}
46704670

@@ -4682,7 +4682,7 @@ TargetTypeContextDescriptor<Runtime>::getFullGenericContextHeader() const {
46824682
return llvm::cast<TargetStructDescriptor<Runtime>>(this)
46834683
->getFullGenericContextHeader();
46844684
default:
4685-
swift_runtime_unreachable("Not a type context descriptor.");
4685+
swift_unreachable("Not a type context descriptor.");
46864686
}
46874687
}
46884688

@@ -4699,7 +4699,7 @@ TargetTypeContextDescriptor<Runtime>::getGenericParams() const {
46994699
case ContextDescriptorKind::OpaqueType:
47004700
return llvm::cast<TargetOpaqueTypeDescriptor<Runtime>>(this)->getGenericParams();
47014701
default:
4702-
swift_runtime_unreachable("Not a type context descriptor.");
4702+
swift_unreachable("Not a type context descriptor.");
47034703
}
47044704
}
47054705

@@ -4717,7 +4717,7 @@ TargetTypeContextDescriptor<Runtime>::getForeignMetadataInitialization() const {
47174717
return llvm::cast<TargetStructDescriptor<Runtime>>(this)
47184718
->getForeignMetadataInitialization();
47194719
default:
4720-
swift_runtime_unreachable("Not a type context descriptor.");
4720+
swift_unreachable("Not a type context descriptor.");
47214721
}
47224722
}
47234723

@@ -4735,7 +4735,7 @@ TargetTypeContextDescriptor<Runtime>::getSingletonMetadataInitialization() const
47354735
return llvm::cast<TargetClassDescriptor<Runtime>>(this)
47364736
->getSingletonMetadataInitialization();
47374737
default:
4738-
swift_runtime_unreachable("Not a enum, struct or class type descriptor.");
4738+
swift_unreachable("Not a enum, struct or class type descriptor.");
47394739
}
47404740
}
47414741

@@ -4753,7 +4753,7 @@ TargetTypeContextDescriptor<Runtime>::getCanonicicalMetadataPrespecializations()
47534753
return llvm::cast<TargetClassDescriptor<Runtime>>(this)
47544754
->getCanonicicalMetadataPrespecializations();
47554755
default:
4756-
swift_runtime_unreachable("Not a type context descriptor.");
4756+
swift_unreachable("Not a type context descriptor.");
47574757
}
47584758
}
47594759

include/swift/ABI/ProtocolDispatchStrategy.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#ifndef SWIFT_ABI_PROTOCOLDISPATCHSTRATEGY_H
2020
#define SWIFT_ABI_PROTOCOLDISPATCHSTRATEGY_H
2121

22-
#include "swift/Runtime/Unreachable.h"
22+
#include "swift/Basic/Unreachable.h"
2323

2424
namespace swift {
2525

@@ -46,7 +46,7 @@ inline bool protocolRequiresWitnessTable(ProtocolDispatchStrategy strategy) {
4646
return true;
4747
}
4848

49-
swift_runtime_unreachable("Unhandled ProtocolDispatchStrategy in switch.");
49+
swift_unreachable("Unhandled ProtocolDispatchStrategy in switch.");
5050
}
5151

5252
}
Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- Unreachable.h - Implements swift_runtime_unreachable ---*- C++ -*-===//
1+
//===--- Unreachable.h - Implements swift_unreachable ---*- C++ -*-===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -10,24 +10,38 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212
//
13-
// This file defines swift_runtime_unreachable, an LLVM-independent
14-
// implementation of llvm_unreachable.
13+
// This file defines swift_unreachable, which provides the
14+
// functionality of llvm_unreachable without necessarily depending on
15+
// the LLVM support libraries.
1516
//
1617
//===----------------------------------------------------------------------===//
1718

18-
#ifndef SWIFT_RUNTIME_UNREACHABLE_H
19-
#define SWIFT_RUNTIME_UNREACHABLE_H
19+
#ifndef SWIFT_BASIC_UNREACHABLE_H
20+
#define SWIFT_BASIC_UNREACHABLE_H
21+
22+
#ifdef SWIFT_LLVM_SUPPORT_IS_AVAILABLE
23+
24+
// The implementation when LLVM is available.
25+
26+
#include "llvm/Support/ErrorHandling.h"
27+
#define swift_unreachable llvm_unreachable
28+
29+
#else
30+
31+
// The implementation when LLVM is not available.
2032

2133
#include <assert.h>
2234
#include <stdlib.h>
2335

2436
#include "swift/Runtime/Config.h"
2537

2638
SWIFT_RUNTIME_ATTRIBUTE_NORETURN
27-
inline static void swift_runtime_unreachable(const char *msg) {
39+
inline static void swift_unreachable(const char *msg) {
2840
assert(false && msg);
2941
(void)msg;
3042
abort();
3143
}
3244

33-
#endif // SWIFT_RUNTIME_UNREACHABLE_H
45+
#endif
46+
47+
#endif

include/swift/Demangling/TypeDecoder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include "swift/Demangling/Demangler.h"
2525
#include "swift/Demangling/NamespaceMacros.h"
2626
#include "swift/Runtime/Portability.h"
27-
#include "swift/Runtime/Unreachable.h"
27+
#include "swift/Basic/Unreachable.h"
2828
#include "swift/Strings.h"
2929
#include "llvm/ADT/ArrayRef.h"
3030
#include <vector>

include/swift/Reflection/ReflectionContext.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include "swift/Reflection/TypeLowering.h"
3434
#include "swift/Reflection/TypeRef.h"
3535
#include "swift/Reflection/TypeRefBuilder.h"
36-
#include "swift/Runtime/Unreachable.h"
36+
#include "swift/Basic/Unreachable.h"
3737

3838
#include <set>
3939
#include <unordered_map>
@@ -1302,7 +1302,7 @@ class ReflectionContext
13021302
return true;
13031303
}
13041304

1305-
swift_runtime_unreachable("Unhandled MetadataSourceKind in switch.");
1305+
swift_unreachable("Unhandled MetadataSourceKind in switch.");
13061306
}
13071307

13081308
/// Read metadata for a captured generic type from a closure context.

include/swift/Reflection/TypeRef.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "llvm/Support/Casting.h"
2323
#include "swift/ABI/MetadataValues.h"
2424
#include "swift/Remote/MetadataReader.h"
25-
#include "swift/Runtime/Unreachable.h"
25+
#include "swift/Basic/Unreachable.h"
2626

2727
namespace swift {
2828
namespace reflection {
@@ -856,7 +856,7 @@ class TypeRefVisitor {
856856
#include "swift/Reflection/TypeRefs.def"
857857
}
858858

859-
swift_runtime_unreachable("Unhandled TypeRefKind in switch.");
859+
swift_unreachable("Unhandled TypeRefKind in switch.");
860860
}
861861
};
862862

include/swift/Remote/MetadataReader.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include "swift/ABI/TypeIdentity.h"
2929
#include "swift/Runtime/ExistentialContainer.h"
3030
#include "swift/Runtime/HeapObject.h"
31-
#include "swift/Runtime/Unreachable.h"
31+
#include "swift/Basic/Unreachable.h"
3232

3333
#include <vector>
3434
#include <unordered_map>
@@ -923,7 +923,7 @@ class MetadataReader {
923923
}
924924
}
925925

926-
swift_runtime_unreachable("Unhandled MetadataKind in switch");
926+
swift_unreachable("Unhandled MetadataKind in switch");
927927
}
928928

929929
TypeLookupErrorOr<typename BuilderType::BuiltType>
@@ -1295,7 +1295,7 @@ class MetadataReader {
12951295
}
12961296
}
12971297

1298-
swift_runtime_unreachable("Unhandled IsaEncodingKind in switch.");
1298+
swift_unreachable("Unhandled IsaEncodingKind in switch.");
12991299
}
13001300

13011301
/// Read the offset of the generic parameters of a class from the nominal

include/swift/Runtime/Debug.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#define SWIFT_RUNTIME_DEBUG_HELPERS_H
1919

2020
#include "swift/Runtime/Config.h"
21-
#include "swift/Runtime/Unreachable.h"
21+
#include "swift/Basic/Unreachable.h"
2222
#include <atomic>
2323
#include <cstdarg>
2424
#include <functional>
@@ -79,7 +79,7 @@ static inline void crash(const char *message) {
7979
CRSetCrashLogMessage(message);
8080

8181
SWIFT_RUNTIME_BUILTIN_TRAP;
82-
swift_runtime_unreachable("Expected compiler to crash.");
82+
swift_unreachable("Expected compiler to crash.");
8383
}
8484

8585
// swift::fatalError() halts with a crash log message,

lib/AST/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ else()
99
)
1010
endif()
1111

12+
set_swift_llvm_is_available()
13+
1214
add_swift_host_library(swiftAST STATIC
1315
AbstractSourceFileDepGraphFactory.cpp
1416
AccessRequests.cpp

lib/ASTSectionImporter/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
set_swift_llvm_is_available()
2+
13
add_swift_host_library(swiftASTSectionImporter STATIC
24
ASTSectionImporter.cpp
35
LLVM_LINK_COMPONENTS core)

lib/ClangImporter/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ set(SWIFT_GYB_FLAGS
44
add_gyb_target(generated_sorted_cf_database
55
SortedCFDatabase.def.gyb)
66

7+
set_swift_llvm_is_available()
8+
79
add_swift_host_library(swiftClangImporter STATIC
810
CFTypeInfo.cpp
911
ClangAdapter.cpp

lib/Driver/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
set_swift_llvm_is_available()
2+
13
set(swiftDriver_sources
24
Action.cpp
35
Compilation.cpp

lib/Frontend/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
set_swift_llvm_is_available()
12
add_swift_host_library(swiftFrontend STATIC
23
ArgsToFrontendInputsConverter.cpp
34
ArgsToFrontendOptionsConverter.cpp

lib/FrontendTool/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
set_swift_llvm_is_available()
12
add_swift_host_library(swiftFrontendTool STATIC
23
FrontendTool.cpp
34
ImportedModules.cpp

lib/IDE/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
set_swift_llvm_is_available()
12
add_swift_host_library(swiftIDE STATIC
23
CodeCompletion.cpp
34
CodeCompletionCache.cpp

lib/IRGen/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
set_swift_llvm_is_available()
12
add_swift_host_library(swiftIRGen STATIC
23
AllocStackHoisting.cpp
34
ClassLayout.cpp

lib/LLVMPasses/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
set_swift_llvm_is_available()
12
add_swift_host_library(swiftLLVMPasses STATIC
23
LLVMSwiftAA.cpp
34
LLVMSwiftRCIdentity.cpp

lib/Migrator/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ swift_install_in_component(FILES ${datafiles}
4747
DESTINATION "lib/swift/migrator"
4848
COMPONENT compiler)
4949

50+
set_swift_llvm_is_available()
51+
5052
add_swift_host_library(swiftMigrator STATIC
5153
APIDiffMigratorPass.cpp
5254
EditorAdapter.cpp

lib/Parse/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
set_swift_llvm_is_available()
2+
13
if(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
24
set(SWIFT_GYB_FLAGS --line-directive "^\"#line %(line)d \\\"%(file)s\\\"^\"")
35
else()

lib/PrintAsObjC/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
set_swift_llvm_is_available()
12
add_swift_host_library(swiftPrintAsObjC STATIC
23
DeclAndTypePrinter.cpp
34
ModuleContentsWriter.cpp

lib/SIL/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
set_swift_llvm_is_available()
12
add_swift_host_library(swiftSIL STATIC
23
SIL.cpp)
34
target_link_libraries(swiftSIL PUBLIC

lib/SILGen/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
set_swift_llvm_is_available()
12
add_swift_host_library(swiftSILGen STATIC
23
ArgumentSource.cpp
34
Cleanup.cpp

lib/SILOptimizer/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
set_swift_llvm_is_available()
12
add_swift_host_library(swiftSILOptimizer STATIC
23
SILOptimizer.cpp)
34
target_link_libraries(swiftSILOptimizer PRIVATE

lib/Sema/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
set_swift_llvm_is_available()
12
add_swift_host_library(swiftSema STATIC
23
BuilderTransform.cpp
34
CSApply.cpp

lib/Serialization/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
set_swift_llvm_is_available()
12
add_swift_host_library(swiftSerialization STATIC
23
Deserialization.cpp
34
DeserializeSIL.cpp

lib/SyntaxParse/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
set_swift_llvm_is_available()
12
add_swift_host_library(swiftSyntaxParse STATIC
23
RawSyntaxTokenCache.cpp
34
SyntaxTreeCreator.cpp)

lib/TBDGen/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
set_swift_llvm_is_available()
12
add_swift_host_library(swiftTBDGen STATIC
23
TBDGen.cpp
34
TBDGenRequests.cpp

stdlib/public/Reflection/TypeLowering.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "swift/Reflection/TypeLowering.h"
2424
#include "swift/Reflection/TypeRef.h"
2525
#include "swift/Reflection/TypeRefBuilder.h"
26-
#include "swift/Runtime/Unreachable.h"
26+
#include "swift/Basic/Unreachable.h"
2727

2828
#ifdef DEBUG_TYPE_LOWERING
2929
#define DEBUG_LOG(expr) expr;
@@ -212,7 +212,7 @@ class PrintTypeInfo {
212212
}
213213
}
214214

215-
swift_runtime_unreachable("Bad TypeInfo kind");
215+
swift_unreachable("Bad TypeInfo kind");
216216
}
217217
};
218218

@@ -2007,7 +2007,7 @@ class LowerType
20072007
return nullptr;
20082008
}
20092009

2010-
swift_runtime_unreachable("Unhandled FieldDescriptorKind in switch.");
2010+
swift_unreachable("Unhandled FieldDescriptorKind in switch.");
20112011
}
20122012

20132013
const TypeInfo *visitNominalTypeRef(const NominalTypeRef *N) {
@@ -2039,7 +2039,7 @@ class LowerType
20392039
return TC.getTypeInfo(TC.getThinFunctionTypeRef(), ExternalTypeInfo);
20402040
}
20412041

2042-
swift_runtime_unreachable("Unhandled FunctionMetadataConvention in switch.");
2042+
swift_unreachable("Unhandled FunctionMetadataConvention in switch.");
20432043
}
20442044

20452045
const TypeInfo *
@@ -2060,7 +2060,7 @@ class LowerType
20602060
return TC.getTypeInfo(TC.getAnyMetatypeTypeRef(), ExternalTypeInfo);
20612061
}
20622062

2063-
swift_runtime_unreachable("Unhandled MetatypeRepresentation in switch.");
2063+
swift_unreachable("Unhandled MetatypeRepresentation in switch.");
20642064
}
20652065

20662066
const TypeInfo *
@@ -2256,7 +2256,7 @@ const TypeInfo *TypeConverter::getClassInstanceTypeInfo(
22562256
return nullptr;
22572257
}
22582258

2259-
swift_runtime_unreachable("Unhandled FieldDescriptorKind in switch.");
2259+
swift_unreachable("Unhandled FieldDescriptorKind in switch.");
22602260
}
22612261

22622262
} // namespace reflection

0 commit comments

Comments
 (0)