Skip to content

Commit d89347b

Browse files
committed
Merge branch 'main' into wip-experimental-isolated-deinit
2 parents 2fd6f00 + d3b788f commit d89347b

File tree

229 files changed

+3243
-1956
lines changed

Some content is hidden

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

229 files changed

+3243
-1956
lines changed

CMakeLists.txt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ else()
155155
set(SWIFT_HOST_VARIANT_SDK_default "ANDROID")
156156
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
157157
set(SWIFT_HOST_VARIANT_SDK_default "OSX")
158+
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "WASI")
159+
set(SWIFT_HOST_VARIANT_SDK_default "WASI")
158160
else()
159161
message(FATAL_ERROR "Unable to detect SDK for host system: ${CMAKE_SYSTEM_NAME}")
160162
endif()
@@ -419,6 +421,17 @@ set(SWIFT_STDLIB_MSVC_RUNTIME_LIBRARY
419421
${SWIFT_STDLIB_MSVC_RUNTIME_LIBRARY_default}
420422
CACHE STRING "MSVC Runtime Library for the standard library")
421423

424+
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows" AND BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS" AND
425+
CMAKE_BUILD_TYPE STREQUAL "Debug")
426+
# Building with the host Swift toolchain requires linking just-built binaries
427+
# against the host Swift runtime. In debug builds, that means linking a debug
428+
# binary against a release binary. The MSVC linker does not normally permit
429+
# this, since debug builds enable bounds-checked C++ iterators by default,
430+
# which are not ABI-compatible with regular iterators. Let's instruct MSVC to
431+
# disable bounds-checked iterators to make it possible to do a debug build of
432+
# the Swift compiler with a host toolchain.
433+
add_definitions(-D_ITERATOR_DEBUG_LEVEL=0)
434+
endif()
422435

423436
if(BRIDGING_MODE STREQUAL "DEFAULT" OR NOT BRIDGING_MODE)
424437
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR "${SWIFT_HOST_VARIANT_SDK}" STREQUAL "WINDOWS" OR (CMAKE_Swift_COMPILER AND CMAKE_Swift_COMPILER_VERSION VERSION_LESS 5.8))
@@ -703,10 +716,6 @@ option(SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED
703716
"Enable experimental distributed actors and functions"
704717
FALSE)
705718

706-
option(SWIFT_ENABLE_EXPERIMENTAL_NONESCAPABLE_TYPES
707-
"Enable experimental NonescapableTypes"
708-
FALSE)
709-
710719
option(SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING
711720
"Enable experimental string processing"
712721
FALSE)
@@ -1385,7 +1394,6 @@ if(SWIFT_BUILD_STDLIB OR SWIFT_BUILD_SDK_OVERLAY)
13851394
message(STATUS "Differentiable Programming Support: ${SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING}")
13861395
message(STATUS "Concurrency Support: ${SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY}")
13871396
message(STATUS "Distributed Support: ${SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED}")
1388-
message(STATUS "NonEscapableTypes Support: ${SWIFT_ENABLE_EXPERIMENTAL_NONESCAPABLE_TYPES}")
13891397
message(STATUS "String Processing Support: ${SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING}")
13901398
message(STATUS "Backtracing Support: ${SWIFT_ENABLE_BACKTRACING}")
13911399
message(STATUS "Unicode Support: ${SWIFT_STDLIB_ENABLE_UNICODE_DATA}")

SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/SimplifyBuiltin.swift

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,19 +150,20 @@ private extension BuiltinInst {
150150
}
151151

152152
func optimizeAssertConfig(_ context: SimplifyContext) {
153-
let literal: IntegerLiteralInst
154-
switch context.options.assertConfiguration {
155-
case .enabled:
156-
let builder = Builder(before: self, context)
157-
literal = builder.createIntegerLiteral(1, type: type)
158-
case .disabled:
153+
// The values for the assert_configuration call are:
154+
// 0: Debug
155+
// 1: Release
156+
// 2: Fast / Unchecked
157+
let config = context.options.assertConfiguration
158+
switch config {
159+
case .debug, .release, .unchecked:
159160
let builder = Builder(before: self, context)
160-
literal = builder.createIntegerLiteral(0, type: type)
161-
default:
161+
let literal = builder.createIntegerLiteral(config.integerValue, type: type)
162+
uses.replaceAll(with: literal, context)
163+
context.erase(instruction: self)
164+
case .unknown:
162165
return
163166
}
164-
uses.replaceAll(with: literal, context)
165-
context.erase(instruction: self)
166167
}
167168

168169
func optimizeTargetTypeConst(_ context: SimplifyContext) {

SwiftCompilerSources/Sources/Optimizer/PassManager/Options.swift

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,31 @@ struct Options {
3636
_bridged.hasFeature(feature)
3737
}
3838

39+
// The values for the assert_configuration call are:
40+
// 0: Debug
41+
// 1: Release
42+
// 2: Fast / Unchecked
3943
enum AssertConfiguration {
40-
case enabled
41-
case disabled
44+
case debug
45+
case release
46+
case unchecked
4247
case unknown
48+
49+
var integerValue: Int {
50+
switch self {
51+
case .debug: return 0
52+
case .release: return 1
53+
case .unchecked: return 2
54+
case .unknown: fatalError()
55+
}
56+
}
4357
}
4458

4559
var assertConfiguration: AssertConfiguration {
4660
switch _bridged.getAssertConfiguration() {
47-
case .Debug: return .enabled
48-
case .Release, .Unchecked: return .disabled
61+
case .Debug: return .debug
62+
case .Release: return .release
63+
case .Unchecked: return .unchecked
4964
default: return .unknown
5065
}
5166
}

SwiftCompilerSources/Sources/Optimizer/Utilities/StaticInitCloner.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,16 @@ struct StaticInitCloner<Context: MutatingContext> {
4646
return getClonedValue(of: value)
4747
}
4848

49+
if let beginAccess = value as? BeginAccessInst {
50+
// Skip access instructions, which might be generated for UnsafePointer globals which point to other globals.
51+
let clonedOperand = clone(beginAccess.address)
52+
bridged.recordFoldedValue(beginAccess.bridged, clonedOperand.bridged)
53+
return clonedOperand
54+
}
55+
4956
let inst = value.definingInstruction!
57+
assert(!(inst is ScopedInstruction), "global init value must not contain a scoped instruction")
58+
5059
for op in inst.operands {
5160
_ = clone(op.value)
5261
}

benchmark/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ set(SWIFT_BENCH_MODULES
210210
single-source/XorLoop
211211
cxx-source/CreateObjects
212212
cxx-source/CxxSetToCollection
213+
cxx-source/CxxSpanTests
213214
cxx-source/CxxStringConversion
214215
cxx-source/CxxVectorSum
215216
# TODO: rdar://92120528

benchmark/Package.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.4
1+
// swift-tools-version:5.9
22

33
import PackageDescription
44
import Foundation
@@ -127,8 +127,8 @@ targets.append(
127127
dependencies: swiftBenchDeps,
128128
path: "utils",
129129
sources: ["main.swift"],
130-
swiftSettings: [.unsafeFlags(["-cxx-interoperability-mode=default",
131-
"-I",
130+
swiftSettings: [.interoperabilityMode(.Cxx),
131+
.unsafeFlags(["-I",
132132
"utils/CxxTests"])]))
133133

134134
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
@@ -165,8 +165,8 @@ targets += cxxSingleSourceLibraries.map { name in
165165
dependencies: singleSourceDeps,
166166
path: "cxx-source",
167167
sources: ["\(name).swift"],
168-
swiftSettings: [.unsafeFlags(["-cxx-interoperability-mode=default",
169-
"-I",
168+
swiftSettings: [.interoperabilityMode(.Cxx),
169+
.unsafeFlags(["-I",
170170
"utils/CxxTests",
171171
// FIXME: https://github.com/apple/swift/issues/61453
172172
"-Xfrontend", "-validate-tbd-against-ir=none"])])
Lines changed: 121 additions & 0 deletions
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

Lines changed: 27 additions & 0 deletions
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+
#ifndef __linux__
9+
#include <span>
10+
#endif
11+
12+
static const size_t spanSize = 50000;
13+
714
using VectorOfU32 = std::vector<uint32_t>;
815
using SetOfU32 = std::set<uint32_t>;
16+
#ifndef __linux__
17+
using ArrayOfU32 = uint32_t[spanSize];
18+
using SpanOfU32 = std::span<uint32_t>;
19+
#endif
920

1021
static inline VectorOfU32 vec;
1122
static inline SetOfU32 set;
23+
#ifndef __linux__
24+
static inline ArrayOfU32 array;
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+
#ifndef __linux__
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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import CountAlgo
5757
import CreateObjects
5858
// rdar://128520766
5959
// import CxxSetToCollection
60+
import CxxSpanTests
6061
import CxxStringConversion
6162
// rdar://128520766
6263
// import CxxVectorSum
@@ -255,6 +256,7 @@ register(ClassArrayGetter.benchmarks)
255256
register(CreateObjects.benchmarks)
256257
// rdar://128520766
257258
// register(CxxSetToCollection.benchmarks)
259+
register(CxxSpanTests.benchmarks)
258260
register(CxxStringConversion.benchmarks)
259261
// rdar://128520766
260262
// register(CxxVectorSum.benchmarks)

cmake/caches/Linux-x86_64.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,14 @@ set(LLDB_TOOLS
142142
set(SWIFT_INSTALL_COMPONENTS
143143
autolink-driver
144144
compiler
145+
compiler-swift-syntax-lib
145146
clang-builtin-headers
146147
editor-integration
147148
tools
148149
sourcekit-inproc
149150
swift-remote-mirror
150151
swift-remote-mirror-headers
152+
swift-syntax-lib
151153
CACHE STRING "")
152154

153155
set(LLVM_DISTRIBUTION_COMPONENTS

0 commit comments

Comments
 (0)