Skip to content

Commit 73f39af

Browse files
Merge remote-tracking branch 'origin/main' into felipe/fix_merge_opaque
The following tests required conflict resolutions, since upstream LLVM did a lot of work to remove dbg.addr, and this work is not available to swift's main. At the same time, swift's main changed these tests to enable opaque pointers. ``` both modified: test/DebugInfo/async-let-await.swift both modified: test/DebugInfo/move_function_dbginfo.swift both modified: test/DebugInfo/move_function_dbginfo_async.swift ``` The conflicts are fairly easy to fix: we keep the "structure" of the CHECK lines present in `next`, but replace all pointers with `ptr`.
2 parents d8e8582 + 0bb142f commit 73f39af

File tree

606 files changed

+13401
-7287
lines changed

Some content is hidden

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

606 files changed

+13401
-7287
lines changed

CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,11 @@ option(SWIFT_THREADING_PACKAGE
646646
Valid package names are 'pthreads', 'darwin', 'linux', 'win32', 'c11', 'none'
647647
or the empty string for the SDK default.")
648648

649+
option(SWIFT_THREADING_HAS_DLSYM
650+
"Enable the use of the dlsym() function. This gets used to provide TSan
651+
support on some platforms."
652+
TRUE)
653+
649654
option(SWIFT_ENABLE_MACCATALYST
650655
"Build the Standard Library and overlays with MacCatalyst support"
651656
FALSE)
@@ -1043,6 +1048,14 @@ elseif("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "ANDROID")
10431048
set(SWIFT_PRIMARY_VARIANT_SDK_default "${SWIFT_HOST_VARIANT_SDK}")
10441049
set(SWIFT_PRIMARY_VARIANT_ARCH_default "${SWIFT_HOST_VARIANT_ARCH}")
10451050

1051+
elseif("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "WASI")
1052+
set(SWIFT_HOST_VARIANT "wasi" CACHE STRING
1053+
"Deployment OS for Swift host tools (the compiler) [wasi]")
1054+
1055+
configure_sdk_unix("WASI" "wasm32")
1056+
set(SWIFT_PRIMARY_VARIANT_SDK_default "${SWIFT_HOST_VARIANT_SDK}")
1057+
set(SWIFT_PRIMARY_VARIANT_ARCH_default "${SWIFT_HOST_VARIANT_ARCH}")
1058+
10461059
elseif("${SWIFT_HOST_VARIANT_SDK}" MATCHES "(OSX|IOS*|TVOS*|WATCHOS*)")
10471060

10481061
set(SWIFT_HOST_VARIANT "macosx" CACHE STRING

SwiftCompilerSources/Sources/Optimizer/DataStructures/Stack.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ struct Stack<Element> : CollectionLikeSequence {
4747

4848
mutating func next() -> Element? {
4949
let end = (slab.data == lastSlab.data ? endIndex : slabCapacity)
50-
if index < end {
51-
let elem = Stack.bind(slab)[index]
52-
index += 1
53-
54-
if index >= end && slab.data != lastSlab.data {
55-
slab = slab.getNext()
56-
index = 0
57-
}
58-
return elem
50+
51+
guard index < end else { return nil }
52+
53+
let elem = Stack.bind(slab)[index]
54+
index += 1
55+
56+
if index >= end && slab.data != lastSlab.data {
57+
slab = slab.getNext()
58+
index = 0
5959
}
60-
return nil
60+
return elem
6161
}
6262
}
6363

SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ swift_compiler_sources(Optimizer
1919
SimplifyInitEnumDataAddr.swift
2020
SimplifyLoad.swift
2121
SimplifyPartialApply.swift
22+
SimplifyRefCasts.swift
2223
SimplifyRetainReleaseValue.swift
2324
SimplifyStrongRetainRelease.swift
2425
SimplifyStructExtract.swift
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
//===--- SimplifyRefCasts.swift -------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2023 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+
// Note: this simplifications are not SILCombineSimplifyable, because SILCombine has
16+
// its own simplifications for those cast instructions which are not ported to Swift, yet.
17+
18+
extension CheckedCastBranchInst : OnoneSimplifyable {
19+
func simplify(_ context: SimplifyContext) {
20+
// Has only an effect if the source is an (existential) reference.
21+
simplifySourceOperandOfRefCast(context)
22+
}
23+
}
24+
25+
extension UncheckedRefCastInst : OnoneSimplifyable {
26+
func simplify(_ context: SimplifyContext) {
27+
simplifySourceOperandOfRefCast(context)
28+
}
29+
}
30+
31+
private extension UnaryInstruction {
32+
33+
/// Look through `upcast` and `init_existential_ref` instructions and replace the
34+
/// operand of this cast instruction with the original value.
35+
/// For example:
36+
/// ```
37+
/// %2 = upcast %1 : $Derived to $Base
38+
/// %3 = init_existential_ref %2 : $Base : $Base, $AnyObject
39+
/// checked_cast_br %3 : $AnyObject to Derived, bb1, bb2
40+
/// ```
41+
///
42+
/// This makes it more likely that the cast can be constant folded because the source
43+
/// operand's type is more accurate. In the example above, the cast reduces to
44+
/// ```
45+
/// checked_cast_br %1 : $Derived to Derived, bb1, bb2
46+
/// ```
47+
/// which can be trivially folded to always-succeeds.
48+
///
49+
func simplifySourceOperandOfRefCast(_ context: SimplifyContext) {
50+
while true {
51+
switch operand.value {
52+
case let ier as InitExistentialRefInst:
53+
if !tryReplaceSource(withOperandOf: ier, context) {
54+
return
55+
}
56+
case let uc as UpcastInst:
57+
if !tryReplaceSource(withOperandOf: uc, context) {
58+
return
59+
}
60+
default:
61+
return
62+
}
63+
}
64+
65+
}
66+
67+
func tryReplaceSource(withOperandOf inst: SingleValueInstruction, _ context: SimplifyContext) -> Bool {
68+
let singleUse = context.preserveDebugInfo ? inst.uses.singleUse : inst.uses.singleNonDebugUse
69+
let canEraseInst = singleUse?.instruction == self
70+
let replacement = inst.operands[0].value
71+
72+
if parentFunction.hasOwnership {
73+
if !canEraseInst && replacement.ownership == .owned {
74+
// We cannot add more uses to `replacement` without inserting a copy.
75+
return false
76+
}
77+
78+
operand.set(to: replacement, context)
79+
80+
if let ccb = self as? CheckedCastBranchInst {
81+
// In OSSA, the source value is passed as block argument to the failure block.
82+
// We have to re-create the skipped source instruction in the failure block.
83+
insertCompensatingInstructions(for: inst, in: ccb.failureBlock, context)
84+
}
85+
} else {
86+
operand.set(to: replacement, context)
87+
}
88+
89+
if canEraseInst {
90+
context.erase(instructionIncludingDebugUses: inst)
91+
}
92+
return true
93+
}
94+
}
95+
96+
/// Compensate a removed source value instruction in the failure block.
97+
/// For example:
98+
/// ```
99+
/// %inst = upcast %sourceValue : $Derived to $Base
100+
/// checked_cast_br %inst : $Base to Derived, success_block, failure_block
101+
/// ...
102+
/// failure_block(%oldArg : $Base):
103+
/// ```
104+
/// is converted to:
105+
/// ```
106+
/// checked_cast_br %sourceValue : $Derived to Derived, success_block, failure_block
107+
/// ...
108+
/// failure_block(%newArg : $Derived):
109+
/// %3 = upcast %newArg : $Derived to $Base
110+
/// ```
111+
private func insertCompensatingInstructions(for inst: Instruction, in failureBlock: BasicBlock, _ context: SimplifyContext) {
112+
assert(failureBlock.arguments.count == 1)
113+
let sourceValue = inst.operands[0].value
114+
let newArg = failureBlock.addBlockArgument(type: sourceValue.type, ownership: sourceValue.ownership, context)
115+
let builder = Builder(atBeginOf: failureBlock, context)
116+
let newInst: SingleValueInstruction
117+
switch inst {
118+
case let ier as InitExistentialRefInst:
119+
newInst = builder.createInitExistentialRef(instance: newArg, existentialType: ier.type, useConformancesOf: ier)
120+
case let uc as UpcastInst:
121+
newInst = builder.createUpcast(from: newArg, to: uc.type)
122+
default:
123+
fatalError("unhandled instruction")
124+
}
125+
let oldArg = failureBlock.arguments[0]
126+
oldArg.uses.replaceAll(with: newInst, context)
127+
failureBlock.eraseArgument(at: 0, context)
128+
}

SwiftCompilerSources/Sources/Optimizer/ModulePasses/StackProtection.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,10 +524,19 @@ private struct NoStores : ValueDefUseWalker, AddressDefUseWalker {
524524
var walkDownCache = WalkerCache<SmallProjectionPath>()
525525

526526
mutating func leafUse(value: Operand, path: SmallProjectionPath) -> WalkResult {
527-
if let ptai = value.instruction as? PointerToAddressInst {
527+
switch value.instruction {
528+
case let ptai as PointerToAddressInst:
528529
return walkDownUses(ofAddress: ptai, path: path)
530+
case let bi as BuiltinInst:
531+
switch bi.intrinsicID {
532+
case .memcpy, .memmove:
533+
return value.index != 0 ? .continueWalk : .abortWalk
534+
default:
535+
return .abortWalk
536+
}
537+
default:
538+
return .abortWalk
529539
}
530-
return .abortWalk
531540
}
532541

533542
mutating func leafUse(address: Operand, path: SmallProjectionPath) -> WalkResult {

SwiftCompilerSources/Sources/SIL/Builder.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,13 @@ public struct Builder {
262262
let store = bridged.createStore(source.bridged, destination.bridged, ownership.rawValue)
263263
return notifyNew(store.getAs(StoreInst.self))
264264
}
265+
266+
public func createInitExistentialRef(instance: Value,
267+
existentialType: Type,
268+
useConformancesOf: InitExistentialRefInst) -> InitExistentialRefInst {
269+
let initExistential = bridged.createInitExistentialRef(instance.bridged,
270+
existentialType.bridged,
271+
useConformancesOf.bridged)
272+
return notifyNew(initExistential.getAs(InitExistentialRefInst.self))
273+
}
265274
}

SwiftCompilerSources/Sources/SIL/Instruction.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,10 @@ final public class BuiltinInst : SingleValueInstruction {
399399
return bridged.BuiltinInst_getID()
400400
}
401401

402+
public var intrinsicID: BridgedInstruction.IntrinsicID {
403+
return bridged.BuiltinInst_getIntrinsicID()
404+
}
405+
402406
public var substitutionMap: SubstitutionMap {
403407
SubstitutionMap(bridged.BuiltinInst_getSubstitutionMap())
404408
}
@@ -1000,6 +1004,9 @@ final public class AwaitAsyncContinuationInst : TermInst, UnaryInstruction {
10001004
}
10011005

10021006
final public class CheckedCastBranchInst : TermInst, UnaryInstruction {
1007+
public var source: Value { operand.value }
1008+
public var successBlock: BasicBlock { bridged.CheckedCastBranch_getSuccessBlock().block }
1009+
public var failureBlock: BasicBlock { bridged.CheckedCastBranch_getFailureBlock().block }
10031010
}
10041011

10051012
final public class CheckedCastAddrBranchInst : TermInst, UnaryInstruction {

benchmark/cmake/modules/AddSwiftBenchmarkSuite.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ macro(configure_sdks_darwin)
110110
set(appletvos_arch "arm64")
111111
set(watchos_arch "armv7k" "arm64_32")
112112

113-
set(macosx_ver "10.9")
114-
set(iphoneos_ver "8.0")
115-
set(appletvos_ver "9.1")
116-
set(watchos_ver "2.0")
113+
set(macosx_ver "10.13")
114+
set(iphoneos_ver "11.0")
115+
set(appletvos_ver "11.0")
116+
set(watchos_ver "4.0")
117117

118118
set(macosx_vendor "apple")
119119
set(iphoneos_vendor "apple")

cmake/modules/AddSwift.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ function(_add_host_variant_c_compile_flags target)
259259
# (see revision d913eefcc93f8c80d6d1a6de4ea898a2838d8b6f)
260260
# This is required to build with VS2017 15.8+
261261
_ENABLE_EXTENDED_ALIGNED_STORAGE=1>)
262+
if(SWIFT_HOST_VARIANT_ARCH MATCHES "ARM64|aarch64")
263+
target_compile_options(${target} PRIVATE
264+
$<$<COMPILE_LANGUAGE:C,CXX,OBJC,OBJCXX>:-D_STD_ATOMIC_USE_ARM64_LDAR_STLR=0>)
265+
endif()
262266

263267
# msvcprt's std::function requires RTTI, but we do not want RTTI data.
264268
# Emulate /GR-.

cmake/modules/AddSwiftUnittests.cmake

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,24 @@ function(add_swift_unittest test_dirname)
4949
endif()
5050

5151
# some headers switch their inline implementations based on
52-
# SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY and
52+
# SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY, SWIFT_STDLIB_HAS_DLSYM and
5353
# SWIFT_THREADING_PACKAGE definitions
5454
if(SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY)
5555
target_compile_definitions("${test_dirname}" PRIVATE
5656
SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY)
5757
endif()
58+
if(SWIFT_STDLIB_HAS_DLSYM)
59+
target_compile_definitions("${test_dirname}" PRIVATE
60+
"SWIFT_STDLIB_HAS_DLSYM=1")
61+
else()
62+
target_compile_definitions("${test_dirname}" PRIVATE
63+
"SWIFT_STDLIB_HAS_DLSYM=0")
64+
endif()
5865

5966
string(TOUPPER "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_THREADING_PACKAGE}" _threading_package)
6067
target_compile_definitions("${test_dirname}" PRIVATE
61-
"SWIFT_THREADING_${_threading_package}")
68+
"SWIFT_THREADING_${_threading_package}"
69+
"SWIFT_THREADING_STATIC")
6270

6371
if(NOT SWIFT_COMPILER_IS_MSVC_LIKE)
6472
if(SWIFT_USE_LINKER)

docs/HowToGuides/GettingStarted.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ toolchain as a one-off, there are a couple of differences:
157157
### Linux
158158
159159
1. The latest Linux dependencies are listed in the respective Dockerfiles:
160+
* [Ubuntu 18.04](https://github.com/apple/swift-docker/blob/main/swift-ci/master/ubuntu/18.04/Dockerfile)
160161
* [Ubuntu 20.04](https://github.com/apple/swift-docker/blob/main/swift-ci/master/ubuntu/20.04/Dockerfile)
161162
* [Ubuntu 22.04](https://github.com/apple/swift-docker/blob/main/swift-ci/master/ubuntu/22.04/Dockerfile)
162163
* [CentOS 7](https://github.com/apple/swift-docker/blob/main/swift-ci/master/centos/7/Dockerfile)

docs/Lexicon.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ guarantee this. This was
188188
"Do not merge". Placed in PR titles where discussion or analysis is still
189189
ongoing.
190190

191+
## DSO
192+
193+
Dynamic shared object, a shared library file (.so/.dylib/.dll, the extension of
194+
which depends on the platform) to be used by multiple applications while they
195+
are executing.
196+
191197
## dup
192198

193199
From "duplicate". As a noun, refers to another filed issue that describes
@@ -250,6 +256,18 @@ A representation of all generic parameters and their requirements. Like
250256
types, generic signatures can be [canonicalized](#canonical-type) to be
251257
compared directly.
252258

259+
## GOT
260+
261+
[Global offset table](https://en.wikipedia.org/wiki/Global_Offset_Table),
262+
a section in an executable or a shared library, which enables code to run
263+
independently of the memory address where it is loaded at runtime. Entries
264+
in GOT directly point to absolute addresses of symbols. The format of GOT
265+
is platform-dependent. Loaders update GOT relocations either on
266+
startup or on symbol access.
267+
268+
Additionally, IRGen makes heavy usage of "GOT" as in "GOT-equivalent variable"
269+
to describe the way it forms references to global objects that may or may not be external references.
270+
253271
## iff
254272

255273
["if and only if"](https://en.wikipedia.org/wiki/If_and_only_if). This term comes from mathematics.
@@ -457,6 +475,12 @@ only to accelerate the process of reading C/C++/Objective-C headers, such as
457475
the bridging headers read in by the `-import-objc-header` command-line
458476
flag to swiftc.
459477

478+
## PLT
479+
480+
Procedure linkage table, which is used to call external functions that don't
481+
have their addresses known at link time. These addresses are then resolved
482+
by a loader at run time.
483+
460484
## PR
461485

462486
1. "Problem Report": An issue reported in [LLVM's bug tracker](https://llvm.org/bugs/).

include/swift/ABI/GenericContext.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,11 @@ class TargetGenericRequirementDescriptor {
183183
return offsetof(typename std::remove_reference<decltype(*this)>::type, Param);
184184
}
185185

186-
/// Retrieve the right-hand type for a SameType or BaseClass requirement.
186+
/// Retrieve the right-hand type for a SameType, BaseClass or SameShape requirement.
187187
llvm::StringRef getMangledTypeName() const {
188188
assert(getKind() == GenericRequirementKind::SameType ||
189-
getKind() == GenericRequirementKind::BaseClass);
189+
getKind() == GenericRequirementKind::BaseClass ||
190+
getKind() == GenericRequirementKind::SameShape);
190191
return swift::Demangle::makeSymbolicMangledNameStringRef(Type.get());
191192
}
192193

0 commit comments

Comments
 (0)