mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Revert "[cxx-interop][SwiftCompilerSources] Use C++ enums directly from Swift"
This commit is contained in:
@@ -134,7 +134,7 @@ struct FunctionUses {
|
||||
|
||||
for witnessTable in context.witnessTables {
|
||||
for entry in witnessTable.entries {
|
||||
if entry.kind == .Method, let f = entry.methodFunction {
|
||||
if entry.kind == .method, let f = entry.methodFunction {
|
||||
markUnknown(f)
|
||||
}
|
||||
}
|
||||
@@ -142,7 +142,7 @@ struct FunctionUses {
|
||||
|
||||
for witnessTable in context.defaultWitnessTables {
|
||||
for entry in witnessTable.entries {
|
||||
if entry.kind == .Method, let f = entry.methodFunction {
|
||||
if entry.kind == .method, let f = entry.methodFunction {
|
||||
markUnknown(f)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ private struct StackProtectionOptimization {
|
||||
mustFixStackNesting: inout Bool, _ context: PassContext) {
|
||||
|
||||
// `withUnsafeTemporaryAllocation(of:capacity:_:)` is compiled to a `builtin "stackAlloc"`.
|
||||
if let bi = instruction as? BuiltinInst, bi.id == .StackAlloc {
|
||||
if let bi = instruction as? BuiltinInst, bi.id == .stackAlloc {
|
||||
function.setNeedsStackProtection(context)
|
||||
return
|
||||
}
|
||||
@@ -332,7 +332,7 @@ private struct StackProtectionOptimization {
|
||||
/// Moves the value of a `beginAccess` to a temporary stack location, if possible.
|
||||
private func moveToTemporary(scope beginAccess: BeginAccessInst, mustFixStackNesting: inout Bool,
|
||||
_ context: PassContext) {
|
||||
if beginAccess.accessKind != .Modify {
|
||||
if beginAccess.accessKind != .modify {
|
||||
// We can only move from a `modify` access.
|
||||
// Also, read-only accesses shouldn't be subject to buffer overflows (because
|
||||
// no one should ever write to such a storage).
|
||||
|
||||
@@ -422,7 +422,7 @@ fileprivate struct EscapeWalker<V: EscapeVisitor> : ValueDefUseWalker,
|
||||
return walkDownUses(ofAddress: pta, path: path.with(knownType: nil))
|
||||
case let bi as BuiltinInst:
|
||||
switch bi.id {
|
||||
case .DestroyArray:
|
||||
case .destroyArray:
|
||||
// If it's not the array base pointer operand -> bail. Though, that shouldn't happen
|
||||
// because the other operands (metatype, count) shouldn't be visited anyway.
|
||||
if operand.index != 1 { return isEscaping }
|
||||
|
||||
@@ -319,10 +319,19 @@ final public class LoadUnownedInst : SingleValueInstruction, UnaryInstruction {}
|
||||
final public class LoadBorrowInst : SingleValueInstruction, UnaryInstruction {}
|
||||
|
||||
final public class BuiltinInst : SingleValueInstruction {
|
||||
public typealias ID = swift.BuiltinValueKind
|
||||
// TODO: find a way to directly reuse the BuiltinValueKind enum
|
||||
public enum ID {
|
||||
case none
|
||||
case destroyArray
|
||||
case stackAlloc
|
||||
}
|
||||
|
||||
public var id: ID {
|
||||
return BuiltinInst_getID(bridged)
|
||||
switch BuiltinInst_getID(bridged) {
|
||||
case DestroyArrayBuiltin: return .destroyArray
|
||||
case StackAllocBuiltin: return .stackAlloc
|
||||
default: return .none
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -533,12 +542,34 @@ final public class BridgeObjectToRefInst : SingleValueInstruction,
|
||||
final public class BridgeObjectToWordInst : SingleValueInstruction,
|
||||
UnaryInstruction {}
|
||||
|
||||
public typealias AccessKind = swift.SILAccessKind
|
||||
public enum AccessKind {
|
||||
case initialize
|
||||
case read
|
||||
case modify
|
||||
case deinitialize
|
||||
}
|
||||
|
||||
extension BridgedAccessKind {
|
||||
var kind: AccessKind {
|
||||
switch self {
|
||||
case AccessKind_Init:
|
||||
return .initialize
|
||||
case AccessKind_Read:
|
||||
return .read
|
||||
case AccessKind_Modify:
|
||||
return .modify
|
||||
case AccessKind_Deinit:
|
||||
return .deinitialize
|
||||
default:
|
||||
fatalError("unsupported access kind")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO: add support for begin_unpaired_access
|
||||
final public class BeginAccessInst : SingleValueInstruction, UnaryInstruction {
|
||||
public var accessKind: AccessKind { BeginAccessInst_getAccessKind(bridged) }
|
||||
public var accessKind: AccessKind { BeginAccessInst_getAccessKind(bridged).kind }
|
||||
}
|
||||
|
||||
public protocol ScopedInstruction {
|
||||
|
||||
@@ -20,14 +20,28 @@ public struct WitnessTable : CustomStringConvertible, CustomReflectable {
|
||||
public struct Entry : CustomStringConvertible, CustomReflectable {
|
||||
fileprivate let bridged: BridgedWitnessTableEntry
|
||||
|
||||
public typealias Kind = swift.SILWitnessTable.WitnessKind
|
||||
public enum Kind {
|
||||
case invalid
|
||||
case method
|
||||
case associatedType
|
||||
case associatedTypeProtocol
|
||||
case baseProtocol
|
||||
}
|
||||
|
||||
public var kind: Kind {
|
||||
return SILWitnessTableEntry_getKind(bridged)
|
||||
switch SILWitnessTableEntry_getKind(bridged) {
|
||||
case SILWitnessTableEntry_Invalid: return .invalid
|
||||
case SILWitnessTableEntry_Method: return .method
|
||||
case SILWitnessTableEntry_AssociatedType: return .associatedType
|
||||
case SILWitnessTableEntry_AssociatedTypeProtocol: return .associatedTypeProtocol
|
||||
case SILWitnessTableEntry_BaseProtocol: return .baseProtocol
|
||||
default:
|
||||
fatalError("unknown witness table kind")
|
||||
}
|
||||
}
|
||||
|
||||
public var methodFunction: Function? {
|
||||
assert(kind == .Method)
|
||||
assert(kind == .method)
|
||||
return SILWitnessTableEntry_getMethodFunction(bridged).function
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,13 @@ SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
|
||||
// Diagnostic Engine
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// TODO: Move this to somewhere common header.
|
||||
#if __has_attribute(enum_extensibility)
|
||||
#define ENUM_EXTENSIBILITY_ATTR(arg) __attribute__((enum_extensibility(arg)))
|
||||
#else
|
||||
#define ENUM_EXTENSIBILITY_ATTR(arg)
|
||||
#endif
|
||||
|
||||
// NOTE: This must be the same underlying value as C++ 'swift::DiagID' defined
|
||||
// in 'DiagnosticList.cpp'.
|
||||
typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedDiagID : uint32_t {
|
||||
|
||||
@@ -187,10 +187,4 @@
|
||||
#define SWIFT_IMPORT_REFERENCE
|
||||
#endif
|
||||
|
||||
#if __has_attribute(enum_extensibility)
|
||||
#define ENUM_EXTENSIBILITY_ATTR(arg) __attribute__((enum_extensibility(arg)))
|
||||
#else
|
||||
#define ENUM_EXTENSIBILITY_ATTR(arg)
|
||||
#endif
|
||||
|
||||
#endif // SWIFT_BASIC_COMPILER_H
|
||||
|
||||
@@ -15,11 +15,8 @@
|
||||
|
||||
#include "swift/Basic/BasicBridging.h"
|
||||
#include "swift/Basic/BridgedSwiftObject.h"
|
||||
#include "swift/AST/Builtins.h"
|
||||
#include "swift/AST/SubstitutionMap.h"
|
||||
#include "swift/SIL/SILInstruction.h"
|
||||
#include "swift/SIL/SILLocation.h"
|
||||
#include "swift/SIL/SILWitnessTable.h"
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <string>
|
||||
@@ -97,6 +94,14 @@ typedef struct {
|
||||
const void * _Nonnull ptr;
|
||||
} BridgedWitnessTableEntry;
|
||||
|
||||
typedef enum {
|
||||
SILWitnessTableEntry_Invalid,
|
||||
SILWitnessTableEntry_Method,
|
||||
SILWitnessTableEntry_AssociatedType,
|
||||
SILWitnessTableEntry_AssociatedTypeProtocol,
|
||||
SILWitnessTableEntry_BaseProtocol
|
||||
} SILWitnessTableEntryKind;
|
||||
|
||||
typedef struct {
|
||||
SwiftObject obj;
|
||||
} BridgedFunction;
|
||||
@@ -170,6 +175,13 @@ typedef enum {
|
||||
MayHaveSideEffectsBehavior
|
||||
} BridgedMemoryBehavior;
|
||||
|
||||
typedef enum {
|
||||
AccessKind_Init,
|
||||
AccessKind_Read,
|
||||
AccessKind_Modify,
|
||||
AccessKind_Deinit
|
||||
} BridgedAccessKind;
|
||||
|
||||
typedef enum {
|
||||
Ownership_Unowned,
|
||||
Ownership_Owned,
|
||||
@@ -191,6 +203,12 @@ typedef enum {
|
||||
|
||||
// AST bridging
|
||||
|
||||
typedef enum {
|
||||
UnknownBuiltin = 0,
|
||||
#define BUILTIN(Id, Name, Attrs) Id##Builtin,
|
||||
#include "swift/AST/Builtins.def"
|
||||
} BridgedBuiltinID;
|
||||
|
||||
struct BridgedEffectInfo {
|
||||
SwiftInt argumentIndex;
|
||||
bool isDerived;
|
||||
@@ -258,7 +276,7 @@ BridgedArrayRef SILWitnessTable_getEntries(BridgedWitnessTable table);
|
||||
std::string SILDefaultWitnessTable_debugDescription(BridgedDefaultWitnessTable table);
|
||||
BridgedArrayRef SILDefaultWitnessTable_getEntries(BridgedDefaultWitnessTable table);
|
||||
std::string SILWitnessTableEntry_debugDescription(BridgedWitnessTableEntry entry);
|
||||
swift::SILWitnessTable::WitnessKind SILWitnessTableEntry_getKind(BridgedWitnessTableEntry entry);
|
||||
SILWitnessTableEntryKind SILWitnessTableEntry_getKind(BridgedWitnessTableEntry entry);
|
||||
OptionalBridgedFunction SILWitnessTableEntry_getMethodFunction(BridgedWitnessTableEntry entry);
|
||||
|
||||
OptionalBridgedBasicBlock SILBasicBlock_next(BridgedBasicBlock block);
|
||||
@@ -334,7 +352,7 @@ BridgedMultiValueResult
|
||||
BridgedArrayRef TermInst_getSuccessors(BridgedInstruction term);
|
||||
|
||||
llvm::StringRef CondFailInst_getMessage(BridgedInstruction cfi);
|
||||
swift::BuiltinValueKind BuiltinInst_getID(BridgedInstruction bi);
|
||||
BridgedBuiltinID BuiltinInst_getID(BridgedInstruction bi);
|
||||
SwiftInt AddressToPointerInst_needsStackProtection(BridgedInstruction atp);
|
||||
SwiftInt IndexAddrInst_needsStackProtection(BridgedInstruction ia);
|
||||
BridgedGlobalVar GlobalAccessInst_getGlobal(BridgedInstruction globalInst);
|
||||
@@ -365,7 +383,7 @@ BridgedBasicBlock BranchInst_getTargetBlock(BridgedInstruction bi);
|
||||
SwiftInt SwitchEnumInst_getNumCases(BridgedInstruction se);
|
||||
SwiftInt SwitchEnumInst_getCaseIndex(BridgedInstruction se, SwiftInt idx);
|
||||
SwiftInt StoreInst_getStoreOwnership(BridgedInstruction store);
|
||||
swift::SILAccessKind BeginAccessInst_getAccessKind(BridgedInstruction beginAccess);
|
||||
BridgedAccessKind BeginAccessInst_getAccessKind(BridgedInstruction beginAccess);
|
||||
SwiftInt CopyAddrInst_isTakeOfSrc(BridgedInstruction copyAddr);
|
||||
SwiftInt CopyAddrInst_isInitializationOfDest(BridgedInstruction copyAddr);
|
||||
void RefCountingInst_setIsAtomic(BridgedInstruction rc, bool isAtomic);
|
||||
|
||||
@@ -90,7 +90,7 @@ public:
|
||||
AssociatedType,
|
||||
AssociatedTypeProtocol,
|
||||
BaseProtocol
|
||||
} ENUM_EXTENSIBILITY_ATTR(open);
|
||||
};
|
||||
|
||||
/// A witness table entry.
|
||||
class Entry {
|
||||
|
||||
@@ -7,17 +7,10 @@ module BasicBridging {
|
||||
}
|
||||
|
||||
module ASTBridging {
|
||||
header "AST/AnyFunctionRef.h"
|
||||
header "AST/ASTBridging.h"
|
||||
header "AST/Builtins.h"
|
||||
header "AST/DiagnosticEngine.h"
|
||||
header "AST/DiagnosticConsumer.h"
|
||||
header "AST/ForeignAsyncConvention.h"
|
||||
header "AST/ForeignErrorConvention.h"
|
||||
header "AST/SubstitutionMap.h"
|
||||
|
||||
textual header "AST/Builtins.def"
|
||||
|
||||
requires cplusplus
|
||||
export *
|
||||
}
|
||||
|
||||
@@ -653,9 +653,19 @@ std::string SILWitnessTableEntry_debugDescription(BridgedWitnessTableEntry entry
|
||||
return str;
|
||||
}
|
||||
|
||||
SILWitnessTable::WitnessKind
|
||||
SILWitnessTableEntry_getKind(BridgedWitnessTableEntry entry) {
|
||||
return castToWitnessTableEntry(entry)->getKind();
|
||||
SILWitnessTableEntryKind SILWitnessTableEntry_getKind(BridgedWitnessTableEntry entry) {
|
||||
switch (castToWitnessTableEntry(entry)->getKind()) {
|
||||
case SILWitnessTable::Invalid:
|
||||
return SILWitnessTableEntry_Invalid;
|
||||
case SILWitnessTable::Method:
|
||||
return SILWitnessTableEntry_Method;
|
||||
case SILWitnessTable::AssociatedType:
|
||||
return SILWitnessTableEntry_AssociatedType;
|
||||
case SILWitnessTable::AssociatedTypeProtocol:
|
||||
return SILWitnessTableEntry_AssociatedTypeProtocol;
|
||||
case SILWitnessTable::BaseProtocol:
|
||||
return SILWitnessTableEntry_BaseProtocol;
|
||||
}
|
||||
}
|
||||
|
||||
OptionalBridgedFunction SILWitnessTableEntry_getMethodFunction(BridgedWitnessTableEntry entry) {
|
||||
@@ -741,8 +751,8 @@ llvm::StringRef CondFailInst_getMessage(BridgedInstruction cfi) {
|
||||
return castToInst<CondFailInst>(cfi)->getMessage();
|
||||
}
|
||||
|
||||
BuiltinValueKind BuiltinInst_getID(BridgedInstruction bi) {
|
||||
return castToInst<BuiltinInst>(bi)->getBuiltinInfo().ID;
|
||||
BridgedBuiltinID BuiltinInst_getID(BridgedInstruction bi) {
|
||||
return (BridgedBuiltinID)castToInst<BuiltinInst>(bi)->getBuiltinInfo().ID;
|
||||
}
|
||||
|
||||
SwiftInt AddressToPointerInst_needsStackProtection(BridgedInstruction atp) {
|
||||
@@ -867,8 +877,18 @@ SwiftInt StoreInst_getStoreOwnership(BridgedInstruction store) {
|
||||
return (SwiftInt)castToInst<StoreInst>(store)->getOwnershipQualifier();
|
||||
}
|
||||
|
||||
SILAccessKind BeginAccessInst_getAccessKind(BridgedInstruction beginAccess) {
|
||||
return castToInst<BeginAccessInst>(beginAccess)->getAccessKind();
|
||||
BridgedAccessKind BeginAccessInst_getAccessKind(BridgedInstruction beginAccess) {
|
||||
auto kind = castToInst<BeginAccessInst>(beginAccess)->getAccessKind();
|
||||
switch (kind) {
|
||||
case SILAccessKind::Init:
|
||||
return BridgedAccessKind::AccessKind_Init;
|
||||
case SILAccessKind::Read:
|
||||
return BridgedAccessKind::AccessKind_Read;
|
||||
case SILAccessKind::Modify:
|
||||
return BridgedAccessKind::AccessKind_Modify;
|
||||
case SILAccessKind::Deinit:
|
||||
return BridgedAccessKind::AccessKind_Deinit;
|
||||
}
|
||||
}
|
||||
|
||||
SwiftInt CopyAddrInst_isTakeOfSrc(BridgedInstruction copyAddr) {
|
||||
|
||||
Reference in New Issue
Block a user