Skip to content

Commit d25fbf8

Browse files
Merge pull request #4723 from swiftwasm/katei/merge-main-2022-07-30
Merge main 2022-07-30
2 parents 969f1ad + ff3612f commit d25fbf8

File tree

303 files changed

+9153
-2311
lines changed

Some content is hidden

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

303 files changed

+9153
-2311
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
1010
The compiler flag `-enable-upcoming-feature X` can now be used to enable a specific feature `X` that has been accepted by the evolution process, but whose introduction into the language is waiting for the next major version (e.g., version 6). The `X` is specified by any proposal that falls into this category:
1111
* `ConciseMagicFile` enables the new `#file` semantics in [SE-0274][].
1212
* `ForwardTrailingClosures` disables the "backward" scanning behavior of [SE-0286][].
13-
* `BareSlashRegexLiterals` enables the regex literal syntax of [SE-0352][].
13+
* `BareSlashRegexLiterals` enables the regex literal syntax of [SE-0354][].
1414

1515
Features can be detected in source code with `#if hasFeature(X)`.
1616

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,15 @@ set(SWIFT_DARWIN_DEPLOYMENT_VERSION_TVOS "9.0" CACHE STRING
454454
set(SWIFT_DARWIN_DEPLOYMENT_VERSION_WATCHOS "2.0" CACHE STRING
455455
"Minimum deployment target version for watchOS")
456456

457+
#
458+
# Compatibility library deployment versions
459+
#
460+
461+
set(COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_OSX "10.9")
462+
set(COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_IOS "7.0")
463+
set(COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_TVOS "9.0")
464+
set(COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_WATCHOS "2.0")
465+
457466
#
458467
# User-configurable debugging options.
459468
#

SwiftCompilerSources/CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ function(add_swift_compiler_modules_library name)
165165
add_custom_command_target(dep_target OUTPUT ${module_obj_file}
166166
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
167167
DEPENDS ${sources} ${deps} ${ALS_DEPENDS}
168+
importedHeaderDependencies
168169
COMMAND ${ALS_SWIFT_EXEC} "-c" "-o" ${module_obj_file}
169170
${sdk_option}
170171
"-target" ${target}
@@ -229,6 +230,24 @@ else()
229230

230231
add_subdirectory(Sources)
231232

233+
# This is a hack to get correct dependencies from imported C++ headers:
234+
# step 1: generate a dummy source file, which just includes all headers defined in include/swift/module.modulemap
235+
add_custom_command(
236+
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/HeaderDependencies.cpp"
237+
COMMAND
238+
"sed"
239+
-n -e "/header/!d" -e "s/.*header/#include/" -e "w ${CMAKE_CURRENT_BINARY_DIR}/HeaderDependencies.cpp"
240+
"${CMAKE_SOURCE_DIR}/include/swift/module.modulemap"
241+
DEPENDS "${CMAKE_SOURCE_DIR}/include/swift/module.modulemap"
242+
COMMENT "Generate HeaderDependencies.cpp"
243+
)
244+
245+
# step 2: build a library containing that source file. This library depends on all the included header files.
246+
# The swift modules can now depend on that target.
247+
# Note that this library is unused, i.e. not linked to anything.
248+
add_library(importedHeaderDependencies "${CMAKE_CURRENT_BINARY_DIR}/HeaderDependencies.cpp")
249+
target_include_directories(importedHeaderDependencies PRIVATE "${CMAKE_SOURCE_DIR}/include/swift")
250+
232251
if(${BOOTSTRAPPING_MODE} MATCHES "HOSTTOOLS|CROSSCOMPILE")
233252

234253
if (NOT SWIFT_EXEC_FOR_SWIFT_MODULES)

SwiftCompilerSources/Sources/AST/DiagnosticEngine.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public protocol DiagnosticArgument {
2121
}
2222
extension String: DiagnosticArgument {
2323
public func _withBridgedDiagnosticArgument(_ fn: (swift.DiagnosticArgument) -> Void) {
24-
withBridgedStringRef { fn(swift.DiagnosticArgument(llvm.StringRef($0))) }
24+
_withStringRef { fn(swift.DiagnosticArgument($0)) }
2525
}
2626
}
2727
extension Int: DiagnosticArgument {
@@ -42,10 +42,10 @@ public struct DiagnosticFixIt {
4242
}
4343

4444
func withBridgedDiagnosticFixIt(_ fn: (swift.DiagnosticInfo.FixIt) -> Void) {
45-
text.withBridgedStringRef { bridgedTextRef in
45+
text._withStringRef { bridgedTextRef in
4646
let bridgedDiagnosticFixIt = swift.DiagnosticInfo.FixIt(
4747
swift.CharSourceRange(start.bridged, UInt32(byteLength)),
48-
llvm.StringRef(bridgedTextRef),
48+
bridgedTextRef,
4949
llvm.ArrayRef<swift.DiagnosticArgument>())
5050
fn(bridgedDiagnosticFixIt)
5151
}

SwiftCompilerSources/Sources/Basic/Utils.swift

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,18 @@ import std
1818
//===----------------------------------------------------------------------===//
1919

2020
public struct StringRef : CustomStringConvertible, CustomReflectable {
21-
let _bridged : BridgedStringRef
21+
let _bridged: llvm.StringRef
2222

23-
public init(bridged: BridgedStringRef) { self._bridged = bridged }
23+
public init(bridged: llvm.StringRef) { self._bridged = bridged }
2424

2525
public var string: String { _bridged.string }
2626
public var description: String { string }
2727
public var customMirror: Mirror { Mirror(self, children: []) }
2828

2929
public static func ==(lhs: StringRef, rhs: StaticString) -> Bool {
30-
let lhsBuffer = UnsafeBufferPointer<UInt8>(start: lhs._bridged.data, count: Int(lhs._bridged.length))
30+
let lhsBuffer = UnsafeBufferPointer<UInt8>(
31+
start: lhs._bridged.__bytes_beginUnsafe(),
32+
count: Int(lhs._bridged.__bytes_endUnsafe() - lhs._bridged.__bytes_beginUnsafe()))
3133
return rhs.withUTF8Buffer { (rhsBuffer: UnsafeBufferPointer<UInt8>) in
3234
if lhsBuffer.count != rhsBuffer.count { return false }
3335
return lhsBuffer.elementsEqual(rhsBuffer, by: ==)
@@ -41,24 +43,19 @@ public struct StringRef : CustomStringConvertible, CustomReflectable {
4143
// Bridging Utilities
4244
//===----------------------------------------------------------------------===//
4345

44-
extension BridgedStringRef {
45-
public var string: String {
46-
let buffer = UnsafeBufferPointer<UInt8>(start: data, count: Int(length))
47-
return String(decoding: buffer, as: UTF8.self)
48-
}
49-
}
50-
5146
extension llvm.StringRef {
52-
public init(_ bridged: BridgedStringRef) {
53-
self.init(bridged.data, bridged.length)
47+
public var string: String {
48+
String(_cxxString: self.str())
5449
}
5550
}
5651

5752
extension String {
58-
public func withBridgedStringRef<T>(_ c: (BridgedStringRef) -> T) -> T {
53+
/// Underscored to avoid name collision with Swift LLVM Bindings.
54+
/// To be replaced with a bindings call once bindings are a dependency.
55+
public func _withStringRef<T>(_ c: (llvm.StringRef) -> T) -> T {
5956
var str = self
6057
return str.withUTF8 { buffer in
61-
return c(BridgedStringRef(data: buffer.baseAddress, length: buffer.count))
58+
return c(llvm.StringRef(buffer.baseAddress, buffer.count))
6259
}
6360
}
6461

SwiftCompilerSources/Sources/Optimizer/PassManager/PassContext.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ struct PassContext {
6666

6767
func loadFunction(name: StaticString) -> Function? {
6868
return name.withUTF8Buffer { (nameBuffer: UnsafeBufferPointer<UInt8>) in
69-
PassContext_loadFunction(_bridged, BridgedStringRef(data: nameBuffer.baseAddress, length: nameBuffer.count)).function
69+
PassContext_loadFunction(_bridged, llvm.StringRef(nameBuffer.baseAddress, nameBuffer.count)).function
7070
}
7171
}
7272

SwiftCompilerSources/Sources/Optimizer/PassManager/PassRegistration.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ public func initializeSwiftModules() {
2424
private func registerPass(
2525
_ pass: FunctionPass,
2626
_ runFn: @escaping (@convention(c) (BridgedFunctionPassCtxt) -> ())) {
27-
pass.name.withBridgedStringRef { nameStr in
27+
pass.name._withStringRef { nameStr in
2828
SILPassManager_registerFunctionPass(nameStr, runFn)
2929
}
3030
}
3131

3232
private func registerPass<InstType: Instruction>(
3333
_ pass: InstructionPass<InstType>,
3434
_ runFn: @escaping (@convention(c) (BridgedInstructionPassCtxt) -> ())) {
35-
pass.name.withBridgedStringRef { nameStr in
35+
pass.name._withStringRef { nameStr in
3636
SILCombine_registerInstructionPass(nameStr, runFn)
3737
}
3838
}

SwiftCompilerSources/Sources/SIL/Builder.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public struct Builder {
6161
operandType: Type, resultType: Type, arguments: [Value]) -> BuiltinInst {
6262
notifyInstructionsChanged()
6363
return arguments.withBridgedValues { valuesRef in
64-
return name.withBridgedStringRef { nameStr in
64+
return name._withStringRef { nameStr in
6565
let bi = SILBuilder_createBuiltinBinaryFunction(
6666
bridged, nameStr, operandType.bridged, resultType.bridged, valuesRef)
6767
return bi.getAs(BuiltinInst.self)
@@ -71,7 +71,7 @@ public struct Builder {
7171

7272
public func createCondFail(condition: Value, message: String) -> CondFailInst {
7373
notifyInstructionsChanged()
74-
return message.withBridgedStringRef { messageStr in
74+
return message._withStringRef { messageStr in
7575
let cf = SILBuilder_createCondFail(bridged, condition.bridged, messageStr)
7676
return cf.getAs(CondFailInst.self)
7777
}

SwiftCompilerSources/Sources/SIL/Function.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ final public class Function : CustomStringConvertible, HasShortDescription {
6767

6868
public func hasSemanticsAttribute(_ attr: StaticString) -> Bool {
6969
attr.withUTF8Buffer { (buffer: UnsafeBufferPointer<UInt8>) in
70-
SILFunction_hasSemanticsAttr(bridged, BridgedStringRef(data: buffer.baseAddress!, length: buffer.count)) != 0
70+
SILFunction_hasSemanticsAttr(bridged, llvm.StringRef(buffer.baseAddress!, buffer.count)) != 0
7171
}
7272
}
7373

@@ -105,18 +105,18 @@ final public class Function : CustomStringConvertible, HasShortDescription {
105105
// writeFn
106106
{ (f: BridgedFunction, os: BridgedOStream, idx: Int) in
107107
let s = f.function.effects.argumentEffects[idx].description
108-
s.withBridgedStringRef { OStream_write(os, $0) }
108+
s._withStringRef { OStream_write(os, $0) }
109109
},
110110
// parseFn:
111-
{ (f: BridgedFunction, str: BridgedStringRef, fromSIL: Int, isDerived: Int, paramNames: BridgedArrayRef) -> BridgedParsingError in
111+
{ (f: BridgedFunction, str: llvm.StringRef, fromSIL: Int, isDerived: Int, paramNames: BridgedArrayRef) -> BridgedParsingError in
112112
do {
113113
var parser = StringParser(str.string)
114114
let effect: ArgumentEffect
115115
if fromSIL != 0 {
116116
effect = try parser.parseEffectFromSIL(for: f.function, isDerived: isDerived != 0)
117117
} else {
118-
let paramToIdx = paramNames.withElements(ofType: BridgedStringRef.self) {
119-
(buffer: UnsafeBufferPointer<BridgedStringRef>) -> Dictionary<String, Int> in
118+
let paramToIdx = paramNames.withElements(ofType: llvm.StringRef.self) {
119+
(buffer: UnsafeBufferPointer<llvm.StringRef>) -> Dictionary<String, Int> in
120120
let keyValPairs = buffer.enumerated().lazy.map { ($0.1.string, $0.0) }
121121
return Dictionary(uniqueKeysWithValues: keyValPairs)
122122
}

SwiftCompilerSources/Sources/SIL/Registration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Basic
1414
import SILBridging
1515

1616
private func register<T: AnyObject>(_ cl: T.Type) {
17-
String(describing: cl).withBridgedStringRef { nameStr in
17+
String(describing: cl)._withStringRef { nameStr in
1818
let metatype = unsafeBitCast(cl, to: SwiftMetatype.self)
1919
registerBridgedClass(nameStr, metatype)
2020
}

0 commit comments

Comments
 (0)