Skip to content

Commit e0ad7bd

Browse files
Merge branch 'main' into mpokhylets/isolated-deinit
# Conflicts: # include/swift/Basic/Features.def # lib/AST/ASTPrinter.cpp # lib/AST/FeatureSet.cpp
2 parents d6673c7 + 406b8bd commit e0ad7bd

File tree

563 files changed

+11313
-6074
lines changed

Some content is hidden

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

563 files changed

+11313
-6074
lines changed

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,13 @@ if(SWIFT_INCLUDE_TOOLS AND SWIFT_BUILD_SWIFT_SYNTAX)
968968
if(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|OPENBSD|FREEBSD" AND NOT BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS")
969969
message(WARNING "Force setting BOOTSTRAPPING=HOSTTOOLS because Swift parser integration is enabled")
970970
set(BOOTSTRAPPING_MODE "HOSTTOOLS")
971+
if(NOT CMAKE_Swift_COMPILER)
972+
message(SEND_ERROR "No Swift compiler found.\n"
973+
"Tell CMake where to find the Swift compiler by setting either the "
974+
"environment variable \"SWIFTC\" or the CMake cache entry "
975+
"CMAKE_Swift_COMPILER to the full path of the compiler, or to the "
976+
"compiler name if it is in the PATH")
977+
endif()
971978
endif()
972979
add_definitions(-DSWIFT_BUILD_SWIFT_SYNTAX)
973980
endif()

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
| **Ubuntu 20.04** | AArch64 |[![Build Status](https://ci.swift.org/job/oss-swift-package-ubuntu-20_04-aarch64/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-ubuntu-20_04-aarch64)|
1414
| **Ubuntu 22.04** | x86_64 |[![Build Status](https://ci.swift.org/job/oss-swift-package-ubuntu-22_04/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-ubuntu-22_04)|
1515
| **Ubuntu 22.04** | AArch64 |[![Build Status](https://ci.swift.org/job/oss-swift-package-ubuntu-22_04-aarch64/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-ubuntu-22_04-aarch64)|
16-
| **CentOS 7** | x86_64 |[![Build Status](https://ci.swift.org/job/oss-swift-package-centos-7/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-centos-7)|
16+
| **Ubuntu 24.04** | x86_64 |[![Build Status](https://ci.swift.org/job/oss-swift-package-ubuntu-24_04/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-ubuntu-24_04)|
17+
| **Ubuntu 24.04** | AArch64 |[![Build Status](https://ci.swift.org/job/oss-swift-package-ubuntu-24_04-aarch64/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-ubuntu-24_04-aarch64)|
1718
| **Amazon Linux 2** | x86_64 |[![Build Status](https://ci.swift.org/job/oss-swift-package-amazon-linux-2/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-amazon-linux-2)|
1819
| **Amazon Linux 2** | AArch64 |[![Build Status](https://ci.swift.org/job/oss-swift-package-amazon-linux-2-aarch64/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-amazon-linux-2-aarch64)|
1920
| **Universal Base Image 9** | x86_64 |[![Build Status](https://ci.swift.org/job/oss-swift-package-ubi-9/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-ubi-9)|
@@ -103,7 +104,7 @@ script is used by swift.org's CI to produce snapshots and can allow for one to
103104
locally reproduce such builds for development or distribution purposes. A typical
104105
invocation looks like the following:
105106

106-
```
107+
```sh
107108
$ ./swift/utils/build-toolchain $BUNDLE_PREFIX
108109
```
109110

@@ -134,7 +135,7 @@ On macOS if one wants to install such a toolchain into Xcode:
134135
1. Untar and copy the toolchain to one of `/Library/Developer/Toolchains/` or
135136
`~/Library/Developer/Toolchains/`. E.g.:
136137

137-
```
138+
```sh
138139
$ sudo tar -xzf swift-LOCAL-YYYY-MM-DD-a-osx.tar.gz -C /
139140
$ tar -xzf swift-LOCAL-YYYY-MM-DD-a-osx.tar.gz -C ~/
140141
```
@@ -143,7 +144,7 @@ The script also generates an archive containing debug symbols which
143144
can be installed over the main archive allowing symbolication of any
144145
compiler crashes.
145146

146-
```
147+
```sh
147148
$ sudo tar -xzf swift-LOCAL-YYYY-MM-DD-a-osx-symbols.tar.gz -C /
148149
$ tar -xzf swift-LOCAL-YYYY-MM-DD-a-osx-symbols.tar.gz -C ~/
149150
```

SwiftCompilerSources/Sources/Optimizer/DataStructures/FunctionUses.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct FunctionUses {
4545
var hasUnknownUses: Bool
4646

4747
init(of function: Function) {
48-
self.hasUnknownUses = function.isPossiblyUsedExternally || function.isAvailableExternally
48+
self.hasUnknownUses = function.isPossiblyUsedExternally || function.isDefinedExternally
4949
}
5050

5151
mutating func insert(_ inst: Instruction, _ uses: inout [Use]) {

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ClosureSpecialization.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ let generalClosureSpecialization = FunctionPass(name: "experimental-swift-based-
119119
let autodiffClosureSpecialization = FunctionPass(name: "autodiff-closure-specialization") {
120120
(function: Function, context: FunctionPassContext) in
121121

122-
guard !function.isAvailableExternally,
122+
guard !function.isDefinedExternally,
123123
function.isAutodiffVJP,
124124
function.blocks.singleElement != nil else {
125125
return
@@ -502,7 +502,7 @@ private func handleApplies(for rootClosure: SingleValueInstruction, callSiteMap:
502502
continue
503503
}
504504

505-
if callee.isAvailableExternally {
505+
if callee.isDefinedExternally {
506506
continue
507507
}
508508

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ComputeSideEffects.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import SIL
2727
let computeSideEffects = FunctionPass(name: "compute-side-effects") {
2828
(function: Function, context: FunctionPassContext) in
2929

30-
if function.isAvailableExternally {
30+
if function.isDefinedExternally {
3131
// We cannot assume anything about function, which are defined in another module,
3232
// even if the serialized SIL of its body is available in the current module.
3333
// If the other module was compiled with library evolution, the implementation

SwiftCompilerSources/Sources/Optimizer/ModulePasses/MandatoryPerformanceOptimizations.swift

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,16 @@ private func optimize(function: Function, _ context: FunctionPassContext, _ modu
118118
context.erase(instructionIncludingDebugUses: iem)
119119
}
120120

121+
case let fri as FunctionRefInst:
122+
// Mandatory de-virtualization and mandatory inlining might leave referenced functions in "serialized"
123+
// functions with wrong linkage. Fix this by making the referenced function public.
124+
// It's not great, because it can prevent dead code elimination. But it's only a rare case.
125+
if function.serializedKind != .notSerialized,
126+
!fri.referencedFunction.hasValidLinkageForFragileRef(function.serializedKind)
127+
{
128+
fri.referencedFunction.set(linkage: .public, moduleContext)
129+
}
130+
121131
default:
122132
break
123133
}
@@ -153,6 +163,8 @@ private func specializeVTableAndAddEntriesToWorklist(for type: Type, in function
153163

154164
private func inlineAndDevirtualize(apply: FullApplySite, alreadyInlinedFunctions: inout Set<PathFunctionTuple>,
155165
_ context: FunctionPassContext, _ simplifyCtxt: SimplifyContext) {
166+
// De-virtualization and inlining in/into a "serialized" function might create function references to functions
167+
// with wrong linkage. We need to fix this later (see handling of FunctionRefInst in `optimize`).
156168
if simplifyCtxt.tryDevirtualize(apply: apply, isMandatory: true) != nil {
157169
return
158170
}
@@ -166,9 +178,7 @@ private func inlineAndDevirtualize(apply: FullApplySite, alreadyInlinedFunctions
166178
return
167179
}
168180

169-
if apply.canInline &&
170-
shouldInline(apply: apply, callee: callee, alreadyInlinedFunctions: &alreadyInlinedFunctions)
171-
{
181+
if shouldInline(apply: apply, callee: callee, alreadyInlinedFunctions: &alreadyInlinedFunctions) {
172182
if apply.inliningCanInvalidateStackNesting {
173183
simplifyCtxt.notifyInvalidatedStackNesting()
174184
}
@@ -196,9 +206,14 @@ private func removeUnusedMetatypeInstructions(in function: Function, _ context:
196206

197207
private func shouldInline(apply: FullApplySite, callee: Function, alreadyInlinedFunctions: inout Set<PathFunctionTuple>) -> Bool {
198208
if callee.isTransparent {
209+
precondition(callee.hasOwnership, "transparent functions should have ownership at this stage of the pipeline")
199210
return true
200211
}
201212

213+
if !apply.canInline {
214+
return false
215+
}
216+
202217
if apply is BeginApplyInst {
203218
// Avoid co-routines because they might allocate (their context).
204219
return true

SwiftCompilerSources/Sources/Optimizer/ModulePasses/ReadOnlyGlobalVariables.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ let readOnlyGlobalVariablesPass = ModulePass(name: "read-only-global-variables")
3535
}
3636

3737
for g in moduleContext.globalVariables {
38-
if !g.isAvailableExternally,
38+
if !g.isDefinedExternally,
3939
!g.isPossiblyUsedExternally,
4040
!g.isLet,
4141
!writtenGlobals.contains(g) {

SwiftCompilerSources/Sources/Optimizer/PassManager/ModulePassContext.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,9 @@ extension GlobalVariable {
171171
bridged.setLet(value)
172172
}
173173
}
174+
175+
extension Function {
176+
func set(linkage: Linkage, _ context: ModulePassContext) {
177+
bridged.setLinkage(linkage.bridged)
178+
}
179+
}

SwiftCompilerSources/Sources/Optimizer/Utilities/LocalVariableUtils.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,8 @@ extension LocalVariableAccessWalker: AddressUseVisitor {
420420
mutating func leafAddressUse(of operand: Operand) -> WalkResult {
421421
switch operand.instruction {
422422
case is StoringInstruction, is SourceDestAddrInstruction, is DestroyAddrInst, is DeinitExistentialAddrInst,
423-
is InjectEnumAddrInst, is TupleAddrConstructorInst, is InitBlockStorageHeaderInst, is PackElementSetInst:
423+
is InjectEnumAddrInst, is SwitchEnumAddrInst, is TupleAddrConstructorInst, is InitBlockStorageHeaderInst,
424+
is PackElementSetInst:
424425
// Handle instructions that initialize both temporaries and local variables.
425426
visit(LocalVariableAccess(.store, operand))
426427
case is DeallocStackInst:

SwiftCompilerSources/Sources/SIL/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ add_swift_compiler_module(SIL
2020
FunctionConvention.swift
2121
GlobalVariable.swift
2222
Instruction.swift
23+
Linkage.swift
2324
Location.swift
2425
Operand.swift
2526
Registration.swift

0 commit comments

Comments
 (0)