Skip to content

Commit 6330df7

Browse files
authored
Merge branch 'main' into wip-generic-reqs-from-actor-da-for-accessor
2 parents b1abccc + 1c3bd3e commit 6330df7

File tree

489 files changed

+11777
-4856
lines changed

Some content is hidden

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

489 files changed

+11777
-4856
lines changed

SwiftCompilerSources/CMakeLists.txt

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,33 @@ function(swift_compiler_sources module)
5959
set(target_name "SwiftModule${module}")
6060
set_property(TARGET "SwiftModule${module}" APPEND PROPERTY SOURCES ${sources})
6161
endfunction()
62-
62+
63+
# Allow the override of the flags used to define the SDK used to compile the
64+
# Swift compiler sources from the CMake configuration (command line or cache
65+
# files). This allows supporting complicated sysroots and some cross-compilation
66+
# scenarios.
67+
set(SWIFT_COMPILER_SOURCES_SDK_FLAGS_default)
68+
if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS)
69+
set(sdk_path "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_PATH}")
70+
list(APPEND SWIFT_COMPILER_SOURCES_SDK_FLAGS_default "-sdk" "${sdk_path}")
71+
if(NOT EXISTS "${sdk_path}/usr/include/c++")
72+
# Darwin SDKs in Xcode 12 or older do not include libc++, which prevents clang from finding libc++ when invoked
73+
# from ClangImporter. This results in build errors. To workaround this, let's explicitly pass the path to libc++
74+
# to clang.
75+
message(WARNING "Building with an outdated Darwin SDK: libc++ missing from the ${SWIFT_HOST_VARIANT_SDK} SDK. Will use libc++ from the toolchain.")
76+
get_filename_component(absolute_libcxx_path "${CMAKE_C_COMPILER}/../../include/c++/v1" REALPATH)
77+
if (EXISTS "${absolute_libcxx_path}")
78+
list(APPEND SWIFT_COMPILER_SOURCES_SDK_FLAGS_default "-Xcc" "-isystem" "-Xcc" "${absolute_libcxx_path}")
79+
else()
80+
message(ERROR "libc++ not found in the toolchain.")
81+
endif()
82+
endif()
83+
elseif(BOOTSTRAPPING_MODE STREQUAL "CROSSCOMPILE")
84+
list(APPEND SWIFT_COMPILER_SOURCES_SDK_FLAGS_default "-sdk" "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_PATH}")
85+
endif()
86+
set(SWIFT_COMPILER_SOURCES_SDK_FLAGS ${SWIFT_COMPILER_SOURCES_SDK_FLAGS_default}
87+
CACHE STRING "Swift flags used to compiler the Swift compiler sources")
88+
6389
# Add a library target for the swift compiler modules.
6490
#
6591
# Adds targets to compile all swift compiler modules and a target for the
@@ -75,6 +101,7 @@ function(add_swift_compiler_modules_library name)
75101
set(swift_compile_options
76102
"-Xfrontend" "-validate-tbd-against-ir=none"
77103
"-Xfrontend" "-enable-experimental-cxx-interop"
104+
"-Xfrontend" "-disable-target-os-checking"
78105
"-Xcc" "-std=c++17"
79106
"-Xcc" "-DCOMPILED_WITH_SWIFT"
80107
"-Xcc" "-UIBOutlet" "-Xcc" "-UIBAction" "-Xcc" "-UIBInspectable")
@@ -102,35 +129,22 @@ function(add_swift_compiler_modules_library name)
102129

103130
get_bootstrapping_path(build_dir ${CMAKE_CURRENT_BINARY_DIR} "${ALS_BOOTSTRAPPING}")
104131

105-
set(sdk_option "")
132+
set(sdk_option ${SWIFT_COMPILER_SOURCES_SDK_FLAGS})
106133

107134
if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS)
108135
set(deployment_version "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_DEPLOYMENT_VERSION}")
109-
set(sdk_path "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_PATH}")
110-
set(sdk_option "-sdk" "${sdk_path}")
111136
if(BOOTSTRAPPING_MODE STREQUAL "CROSSCOMPILE-WITH-HOSTLIBS")
112137
# Let the cross-compiled compile don't pick up the compiled stdlib by providing
113138
# an (almost) empty resource dir.
114139
# The compiler will instead pick up the stdlib from the SDK.
115140
get_filename_component(swift_exec_bin_dir ${ALS_SWIFT_EXEC} DIRECTORY)
116-
set(sdk_option ${sdk_option} "-resource-dir" "${swift_exec_bin_dir}/../bootstrapping0/lib/swift")
117-
endif()
118-
if(NOT EXISTS "${sdk_path}/usr/include/c++")
119-
# Darwin SDKs in Xcode 12 or older do not include libc++, which prevents clang from finding libc++ when invoked
120-
# from ClangImporter. This results in build errors. To workaround this, let's explicitly pass the path to libc++
121-
# to clang.
122-
message(WARNING "Building with an outdated Darwin SDK: libc++ missing from the ${SWIFT_HOST_VARIANT_SDK} SDK. Will use libc++ from the toolchain.")
123-
get_filename_component(absolute_libcxx_path "${CMAKE_C_COMPILER}/../../include/c++/v1" REALPATH)
124-
if (EXISTS "${absolute_libcxx_path}")
125-
set(sdk_option ${sdk_option} "-Xcc" "-isystem" "-Xcc" "${absolute_libcxx_path}")
126-
else()
127-
message(ERROR "libc++ not found in the toolchain.")
128-
endif()
141+
list(APPEND sdk_option "-resource-dir" "${swift_exec_bin_dir}/../bootstrapping0/lib/swift")
129142
endif()
130143
elseif(BOOTSTRAPPING_MODE STREQUAL "CROSSCOMPILE")
131-
set(sdk_option "-sdk" "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_PATH}")
132144
get_filename_component(swift_exec_bin_dir ${ALS_SWIFT_EXEC} DIRECTORY)
133-
set(sdk_option ${sdk_option} "-resource-dir" "${swift_exec_bin_dir}/../lib/swift")
145+
# NOTE: prepending allows SWIFT_COMPILER_SOURCES_SDK_FLAGS to override the
146+
# resource directory if needed.
147+
list(PREPEND sdk_option "-resource-dir" "${swift_exec_bin_dir}/../lib/swift")
134148
endif()
135149
get_versioned_target_triple(target ${SWIFT_HOST_VARIANT_SDK}
136150
${SWIFT_HOST_VARIANT_ARCH} "${deployment_version}")
@@ -139,7 +153,7 @@ function(add_swift_compiler_modules_library name)
139153
# under `include/swift`. These are either located next to the compiler (in case of open source toolchains) or
140154
# in the SDK (in case a Swift compiler from Xcode)
141155
get_filename_component(swift_exec_bin_dir ${ALS_SWIFT_EXEC} DIRECTORY)
142-
set(sdk_option ${sdk_option} "-I" "${swift_exec_bin_dir}/../lib" "-I" "${sdk_path}/usr/lib")
156+
list(APPEND sdk_option "-I" "${swift_exec_bin_dir}/../lib" "-I" "${sdk_path}/usr/lib")
143157

144158
set(all_obj_files)
145159
set(all_module_targets)
@@ -262,6 +276,15 @@ else()
262276
add_library(importedHeaderDependencies "${CMAKE_CURRENT_BINARY_DIR}/HeaderDependencies.cpp")
263277
target_include_directories(importedHeaderDependencies PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../include/swift")
264278

279+
# When building unified, we need to make sure all the Clang headers are
280+
# generated before we try to use them.
281+
# When building Swift against an already compiled LLVM/Clang, like
282+
# build-script does, this target does not exist, but the headers
283+
# are already completely generated at that point.
284+
if(TARGET clang-tablegen-targets)
285+
add_dependencies(importedHeaderDependencies clang-tablegen-targets)
286+
endif()
287+
265288
if(BOOTSTRAPPING_MODE MATCHES "HOSTTOOLS|CROSSCOMPILE")
266289

267290
if (NOT SWIFT_EXEC_FOR_SWIFT_MODULES)

SwiftCompilerSources/Sources/Basic/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99
add_swift_compiler_module(Basic
1010
SOURCES
1111
SourceLoc.swift
12+
StringParser.swift
1213
Utils.swift)
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
//===--- StringParser.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+
/// A simple utility to parse a string.
14+
public struct StringParser {
15+
private var s: Substring
16+
private let originalLength: Int
17+
18+
private mutating func consumeWhitespace() {
19+
s = s.drop { $0.isWhitespace }
20+
}
21+
22+
public init(_ string: String) {
23+
s = Substring(string)
24+
originalLength = string.count
25+
}
26+
27+
public mutating func isEmpty() -> Bool {
28+
consumeWhitespace()
29+
return s.isEmpty
30+
}
31+
32+
public mutating func consume(_ str: String) -> Bool {
33+
consumeWhitespace()
34+
if !s.starts(with: str) { return false }
35+
s = s.dropFirst(str.count)
36+
return true
37+
}
38+
39+
public mutating func consumeInt(withWhiteSpace: Bool = true) -> Int? {
40+
if withWhiteSpace {
41+
consumeWhitespace()
42+
}
43+
var intStr = ""
44+
s = s.drop {
45+
if $0.isNumber {
46+
intStr.append($0)
47+
return true
48+
}
49+
return false
50+
}
51+
return Int(intStr)
52+
}
53+
54+
public mutating func consumeIdentifier() -> String? {
55+
consumeWhitespace()
56+
var name = ""
57+
s = s.drop {
58+
if $0.isLetter {
59+
name.append($0)
60+
return true
61+
}
62+
return false
63+
}
64+
return name.isEmpty ? nil : name
65+
}
66+
67+
public func throwError(_ message: StaticString) throws -> Never {
68+
throw ParsingError(message: message, position: originalLength - s.count)
69+
}
70+
}
71+
72+
public struct ParsingError : Error {
73+
public let message: StaticString
74+
public let position: Int
75+
}

SwiftCompilerSources/Sources/Optimizer/Utilities/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ swift_compiler_sources(Optimizer
1212
EscapeUtils.swift
1313
OptUtils.swift
1414
ForwardingUtils.swift
15-
WalkUtils.swift
16-
AccessUtils.swift
1715
SSAUpdater.swift
1816
StaticInitCloner.swift
1917
Test.swift

SwiftCompilerSources/Sources/Optimizer/Utilities/Devirtualization.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ private func devirtualize(destroy: some DevirtualizableDestroy, _ context: some
3636
precondition(type.isNominal, "non-copyable non-nominal types not supported, yet")
3737

3838
let result: Bool
39-
if type.nominal.hasValueDeinit && !destroy.hasDropDeinit {
39+
if type.nominal.hasValueDeinit && !destroy.shouldDropDeinit {
4040
guard let deinitFunc = context.lookupDeinit(ofNominal: type.nominal) else {
4141
return false
4242
}
@@ -58,6 +58,7 @@ private func devirtualize(destroy: some DevirtualizableDestroy, _ context: some
5858

5959
// Used to dispatch devirtualization tasks to `destroy_value` and `destroy_addr`.
6060
private protocol DevirtualizableDestroy : UnaryInstruction {
61+
var shouldDropDeinit: Bool { get }
6162
func createDeinitCall(to deinitializer: Function, _ context: some MutatingContext)
6263
func devirtualizeStructFields(_ context: some MutatingContext) -> Bool
6364
func devirtualizeEnumPayload(enumCase: EnumCase, in block: BasicBlock, _ context: some MutatingContext) -> Bool
@@ -67,8 +68,6 @@ private protocol DevirtualizableDestroy : UnaryInstruction {
6768
private extension DevirtualizableDestroy {
6869
var type: Type { operand.value.type }
6970

70-
var hasDropDeinit: Bool { operand.value.lookThoughOwnershipInstructions is DropDeinitInst }
71-
7271
func devirtualizeEnumPayloads(_ context: some MutatingContext) -> Bool {
7372
guard let cases = type.getEnumCases(in: parentFunction) else {
7473
return false
@@ -99,6 +98,8 @@ private extension DevirtualizableDestroy {
9998
}
10099

101100
extension DestroyValueInst : DevirtualizableDestroy {
101+
fileprivate var shouldDropDeinit: Bool { operand.value.lookThoughOwnershipInstructions is DropDeinitInst }
102+
102103
fileprivate func createDeinitCall(to deinitializer: Function, _ context: some MutatingContext) {
103104
let builder = Builder(before: self, context)
104105
let subs = context.getContextSubstitutionMap(for: type)
@@ -162,6 +163,11 @@ extension DestroyValueInst : DevirtualizableDestroy {
162163
}
163164

164165
extension DestroyAddrInst : DevirtualizableDestroy {
166+
fileprivate var shouldDropDeinit: Bool {
167+
// The deinit is always called by a destroy_addr. There must not be a `drop_deinit` as operand.
168+
false
169+
}
170+
165171
fileprivate func createDeinitCall(to deinitializer: Function, _ context: some MutatingContext) {
166172
let builder = Builder(before: self, context)
167173
let subs = context.getContextSubstitutionMap(for: destroyedAddress.type)

SwiftCompilerSources/Sources/Optimizer/Utilities/OptUtils.swift

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -322,22 +322,6 @@ extension LoadInst {
322322
}
323323
}
324324

325-
extension SmallProjectionPath {
326-
/// Returns true if the path only contains projections which can be materialized as
327-
/// SIL struct or tuple projection instructions - for values or addresses.
328-
var isMaterializable: Bool {
329-
let (kind, _, subPath) = pop()
330-
switch kind {
331-
case .root:
332-
return true
333-
case .structField, .tupleField:
334-
return subPath.isMaterializable
335-
default:
336-
return false
337-
}
338-
}
339-
}
340-
341325
extension FunctionPassContext {
342326
/// Returns true if any blocks were removed.
343327
func removeDeadBlocks(in function: Function) -> Bool {

SwiftCompilerSources/Sources/SIL/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ add_swift_compiler_module(SIL
2222
Location.swift
2323
Operand.swift
2424
Registration.swift
25-
SmallProjectionPath.swift
25+
SILStage.swift
2626
SubstitutionMap.swift
2727
Type.swift
28-
Utils.swift
2928
Value.swift
3029
VTable.swift
3130
WitnessTable.swift)
31+
32+
add_subdirectory(Utilities)
33+

SwiftCompilerSources/Sources/SIL/Function.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,19 @@ final public class Function : CustomStringConvertible, HasShortDescription, Hash
203203
case none
204204
case noAllocations
205205
case noLocks
206+
case noRuntime
207+
case noExistentials
208+
case noObjCRuntime
206209
}
207210

208211
public var performanceConstraints: PerformanceConstraints {
209212
switch bridged.getPerformanceConstraints() {
210213
case .None: return .none
211214
case .NoAllocation: return .noAllocations
212215
case .NoLocks: return .noLocks
216+
case .NoRuntime: return .noRuntime
217+
case .NoExistentials: return .noExistentials
218+
case .NoObjCBridging: return .noObjCRuntime
213219
default: fatalError("unknown performance constraint")
214220
}
215221
}
@@ -368,6 +374,24 @@ final public class Function : CustomStringConvertible, HasShortDescription, Hash
368374
{ (f: BridgedFunction, observeRetains: Bool) -> BridgedMemoryBehavior in
369375
let e = f.function.getSideEffects()
370376
return e.getMemBehavior(observeRetains: observeRetains)
377+
},
378+
// argumentMayRead (used by the MemoryLifetimeVerifier)
379+
{ (f: BridgedFunction, bridgedArgOp: BridgedOperand, bridgedAddr: BridgedValue) -> Bool in
380+
let argOp = Operand(bridged: bridgedArgOp)
381+
let addr = bridgedAddr.value
382+
let applySite = argOp.instruction as! FullApplySite
383+
let addrPath = addr.accessPath
384+
let argIdx = argOp.index - ApplyOperands.firstArgumentIndex
385+
let calleeArgIdx = applySite.calleeArgIndex(callerArgIndex: argIdx)
386+
let convention = applySite.getArgumentConvention(calleeArgIndex: calleeArgIdx)
387+
assert(convention.isIndirectIn || convention.isInout)
388+
let argPath = argOp.value.accessPath
389+
assert(!argPath.isDistinct(from: addrPath))
390+
let path = argPath.getProjection(to: addrPath) ?? SmallProjectionPath()
391+
let effects = f.function.getSideEffects(forArgument: argOp.value.at(path),
392+
atIndex: calleeArgIdx,
393+
withConvention: convention)
394+
return effects.memory.read
371395
}
372396
)
373397
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//===--- SILStage.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+
public enum SILStage: Int {
14+
/// "Raw" SIL, emitted by SILGen, but not yet run through guaranteed
15+
/// optimization and diagnostic passes.
16+
///
17+
/// Raw SIL does not have fully-constructed SSA and may contain undiagnosed
18+
/// dataflow errors.
19+
case raw
20+
21+
/// Canonical SIL, which has been run through at least the guaranteed
22+
/// optimization and diagnostic passes.
23+
///
24+
/// Canonical SIL has stricter invariants than raw SIL. It must not contain
25+
/// dataflow errors, and some instructions must be canonicalized to simpler
26+
/// forms.
27+
case canonical
28+
29+
/// Lowered SIL, which has been prepared for IRGen and will no longer
30+
/// be passed to canonical SIL transform passes.
31+
///
32+
/// In lowered SIL, the SILType of all SILValues is its SIL storage
33+
/// type. Explicit storage is required for all address-only and resilient
34+
/// types.
35+
///
36+
/// Generating the initial Raw SIL is typically referred to as lowering (from
37+
/// the AST). To disambiguate, refer to the process of generating the lowered
38+
/// stage of SIL as "address lowering".
39+
case lowered
40+
}

0 commit comments

Comments
 (0)