Skip to content

Revert "Revert "[cxx-interop][SwiftCompilerSources] Fix conversion between std::string and Swift.String"" #59353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions SwiftCompilerSources/Sources/Basic/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//

@_exported import BasicBridging
import std

//===----------------------------------------------------------------------===//
// StringRef
Expand Down Expand Up @@ -60,6 +61,13 @@ extension String {
return c(BridgedStringRef(data: buffer.baseAddress, length: buffer.count))
}
}

/// Underscored to avoid name collision with the std overlay.
/// To be replaced with an overlay call once the CI uses SDKs built with Swift 5.8.
public init(_cxxString s: std.string) {
self.init(cString: s.c_str())
withExtendedLifetime(s) {}
}
}

extension Array {
Expand Down
3 changes: 1 addition & 2 deletions SwiftCompilerSources/Sources/SIL/BasicBlock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ final public class BasicBlock : ListNode, CustomStringConvertible, HasShortDescr
public var function: Function { SILBasicBlock_getFunction(bridged).function }

public var description: String {
var s = SILBasicBlock_debugDescription(bridged)
return String(cString: s.c_str())
String(_cxxString: SILBasicBlock_debugDescription(bridged))
}
public var shortDescription: String { name }

Expand Down
3 changes: 1 addition & 2 deletions SwiftCompilerSources/Sources/SIL/Function.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ final public class Function : CustomStringConvertible, HasShortDescription {
}

final public var description: String {
var s = SILFunction_debugDescription(bridged)
return String(cString: s.c_str())
String(_cxxString: SILFunction_debugDescription(bridged))
}

public var shortDescription: String { name.string }
Expand Down
3 changes: 1 addition & 2 deletions SwiftCompilerSources/Sources/SIL/GlobalVariable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ final public class GlobalVariable : CustomStringConvertible, HasShortDescription
}

public var description: String {
var s = SILGlobalVariable_debugDescription(bridged)
return String(cString: s.c_str())
String(_cxxString: SILGlobalVariable_debugDescription(bridged))
}

public var shortDescription: String { name.string }
Expand Down
6 changes: 2 additions & 4 deletions SwiftCompilerSources/Sources/SIL/Instruction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ public class Instruction : ListNode, CustomStringConvertible, Hashable {
final public var function: Function { block.function }

final public var description: String {
var s = SILNode_debugDescription(bridgedNode)
return String(cString: s.c_str())
String(_cxxString: SILNode_debugDescription(bridgedNode))
}

final public var operands: OperandArray {
Expand Down Expand Up @@ -143,8 +142,7 @@ public class SingleValueInstruction : Instruction, Value {

public final class MultipleValueInstructionResult : Value {
final public var description: String {
var s = SILNode_debugDescription(bridgedNode)
return String(cString: s.c_str())
String(_cxxString: SILNode_debugDescription(bridgedNode))
}

public var instruction: Instruction {
Expand Down
3 changes: 1 addition & 2 deletions SwiftCompilerSources/Sources/SIL/Value.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ public enum Ownership {

extension Value {
public var description: String {
var s = SILNode_debugDescription(bridgedNode)
return String(cString: s.c_str())
String(_cxxString: SILNode_debugDescription(bridgedNode))
}

public var uses: UseList {
Expand Down
3 changes: 0 additions & 3 deletions test/SILOptimizer/addr_escape_info.sil
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

// REQUIRES: swift_in_compiler

// rdar92963081
// UNSUPPORTED: OS=linux-gnu

sil_stage canonical

import Builtin
Expand Down
3 changes: 0 additions & 3 deletions test/SILOptimizer/escape_info.sil
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

// REQUIRES: swift_in_compiler

// rdar92963081
// UNSUPPORTED: OS=linux-gnu


sil_stage canonical

Expand Down
3 changes: 0 additions & 3 deletions test/SILOptimizer/ranges.sil
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

// REQUIRES: swift_in_compiler

// rdar92963081
// UNSUPPORTED: OS=linux-gnu


sil_stage canonical

Expand Down