Skip to content

Commit bfc964c

Browse files
authored
Merge pull request #4293 from swiftwasm/main
[pull] swiftwasm from main
2 parents 9616944 + 496da9d commit bfc964c

File tree

123 files changed

+2561
-814
lines changed

Some content is hidden

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

123 files changed

+2561
-814
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,10 @@ option(SWIFT_ENABLE_STDLIBCORE_EXCLUSIVITY_CHECKING
439439
"Build stdlibCore with exclusivity checking enabled"
440440
FALSE)
441441

442+
option(SWIFT_STDLIB_ENABLE_DEBUG_PRECONDITIONS_IN_RELEASE
443+
"Enable _debugPrecondition checks in the stdlib in Release configurations"
444+
FALSE)
445+
442446
option(SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING
443447
"Enable experimental Swift differentiable programming features"
444448
FALSE)

SwiftCompilerSources/CMakeLists.txt

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
# See http://swift.org/LICENSE.txt for license information
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

9-
109
# Following function are needed as a workaround until it's possible to compile
1110
# swift code with cmake's builtin swift support.
1211

@@ -19,15 +18,9 @@ function(add_swift_compiler_module module)
1918
cmake_parse_arguments(ALSM
2019
""
2120
""
22-
"DEPENDS"
21+
"DEPENDS;SOURCES"
2322
${ARGN})
24-
set(raw_sources ${ALSM_UNPARSED_ARGUMENTS})
25-
set(sources)
26-
foreach(raw_source ${raw_sources})
27-
get_filename_component(
28-
raw_source "${raw_source}" REALPATH BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
29-
list(APPEND sources "${raw_source}")
30-
endforeach()
23+
set(raw_sources ${ALSM_SOURCES} ${ALSM_UNPARSED_ARGUMENTS})
3124

3225
set(target_name "SwiftModule${module}")
3326

@@ -36,9 +29,10 @@ function(add_swift_compiler_module module)
3629
# This target is mainly used to add properties, like the list of source files.
3730
add_custom_target(
3831
${target_name}
39-
SOURCES ${sources}
4032
COMMENT "swift compiler module ${module}")
4133

34+
swift_compiler_sources(${module} ${raw_sources})
35+
4236
set_property(TARGET ${target_name} PROPERTY module_name ${module})
4337
set_property(TARGET ${target_name} PROPERTY module_depends ${ALSM_DEPENDS})
4438

@@ -54,8 +48,13 @@ function(swift_compiler_sources module)
5448
""
5549
""
5650
${ARGN})
57-
set(sources ${LSS_UNPARSED_ARGUMENTS})
58-
list(TRANSFORM sources PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/")
51+
set(raw_sources ${LSS_UNPARSED_ARGUMENTS})
52+
set(sources)
53+
foreach(raw_source ${raw_sources})
54+
get_filename_component(
55+
raw_source "${raw_source}" REALPATH BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
56+
list(APPEND sources "${raw_source}")
57+
endforeach()
5958

6059
set(target_name "SwiftModule${module}")
6160
set_property(TARGET "SwiftModule${module}" APPEND PROPERTY SOURCES ${sources})
@@ -146,8 +145,11 @@ function(add_swift_compiler_modules_library name)
146145
"-emit-module-path" "${build_dir}/${module}.swiftmodule"
147146
"-parse-as-library" ${sources}
148147
"-wmo" ${swift_compile_options}
149-
"-I" "${SWIFT_SOURCE_DIR}/include/swift"
150-
"-I" "${SWIFT_SOURCE_DIR}/include"
148+
# Bridging modules and headers.
149+
"-Xcc" "-I" "-Xcc" "${SWIFT_SOURCE_DIR}/include"
150+
# Generated C headers.
151+
"-Xcc" "-I" "-Xcc" "${CMAKE_BINARY_DIR}/include"
152+
# Generated swift modules.
151153
"-I" "${build_dir}"
152154
COMMENT "Building swift module ${module}")
153155

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2022 Apple Inc. and the Swift project authors
4+
# Licensed under Apache License v2.0 with Runtime Library Exception
5+
#
6+
# See http://swift.org/LICENSE.txt for license information
7+
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
8+
9+
add_swift_compiler_module(Basic
10+
Utils.swift)
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
//===--- Utils.swift - Some bridging utilities ----------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2022 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
@_exported import BasicBridging
14+
15+
//===----------------------------------------------------------------------===//
16+
// Bridging Utilities
17+
//===----------------------------------------------------------------------===//
18+
19+
extension BridgedStringRef {
20+
public var string: String {
21+
let buffer = UnsafeBufferPointer<UInt8>(start: data, count: Int(length))
22+
return String(decoding: buffer, as: UTF8.self)
23+
}
24+
25+
public func takeString() -> String {
26+
let str = string
27+
freeBridgedStringRef(self)
28+
return str
29+
}
30+
}
31+
32+
extension String {
33+
public func withBridgedStringRef<T>(_ c: (BridgedStringRef) -> T) -> T {
34+
var str = self
35+
return str.withUTF8 { buffer in
36+
return c(BridgedStringRef(data: buffer.baseAddress, length: buffer.count))
37+
}
38+
}
39+
}
40+
41+
extension Array {
42+
public func withBridgedArrayRef<T>(_ c: (BridgedArrayRef) -> T) -> T {
43+
return withUnsafeBytes { buf in
44+
return c(BridgedArrayRef(data: buf.baseAddress!, numElements: count))
45+
}
46+
}
47+
}
48+
49+
public typealias SwiftObject = UnsafeMutablePointer<BridgedSwiftObject>
50+
51+
extension UnsafeMutablePointer where Pointee == BridgedSwiftObject {
52+
public init<T: AnyObject>(_ object: T) {
53+
let ptr = Unmanaged.passUnretained(object).toOpaque()
54+
self = ptr.bindMemory(to: BridgedSwiftObject.self, capacity: 1)
55+
}
56+
57+
public func getAs<T: AnyObject>(_ objectType: T.Type) -> T {
58+
return Unmanaged<T>.fromOpaque(self).takeUnretainedValue()
59+
}
60+
}
61+
62+
extension Optional where Wrapped == UnsafeMutablePointer<BridgedSwiftObject> {
63+
public func getAs<T: AnyObject>(_ objectType: T.Type) -> T? {
64+
if let pointer = self {
65+
return Unmanaged<T>.fromOpaque(pointer).takeUnretainedValue()
66+
}
67+
return nil
68+
}
69+
}
70+
71+
extension BridgedArrayRef {
72+
public func withElements<T, R>(ofType ty: T.Type, _ c: (UnsafeBufferPointer<T>) -> R) -> R {
73+
let start = data?.bindMemory(to: ty, capacity: numElements);
74+
let buffer = UnsafeBufferPointer(start: start, count: numElements);
75+
return c(buffer)
76+
}
77+
}

SwiftCompilerSources/Sources/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
# See http://swift.org/LICENSE.txt for license information
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

9+
# NOTE: Subdirectories must be added in dependency order.
10+
11+
add_subdirectory(Basic)
912
if(SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING)
1013
add_subdirectory(ExperimentalRegex)
1114
endif()

SwiftCompilerSources/Sources/Optimizer/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

99
set(dependencies)
10-
list(APPEND dependencies SIL)
10+
list(APPEND dependencies Basic SIL)
1111
if(SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING)
1212
list(APPEND dependencies ExperimentalRegex)
1313
endif()

SwiftCompilerSources/Sources/SIL/Argument.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
import Basic
1314
import SILBridging
1415

1516
/// A basic block argument.

SwiftCompilerSources/Sources/SIL/BasicBlock.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
import Basic
1314
import SILBridging
1415

1516
final public class BasicBlock : ListNode, CustomStringConvertible, HasName {
@@ -95,7 +96,7 @@ public struct SuccessorArray : RandomAccessCollection, FormattedLikeArray {
9596

9697
public subscript(_ index: Int) -> BasicBlock {
9798
precondition(index >= 0 && index < endIndex)
98-
let s = BridgedSuccessor(succ: succArray.data + index &* BridgedSuccessorSize);
99+
let s = BridgedSuccessor(succ: succArray.data! + index &* BridgedSuccessorSize);
99100
return SILSuccessor_getTargetBlock(s).block
100101
}
101102
}

SwiftCompilerSources/Sources/SIL/Builder.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
import Basic
1314
import SILBridging
1415

1516
/// A utility to create new instructions at a given insertion point.

SwiftCompilerSources/Sources/SIL/CMakeLists.txt

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,23 @@
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

99
add_swift_compiler_module(SIL
10-
ApplySite.swift
11-
Argument.swift
12-
BasicBlock.swift
13-
Builder.swift
14-
Effects.swift
15-
Function.swift
16-
GlobalVariable.swift
17-
Instruction.swift
18-
Location.swift
19-
Operand.swift
20-
Registration.swift
21-
SmallProjectionPath.swift
22-
SubstitutionMap.swift
23-
Type.swift
24-
Utils.swift
25-
Value.swift)
10+
DEPENDS
11+
Basic
12+
SOURCES
13+
ApplySite.swift
14+
Argument.swift
15+
BasicBlock.swift
16+
Builder.swift
17+
Effects.swift
18+
Function.swift
19+
GlobalVariable.swift
20+
Instruction.swift
21+
Location.swift
22+
Operand.swift
23+
Registration.swift
24+
SmallProjectionPath.swift
25+
SubstitutionMap.swift
26+
Type.swift
27+
Utils.swift
28+
Value.swift)
2629

SwiftCompilerSources/Sources/SIL/Function.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
import Basic
1314
import SILBridging
1415

1516
final public class Function : CustomStringConvertible, HasName {

SwiftCompilerSources/Sources/SIL/GlobalVariable.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
import Basic
1314
import SILBridging
1415

1516
final public class GlobalVariable : CustomStringConvertible, HasName {

SwiftCompilerSources/Sources/SIL/Instruction.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
import Basic
1314
import SILBridging
1415

1516
//===----------------------------------------------------------------------===//

SwiftCompilerSources/Sources/SIL/Operand.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ public struct OperandArray : RandomAccessCollection, CustomReflectable {
6767

6868
public subscript(_ index: Int) -> Operand {
6969
precondition(index >= 0 && index < endIndex)
70-
return Operand(BridgedOperand(op: opArray.data + index &* BridgedOperandSize))
70+
return Operand(BridgedOperand(op: opArray.data! + index &* BridgedOperandSize))
7171
}
7272

7373
public func getIndex(of operand: Operand) -> Int {
74-
let idx = (operand.bridged.op - UnsafeRawPointer(opArray.data)) /
74+
let idx = (operand.bridged.op - UnsafeRawPointer(opArray.data!)) /
7575
BridgedOperandSize
7676
precondition(self[idx].bridged.op == operand.bridged.op)
7777
return idx
@@ -86,7 +86,7 @@ public struct OperandArray : RandomAccessCollection, CustomReflectable {
8686
precondition(bounds.lowerBound >= 0)
8787
precondition(bounds.upperBound <= endIndex)
8888
return OperandArray(opArray: BridgedArrayRef(
89-
data: opArray.data + bounds.lowerBound &* BridgedOperandSize,
89+
data: opArray.data! + bounds.lowerBound &* BridgedOperandSize,
9090
numElements: bounds.upperBound - bounds.lowerBound))
9191
}
9292
}

SwiftCompilerSources/Sources/SIL/Registration.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
import Basic
1314
import SILBridging
1415

1516
private func register<T: AnyObject>(_ cl: T.Type) {

SwiftCompilerSources/Sources/SIL/Type.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
import Basic
1314
import SILBridging
1415

1516
public struct Type : CustomStringConvertible, CustomReflectable {

SwiftCompilerSources/Sources/SIL/Utils.swift

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -234,28 +234,6 @@ public struct ParsingError : Error {
234234
// Bridging Utilities
235235
//===----------------------------------------------------------------------===//
236236

237-
extension BridgedStringRef {
238-
public var string: String {
239-
let buffer = UnsafeBufferPointer<UInt8>(start: data, count: Int(length))
240-
return String(decoding: buffer, as: UTF8.self)
241-
}
242-
243-
func takeString() -> String {
244-
let str = string
245-
freeBridgedStringRef(self)
246-
return str
247-
}
248-
}
249-
250-
extension String {
251-
public func withBridgedStringRef<T>(_ c: (BridgedStringRef) -> T) -> T {
252-
var str = self
253-
return str.withUTF8 { buffer in
254-
return c(BridgedStringRef(data: buffer.baseAddress, length: buffer.count))
255-
}
256-
}
257-
}
258-
259237
extension Array where Element == Value {
260238
public func withBridgedValues<T>(_ c: (BridgedValueArray) -> T) -> T {
261239
return self.withUnsafeBytes { valPtr in
@@ -265,33 +243,3 @@ extension Array where Element == Value {
265243
}
266244
}
267245

268-
public typealias SwiftObject = UnsafeMutablePointer<BridgedSwiftObject>
269-
270-
extension UnsafeMutablePointer where Pointee == BridgedSwiftObject {
271-
init<T: AnyObject>(_ object: T) {
272-
let ptr = Unmanaged.passUnretained(object).toOpaque()
273-
self = ptr.bindMemory(to: BridgedSwiftObject.self, capacity: 1)
274-
}
275-
276-
func getAs<T: AnyObject>(_ objectType: T.Type) -> T {
277-
return Unmanaged<T>.fromOpaque(self).takeUnretainedValue()
278-
}
279-
}
280-
281-
extension Optional where Wrapped == UnsafeMutablePointer<BridgedSwiftObject> {
282-
func getAs<T: AnyObject>(_ objectType: T.Type) -> T? {
283-
if let pointer = self {
284-
return Unmanaged<T>.fromOpaque(pointer).takeUnretainedValue()
285-
}
286-
return nil
287-
}
288-
}
289-
290-
extension BridgedArrayRef {
291-
func withElements<T, R>(ofType ty: T.Type, _ c: (UnsafeBufferPointer<T>) -> R) -> R {
292-
return data.withMemoryRebound(to: ty, capacity: numElements) { (ptr: UnsafePointer<T>) -> R in
293-
let buffer = UnsafeBufferPointer(start: ptr, count: numElements)
294-
return c(buffer)
295-
}
296-
}
297-
}

SwiftCompilerSources/Sources/SIL/Value.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
import Basic
1314
import SILBridging
1415

1516
public protocol Value : AnyObject, CustomStringConvertible {

0 commit comments

Comments
 (0)