Skip to content

Commit e100449

Browse files
committed
[NFC] Split ProtocolDispatchStrategy out of MetadataValues.h.
This allows us to avoid rebuilding most of the compiler whenever we add a new ABI constant.
1 parent 3972a13 commit e100449

File tree

5 files changed

+65
-30
lines changed

5 files changed

+65
-30
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,3 +630,9 @@ macro(add_swift_tool_symlink name dest component)
630630
add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE)
631631
llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE COMPONENT ${component})
632632
endmacro()
633+
634+
# Declare that files in this library are built with LLVM's support
635+
# libraries available.
636+
macro(set_swift_llvm_is_available)
637+
add_compile_options(-DSWIFT_LLVM_SUPPORT_IS_AVAILABLE)
638+
endmacro()

include/swift/ABI/MetadataValues.h

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
#define SWIFT_ABI_METADATAVALUES_H
2121

2222
#include "swift/ABI/KeyPath.h"
23+
#include "swift/ABI/ProtocolDispatchStrategy.h"
2324
#include "swift/AST/Ownership.h"
2425
#include "swift/Basic/LLVM.h"
2526
#include "swift/Basic/FlagSet.h"
26-
#include "swift/Runtime/Unreachable.h"
2727

2828
#include <stdlib.h>
2929
#include <stdint.h>
@@ -410,20 +410,6 @@ enum class SpecialProtocol: uint8_t {
410410
Error = 1,
411411
};
412412

413-
/// Identifiers for protocol method dispatch strategies.
414-
enum class ProtocolDispatchStrategy: uint8_t {
415-
/// Uses ObjC method dispatch.
416-
///
417-
/// This must be 0 for ABI compatibility with Objective-C protocol_t records.
418-
ObjC = 0,
419-
420-
/// Uses Swift protocol witness table dispatch.
421-
///
422-
/// To invoke methods of this protocol, a pointer to a protocol witness table
423-
/// corresponding to the protocol conformance must be available.
424-
Swift = 1,
425-
};
426-
427413
/// Flags for protocol descriptors.
428414
class ProtocolDescriptorFlags {
429415
typedef uint32_t int_type;
@@ -486,18 +472,7 @@ class ProtocolDescriptorFlags {
486472

487473
/// Does the protocol require a witness table for method dispatch?
488474
bool needsWitnessTable() const {
489-
return needsWitnessTable(getDispatchStrategy());
490-
}
491-
492-
static bool needsWitnessTable(ProtocolDispatchStrategy strategy) {
493-
switch (strategy) {
494-
case ProtocolDispatchStrategy::ObjC:
495-
return false;
496-
case ProtocolDispatchStrategy::Swift:
497-
return true;
498-
}
499-
500-
swift_runtime_unreachable("Unhandled ProtocolDispatchStrategy in switch.");
475+
return swift::protocolRequiresWitnessTable(getDispatchStrategy());
501476
}
502477

503478
/// Return the identifier if this is a special runtime-known protocol.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//===--- ProtocolDispatchStrategy.h - ---------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This header declares the ProtocolDispatchStrategy enum and some
14+
// related operations. It's split out because we would otherwise need
15+
// to include MetadataValues.h in some relatively central headers.s
16+
//
17+
//===----------------------------------------------------------------------===//
18+
19+
#ifndef SWIFT_ABI_PROTOCOLDISPATCHSTRATEGY_H
20+
#define SWIFT_ABI_PROTOCOLDISPATCHSTRATEGY_H
21+
22+
#include "swift/Runtime/Unreachable.h"
23+
24+
namespace swift {
25+
26+
/// Identifiers for protocol method dispatch strategies.
27+
enum class ProtocolDispatchStrategy: uint8_t {
28+
/// Uses ObjC method dispatch.
29+
///
30+
/// This must be 0 for ABI compatibility with Objective-C protocol_t records.
31+
ObjC = 0,
32+
33+
/// Uses Swift protocol witness table dispatch.
34+
///
35+
/// To invoke methods of this protocol, a pointer to a protocol witness table
36+
/// corresponding to the protocol conformance must be available.
37+
Swift = 1,
38+
};
39+
40+
/// Does a protocol using the given strategy require a witness table?
41+
inline bool protocolRequiresWitnessTable(ProtocolDispatchStrategy strategy) {
42+
switch (strategy) {
43+
case ProtocolDispatchStrategy::ObjC:
44+
return false;
45+
case ProtocolDispatchStrategy::Swift:
46+
return true;
47+
}
48+
49+
swift_runtime_unreachable("Unhandled ProtocolDispatchStrategy in switch.");
50+
}
51+
52+
}
53+
54+
#endif

include/swift/SIL/TypeLowering.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#ifndef SWIFT_SIL_TYPELOWERING_H
1414
#define SWIFT_SIL_TYPELOWERING_H
1515

16-
#include "swift/ABI/MetadataValues.h"
16+
#include "swift/ABI/ProtocolDispatchStrategy.h"
1717
#include "swift/AST/CaptureInfo.h"
1818
#include "swift/AST/Module.h"
1919
#include "swift/SIL/AbstractionPattern.h"
@@ -792,8 +792,7 @@ class TypeConverter {
792792

793793
/// True if a protocol uses witness tables for dynamic dispatch.
794794
static bool protocolRequiresWitnessTable(ProtocolDecl *P) {
795-
return ProtocolDescriptorFlags::needsWitnessTable
796-
(getProtocolDispatchStrategy(P));
795+
return swift::protocolRequiresWitnessTable(getProtocolDispatchStrategy(P));
797796
}
798797

799798
/// True if a type is passed indirectly at +0 when used as the "self"

lib/IRGen/IRGen.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#define DEBUG_TYPE "irgen"
1818
#include "IRGenModule.h"
19+
#include "swift/ABI/MetadataValues.h"
1920
#include "swift/AST/DiagnosticsIRGen.h"
2021
#include "swift/AST/IRGenOptions.h"
2122
#include "swift/AST/IRGenRequests.h"

0 commit comments

Comments
 (0)