Skip to content

Commit aceec34

Browse files
authored
Merge branch 'apple:main' into autodiff-fix-generic-param-decl-verification
2 parents 6e08ded + a5ba086 commit aceec34

File tree

402 files changed

+12921
-6141
lines changed

Some content is hidden

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

402 files changed

+12921
-6141
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,10 @@ option(SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER
250250
"Use the host compiler and not the internal clang to build the swift runtime"
251251
FALSE)
252252

253+
option(SWIFT_RUN_TESTS_WITH_HOST_COMPILER
254+
"Run tests against the host compiler and not the just built swift"
255+
FALSE)
256+
253257
set(SWIFT_SDKS "" CACHE STRING
254258
"If non-empty, limits building target binaries only to specified SDKs (despite other SDKs being available)")
255259

benchmark/single-source/BufferFill.swift

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ public let BufferFill = [
2828
tags: [.validation, .api],
2929
setUpFunction: rawBufferInitializeMemorySetup,
3030
tearDownFunction: rawBufferInitializeMemoryTeardown),
31+
BenchmarkInfo(name: "RawBuffer.copyContents",
32+
runFunction: rawBufferCopyContentsExecute,
33+
tags: [.validation, .api],
34+
setUpFunction: rawBufferCopyContentsSetup,
35+
tearDownFunction: rawBufferCopyContentsTeardown),
3136
]
3237

3338
let c = 100_000
@@ -119,3 +124,43 @@ public func rawBufferInitializeMemoryExecute(n: Int) {
119124
let value = offset.load(as: Int.self)
120125
CheckResults(value == a[r])
121126
}
127+
128+
var r8: UnsafeRawBufferPointer = .init(start: nil, count: 0)
129+
var b8: UnsafeMutableBufferPointer<UInt8> = .init(start: nil, count: 0)
130+
131+
public func rawBufferCopyContentsSetup() {
132+
assert(r8.baseAddress == nil)
133+
let count = a.count * MemoryLayout<Int>.stride
134+
let rb = UnsafeMutableRawBufferPointer.allocate(
135+
byteCount: count,
136+
alignment: MemoryLayout<Int>.alignment)
137+
a.withUnsafeBytes {
138+
rb.copyMemory(from: $0)
139+
}
140+
r8 = UnsafeRawBufferPointer(rb)
141+
assert(b8.baseAddress == nil)
142+
b8 = .allocate(capacity: rb.count)
143+
r = rb.indices.randomElement()!
144+
}
145+
146+
public func rawBufferCopyContentsTeardown() {
147+
r8.deallocate()
148+
r8 = .init(start: nil, count: 0)
149+
b8.deallocate()
150+
b8 = .init(start: nil, count: 0)
151+
}
152+
153+
@inline(never)
154+
public func rawBufferCopyContentsExecute(n: Int) {
155+
// Measure performance of copying bytes from an
156+
// `UnsafeRawBufferPointer` to an `UnsafeMutableBufferPointer<UInt8>`.
157+
// See: https://bugs.swift.org/browse/SR-9604
158+
159+
for _ in 0..<n {
160+
var (iterator, initialized) = b8.initialize(from: r8)
161+
blackHole(b8)
162+
CheckResults(initialized == r8.count && iterator.next() == nil)
163+
}
164+
165+
CheckResults(b8[r] == r8[r])
166+
}

benchmark/single-source/ObjectiveCBridgingStubs.swift

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import ObjectiveCTests
1818

1919
let t: [BenchmarkCategory] = [.validation, .bridging]
2020
let ts: [BenchmarkCategory] = [.validation, .String, .bridging]
21+
let bs: [BenchmarkCategory] = [.String, .bridging]
2122

2223
public let ObjectiveCBridgingStubs = [
2324
BenchmarkInfo(name: "ObjectiveCBridgeStubDataAppend",
@@ -68,9 +69,24 @@ public let ObjectiveCBridgingStubs = [
6869
BenchmarkInfo(name: "ObjectiveCBridgeStringGetUTF8Contents",
6970
runFunction: run_ObjectiveCBridgeStringGetUTF8Contents, tags: ts,
7071
setUpFunction: setup_StringBridgeBenchmark),
71-
BenchmarkInfo(name: "ObjectiveCBridgeStringRangeOfString",
72+
BenchmarkInfo(name: "ObjectiveCBridgeStringRangeOfString", //should be BridgeString.find.mixed
7273
runFunction: run_ObjectiveCBridgeStringRangeOfString, tags: ts,
7374
setUpFunction: setup_StringBridgeBenchmark),
75+
BenchmarkInfo(name: "BridgeString.find.native",
76+
runFunction: run_ObjectiveCBridgeStringRangeOfStringAllSwift, tags: bs,
77+
setUpFunction: setup_SpecificRangeOfStringBridging),
78+
BenchmarkInfo(name: "BridgeString.find.native.nonASCII",
79+
runFunction: run_ObjectiveCBridgeStringRangeOfStringAllSwiftNonASCII, tags: bs,
80+
setUpFunction: setup_SpecificRangeOfStringBridging),
81+
BenchmarkInfo(name: "BridgeString.find.native.long",
82+
runFunction: run_ObjectiveCBridgeStringRangeOfStringAllSwiftLongHaystack, tags: bs,
83+
setUpFunction: setup_SpecificRangeOfStringBridging),
84+
BenchmarkInfo(name: "BridgeString.find.native.longBoth",
85+
runFunction: run_ObjectiveCBridgeStringRangeOfStringAllSwiftLongHaystackLongNeedle, tags: bs,
86+
setUpFunction: setup_SpecificRangeOfStringBridging),
87+
BenchmarkInfo(name: "BridgeString.find.native.longNonASCII",
88+
runFunction: run_ObjectiveCBridgeStringRangeOfStringAllSwiftLongHaystackNonASCII, tags: bs,
89+
setUpFunction: setup_SpecificRangeOfStringBridging),
7490
BenchmarkInfo(name: "ObjectiveCBridgeStringHash",
7591
runFunction: run_ObjectiveCBridgeStringHash, tags: ts,
7692
setUpFunction: setup_StringBridgeBenchmark),
@@ -408,6 +424,47 @@ public func run_ObjectiveCBridgeStringRangeOfString(N: Int) {
408424
#endif
409425
}
410426

427+
@inline(__always)
428+
func run_rangeOfStringSpecific(needle: String, haystack: String, N: Int) {
429+
#if _runtime(_ObjC)
430+
b.testRangeOfStringSpecific(withNeedle: needle, haystack: haystack, n: N)
431+
#endif
432+
}
433+
434+
@inline(never)
435+
public func run_ObjectiveCBridgeStringRangeOfStringAllSwift(N: Int) {
436+
run_rangeOfStringSpecific(needle: "y", haystack: "The quick brown fox jumps over the lazy dog", N: 100 * N)
437+
}
438+
439+
var longNativeASCII: String! = nil
440+
var longNativeNonASCII: String! = nil
441+
public func setup_SpecificRangeOfStringBridging() {
442+
setup_StringBridgeBenchmark()
443+
longNativeASCII = Array(repeating: "The quick brown fox jump over the lazy dog", count: 1000).joined() + "s"
444+
longNativeNonASCII = "ü" + longNativeASCII + "ö"
445+
446+
}
447+
448+
@inline(never)
449+
public func run_ObjectiveCBridgeStringRangeOfStringAllSwiftLongHaystack(N: Int) {
450+
run_rangeOfStringSpecific(needle: "s", haystack: longNativeASCII, N: N)
451+
}
452+
453+
@inline(never)
454+
public func run_ObjectiveCBridgeStringRangeOfStringAllSwiftLongHaystackNonASCII(N: Int) {
455+
run_rangeOfStringSpecific(needle: "s", haystack: longNativeNonASCII, N: N)
456+
}
457+
458+
@inline(never)
459+
public func run_ObjectiveCBridgeStringRangeOfStringAllSwiftNonASCII(N: Int) {
460+
run_rangeOfStringSpecific(needle: "ü", haystack: "The quick brown fox jump over the lazy dogü", N: 100 * N)
461+
}
462+
463+
@inline(never)
464+
public func run_ObjectiveCBridgeStringRangeOfStringAllSwiftLongHaystackLongNeedle(N: Int) {
465+
run_rangeOfStringSpecific(needle: "The quick brown fox jump over the lazy dogs", haystack: longNativeASCII, N: N)
466+
}
467+
411468
@inline(never)
412469
public func run_ObjectiveCBridgeStringHash(N: Int) {
413470
#if _runtime(_ObjC)

benchmark/utils/ObjectiveCTests/ObjectiveCTests.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ NS_ASSUME_NONNULL_BEGIN
4242
- (void)testGetUTF8Contents;
4343
- (void)testGetASCIIContents;
4444
- (void)testRangeOfString;
45+
- (void)testRangeOfStringSpecificWithNeedle:(NSString *)needle
46+
haystack:(NSString *)haystack
47+
n:(NSInteger)n;
4548
- (void)testHash;
4649
- (void)testCompare;
4750
- (void)testCompare2;

benchmark/utils/ObjectiveCTests/ObjectiveCTests.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,14 @@ - (void)testRangeOfString {
307307
};
308308
}
309309

310+
- (void)testRangeOfStringSpecificWithNeedle:(NSString *)needle
311+
haystack:(NSString *)haystack
312+
n:(NSInteger)n {
313+
for (int i = 0; i < n; i++) {
314+
(void)[haystack rangeOfString:needle];
315+
}
316+
}
317+
310318
- (void) testHash {
311319
for (NSString *str1 in bridgedStrings) {
312320
@autoreleasepool {

cmake/modules/AddSwift.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ include(SwiftAndroidSupport)
77
function(_swift_gyb_target_sources target scope)
88
file(GLOB GYB_UNICODE_DATA ${SWIFT_SOURCE_DIR}/utils/UnicodeData/*)
99
file(GLOB GYB_STDLIB_SUPPORT ${SWIFT_SOURCE_DIR}/utils/gyb_stdlib_support.py)
10-
file(GLOB GYB_SYNTAX_SUPPORT ${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/*)
11-
file(GLOB GYB_SOURCEKIT_SUPPORT ${SWIFT_SOURCE_DIR}/utils/gyb_sourcekit_support/*)
10+
file(GLOB GYB_SYNTAX_SUPPORT ${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/*.py)
11+
file(GLOB GYB_SOURCEKIT_SUPPORT ${SWIFT_SOURCE_DIR}/utils/gyb_sourcekit_support/*.py)
1212
set(GYB_SOURCES
13+
${SWIFT_SOURCE_DIR}/utils/gyb
14+
${SWIFT_SOURCE_DIR}/utils/gyb.py
1315
${SWIFT_SOURCE_DIR}/utils/GYBUnicodeDataUtils.py
1416
${SWIFT_SOURCE_DIR}/utils/SwiftIntTypes.py
1517
${GYB_UNICODE_DATA}

cmake/modules/SwiftHandleGybSources.cmake

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ endfunction()
7777
# handle_gyb_sources(
7878
# dependency_out_var_name
7979
# sources_var_name
80-
# arch)
80+
# [ARCH arch]
81+
# [DEPENDS [depends ...]])
8182
#
8283
# Replace, in ${sources_var_name}, the given .gyb-suffixed sources with
8384
# their un-suffixed intermediate files, which will be generated by processing
@@ -93,11 +94,21 @@ endfunction()
9394
# false, the files are architecture-independent and will be emitted
9495
# into ${CMAKE_CURRENT_BINARY_DIR} instead of an architecture-specific
9596
# destination; this is useful for generated include files.
96-
function(handle_gyb_sources dependency_out_var_name sources_var_name arch)
97+
#
98+
# depends
99+
# Additional file dependencies beyond the standard dependencies that all gyb
100+
# invocations get.
101+
function(handle_gyb_sources dependency_out_var_name sources_var_name)
102+
set(options)
103+
set(single_value_args ARCH)
104+
set(multi_value_args DEPENDS)
105+
cmake_parse_arguments(GYB
106+
"${options}" "${single_value_args}" "${multi_value_args}" ${ARGN})
107+
97108
set(extra_gyb_flags "")
98-
if (arch)
109+
if (GYB_ARCH)
99110
set_if_arch_bitness(ptr_size
100-
ARCH "${arch}"
111+
ARCH "${GYB_ARCH}"
101112
CASE_32_BIT "4"
102113
CASE_64_BIT "8")
103114
set(extra_gyb_flags "-DCMAKE_SIZEOF_VOID_P=${ptr_size}")
@@ -141,7 +152,7 @@ function(handle_gyb_sources dependency_out_var_name sources_var_name arch)
141152
set(dir_root ${CMAKE_CURRENT_BINARY_DIR})
142153
endif()
143154

144-
if (arch)
155+
if (GYB_ARCH)
145156
set(dir "${dir_root}/${ptr_size}")
146157
else()
147158
set(dir "${dir_root}")
@@ -154,7 +165,7 @@ function(handle_gyb_sources dependency_out_var_name sources_var_name arch)
154165
SOURCE "${src}"
155166
OUTPUT "${output_file_name}"
156167
FLAGS ${extra_gyb_flags}
157-
DEPENDS "${gyb_extra_sources}"
168+
DEPENDS "${GYB_DEPENDS}" "${gyb_extra_sources}"
158169
COMMENT "with ptr size = ${ptr_size}")
159170
list(APPEND dependency_targets "${dependency_target}")
160171
endforeach()
@@ -163,13 +174,7 @@ function(handle_gyb_sources dependency_out_var_name sources_var_name arch)
163174
endfunction()
164175

165176
function(add_gyb_target target sources)
166-
set(options)
167-
set(single_value_args ARCH)
168-
set(multi_value_args)
169-
cmake_parse_arguments(GYB
170-
"${options}" "${single_value_args}" "${multi_value_args}" ${ARGN})
171-
172-
handle_gyb_sources(gyb_sources_depends sources "${GYB_ARCH}")
177+
handle_gyb_sources(gyb_sources_depends sources ${ARGN})
173178

174179
add_custom_target(${target}
175180
DEPENDS "${gyb_sources_depends}")

docs/CppInteroperabilityManifesto.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,13 +407,13 @@ void printInt(const int &value);
407407
```swift
408408
// C++ header imported in Swift.
409409
410-
void printInt(_ value: UnsafePointer<Int>)
410+
func printInt(_ value: UnsafePointer<Int>)
411411
```
412412

413413
```swift
414414
// Usage example.
415415

416-
void caller() {
416+
func caller() {
417417
var x = 42
418418
printInt(&x) // OK
419419

@@ -450,13 +450,13 @@ void printInt(const int &value);
450450
```swift
451451
// C++ header imported in Swift.
452452
453-
void printInt(_ value: Int)
453+
func printInt(_ value: Int)
454454
```
455455

456456
```swift
457457
// Usage example.
458458

459-
void caller() {
459+
func caller() {
460460
let x = 42
461461
printInt(y) // OK
462462
}

docs/ReferenceGuides/UnderscoredAttributes.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ Most notably, default argument expressions are implicitly
3939
`@_alwaysEmitIntoClient`, which means that adding a default argument to a
4040
function which did not have one previously does not break ABI.
4141

42+
## `@_assemblyVision`
43+
44+
Forces emission of assembly vision remarks for a function or method, showing
45+
where various runtime calls and performance impacting hazards are in the code
46+
at source level after optimization.
47+
48+
Adding this attribute to a type leads to remarks being emitted for all methods.
49+
4250
## `@_borrowed`
4351

4452
Indicates that the [conservative access pattern](/docs/Lexicon.md#access-pattern)
@@ -95,15 +103,15 @@ extension Text {
95103
}
96104
```
97105

98-
## `@_dynamicReplacement(for:)`
106+
## `@_dynamicReplacement(for: targetFunc(label:))`
99107

100108
Marks a function as the dynamic replacement for another `dynamic` function.
101109
This is similar to method swizzling in other languages such as Objective-C,
102110
except that the replacement happens at program start (or loading a shared
103111
library), instead of at an arbitrary point in time.
104112

105113
For more details, see the forum post on
106-
[Dynamic method replacement](https://forums.swift.org/t/dynamic-method-replacement/16619).
114+
[dynamic method replacement](https://forums.swift.org/t/dynamic-method-replacement/16619).
107115

108116
## `@_distributedActorIndependent`
109117

@@ -124,7 +132,7 @@ already infer from static analysis.
124132
Changing the implementation in a way that violates the optimizer's assumptions
125133
about the effects results in undefined behavior.
126134

127-
For more details, see [OptimizerEffects.rst](/docs/Proposals/OptimizerEffects.rst).
135+
For more details, see [OptimizerEffects.rst](/docs/proposals/OptimizerEffects.rst).
128136

129137
## `@_exported`
130138

@@ -134,7 +142,7 @@ This attribute is most commonly used by overlays.
134142

135143
```swift
136144
// module M
137-
func f() {}
145+
public func f() {}
138146

139147
// module N
140148
@_exported import M
@@ -264,17 +272,12 @@ class C {
264272

265273
(Note that it is "inherit", not "inherits", unlike below.)
266274

267-
Marks that a `@Sendable async` closure argument should inherited the actor
275+
Marks that a `@Sendable async` closure argument should inherit the actor
268276
context (i.e. what actor it should be run on) based on the declaration site
269277
of the closure. This is different from the typical behavior, where the closure
270278
may be runnable anywhere unless its type specifically declares that it will
271279
run on a specific actor.
272280

273-
This new attribute can be used on parameters of `@Sendable async` type
274-
to indicate that the closures arguments passed to such parameters
275-
should inherit the actor context where they are formed, which is not
276-
the normal behavior for `@Sendable` closures.
277-
278281
## `@_inheritsConvenienceInitializers`
279282

280283
An attribute that signals that a class declaration inherits its convenience
@@ -289,7 +292,6 @@ Indicates that a protocol is a marker protocol. Marker protocols represent some
289292
meaningful property at compile-time but have no runtime representation.
290293

291294
For more details, see [SE-0302](https://github.com/apple/swift-evolution/blob/main/proposals/0302-concurrent-value-and-concurrent-closures.md#marker-protocols), which introduces marker protocols.
292-
293295
At the moment, the language only has one marker protocol: `Sendable`.
294296

295297
Fun fact: Rust has a very similar concept called

docs/SIL.rst

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3505,6 +3505,7 @@ The operand must have loadable type.
35053505
debug-var-attr ::= 'let'
35063506
debug-var-attr ::= 'name' string-literal
35073507
debug-var-attr ::= 'argno' integer-literal
3508+
debug-var-attr ::= 'implicit'
35083509

35093510
::
35103511

@@ -3520,12 +3521,13 @@ The operand must have loadable type.
35203521
There are a number of attributes that provide details about the source
35213522
variable that is being described, including the name of the
35223523
variable. For function and closure arguments ``argno`` is the number
3523-
of the function argument starting with 1. The advanced debug variable
3524-
attributes represent source locations and type of the source variable
3525-
when it was originally declared. It is useful when we're indirectly
3526-
associating the SSA value with the source variable (via di-expression,
3527-
for example) in which case SSA value's type is different from that of
3528-
source variable.
3524+
of the function argument starting with 1. A compiler-generated source
3525+
variable will be marked ``implicit`` and optimizers are free to remove
3526+
it even in -Onone. The advanced debug variable attributes represent source
3527+
locations and type of the source variable when it was originally declared.
3528+
It is useful when we're indirectly associating the SSA value with the
3529+
source variable (via di-expression, for example) in which case SSA value's
3530+
type is different from that of source variable.
35293531

35303532
If the '[poison]' flag is set, then all references within this debug
35313533
value will be overwritten with a sentinel at this point in the

0 commit comments

Comments
 (0)