Skip to content

Commit 8e2626e

Browse files
Merge pull request #4906 from swiftwasm/katei/merge-main-2022-09-17
Merge main 2022-09-17
2 parents 290e083 + b49e7ed commit 8e2626e

File tree

355 files changed

+7317
-4724
lines changed

Some content is hidden

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

355 files changed

+7317
-4724
lines changed

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,7 @@ get_filename_component(SWIFT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} REALPATH)
740740
set(SWIFT_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
741741
set(SWIFT_CMAKE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
742742
set(SWIFT_MAIN_INCLUDE_DIR "${SWIFT_SOURCE_DIR}/include")
743+
set(SWIFT_SHIMS_INCLUDE_DIR "${SWIFT_SOURCE_DIR}/stdlib/public/SwiftShims")
743744
set(SWIFT_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/include")
744745

745746
set(SWIFT_RUNTIME_OUTPUT_INTDIR "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin")
@@ -790,6 +791,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
790791
include_directories(BEFORE
791792
${SWIFT_MAIN_INCLUDE_DIR}
792793
${SWIFT_INCLUDE_DIR}
794+
${SWIFT_SHIMS_INCLUDE_DIR}
793795
)
794796

795797
# Configuration flags passed to all of our invocations of gyb. Try to
@@ -1197,7 +1199,7 @@ else()
11971199
# Some tools (e.g. swift-reflection-dump) rely on a host swiftReflection, so
11981200
# ensure we build that when building tools.
11991201
if(SWIFT_INCLUDE_TOOLS)
1200-
add_subdirectory(stdlib/public/SwiftShims)
1202+
add_subdirectory(stdlib/public/SwiftShims/swift/shims)
12011203
endif()
12021204
endif()
12031205

SwiftCompilerSources/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ function(add_swift_compiler_modules_library name)
126126
get_versioned_target_triple(target ${SWIFT_HOST_VARIANT_SDK}
127127
${SWIFT_HOST_VARIANT_ARCH} "${deployment_version}")
128128

129+
# Let Swift discover SwiftShims headers which are included by some headers
130+
# under `include/swift`.
131+
get_filename_component(swift_exec_bin_dir ${ALS_SWIFT_EXEC} DIRECTORY)
132+
set(sdk_option ${sdk_option} "-I" "${swift_exec_bin_dir}/../lib")
133+
129134
set(all_obj_files)
130135
set(all_module_targets)
131136
set(syntaxparse_obj_files)
@@ -264,6 +269,7 @@ else()
264269
# The swift modules can now depend on that target.
265270
# Note that this library is unused, i.e. not linked to anything.
266271
add_library(importedHeaderDependencies "${CMAKE_CURRENT_BINARY_DIR}/HeaderDependencies.cpp")
272+
add_dependencies(importedHeaderDependencies swift-ast-generated-headers)
267273
target_include_directories(importedHeaderDependencies PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../include/swift")
268274

269275
if(${BOOTSTRAPPING_MODE} MATCHES "HOSTTOOLS|CROSSCOMPILE")

SwiftCompilerSources/Sources/Basic/Utils.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,34 @@
1313
@_exported import BasicBridging
1414
import std
1515

16+
/// The assert function to be used in the compiler.
17+
///
18+
/// This overrides the standard Swift assert for two reasons:
19+
/// * We also like to check for assert failures in release builds. Although this could be
20+
/// achieved with `precondition`, it's easy to forget about it and use `assert` instead.
21+
/// * We need to see the error message in crashlogs of release builds. This is even not the
22+
/// case for `precondition`.
23+
@_transparent
24+
public func assert(_ condition: Bool, _ message: @autoclosure () -> String,
25+
file: StaticString = #fileID, line: UInt = #line) {
26+
if !condition {
27+
print("### basic")
28+
fatalError(message(), file: file, line: line)
29+
}
30+
}
31+
32+
/// The assert function (without a message) to be used in the compiler.
33+
///
34+
/// Unforuntately it's not possible to just add a default argument to `message` in the
35+
/// other `assert` function. We need to defined this overload.
36+
@_transparent
37+
public func assert(_ condition: Bool, file: StaticString = #fileID, line: UInt = #line) {
38+
if !condition {
39+
fatalError("", file: file, line: line)
40+
}
41+
}
42+
43+
1644
//===----------------------------------------------------------------------===//
1745
// StringRef
1846
//===----------------------------------------------------------------------===//

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ObjCBridgingOptimization.swift

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

13-
import Basic
1413
import SIL
1514

1615
/// Removes redundant ObjectiveC <-> Swift bridging calls.

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/StackPromotion.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func tryPromoteAlloc(_ allocRef: AllocRefInstBase,
125125
var (innerRange, outerBlockRange) = computeInnerAndOuterLiferanges(instruction: allocRef, in: outerDominatingBlock, domTree: domTree, context: context)
126126
defer { innerRange.deinitialize(); outerBlockRange.deinitialize() }
127127

128-
precondition(innerRange.blockRange.isValid, "inner range should be valid because we did a dominance check")
128+
assert(innerRange.blockRange.isValid, "inner range should be valid because we did a dominance check")
129129

130130
if !outerBlockRange.isValid {
131131
// This happens if we fail to find a correct outerDominatingBlock.
@@ -282,7 +282,7 @@ private extension BasicBlockRange {
282282
}
283283

284284
for lifeBlock in inclusiveRange {
285-
precondition(otherRange.inclusiveRangeContains(lifeBlock), "range must be a subset of other range")
285+
assert(otherRange.inclusiveRangeContains(lifeBlock), "range must be a subset of other range")
286286
for succ in lifeBlock.successors {
287287
if isOnlyInOtherRange(succ) {
288288
return true

SwiftCompilerSources/Sources/Optimizer/InstructionPasses/SimplifyBeginCOWMutation.swift

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

13-
import Basic
1413
import SIL
1514

1615
/// Simplify begin_cow_mutation instructions.

SwiftCompilerSources/Sources/Optimizer/PassManager/ModulePassContext.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct ModulePassContext {
4242
var endIndex: Int { return Int(bridged.count) }
4343

4444
subscript(_ index: Int) -> VTable {
45-
precondition(index >= 0 && index < bridged.count)
45+
assert(index >= 0 && index < bridged.count)
4646
return VTable(bridged: bridged.vTables![index])
4747
}
4848
}

SwiftCompilerSources/Sources/Optimizer/TestPasses/RangeDumper.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ let rangeDumper = FunctionPass(name: "dump-ranges", {
2929
if let sli = inst as? StringLiteralInst {
3030
switch sli.string {
3131
case "begin":
32-
precondition(begin == nil, "more than one begin instruction")
32+
assert(begin == nil, "more than one begin instruction")
3333
begin = sli
3434
case "end":
3535
ends.append(sli)
@@ -62,16 +62,16 @@ let rangeDumper = FunctionPass(name: "dump-ranges", {
6262
verify(instRange.blockRange, context)
6363

6464
for i in ins {
65-
precondition(instRange.contains(i))
66-
precondition(instRange.inclusiveRangeContains(i))
65+
assert(instRange.contains(i))
66+
assert(instRange.inclusiveRangeContains(i))
6767
}
6868
for e in ends {
69-
precondition(!instRange.contains(e))
70-
precondition(instRange.inclusiveRangeContains(e))
69+
assert(!instRange.contains(e))
70+
assert(instRange.inclusiveRangeContains(e))
7171
}
7272
for o in outs {
73-
precondition(!instRange.contains(o))
74-
precondition(!instRange.inclusiveRangeContains(o))
73+
assert(!instRange.contains(o))
74+
assert(!instRange.inclusiveRangeContains(o))
7575
}
7676
})
7777

@@ -89,8 +89,8 @@ private func verify(_ blockRange: BasicBlockRange, _ context: PassContext) {
8989
}
9090

9191
for b in blockRange.begin.function.blocks {
92-
precondition(blockRange.contains(b) == inRange.contains(b))
93-
precondition(blockRange.inclusiveRangeContains(b) == inInclusiveRange.contains(b))
92+
assert(blockRange.contains(b) == inRange.contains(b))
93+
assert(blockRange.inclusiveRangeContains(b) == inInclusiveRange.contains(b))
9494
}
9595
}
9696

SwiftCompilerSources/Sources/Optimizer/Utilities/EscapeInfo.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ fileprivate struct EscapeInfoWalker<V: EscapeInfoVisitor> : ValueDefUseWalker,
303303
}
304304

305305
mutating func start(forAnalyzingAddresses: Bool) {
306-
precondition(walkDownCache.isEmpty && walkUpCache.isEmpty)
306+
assert(walkDownCache.isEmpty && walkUpCache.isEmpty)
307307
analyzeAddresses = forAnalyzingAddresses
308308
}
309309

SwiftCompilerSources/Sources/Optimizer/Utilities/OptUtils.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ extension Value {
4444
/// in a loop while this value is not in that loop, the value has to be copied for
4545
/// each loop iteration.
4646
func makeAvailable(in destBlock: BasicBlock, _ context: PassContext) -> Value {
47-
precondition(uses.isEmpty)
48-
precondition(ownership == .owned)
47+
assert(uses.isEmpty)
48+
assert(ownership == .owned)
4949

5050
let beginBlock = definingBlock
5151
var useToDefRange = BasicBlockRange(begin: beginBlock, context)

0 commit comments

Comments
 (0)