Skip to content

Commit c55ad6f

Browse files
authored
Merge branch 'main' into mpokhylets/isolated-deinit
2 parents e0ad7bd + 39b8b3c commit c55ad6f

File tree

207 files changed

+3807
-2374
lines changed

Some content is hidden

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

207 files changed

+3807
-2374
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ComputeSideEffects.swift

+12-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ let computeSideEffects = FunctionPass(name: "compute-side-effects") {
5757
// instruction the argument might have escaped.
5858
for argument in function.arguments {
5959
collectedEffects.addEffectsForEscapingArgument(argument: argument)
60+
collectedEffects.addEffectsForConsumingArgument(argument: argument)
6061
}
6162

6263
// Don't modify the effects if they didn't change. This avoids sending a change notification
@@ -236,7 +237,17 @@ private struct CollectedEffects {
236237
addEffects(.destroy, to: argument)
237238
}
238239
}
239-
240+
241+
mutating func addEffectsForConsumingArgument(argument: FunctionArgument) {
242+
if argument.convention == .indirectIn {
243+
// Usually there _must_ be a read from a consuming in-argument, because the function has to consume the argument.
244+
// But in the special case if all control paths end up in an `unreachable`, the consuming read might have been
245+
// dead-code eliminated. Therefore make sure to add the read-effect in any case. Otherwise it can result
246+
// in memory lifetime failures at a call site.
247+
addEffects(.read, to: argument)
248+
}
249+
}
250+
240251
private mutating func handleApply(_ apply: ApplySite) {
241252
let callees = calleeAnalysis.getCallees(callee: apply.callee)
242253
let args = apply.argumentOperands.lazy.map {

benchmark/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ set(SWIFT_BENCH_MODULES
214214
cxx-source/CxxVectorSum
215215
# TODO: rdar://92120528
216216
# cxx-source/ReadAccessor
217+
cxx-source/CxxSpanTests
217218
)
218219

219220
set(SWIFT_MULTISOURCE_SWIFT_BENCHES
+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
//===--- CxxSpanTests.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 TestsUtils
14+
import CxxStdlibPerformance
15+
16+
let iterRepeatFactor = 7
17+
18+
// FIXME swift-ci linux tests do not support std::span
19+
#if os(Linux)
20+
public let benchmarks = [BenchmarkInfo]()
21+
#else
22+
23+
public let benchmarks = [
24+
BenchmarkInfo(
25+
name: "CxxSpanTests.raw.iterator",
26+
runFunction: run_CxxSpanOfU32_RawIterator,
27+
tags: [.validation, .bridging, .cxxInterop],
28+
setUpFunction: makeSpanOnce),
29+
BenchmarkInfo(
30+
name: "CxxSpanTests.index.subscript",
31+
runFunction: run_CxxSpanOfU32_IndexAndSubscript,
32+
tags: [.validation, .bridging, .cxxInterop],
33+
setUpFunction: makeSpanOnce),
34+
BenchmarkInfo(
35+
name: "CxxSpanTests.for.loop",
36+
runFunction: run_CxxSpanOfU32_ForInLoop,
37+
tags: [.validation, .bridging, .cxxInterop],
38+
setUpFunction: makeSpanOnce),
39+
BenchmarkInfo(
40+
name: "CxxSpanTests.map",
41+
runFunction: run_CxxSpanOfU32_MapSpan,
42+
tags: [.validation, .bridging, .cxxInterop],
43+
setUpFunction: makeSpanOnce),
44+
BenchmarkInfo(
45+
name: "CxxSpanTests.filter",
46+
runFunction: run_CxxSpanOfU32_FilterSpan,
47+
tags: [.validation, .bridging, .cxxInterop],
48+
setUpFunction: makeSpanOnce),
49+
BenchmarkInfo(
50+
name: "CxxSpanTests.reduce",
51+
runFunction: run_CxxSpanOfU32_ReduceSpan,
52+
tags: [.validation, .bridging, .cxxInterop],
53+
setUpFunction: makeSpanOnce),
54+
]
55+
56+
func makeSpanOnce() {
57+
initSpan()
58+
}
59+
60+
@inline(never)
61+
public func run_CxxSpanOfU32_RawIterator(_ n: Int) {
62+
var sum: UInt32 = 0
63+
for _ in 0..<(n * iterRepeatFactor * 2) {
64+
var b = span.__beginUnsafe()
65+
let e = span.__endUnsafe()
66+
while b != e {
67+
sum = sum &+ b.pointee
68+
b = b.successor()
69+
}
70+
}
71+
blackHole(sum)
72+
}
73+
74+
@inline(never)
75+
public func run_CxxSpanOfU32_IndexAndSubscript(_ n: Int) {
76+
var sum: UInt32 = 0
77+
for _ in 0..<(n * iterRepeatFactor * 2) {
78+
for i in 0..<span.size() {
79+
sum = sum &+ span[i]
80+
}
81+
}
82+
blackHole(sum)
83+
}
84+
85+
@inline(never)
86+
public func run_CxxSpanOfU32_ForInLoop(_ n: Int) {
87+
var sum: UInt32 = 0
88+
for _ in 0..<(n * iterRepeatFactor * 2) {
89+
for x in span {
90+
sum = sum &+ x
91+
}
92+
}
93+
blackHole(sum)
94+
}
95+
96+
@inline(never)
97+
public func run_CxxSpanOfU32_MapSpan(_ n: Int) {
98+
for _ in 0..<(n * iterRepeatFactor) {
99+
let result = span.map { $0 &+ 5 }
100+
blackHole(result)
101+
}
102+
}
103+
104+
@inline(never)
105+
public func run_CxxSpanOfU32_FilterSpan(_ n: Int) {
106+
for _ in 0..<(n * iterRepeatFactor) {
107+
let result = span.filter { $0 % 2 == 0 }
108+
blackHole(result)
109+
}
110+
}
111+
112+
@inline(never)
113+
public func run_CxxSpanOfU32_ReduceSpan(_ n: Int) {
114+
var sum: UInt32 = 0
115+
for _ in 0..<(n * iterRepeatFactor * 2) {
116+
sum = sum &+ span.reduce(sum, &+)
117+
}
118+
blackHole(sum)
119+
}
120+
121+
#endif

benchmark/utils/CxxTests/CxxStdlibPerformance.h

+27
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,26 @@
44
#include <vector>
55
#include <set>
66

7+
// FIXME swift-ci linux tests do not support std::span
8+
#if __has_include(<span>)
9+
#include <span>
10+
#endif
11+
12+
static const size_t spanSize = 50000;
13+
14+
using ArrayOfU32 = uint32_t[spanSize];
715
using VectorOfU32 = std::vector<uint32_t>;
816
using SetOfU32 = std::set<uint32_t>;
17+
#if __has_include(<span>)
18+
using SpanOfU32 = std::span<uint32_t>;
19+
#endif
920

21+
static inline ArrayOfU32 array;
1022
static inline VectorOfU32 vec;
1123
static inline SetOfU32 set;
24+
#if __has_include(<span>)
25+
static inline SpanOfU32 span;
26+
#endif
1227

1328
inline void initVector(size_t size) {
1429
if (!vec.empty()) {
@@ -29,6 +44,18 @@ inline void initSet(size_t size) {
2944
}
3045
}
3146

47+
#if __has_include(<span>)
48+
inline void initSpan() {
49+
if (!span.empty()) {
50+
return;
51+
}
52+
for (size_t i = 0; i < spanSize; ++i) {
53+
array[i] = uint32_t(i);
54+
}
55+
span = SpanOfU32(array);
56+
}
57+
#endif
58+
3259
inline VectorOfU32 makeVector32(size_t size) {
3360
initVector(size);
3461
return vec;

benchmark/utils/main.swift

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ import CreateObjects
6060
import CxxStringConversion
6161
// rdar://128520766
6262
// import CxxVectorSum
63+
import CxxSpanTests
6364
import DataBenchmarks
6465
import DeadArray
6566
import DevirtualizeProtocolComposition
@@ -258,6 +259,7 @@ register(CreateObjects.benchmarks)
258259
register(CxxStringConversion.benchmarks)
259260
// rdar://128520766
260261
// register(CxxVectorSum.benchmarks)
262+
register(CxxSpanTests.benchmarks)
261263
register(DataBenchmarks.benchmarks)
262264
register(DeadArray.benchmarks)
263265
register(DevirtualizeProtocolComposition.benchmarks)

cmake/modules/AddPureSwift.cmake

+33-2
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,27 @@ function(_set_pure_swift_profile_flags target_name)
120120
endif()
121121
endfunction()
122122

123+
function(_set_pure_swift_package_options target_name package_name)
124+
if(NOT package_name OR NOT Swift_COMPILER_PACKAGE_CMO_SUPPORT)
125+
return()
126+
endif()
127+
128+
# Enable package CMO if possible
129+
if(Swift_COMPILER_PACKAGE_CMO_SUPPORT STREQUAL "IMPLEMENTED")
130+
target_compile_options("${target_name}" PRIVATE
131+
"SHELL:-package-name ${package_name}"
132+
"SHELL:-Xfrontend -package-cmo"
133+
"SHELL:-Xfrontend -allow-non-resilient-access"
134+
)
135+
elseif(Swift_COMPILER_PACKAGE_CMO_SUPPORT STREQUAL "EXPERIMENTAL")
136+
target_compile_options("${target_name}" PRIVATE
137+
"SHELL:-package-name ${package_name}"
138+
"SHELL:-Xfrontend -experimental-package-cmo"
139+
"SHELL:-Xfrontend -experimental-allow-non-resilient-access"
140+
"SHELL:-Xfrontend -experimental-package-bypass-resilience"
141+
)
142+
endif()
143+
endfunction()
123144

124145
# Add a new "pure" Swift host library.
125146
#
@@ -149,6 +170,9 @@ endfunction()
149170
# EMIT_MODULE
150171
# Emit '.swiftmodule' to
151172
#
173+
# PACKAGE_NAME
174+
# Name of the Swift package this library belongs to.
175+
#
152176
# DEPENDENCIES
153177
# Target names to pass target_link_library
154178
#
@@ -169,7 +193,8 @@ function(add_pure_swift_host_library name)
169193
SHARED
170194
STATIC
171195
EMIT_MODULE)
172-
set(single_parameter_options)
196+
set(single_parameter_options
197+
PACKAGE_NAME)
173198
set(multiple_parameter_options
174199
DEPENDENCIES
175200
SWIFT_DEPENDENCIES)
@@ -193,6 +218,7 @@ function(add_pure_swift_host_library name)
193218
# Create the library.
194219
add_library(${name} ${libkind} ${APSHL_SOURCES})
195220
_add_host_swift_compile_options(${name})
221+
_set_pure_swift_package_options(${name} "${APSHL_PACKAGE_NAME}")
196222

197223
set_property(TARGET ${name}
198224
PROPERTY BUILD_WITH_INSTALL_RPATH YES)
@@ -315,6 +341,9 @@ endfunction()
315341
# name
316342
# Name of the tool (e.g., swift-frontend).
317343
#
344+
# PACKAGE_NAME
345+
# Name of the Swift package this executable belongs to.
346+
#
318347
# DEPENDENCIES
319348
# Target names to pass target_link_library
320349
#
@@ -333,7 +362,8 @@ function(add_pure_swift_host_tool name)
333362
# Option handling
334363
set(options)
335364
set(single_parameter_options
336-
SWIFT_COMPONENT)
365+
SWIFT_COMPONENT
366+
PACKAGE_NAME)
337367
set(multiple_parameter_options
338368
DEPENDENCIES
339369
SWIFT_DEPENDENCIES)
@@ -349,6 +379,7 @@ function(add_pure_swift_host_tool name)
349379
add_executable(${name} ${APSHT_SOURCES})
350380
_add_host_swift_compile_options(${name})
351381
_set_pure_swift_link_flags(${name} "../lib/")
382+
_set_pure_swift_package_options(${name} "${APSHT_PACKAGE_NAME}")
352383

353384
if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS)
354385
set_property(TARGET ${name}

cmake/modules/macCatalystUtils.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function(get_target_triple target_out_var target_variant_out_var sdk arch)
7878
elseif(maccatalyst_build_flavor STREQUAL "macos-like")
7979
# Use the default macOS triple.
8080
elseif(maccatalyst_build_flavor STREQUAL "zippered")
81-
set(target "${arch}-apple-macosx${SWIFT_DARWIN_DEPLOYMENT_VERSION_OSX}")
81+
set(target "${arch}-apple-macosx${deployment_version}")
8282
set(target_variant "${arch}-apple-ios${SWIFT_DARWIN_DEPLOYMENT_VERSION_MACCATALYST}-macabi")
8383
elseif(maccatalyst_build_flavor STREQUAL "unzippered-twin")
8484
# Use the default triple for now

docs/EmbeddedSwift/UserManual.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Segment __TEXT: 16384
100100

101101
## Strings
102102

103-
Both StaticString and String types are available in Embedded Swift. As is the case in desktop Swift, certain operations on strings require Unicode data tables for strict Unicode compliance. In Embedded Swift. these data tables are provided as a separate static library (libUnicodeDataTables.a) that users need to link in manually – if they need to use these string operations. If the library is required, linking will fail due to missing on one or more of the following symbols:
103+
Both StaticString and String types are available in Embedded Swift. As is the case in desktop Swift, certain operations on strings require Unicode data tables for strict Unicode compliance. In Embedded Swift these data tables are provided as a separate static library (libUnicodeDataTables.a) that users need to link in manually – if they need to use these string operations. If the library is required, linking will fail due to missing on one or more of the following symbols:
104104

105105
```
106106
_swift_stdlib_getAge

0 commit comments

Comments
 (0)