Skip to content

Commit 3f15285

Browse files
committed
Merge branch 'main' of github.com:apple/swift into maxd/main-merge
# Conflicts: # cmake/modules/Libdispatch.cmake # stdlib/cmake/modules/SwiftSource.cmake # test/stdlib/InputStream.swift.gyb
2 parents 42db234 + db90ea2 commit 3f15285

File tree

98 files changed

+644
-320
lines changed

Some content is hidden

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

98 files changed

+644
-320
lines changed

benchmark/README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,30 @@ benchmarks will be compiled with -Onone!**
199199
* `$ ./Benchmark_O --tags=Dictionary`
200200
* `$ ./Benchmark_O --skip-tags=unstable,skip,validation`
201201

202-
### Note
202+
### Deterministic Hashing Requirement
203+
204+
To run benchmarks, you'll need to disable randomized hash seeding by setting the
205+
`SWIFT_DETERMINISTIC_HASHING` environment variable to `1`. (You only need to do
206+
this when running the benchmark executables directly -- the driver script does
207+
this for you automatically.)
208+
209+
* `$ env SWIFT_DETERMINISTIC_HASHING=1 ./Benchmark_O --num-iters=1 --num-samples=1`
210+
211+
This makes for more stable results, by preventing random hash collision changes
212+
from affecting benchmark measurements. Benchmark measurements start by checking
213+
that deterministic hashing is enabled and they fail with a runtime trap when it
214+
isn't.
215+
216+
If for some reason you want to run the benchmarks using standard randomized
217+
hashing, you can disable this check by passing the
218+
`--allow-nondeterministic-hashing` option to the executable.
219+
220+
* `$ ./Benchmark_O --num-iters=1 --num-samples=1 --allow-nondeterministic-hashing`
221+
222+
This will affect the reliability of measurements, so this is not recommended.
223+
224+
### Benchmarking by Numbers
225+
203226
As a shortcut, you can also refer to benchmarks by their ordinal numbers.
204227
These are printed out together with benchmark names and tags using the
205228
`--list` parameter. For a complete list of all available performance tests run

benchmark/cmake/modules/AddSwiftBenchmarkSuite.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ function (swift_benchmark_compile_archopts)
683683
${objcfile}
684684
"-o" "${OUTPUT_EXEC}"
685685
COMMAND
686-
"codesign" "-f" "-s" "-" "${OUTPUT_EXEC}")
686+
"${srcdir}/../utils/swift-darwin-postprocess.py" "${OUTPUT_EXEC}")
687687
else()
688688
# TODO: rpath.
689689
add_custom_command(

benchmark/scripts/Benchmark_Driver

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ class BenchmarkDriver(object):
5656
"""
5757
self.args = args
5858
self.run_env = os.environ.copy()
59+
60+
# Set a constant hash seed. Some tests are highly sensitive to
61+
# fluctuations in the number of hash collisions.
62+
self.run_env["SWIFT_DETERMINISTIC_HASHING"] = "1"
63+
5964
if hasattr(args, 'libdir') and args.libdir:
6065
# The benchmark binaries should pick up the built swift libraries
6166
# automatically, because their RPATH should point to ../lib/swift
@@ -65,15 +70,13 @@ class BenchmarkDriver(object):
6570
self.run_env["DYLD_LIBRARY_PATH"] = args.libdir
6671
elif platform.system() == "Linux":
6772
self.run_env["LD_LIBRARY_PATH"] = args.libdir
73+
6874
self._subprocess = _subprocess or subprocess
6975
self.all_tests = []
7076
self.test_number = {}
7177
self.tests = tests or self._get_tests()
7278
self.parser = parser or LogParser()
7379
self.results = {}
74-
# Set a constant hash seed. Some tests are currently sensitive to
75-
# fluctuations in the number of hash collisions.
76-
os.environ["SWIFT_DETERMINISTIC_HASHING"] = "1"
7780

7881
def _invoke(self, cmd):
7982
return self._subprocess.check_output(

benchmark/utils/DriverUtils.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ struct TestConfig {
104104
// Should we log the measurement metadata?
105105
let logMeta: Bool
106106

107+
// Allow running with nondeterministic hashing?
108+
var allowNondeterministicHashing: Bool
109+
107110
/// After we run the tests, should the harness sleep to allow for utilities
108111
/// like leaks that require a PID to run on the test harness.
109112
let afterRunSleep: UInt32?
@@ -128,6 +131,7 @@ struct TestConfig {
128131
var verbose: Bool?
129132
var logMemory: Bool?
130133
var logMeta: Bool?
134+
var allowNondeterministicHashing: Bool?
131135
var action: TestAction?
132136
var tests: [String]?
133137
}
@@ -191,6 +195,10 @@ struct TestConfig {
191195
p.addArgument("--list", \.action, defaultValue: .listTests,
192196
help: "don't run the tests, just log the list of test \n" +
193197
"numbers, names and tags (respects specified filters)")
198+
p.addArgument("--allow-nondeterministic-hashing",
199+
\.allowNondeterministicHashing, defaultValue: true,
200+
help: "Don't trap when running without the \n" +
201+
"SWIFT_DETERMINISTIC_HASHING=1 environment variable")
194202
p.addArgument(nil, \.tests) // positional arguments
195203

196204
let c = p.parse()
@@ -208,6 +216,7 @@ struct TestConfig {
208216
logMeta = c.logMeta ?? false
209217
afterRunSleep = c.afterRunSleep
210218
action = c.action ?? .run
219+
allowNondeterministicHashing = c.allowNondeterministicHashing ?? false
211220
tests = TestConfig.filterTests(registeredBenchmarks,
212221
tests: c.tests ?? [],
213222
tags: c.tags ?? [],
@@ -671,6 +680,17 @@ final class TestRunner {
671680
}
672681
}
673682

683+
extension Hasher {
684+
static var isDeterministic: Bool {
685+
// This is a quick test for deterministic hashing.
686+
// When hashing uses a random seed, each `Set` value
687+
// contains its members in some unique, random order.
688+
let set1 = Set(0 ..< 100)
689+
let set2 = Set(0 ..< 100)
690+
return set1.elementsEqual(set2)
691+
}
692+
}
693+
674694
public func main() {
675695
let config = TestConfig(registeredBenchmarks)
676696
switch (config.action) {
@@ -682,6 +702,18 @@ public func main() {
682702
print(testDescription)
683703
}
684704
case .run:
705+
if !config.allowNondeterministicHashing && !Hasher.isDeterministic {
706+
fatalError("""
707+
Benchmark runs require deterministic hashing to be enabled.
708+
709+
This prevents spurious regressions in hashed collection performance.
710+
You can do this by setting the SWIFT_DETERMINISTIC_HASHING environment
711+
variable to 1.
712+
713+
If you know what you're doing, you can disable this check by passing
714+
the option '--allow-nondeterministic-hashing to the benchmarking executable.
715+
""")
716+
}
685717
TestRunner(config).runBenchmarks()
686718
if let x = config.afterRunSleep {
687719
sleep(x)

cmake/modules/Libdispatch.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ endif()
4747
# Build any target libdispatch if needed.
4848
foreach(sdk ${SWIFT_SDKS})
4949
# Darwin targets have libdispatch available, do not build it.
50-
# Wasm/WASI doesn't support libdispatch yet.
50+
# Wasm/WASI doesn't support libdispatch yet. See https://bugs.swift.org/browse/SR-12097 for more details.
5151
if(NOT "${sdk}" IN_LIST SWIFT_DARWIN_PLATFORMS AND NOT "${sdk}" STREQUAL WASI)
5252
list(APPEND DISPATCH_SDKS "${sdk}")
5353
endif()

docs/SIL.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3671,7 +3671,7 @@ begin_borrow
36713671

36723672
::
36733673

3674-
sil-instruction ::= 'begin_borrow' '[defined]'? sil-operand
3674+
sil-instruction ::= 'begin_borrow' '[lexical]'? sil-operand
36753675

36763676
%1 = begin_borrow %0 : $T
36773677

@@ -3684,7 +3684,7 @@ region in between this borrow and its lifetime ending use, ``%0`` must be
36843684
live. This makes sense semantically since ``%1`` is modeling a new value with a
36853685
dependent lifetime on ``%0``.
36863686

3687-
The optional ``defined`` attribute specifies that the operand corresponds to a
3687+
The optional ``lexical`` attribute specifies that the operand corresponds to a
36883688
local variable in the Swift source, so special care must be taken when moving
36893689
the end_borrow.
36903690

include/swift/AST/DiagnosticsDriver.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,6 @@ WARNING(warning_unsupported_driver_option,none,
174174
"option '%0' is ony supported in swift-driver", (StringRef))
175175

176176
WARNING(old_driver_deprecated,none,
177-
"legacy driver is now deprecated; consider avoiding specifying `%0`", (StringRef))
177+
"legacy driver is now deprecated; consider avoiding specifying '%0'", (StringRef))
178178
#define UNDEFINE_DIAGNOSTIC_MACROS
179179
#include "DefineDiagnosticMacros.h"

include/swift/AST/DiagnosticsSema.def

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,7 +1940,7 @@ NOTE(nonsendable_tuple_type,none,
19401940
"a tuple type must be composed of 'Sendable' elements to conform to "
19411941
"'Sendable'", ())
19421942
NOTE(non_sendable_nominal,none,
1943-
"%0 %1 does not conform to the `Sendable` protocol",
1943+
"%0 %1 does not conform to the 'Sendable' protocol",
19441944
(DescriptiveDeclKind, DeclName))
19451945
NOTE(add_nominal_sendable_conformance,none,
19461946
"consider making %0 %1 conform to the 'Sendable' protocol",
@@ -2963,7 +2963,7 @@ WARNING(differentiable_immutable_wrapper_implicit_noderivative_fixit,none,
29632963
/*nominalCanDeriveAdditiveArithmetic*/ bool))
29642964
WARNING(differentiable_let_property_implicit_noderivative_fixit,none,
29652965
"synthesis of the 'Differentiable.move(by:)' requirement for %0 "
2966-
"requires all stored properties not marked with `@noDerivative` to be "
2966+
"requires all stored properties not marked with '@noDerivative' to be "
29672967
"mutable or have a non-mutating 'move(by:)'; use 'var' instead, or "
29682968
"add an explicit '@noDerivative' attribute "
29692969
"%select{|, or conform %0 to 'AdditiveArithmetic'}1",
@@ -4536,10 +4536,10 @@ ERROR(concurrent_value_outside_source_file,none,
45364536
"%0 %1; use '@unchecked Sendable' for retroactive conformance",
45374537
(DescriptiveDeclKind, DeclName))
45384538
ERROR(concurrent_value_nonfinal_class,none,
4539-
"non-final class %0 cannot conform to `Sendable`; "
4540-
"use `@unchecked Sendable`", (DeclName))
4539+
"non-final class %0 cannot conform to 'Sendable'; "
4540+
"use '@unchecked Sendable'", (DeclName))
45414541
ERROR(concurrent_value_inherit,none,
4542-
"`Sendable` class %1 cannot inherit from another class"
4542+
"'Sendable' class %1 cannot inherit from another class"
45434543
"%select{| other than 'NSObject'}0",
45444544
(bool, DeclName))
45454545
ERROR(non_sendable_type,none,

include/swift/AST/IRGenOptions.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ enum class IRGenEmbedMode : unsigned {
8181
EmbedBitcode
8282
};
8383

84+
enum class SwiftAsyncFramePointerKind : unsigned {
85+
Auto, // Choose Swift async extended frame info based on deployment target.
86+
Always, // Unconditionally emit Swift async extended frame info.
87+
Never, // Don't emit Swift async extended frame info.
88+
};
89+
8490
using clang::PointerAuthSchema;
8591

8692
struct PointerAuthOptions : clang::PointerAuthOptions {
@@ -282,6 +288,8 @@ class IRGenOptions {
282288

283289
IRGenLLVMLTOKind LLVMLTOKind : 2;
284290

291+
SwiftAsyncFramePointerKind SwiftAsyncFramePointer : 2;
292+
285293
/// Add names to LLVM values.
286294
unsigned HasValueNamesSetting : 1;
287295
unsigned ValueNames : 1;
@@ -393,7 +401,9 @@ class IRGenOptions {
393401
Playground(false),
394402
EmitStackPromotionChecks(false), FunctionSections(false),
395403
PrintInlineTree(false), EmbedMode(IRGenEmbedMode::None),
396-
LLVMLTOKind(IRGenLLVMLTOKind::None), HasValueNamesSetting(false),
404+
LLVMLTOKind(IRGenLLVMLTOKind::None),
405+
SwiftAsyncFramePointer(SwiftAsyncFramePointerKind::Auto),
406+
HasValueNamesSetting(false),
397407
ValueNames(false), EnableReflectionMetadata(true),
398408
EnableReflectionNames(true), EnableAnonymousContextMangledNames(false),
399409
ForcePublicLinkage(false), LazyInitializeClassMetadata(false),

include/swift/AST/SourceFile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ class SourceFile final : public FileUnit {
515515
/// null if the context hierarchy has not been built yet. Use
516516
/// TypeChecker::getOrBuildTypeRefinementContext() to get a built
517517
/// root of the hierarchy.
518-
TypeRefinementContext *getTypeRefinementContext();
518+
TypeRefinementContext *getTypeRefinementContext() const;
519519

520520
/// Set the root refinement context for the file.
521521
void setTypeRefinementContext(TypeRefinementContext *TRC);

0 commit comments

Comments
 (0)