Revert [cxx-interop][libswift] Use std::string instead of BridgedStringRef

This causes problem with the Windows build and also causes a deserialization crash on Linux.
This commit is contained in:
Erik Eckstein
2021-12-17 13:45:46 +01:00
parent 1647cdd04c
commit 2900dec755
7 changed files with 26 additions and 31 deletions

View File

@@ -15,7 +15,10 @@
#include "BridgedSwiftObject.h" #include "BridgedSwiftObject.h"
#include <stddef.h> #include <stddef.h>
#include <string>
#ifdef __cplusplus
extern "C" {
#endif
SWIFT_BEGIN_NULLABILITY_ANNOTATIONS SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
@@ -161,19 +164,19 @@ BridgedSlab PassContext_freeSlab(BridgedPassContext passContext,
BridgedSlab slab); BridgedSlab slab);
BridgedStringRef SILFunction_getName(BridgedFunction function); BridgedStringRef SILFunction_getName(BridgedFunction function);
std::string SILFunction_debugDescription(BridgedFunction function); BridgedStringRef SILFunction_debugDescription(BridgedFunction function);
OptionalBridgedBasicBlock SILFunction_firstBlock(BridgedFunction function); OptionalBridgedBasicBlock SILFunction_firstBlock(BridgedFunction function);
OptionalBridgedBasicBlock SILFunction_lastBlock(BridgedFunction function); OptionalBridgedBasicBlock SILFunction_lastBlock(BridgedFunction function);
SwiftInt SILFunction_numIndirectResultArguments(BridgedFunction function); SwiftInt SILFunction_numIndirectResultArguments(BridgedFunction function);
SwiftInt SILFunction_getSelfArgumentIndex(BridgedFunction function); SwiftInt SILFunction_getSelfArgumentIndex(BridgedFunction function);
BridgedStringRef SILGlobalVariable_getName(BridgedGlobalVar global); BridgedStringRef SILGlobalVariable_getName(BridgedGlobalVar global);
std::string SILGlobalVariable_debugDescription(BridgedGlobalVar global); BridgedStringRef SILGlobalVariable_debugDescription(BridgedGlobalVar global);
OptionalBridgedBasicBlock SILBasicBlock_next(BridgedBasicBlock block); OptionalBridgedBasicBlock SILBasicBlock_next(BridgedBasicBlock block);
OptionalBridgedBasicBlock SILBasicBlock_previous(BridgedBasicBlock block); OptionalBridgedBasicBlock SILBasicBlock_previous(BridgedBasicBlock block);
BridgedFunction SILBasicBlock_getFunction(BridgedBasicBlock block); BridgedFunction SILBasicBlock_getFunction(BridgedBasicBlock block);
std::string SILBasicBlock_debugDescription(BridgedBasicBlock block); BridgedStringRef SILBasicBlock_debugDescription(BridgedBasicBlock block);
OptionalBridgedInstruction SILBasicBlock_firstInst(BridgedBasicBlock block); OptionalBridgedInstruction SILBasicBlock_firstInst(BridgedBasicBlock block);
OptionalBridgedInstruction SILBasicBlock_lastInst(BridgedBasicBlock block); OptionalBridgedInstruction SILBasicBlock_lastInst(BridgedBasicBlock block);
SwiftInt SILBasicBlock_getNumArguments(BridgedBasicBlock block); SwiftInt SILBasicBlock_getNumArguments(BridgedBasicBlock block);
@@ -188,7 +191,7 @@ OptionalBridgedOperand Operand_nextUse(BridgedOperand);
BridgedInstruction Operand_getUser(BridgedOperand); BridgedInstruction Operand_getUser(BridgedOperand);
SwiftInt Operand_isTypeDependent(BridgedOperand); SwiftInt Operand_isTypeDependent(BridgedOperand);
std::string SILNode_debugDescription(BridgedNode node); BridgedStringRef SILNode_debugDescription(BridgedNode node);
OptionalBridgedOperand SILValue_firstUse(BridgedValue value); OptionalBridgedOperand SILValue_firstUse(BridgedValue value);
BridgedType SILValue_getType(BridgedValue value); BridgedType SILValue_getType(BridgedValue value);
@@ -242,4 +245,8 @@ BridgedInstruction SILBuilder_createIntegerLiteral(BridgedInstruction insertionP
SWIFT_END_NULLABILITY_ANNOTATIONS SWIFT_END_NULLABILITY_ANNOTATIONS
#ifdef __cplusplus
} // extern "C"
#endif
#endif #endif

View File

@@ -15,8 +15,6 @@
#include "swift/SIL/SILGlobalVariable.h" #include "swift/SIL/SILGlobalVariable.h"
#include "swift/SIL/SILBuilder.h" #include "swift/SIL/SILBuilder.h"
#include <string>
using namespace swift; using namespace swift;
namespace { namespace {
@@ -165,12 +163,11 @@ BridgedStringRef SILFunction_getName(BridgedFunction function) {
return getBridgedStringRef(castToFunction(function)->getName()); return getBridgedStringRef(castToFunction(function)->getName());
} }
std::string SILFunction_debugDescription(BridgedFunction function) { BridgedStringRef SILFunction_debugDescription(BridgedFunction function) {
std::string str; std::string str;
llvm::raw_string_ostream os(str); llvm::raw_string_ostream os(str);
castToFunction(function)->print(os); castToFunction(function)->print(os);
str.pop_back(); // Remove trailing newline. return getCopiedBridgedStringRef(str, /*removeTrailingNewline*/ true);
return str;
} }
OptionalBridgedBasicBlock SILFunction_firstBlock(BridgedFunction function) { OptionalBridgedBasicBlock SILFunction_firstBlock(BridgedFunction function) {
@@ -226,12 +223,11 @@ BridgedFunction SILBasicBlock_getFunction(BridgedBasicBlock block) {
return {castToBasicBlock(block)->getParent()}; return {castToBasicBlock(block)->getParent()};
} }
std::string SILBasicBlock_debugDescription(BridgedBasicBlock block) { BridgedStringRef SILBasicBlock_debugDescription(BridgedBasicBlock block) {
std::string str; std::string str;
llvm::raw_string_ostream os(str); llvm::raw_string_ostream os(str);
castToBasicBlock(block)->print(os); castToBasicBlock(block)->print(os);
str.pop_back(); // Remove trailing newline. return getCopiedBridgedStringRef(str, /*removeTrailingNewline*/ true);
return str;
} }
OptionalBridgedInstruction SILBasicBlock_firstInst(BridgedBasicBlock block) { OptionalBridgedInstruction SILBasicBlock_firstInst(BridgedBasicBlock block) {
@@ -291,12 +287,11 @@ BridgedBasicBlock SILArgument_getParent(BridgedArgument argument) {
static_assert(BridgedOperandSize == sizeof(Operand), static_assert(BridgedOperandSize == sizeof(Operand),
"wrong bridged Operand size"); "wrong bridged Operand size");
std::string SILNode_debugDescription(BridgedNode node) { BridgedStringRef SILNode_debugDescription(BridgedNode node) {
std::string str; std::string str;
llvm::raw_string_ostream os(str); llvm::raw_string_ostream os(str);
castToSILNode(node)->print(os); castToSILNode(node)->print(os);
str.pop_back(); // Remove trailing newline. return getCopiedBridgedStringRef(str, /*removeTrailingNewline*/ true);
return str;
} }
static Operand *castToOperand(BridgedOperand operand) { static Operand *castToOperand(BridgedOperand operand) {
@@ -347,12 +342,11 @@ BridgedStringRef SILGlobalVariable_getName(BridgedGlobalVar global) {
return getBridgedStringRef(castToGlobal(global)->getName()); return getBridgedStringRef(castToGlobal(global)->getName());
} }
std::string SILGlobalVariable_debugDescription(BridgedGlobalVar global) { BridgedStringRef SILGlobalVariable_debugDescription(BridgedGlobalVar global) {
std::string str; std::string str;
llvm::raw_string_ostream os(str); llvm::raw_string_ostream os(str);
castToGlobal(global)->print(os); castToGlobal(global)->print(os);
str.pop_back(); // Remove trailing newline. return getCopiedBridgedStringRef(str, /*removeTrailingNewline*/ true);
return str;
} }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//

View File

@@ -19,8 +19,7 @@ final public class BasicBlock : ListNode, CustomStringConvertible {
public var function: Function { SILBasicBlock_getFunction(bridged).function } public var function: Function { SILBasicBlock_getFunction(bridged).function }
public var description: String { public var description: String {
var s = SILBasicBlock_debugDescription(bridged) SILBasicBlock_debugDescription(bridged).takeString()
return String(cString: s.c_str())
} }
public var arguments: ArgumentArray { ArgumentArray(block: self) } public var arguments: ArgumentArray { ArgumentArray(block: self) }

View File

@@ -18,8 +18,7 @@ final public class Function : CustomStringConvertible {
} }
final public var description: String { final public var description: String {
var s = SILFunction_debugDescription(bridged) return SILFunction_debugDescription(bridged).takeString()
return String(cString: s.c_str())
} }
public var entryBlock: BasicBlock { public var entryBlock: BasicBlock {

View File

@@ -18,8 +18,7 @@ final public class GlobalVariable : CustomStringConvertible {
} }
public var description: String { public var description: String {
var s = SILGlobalVariable_debugDescription(bridged) return SILGlobalVariable_debugDescription(bridged).takeString()
return String(cString: s.c_str())
} }
// TODO: initializer instructions // TODO: initializer instructions

View File

@@ -30,8 +30,7 @@ public class Instruction : ListNode, CustomStringConvertible, Hashable {
} }
final public var description: String { final public var description: String {
var s = SILNode_debugDescription(bridgedNode) SILNode_debugDescription(bridgedNode).takeString()
return String(cString: s.c_str())
} }
final public var operands: OperandArray { final public var operands: OperandArray {
@@ -124,8 +123,7 @@ public class SingleValueInstruction : Instruction, Value {
public final class MultipleValueInstructionResult : Value { public final class MultipleValueInstructionResult : Value {
final public var description: String { final public var description: String {
var s = SILNode_debugDescription(bridgedNode) SILNode_debugDescription(bridgedNode).takeString()
return String(cString: s.c_str())
} }
public var instruction: Instruction { public var instruction: Instruction {

View File

@@ -20,8 +20,7 @@ public protocol Value : AnyObject, CustomStringConvertible {
extension Value { extension Value {
public var description: String { public var description: String {
var s = SILNode_debugDescription(bridgedNode) SILNode_debugDescription(bridgedNode).takeString()
return String(cString: s.c_str())
} }
public var uses: UseList { public var uses: UseList {