Skip to content

Commit 45e8454

Browse files
authored
Merge branch 'main' into elsh/pkg-sil-verify
2 parents fbb3382 + 2a9a780 commit 45e8454

File tree

604 files changed

+9676
-3689
lines changed

Some content is hidden

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

604 files changed

+9676
-3689
lines changed

CMakeLists.txt

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,9 @@ if(CMAKE_Swift_COMPILER)
108108
enable_language(Swift)
109109
set(DEFAULT_SWIFT_MIN_RUNTIME_VERSION "${CMAKE_Swift_COMPILER_VERSION}")
110110
else()
111-
message(STATUS "WARNING! Did not find a host compiler swift?! Can not build
112-
any compiler host sources written in Swift")
111+
message(WARNING "Swift compiler not found on path.
112+
Cannot build compiler sources written in Swift.
113+
If this is unexpected, please pass the path to the swiftc binary by defining the `CMAKE_Swift_COMPILER` variable.")
113114
set(DEFAULT_SWIFT_MIN_RUNTIME_VERSION)
114115
endif()
115116

@@ -124,7 +125,7 @@ set(SWIFT_DARWIN_EMBEDDED_VARIANTS "^(iphoneos|iphonesimulator|appletvos|appletv
124125
# if("${SWIFT_HOST_VARIANT_SDK}" IN_LIST SWIFT_DARWIN_PLATFORMS)
125126
# ...
126127
# endif()
127-
set(SWIFT_DARWIN_PLATFORMS "IOS" "IOS_SIMULATOR" "TVOS" "TVOS_SIMULATOR" "WATCHOS" "WATCHOS_SIMULATOR" "OSX")
128+
set(SWIFT_DARWIN_PLATFORMS "IOS" "IOS_SIMULATOR" "TVOS" "TVOS_SIMULATOR" "WATCHOS" "WATCHOS_SIMULATOR" "OSX" "XROS" "XROS_SIMULATOR")
128129

129130
set(SWIFT_APPLE_PLATFORMS ${SWIFT_DARWIN_PLATFORMS})
130131
if(SWIFT_FREESTANDING_FLAVOR STREQUAL "apple")
@@ -543,6 +544,9 @@ set(SWIFT_DARWIN_DEPLOYMENT_VERSION_TVOS "11.0" CACHE STRING
543544
set(SWIFT_DARWIN_DEPLOYMENT_VERSION_WATCHOS "4.0" CACHE STRING
544545
"Minimum deployment target version for watchOS")
545546

547+
set(SWIFT_DARWIN_DEPLOYMENT_VERSION_XROS "1.0" CACHE STRING
548+
"Minimum deployment target version for xrOS")
549+
546550
#
547551
# Compatibility library deployment versions
548552
#
@@ -551,6 +555,7 @@ set(COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_OSX "10.9")
551555
set(COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_IOS "7.0")
552556
set(COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_TVOS "9.0")
553557
set(COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_WATCHOS "2.0")
558+
set(COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_XROS "1.0")
554559
set(COMPATIBILITY_MINIMUM_DEPLOYMENT_VERSION_MACCATALYST "13.1")
555560

556561
#
@@ -596,7 +601,7 @@ option(SWIFT_REPORT_STATISTICS
596601
FALSE)
597602

598603
# Only Darwin platforms enable ObjC interop by default.
599-
if("${SWIFT_HOST_VARIANT_SDK}" MATCHES "(OSX|IOS*|TVOS*|WATCHOS*)")
604+
if("${SWIFT_HOST_VARIANT_SDK}" MATCHES "(OSX|IOS*|TVOS*|WATCHOS*|XROS*)")
600605
set(SWIFT_STDLIB_ENABLE_OBJC_INTEROP_default TRUE)
601606
else()
602607
set(SWIFT_STDLIB_ENABLE_OBJC_INTEROP_default FALSE)
@@ -692,6 +697,10 @@ option(SWIFT_ENABLE_GLOBAL_ISEL_ARM64
692697
"Enable global isel on arm64"
693698
FALSE)
694699

700+
option(SWIFT_ENABLE_EXPERIMENTAL_PARSER_VALIDATION
701+
"Enable experimental SwiftParser validation by default"
702+
FALSE)
703+
695704
cmake_dependent_option(SWIFT_BUILD_SOURCEKIT
696705
"Build SourceKit" TRUE
697706
"SWIFT_ENABLE_DISPATCH" FALSE)
@@ -959,6 +968,12 @@ if(XCODE)
959968
swift_common_xcode_cxx_config()
960969
endif()
961970

971+
# Check what linux distribution is being used.
972+
# This can be used to determine the default linker to use.
973+
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.22")
974+
cmake_host_system_information(RESULT DISTRO_NAME QUERY DISTRIB_PRETTY_NAME)
975+
endif()
976+
962977
# Which default linker to use. Prefer LLVM_USE_LINKER if it set, otherwise use
963978
# our own defaults. This should only be possible in a unified (not stand alone)
964979
# build environment.
@@ -970,6 +985,8 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows" AND NOT CMAKE_HOST_SYSTEM_NAME STREQ
970985
set(SWIFT_USE_LINKER_default "lld")
971986
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
972987
set(SWIFT_USE_LINKER_default "")
988+
elseif(DISTRO_NAME STREQUAL "Amazon Linux 2023")
989+
set(SWIFT_USE_LINKER_default "lld")
973990
else()
974991
set(SWIFT_USE_LINKER_default "gold")
975992
endif()
@@ -1136,7 +1153,7 @@ elseif("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "WASI")
11361153
set(SWIFT_PRIMARY_VARIANT_SDK_default "${SWIFT_HOST_VARIANT_SDK}")
11371154
set(SWIFT_PRIMARY_VARIANT_ARCH_default "${SWIFT_HOST_VARIANT_ARCH}")
11381155

1139-
elseif("${SWIFT_HOST_VARIANT_SDK}" MATCHES "(OSX|IOS*|TVOS*|WATCHOS*)")
1156+
elseif("${SWIFT_HOST_VARIANT_SDK}" MATCHES "(OSX|IOS*|TVOS*|WATCHOS*|XROS*)")
11401157

11411158
set(SWIFT_HOST_VARIANT "macosx" CACHE STRING
11421159
"Deployment OS for Swift host tools (the compiler) [macosx, iphoneos].")

SwiftCompilerSources/CMakeLists.txt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,6 @@ function(add_swift_compiler_modules_library name)
9898
"DEPENDS"
9999
${ARGN})
100100

101-
# Prior to 5.9, we have to use the experimental flag for C++ interop.
102-
if (CMAKE_Swift_COMPILER_VERSION VERSION_LESS 5.9)
103-
set(cxx_interop_flag "-enable-experimental-cxx-interop")
104-
else()
105-
set(cxx_interop_flag "-cxx-interoperability-mode=default")
106-
endif()
107-
108101
set(swift_compile_options
109102
"-color-diagnostics"
110103
"-Xfrontend" "-validate-tbd-against-ir=none"
@@ -113,6 +106,12 @@ function(add_swift_compiler_modules_library name)
113106
"-Xcc" "-std=c++17"
114107
"-Xcc" "-DCOMPILED_WITH_SWIFT" "-Xcc" "-DSWIFT_TARGET"
115108
"-Xcc" "-UIBOutlet" "-Xcc" "-UIBAction" "-Xcc" "-UIBInspectable")
109+
# Prior to 5.9, we have to use the experimental flag for C++ interop.
110+
if (CMAKE_Swift_COMPILER_VERSION VERSION_LESS 5.9)
111+
list(APPEND swift_compile_options "-Xfrontend" "-enable-experimental-cxx-interop")
112+
else()
113+
list(APPEND swift_compile_options "-cxx-interoperability-mode=default")
114+
endif()
116115

117116
if (NOT BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS")
118117
if(SWIFT_MIN_RUNTIME_VERSION)
@@ -129,7 +128,9 @@ function(add_swift_compiler_modules_library name)
129128
list(APPEND swift_compile_options "-O" "-cross-module-optimization")
130129
endif()
131130

132-
if(NOT LLVM_ENABLE_ASSERTIONS)
131+
if(LLVM_ENABLE_ASSERTIONS)
132+
list(APPEND swift_compile_options "-Xcc" "-UNDEBUG")
133+
else()
133134
list(APPEND swift_compile_options "-Xcc" "-DNDEBUG")
134135
endif()
135136

@@ -304,7 +305,7 @@ else()
304305

305306
elseif(BOOTSTRAPPING_MODE MATCHES "BOOTSTRAPPING.*")
306307

307-
set(b0_deps swift-frontend-bootstrapping0 symlink-headers-bootstrapping0)
308+
set(b0_deps swift-frontend-bootstrapping0 symlink-headers-bootstrapping0 copy-legacy-layouts)
308309
set(b1_deps swift-frontend-bootstrapping1 symlink-headers-bootstrapping1)
309310
if(BOOTSTRAPPING_MODE STREQUAL "BOOTSTRAPPING")
310311
list(APPEND b0_deps swiftCore-bootstrapping0)

SwiftCompilerSources/Sources/Optimizer/DataStructures/Set.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,16 @@ struct OperandSet : IntrusiveSet {
228228
context.freeOperandSet(bridged)
229229
}
230230
}
231+
232+
extension IntrusiveSet {
233+
mutating func insert(contentsOf source: some Sequence<Element>) {
234+
for element in source {
235+
_ = insert(element)
236+
}
237+
}
238+
239+
init(insertContentsOf source: some Sequence<Element>, _ context: some Context) {
240+
self.init(context)
241+
insert(contentsOf: source)
242+
}
243+
}

SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ swift_compiler_sources(Optimizer
3131
SimplifyStrongRetainRelease.swift
3232
SimplifyStructExtract.swift
3333
SimplifySwitchEnum.swift
34+
SimplifyTuple.swift
3435
SimplifyTupleExtract.swift
3536
SimplifyUncheckedEnumData.swift
3637
SimplifyValueToBridgeObject.swift)

SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/SimplifyBranch.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,15 @@ private extension BranchInst {
4949
let parentBB = parentBlock
5050

5151
for (argIdx, op) in operands.enumerated() {
52-
targetBB.arguments[argIdx].uses.replaceAll(with: op.value, context)
52+
let arg = targetBB.arguments[argIdx]
53+
if let phi = Phi(arg),
54+
let bfi = phi.borrowedFrom
55+
{
56+
bfi.uses.replaceAll(with: op.value, context)
57+
context.erase(instruction: bfi)
58+
} else {
59+
arg.uses.replaceAll(with: op.value, context)
60+
}
5361
}
5462
targetBB.eraseAllArguments(context)
5563

SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/SimplifySwitchEnum.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,14 @@ extension SwitchEnumInst : OnoneSimplifyable {
4848
precondition(enumInst.payload == nil || !parentFunction.hasOwnership,
4949
"missing payload argument in switch_enum case block")
5050
builder.createBranch(to: caseBlock)
51+
context.erase(instruction: self)
5152
case 1:
5253
builder.createBranch(to: caseBlock, arguments: [enumInst.payload!])
54+
context.erase(instruction: self)
55+
updateBorrowedFrom(for: [Phi(caseBlock.arguments[0])!], context)
5356
default:
5457
fatalError("case block of switch_enum cannot have more than 1 argument")
5558
}
56-
context.erase(instruction: self)
5759

5860
if canEraseEnumInst {
5961
context.erase(instructionIncludingDebugUses: enumInst)
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
//===--- SimplifyTuple.swift ---------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2024 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+
import SIL
14+
15+
extension TupleInst : OnoneSimplifyable {
16+
func simplify(_ context: SimplifyContext) {
17+
18+
// Eliminate the redundant instruction pair
19+
// ```
20+
// (%3, %4, %5) = destructure_tuple %input
21+
// %output = tuple (%3, %4, %5)
22+
// ```
23+
// and replace the result %output with %input
24+
//
25+
var destructure: DestructureTupleInst?
26+
for operand in operands {
27+
guard let def = operand.value.definingInstruction as? DestructureTupleInst else {
28+
return
29+
}
30+
guard let destructure else {
31+
destructure = def
32+
continue
33+
}
34+
if destructure != def {
35+
return
36+
}
37+
}
38+
guard let destructure else {
39+
return
40+
}
41+
guard destructure.operand.value.type == type else {
42+
return
43+
}
44+
// The destructure's operand having the same type as the tuple ensures that
45+
// the count of results of the destructure is equal to the count of operands
46+
// of the tuple.
47+
assert(destructure.results.count == operands.count)
48+
for (result, operand) in zip(destructure.results, operands) {
49+
if result != operand.value {
50+
return
51+
}
52+
}
53+
tryReplaceDestructConstructPair(destruct: destructure, construct: self, context)
54+
}
55+
}
56+
57+
private func tryReplaceDestructConstructPair(destruct: MultipleValueInstruction & UnaryInstruction,
58+
construct: SingleValueInstruction,
59+
_ context: SimplifyContext) {
60+
let everyResultUsedOnce = context.preserveDebugInfo
61+
? destruct.results.allSatisfy { $0.uses.singleUse != nil }
62+
: destruct.results.allSatisfy { $0.uses.ignoreDebugUses.singleUse != nil }
63+
let anyOwned = destruct.results.contains { $0.ownership == .owned }
64+
65+
if !everyResultUsedOnce && construct.parentFunction.hasOwnership && anyOwned {
66+
// We cannot add more uses to this destructure without inserting a copy.
67+
return
68+
}
69+
70+
construct.uses.replaceAll(with: destruct.operand.value, context)
71+
72+
if everyResultUsedOnce {
73+
context.erase(instructionIncludingDebugUses: construct)
74+
}
75+
}

SwiftCompilerSources/Sources/Optimizer/PassManager/PassRegistration.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ private func registerSwiftPasses() {
117117
registerPass(rangeDumper, { rangeDumper.run($0) })
118118
registerPass(runUnitTests, { runUnitTests.run($0) })
119119
registerPass(testInstructionIteration, { testInstructionIteration.run($0) })
120+
registerPass(updateBorrowedFromPass, { updateBorrowedFromPass.run($0) })
120121
}
121122

122123
private func registerSwiftAnalyses() {
@@ -126,4 +127,5 @@ private func registerSwiftAnalyses() {
126127

127128
private func registerUtilities() {
128129
registerVerifier()
130+
registerBorrowedFromUpdater()
129131
}

0 commit comments

Comments
 (0)