Skip to content

Commit d67dc0a

Browse files
authored
Merge pull request #69440 from hamishknight/double-plus
2 parents 9e7d927 + 3cb74e9 commit d67dc0a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+3238
-2991
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,10 @@ set(SWIFT_STDLIB_MSVC_RUNTIME_LIBRARY
405405

406406

407407
if(BRIDGING_MODE STREQUAL "DEFAULT" OR NOT BRIDGING_MODE)
408-
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
408+
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows" OR (CMAKE_Swift_COMPILER AND CMAKE_Swift_COMPILER_VERSION VERSION_LESS 5.8))
409409
# In debug builds, to workaround a problem with LLDB's `po` command (rdar://115770255).
410410
# On windows to workaround a build problem.
411+
# If the host Swift version is less than 5.8, use pure mode to workaround a C++ interop compiler crash.
411412
set(BRIDGING_MODE "PURE")
412413
else()
413414
set(BRIDGING_MODE "INLINE")

SwiftCompilerSources/Package.swift

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14+
// To successfully build, you'll need to create a couple of symlinks to an
15+
// existing Ninja build:
16+
//
17+
// ln -s <project-root>/build/<Ninja-Build>/llvm-<os+arch> <project-root>/build/Default/llvm
18+
// ln -s <project-root>/build/<Ninja-Build>/swift-<os+arch> <project-root>/build/Default/swift
19+
//
20+
// where <project-root> is the parent directory of the swift repository.
21+
//
22+
// FIXME: We may want to consider generating Package.swift as a part of the
23+
// build.
24+
1425
import PackageDescription
1526

1627
private extension Target {
@@ -30,9 +41,14 @@ private extension Target {
3041
.interoperabilityMode(.Cxx),
3142
.unsafeFlags([
3243
"-static",
44+
"-Xcc", "-DCOMPILED_WITH_SWIFT", "-Xcc", "-DPURE_BRIDGING_MODE",
45+
"-Xcc", "-UIBOutlet", "-Xcc", "-UIBAction", "-Xcc", "-UIBInspectable",
3346
"-Xcc", "-I../include",
3447
"-Xcc", "-I../../llvm-project/llvm/include",
3548
"-Xcc", "-I../../llvm-project/clang/include",
49+
"-Xcc", "-I../../build/Default/swift/include",
50+
"-Xcc", "-I../../build/Default/llvm/include",
51+
"-Xcc", "-I../../build/Default/llvm/tools/clang/include",
3652
"-cross-module-optimization",
3753
]),
3854
] + swiftSettings)
@@ -42,7 +58,10 @@ private extension Target {
4258
let package = Package(
4359
name: "SwiftCompilerSources",
4460
platforms: [
45-
.macOS("10.9"),
61+
// We need at least macOS 13 here to avoid hitting an availability error
62+
// for CxxStdlib. It's only needed for the package though, the CMake build
63+
// works fine with a lower deployment target.
64+
.macOS(.v13),
4665
],
4766
products: [
4867
.library(

SwiftCompilerSources/Sources/AST/DiagnosticEngine.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,16 @@ public struct DiagnosticFixIt {
5252
}
5353

5454
public struct DiagnosticEngine {
55-
private let bridged: BridgedDiagEngine
55+
private let bridged: BridgedDiagnosticEngine
5656

57-
public init(bridged: BridgedDiagEngine) {
57+
public init(bridged: BridgedDiagnosticEngine) {
5858
self.bridged = bridged
5959
}
60-
public init?(bridged: BridgedOptionalDiagnosticEngine) {
61-
guard let object = bridged.object else {
60+
public init?(bridged: BridgedNullableDiagnosticEngine) {
61+
guard let raw = bridged.raw else {
6262
return nil
6363
}
64-
self.bridged = BridgedDiagEngine(object: object)
64+
self.bridged = BridgedDiagnosticEngine(raw: raw)
6565
}
6666

6767
public func diagnose(_ position: SourceLoc?,
@@ -91,10 +91,10 @@ public struct DiagnosticEngine {
9191
var closure: () -> Void = {
9292
bridgedArgs.withBridgedArrayRef { bridgedArgsRef in
9393
bridgedFixIts.withBridgedArrayRef { bridgedFixItsRef in
94-
DiagnosticEngine_diagnose(bridged, bridgedSourceLoc,
95-
id, bridgedArgsRef,
96-
highlightStart, highlightLength,
97-
bridgedFixItsRef)
94+
bridged.diagnose(at: bridgedSourceLoc, id, bridgedArgsRef,
95+
highlightAt: highlightStart,
96+
highlightLength: highlightLength,
97+
fixIts: bridgedFixItsRef)
9898
}
9999
}
100100
}

SwiftCompilerSources/Sources/Basic/SourceLoc.swift

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,19 @@ import ASTBridging
1414

1515
public struct SourceLoc {
1616
/// Points into a source file.
17-
let locationInFile: UnsafePointer<UInt8>
18-
19-
public init?(locationInFile: UnsafePointer<UInt8>?) {
20-
guard let locationInFile = locationInFile else {
21-
return nil
22-
}
23-
self.locationInFile = locationInFile
24-
}
17+
public let bridged: BridgedSourceLoc
2518

2619
public init?(bridged: BridgedSourceLoc) {
27-
guard bridged.isValid() else {
20+
guard bridged.isValid else {
2821
return nil
2922
}
30-
self.locationInFile = bridged.uint8Pointer()!
31-
}
32-
33-
public var bridged: BridgedSourceLoc {
34-
.init(locationInFile)
23+
self.bridged = bridged
3524
}
3625
}
3726

3827
extension SourceLoc {
3928
public func advanced(by n: Int) -> SourceLoc {
40-
SourceLoc(locationInFile: locationInFile.advanced(by: n))!
29+
SourceLoc(bridged: bridged.advanced(by: n))!
4130
}
4231
}
4332

SwiftCompilerSources/Sources/Basic/Utils.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,23 +79,23 @@ public struct StringRef : CustomStringConvertible, NoReflectionChildren {
7979
public var description: String { string }
8080

8181
public var count: Int {
82-
Int(_bridged.size())
82+
_bridged.count
8383
}
8484

8585
public subscript(index: Int) -> UInt8 {
86-
let buffer = UnsafeBufferPointer<UInt8>(start: _bridged.uintData(), count: count)
86+
let buffer = UnsafeBufferPointer<UInt8>(start: _bridged.data, count: count)
8787
return buffer[index]
8888
}
8989

9090
public static func ==(lhs: StringRef, rhs: StringRef) -> Bool {
91-
let lhsBuffer = UnsafeBufferPointer<UInt8>(start: lhs._bridged.uintData(), count: lhs.count)
92-
let rhsBuffer = UnsafeBufferPointer<UInt8>(start: rhs._bridged.uintData(), count: rhs.count)
91+
let lhsBuffer = UnsafeBufferPointer<UInt8>(start: lhs._bridged.data, count: lhs.count)
92+
let rhsBuffer = UnsafeBufferPointer<UInt8>(start: rhs._bridged.data, count: rhs.count)
9393
if lhsBuffer.count != rhsBuffer.count { return false }
9494
return lhsBuffer.elementsEqual(rhsBuffer, by: ==)
9595
}
9696

9797
public static func ==(lhs: StringRef, rhs: StaticString) -> Bool {
98-
let lhsBuffer = UnsafeBufferPointer<UInt8>(start: lhs._bridged.uintData(), count: lhs.count)
98+
let lhsBuffer = UnsafeBufferPointer<UInt8>(start: lhs._bridged.data, count: lhs.count)
9999
return rhs.withUTF8Buffer { (rhsBuffer: UnsafeBufferPointer<UInt8>) in
100100
if lhsBuffer.count != rhsBuffer.count { return false }
101101
return lhsBuffer.elementsEqual(rhsBuffer, by: ==)
@@ -116,17 +116,17 @@ extension String {
116116
public func _withBridgedStringRef<T>(_ c: (BridgedStringRef) -> T) -> T {
117117
var str = self
118118
return str.withUTF8 { buffer in
119-
return c(BridgedStringRef(buffer.baseAddress, buffer.count))
119+
return c(BridgedStringRef(data: buffer.baseAddress, count: buffer.count))
120120
}
121121
}
122122

123123
public init(_ s: BridgedStringRef) {
124-
let buffer = UnsafeBufferPointer<UInt8>(start: s.uintData(), count: Int(s.size()))
124+
let buffer = UnsafeBufferPointer<UInt8>(start: s.data, count: s.count)
125125
self.init(decoding: buffer, as: UTF8.self)
126126
}
127127

128128
public init(taking s: BridgedOwnedString) {
129-
let buffer = UnsafeBufferPointer<UInt8>(start: s.uintData(), count: s.size())
129+
let buffer = UnsafeBufferPointer<UInt8>(start: s.data, count: s.count)
130130
self.init(decoding: buffer, as: UTF8.self)
131131
s.destroy()
132132
}
@@ -135,7 +135,7 @@ extension String {
135135
extension Array {
136136
public func withBridgedArrayRef<T>(_ c: (BridgedArrayRef) -> T) -> T {
137137
return withUnsafeBytes { buf in
138-
return c(BridgedArrayRef(data: buf.baseAddress!, numElements: count))
138+
return c(BridgedArrayRef(data: buf.baseAddress!, count: count))
139139
}
140140
}
141141
}
@@ -164,8 +164,8 @@ extension Optional where Wrapped == UnsafeMutablePointer<BridgedSwiftObject> {
164164

165165
extension BridgedArrayRef {
166166
public func withElements<T, R>(ofType ty: T.Type, _ c: (UnsafeBufferPointer<T>) -> R) -> R {
167-
let start = data?.bindMemory(to: ty, capacity: numElements);
168-
let buffer = UnsafeBufferPointer(start: start, count: numElements);
167+
let start = data?.bindMemory(to: ty, capacity: count)
168+
let buffer = UnsafeBufferPointer(start: start, count: count)
169169
return c(buffer)
170170
}
171171
}

SwiftCompilerSources/Sources/Optimizer/PassManager/Context.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ struct FunctionPassContext : MutatingContext {
226226

227227
func loadFunction(name: StaticString, loadCalleesRecursively: Bool) -> Function? {
228228
return name.withUTF8Buffer { (nameBuffer: UnsafeBufferPointer<UInt8>) in
229-
let nameStr = BridgedStringRef(nameBuffer.baseAddress, nameBuffer.count)
229+
let nameStr = BridgedStringRef(data: nameBuffer.baseAddress, count: nameBuffer.count)
230230
return _bridged.loadFunction(nameStr, loadCalleesRecursively).function
231231
}
232232
}
@@ -244,7 +244,7 @@ struct FunctionPassContext : MutatingContext {
244244
/// Returns nil if no such function or multiple matching functions are found.
245245
func lookupStdlibFunction(name: StaticString) -> Function? {
246246
return name.withUTF8Buffer { (nameBuffer: UnsafeBufferPointer<UInt8>) in
247-
let nameStr = BridgedStringRef(nameBuffer.baseAddress, nameBuffer.count)
247+
let nameStr = BridgedStringRef(data: nameBuffer.baseAddress, count: nameBuffer.count)
248248
return _bridged.lookupStdlibFunction(nameStr).function
249249
}
250250
}

SwiftCompilerSources/Sources/Optimizer/Utilities/EscapeUtils.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ protocol EscapeVisitorWithResult : EscapeVisitor {
184184
var result: Result { get }
185185
}
186186

187-
private struct DefaultVisitor : EscapeVisitor {}
187+
// FIXME: This ought to be marked private, but that triggers a compiler bug
188+
// in debug builds (rdar://117413192)
189+
struct DefaultVisitor : EscapeVisitor {}
188190

189191
struct EscapeUtilityTypes {
190192

SwiftCompilerSources/Sources/Parse/Regex.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ private func _RegexLiteralLexingFn(
4646
_ curPtrPtr: UnsafeMutablePointer<UnsafePointer<CChar>>,
4747
_ bufferEndPtr: UnsafePointer<CChar>,
4848
_ mustBeRegex: CBool,
49-
_ bridgedDiagnosticEngine: BridgedOptionalDiagnosticEngine
49+
_ bridgedDiagnosticEngine: BridgedNullableDiagnosticEngine
5050
) -> /*CompletelyErroneous*/ CBool {
5151
let inputPtr = curPtrPtr.pointee
5252

@@ -63,8 +63,7 @@ private func _RegexLiteralLexingFn(
6363
if let error = error {
6464
// Emit diagnostic if diagnostics are enabled.
6565
if let diagEngine = DiagnosticEngine(bridged: bridgedDiagnosticEngine) {
66-
let startLoc = SourceLoc(
67-
locationInFile: error.location.assumingMemoryBound(to: UInt8.self))!
66+
let startLoc = SourceLoc(bridged: BridgedSourceLoc(raw: error.location))!
6867
diagEngine.diagnose(startLoc, .foreign_diagnostic, error.message)
6968
}
7069
return error.completelyErroneous
@@ -93,7 +92,7 @@ public func _RegexLiteralParsingFn(
9392
_ captureStructureOut: UnsafeMutableRawPointer,
9493
_ captureStructureSize: CUnsignedInt,
9594
_ bridgedDiagnosticBaseLoc: BridgedSourceLoc,
96-
_ bridgedDiagnosticEngine: BridgedDiagEngine
95+
_ bridgedDiagnosticEngine: BridgedDiagnosticEngine
9796
) -> Bool {
9897
let str = String(cString: inputPtr)
9998
let captureBuffer = UnsafeMutableRawBufferPointer(

SwiftCompilerSources/Sources/SIL/Function.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ final public class Function : CustomStringConvertible, HasShortDescription, Hash
112112

113113
public func hasSemanticsAttribute(_ attr: StaticString) -> Bool {
114114
attr.withUTF8Buffer { (buffer: UnsafeBufferPointer<UInt8>) in
115-
bridged.hasSemanticsAttr(BridgedStringRef(buffer.baseAddress!, buffer.count))
115+
bridged.hasSemanticsAttr(BridgedStringRef(data: buffer.baseAddress!, count: buffer.count))
116116
}
117117
}
118118

SwiftCompilerSources/Sources/SIL/Instruction.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,9 @@ final public class FixLifetimeInst : Instruction, UnaryInstruction {}
357357
public struct VarDecl {
358358
var bridged: BridgedVarDecl
359359

360-
public init?(bridged: OptionalBridgedVarDecl) {
361-
guard let decl = bridged.decl else { return nil }
362-
self.bridged = BridgedVarDecl(decl: decl)
360+
public init?(bridged: BridgedNullableVarDecl) {
361+
guard let decl = bridged.raw else { return nil }
362+
self.bridged = BridgedVarDecl(raw: decl)
363363
}
364364

365365
public var userFacingName: String { String(bridged.getUserFacingName()) }

SwiftCompilerSources/Sources/SIL/Type.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,11 @@ public struct NominalTypeDecl : Equatable, Hashable {
216216
public var name: StringRef { StringRef(bridged: bridged.getName()) }
217217

218218
public static func ==(lhs: NominalTypeDecl, rhs: NominalTypeDecl) -> Bool {
219-
lhs.bridged.decl == rhs.bridged.decl
219+
lhs.bridged.raw == rhs.bridged.raw
220220
}
221221

222222
public func hash(into hasher: inout Hasher) {
223-
hasher.combine(bridged.decl)
223+
hasher.combine(bridged.raw)
224224
}
225225

226226
public var isStructWithUnreferenceableStorage: Bool {

cmake/modules/AddPureSwift.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ function(_add_host_swift_compile_options name)
3737
target_link_options(${name} PRIVATE ${_cov_flags})
3838
endif()
3939

40+
if("${BRIDGING_MODE}" STREQUAL "PURE")
41+
target_compile_options(${name} PRIVATE
42+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xcc -DPURE_BRIDGING_MODE>")
43+
endif()
44+
4045
# The compat56 library is not available in current toolchains. The stage-0
4146
# compiler will build fine since the builder compiler is not aware of the 56
4247
# compat library, but the stage-1 and subsequent stage compilers will fail as

include/module.modulemap

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,12 @@ module BasicBridging {
44
export *
55
}
66

7-
module CBasicBridging {
8-
header "swift/Basic/CBasicBridging.h"
9-
}
10-
117
module ASTBridging {
128
header "swift/AST/ASTBridging.h"
139
requires cplusplus
1410
export *
1511
}
1612

17-
module CASTBridging {
18-
header "swift/AST/CASTBridging.h"
19-
}
20-
2113
module SILBridging {
2214
header "swift/SIL/SILBridging.h"
2315
requires cplusplus

0 commit comments

Comments
 (0)