Skip to content

Commit d366105

Browse files
authored
Merge branch 'master' into and-dreadfully-distinct
2 parents 9919bc7 + de86e4f commit d366105

File tree

1,285 files changed

+46993
-13912
lines changed

Some content is hidden

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

1,285 files changed

+46993
-13912
lines changed

CMakeLists.txt

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,14 @@ option(SWIFT_ENABLE_PARSEABLE_MODULE_INTERFACES
180180
"Generate .swiftinterface files alongside .swiftmodule files"
181181
TRUE)
182182

183+
# Allow building Swift with Clang's Profile Guided Optimization
184+
if(SWIFT_PROFDATA_FILE AND EXISTS ${SWIFT_PROFDATA_FILE})
185+
if(NOT CMAKE_C_COMPILER_ID MATCHES Clang)
186+
message(FATAL_ERROR "SWIFT_PROFDATA_FILE can only be specified when compiling with clang")
187+
endif()
188+
add_definitions("-fprofile-instr-use=${SWIFT_PROFDATA_FILE}")
189+
endif()
190+
183191
#
184192
# User-configurable Android specific options.
185193
#
@@ -311,10 +319,6 @@ option(SWIFT_STDLIB_ENABLE_SIL_OWNERSHIP
311319
"Build the standard libraries and overlays with sil ownership enabled."
312320
FALSE)
313321

314-
option(SWIFT_ENABLE_GUARANTEED_NORMAL_ARGUMENTS
315-
"Build the standard libraries, overlays, and runtime with normal arguments at +0"
316-
TRUE)
317-
318322
option(SWIFT_ENABLE_RUNTIME_FUNCTION_COUNTERS
319323
"Enable runtime function counters and expose the API."
320324
FALSE)
@@ -803,20 +807,17 @@ message(STATUS "Building host Swift tools for ${SWIFT_HOST_VARIANT_SDK} ${SWIFT_
803807
message(STATUS " Build type: ${CMAKE_BUILD_TYPE}")
804808
message(STATUS " Assertions: ${LLVM_ENABLE_ASSERTIONS}")
805809
message(STATUS " LTO: ${SWIFT_TOOLS_ENABLE_LTO}")
806-
message(STATUS " +0 Normal Args: ${SWIFT_ENABLE_GUARANTEED_NORMAL_ARGUMENTS}")
807810
message(STATUS "")
808811

809812
if (SWIFT_BUILD_STDLIB OR SWIFT_BUILD_SDK_OVERLAY)
810813

811814
message(STATUS "Building Swift standard library and overlays for SDKs: ${SWIFT_SDKS}")
812815
message(STATUS " Build type: ${SWIFT_STDLIB_BUILD_TYPE}")
813816
message(STATUS " Assertions: ${SWIFT_STDLIB_ASSERTIONS}")
814-
message(STATUS " +0 Normal Args: ${SWIFT_ENABLE_GUARANTEED_NORMAL_ARGUMENTS}")
815817
message(STATUS "")
816818

817819
message(STATUS "Building Swift runtime with:")
818820
message(STATUS " Leak Detection Checker Entrypoints: ${SWIFT_RUNTIME_ENABLE_LEAK_CHECKER}")
819-
message(STATUS " +0 Normal Args: ${SWIFT_ENABLE_GUARANTEED_NORMAL_ARGUMENTS}")
820821
message(STATUS "")
821822

822823
else()
@@ -977,12 +978,24 @@ if(SWIFT_NEED_EXPLICIT_LIBDISPATCH)
977978
add_dependencies(dispatch libdispatch-install)
978979
add_dependencies(BlocksRuntime libdispatch-install)
979980

981+
if(SWIFT_HOST_VARIANT_SDK STREQUAL WINDOWS)
982+
set(SOURCEKIT_RUNTIME_DIR bin)
983+
else()
984+
set(SOURCEKIT_RUNTIME_DIR lib)
985+
endif()
980986
swift_install_in_component(sourcekit-inproc
981987
FILES
982988
$<TARGET_FILE:dispatch>
983989
$<TARGET_FILE:BlocksRuntime>
984-
DESTINATION
985-
lib${LLVM_LIBDIR_SUFFIX})
990+
DESTINATION ${SOURCEKIT_RUNTIME_DIR})
991+
if(SWIFT_HOST_VARIANT_SDK STREQUAL WINDOWS)
992+
swift_install_in_component(sourcekit-inproc
993+
FILES
994+
$<TARGET_LINKER_FILE:dispatch>
995+
$<TARGET_LINKER_FILE:BlocksRuntime>
996+
DESTINATION lib)
997+
endif()
998+
986999

9871000
# FIXME(compnerd) this should be taken care of by the
9881001
# INTERFACE_INCLUDE_DIRECTORIES above

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ supported host development operating systems.
7272

7373
#### macOS
7474

75-
To build for macOS, you need [Xcode 10.0](https://developer.apple.com/xcode/downloads/).
75+
To build for macOS, you need [Xcode 10.2 beta](https://developer.apple.com/xcode/downloads/).
7676
The required version of Xcode changes frequently, and is often a beta release.
7777
Check this document or the host information on <https://ci.swift.org> for the
7878
current required version.

apinotes/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ add_custom_target("copy_apinotes"
2828
COMMENT "Copying API notes to ${output_dir}"
2929
SOURCES "${sources}")
3030

31+
# This is treated as an OPTIONAL target because if we don't build the SDK
32+
# overlay, the files will be missing anyway. It also allows us to build
33+
# single overlays without installing the API notes.
3134
swift_install_in_component(sdk-overlay
32-
FILES ${sources}
33-
DESTINATION "lib/swift/apinotes")
35+
DIRECTORY "${output_dir}"
36+
DESTINATION "lib/swift/"
37+
OPTIONAL)

benchmark/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ set(SWIFT_BENCH_MODULES
5858
single-source/ClassArrayGetter
5959
single-source/Codable
6060
single-source/Combos
61-
single-source/CountAlgo
6261
single-source/DataBenchmarks
6362
single-source/DeadArray
6463
single-source/DictOfArraysToArrayOfDicts

benchmark/README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,17 @@ Adding New Benchmarks
132132

133133
The harness generator supports both single and multiple file tests.
134134

135-
To add a new single file test:
135+
To add a new single file test, execute the following script with the new of the benchmark:
136136

137+
```
138+
swift-source$ ./swift/benchmark/scripts/create_benchmark.py YourTestNameHere
139+
```
140+
141+
The script will automatically:
137142
1. Add a new Swift file (`YourTestNameHere.swift`), built according to
138143
the template below, to the `single-source` directory.
139-
2. Add the filename of the new Swift file to CMakeLists.txt
140-
3. Edit `main.swift`. Import and register your new Swift module.
144+
2. Add the filename of the new Swift file to `CMakeLists.txt`.
145+
3. Edit `main.swift` by importing and registering your new Swift module.
141146

142147
To add a new multiple file test:
143148

benchmark/multi-source/PrimsSplit/Prims_main.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ import TestsUtils
1515
public let PrimsSplit = BenchmarkInfo(
1616
name: "PrimsSplit",
1717
runFunction: run_PrimsSplit,
18-
tags: [.validation, .algorithm])
18+
tags: [.validation, .algorithm],
19+
legacyFactor: 5)
1920

2021
@inline(never)
2122
public func run_PrimsSplit(_ N: Int) {
22-
for _ in 1...5*N {
23+
for _ in 1...N {
2324
let nodes : [Int] = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
2425
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
2526
29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,

benchmark/scripts/Template.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===--- {name}.swift -------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2019 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+
15+
public let {name} = [
16+
BenchmarkInfo(name: "{name}", runFunction: run_{name}, tags: [.validation, .api]),
17+
]
18+
19+
@inline(never)
20+
public func run_{name}(N: Int) {{
21+
// TODO
22+
}}

benchmark/scripts/create_benchmark.py

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#!/usr/bin/env python
2+
3+
import argparse
4+
import os
5+
import re
6+
7+
8+
def main():
9+
p = argparse.ArgumentParser()
10+
p.add_argument('name', help='The name of the new benchmark to be created')
11+
args = p.parse_args()
12+
13+
# adds benchmark to `CMakeLists.txt`
14+
update_cmakelists(args.name)
15+
# create benchmark Swift file
16+
create_benchmark_file(args.name)
17+
# imports the benchmark module in `main.swift`
18+
add_import_benchmark(args.name)
19+
# registers the benchmark with the driver in `main.swift`
20+
add_register_benchmark(args.name)
21+
22+
23+
def update_cmakelists(name):
24+
"""Adds a new entry to the `CMakeLists.txt` file with the given
25+
benchmark name.
26+
"""
27+
relative_path = create_relative_path('../CMakeLists.txt')
28+
29+
file_contents = []
30+
with open(relative_path, 'r') as f:
31+
file_contents = f.readlines()
32+
33+
file_new_contents = insert_line_alphabetically(
34+
name,
35+
' single-source/' + name + '\n',
36+
file_contents,
37+
r" single-source\/([a-zA-Z]+)"
38+
)
39+
with open(relative_path, 'w') as f:
40+
for line in file_new_contents:
41+
f.write(line)
42+
43+
44+
def create_benchmark_file(name):
45+
"""Creates a new Swift file with the given name based on the template
46+
and places it in the `single-source` directory.
47+
"""
48+
49+
template_path = create_relative_path('Template.swift')
50+
benchmark_template = ''
51+
with open(template_path, 'r') as f:
52+
benchmark_template = ''.join(f.readlines())
53+
54+
# fill in template with benchmark name.
55+
formatted_template = benchmark_template.format(name=name)
56+
57+
relative_path = create_relative_path('../single-source/')
58+
source_file_path = os.path.join(relative_path, name + '.swift')
59+
with open(source_file_path, 'w') as f:
60+
f.write(formatted_template)
61+
62+
63+
def add_import_benchmark(name):
64+
"""Adds an `import` statement to the `main.swift` file for the new
65+
benchmark.
66+
"""
67+
relative_path = create_relative_path('../utils/main.swift')
68+
69+
# read current contents into an array
70+
file_contents = []
71+
with open(relative_path, 'r') as f:
72+
file_contents = f.readlines()
73+
74+
# the test dependencies are placed before all benchmarks, so we have to
75+
# insert the benchmark in the right alphabetical order after we have seen
76+
# all test dependencies.
77+
read_test_dependencies = False
78+
previous_benchmark_name = None
79+
file_new_contents = []
80+
for line in file_contents:
81+
# check if this line is a definition of a benchmark and get its name
82+
match = re.search(r"import ([a-zA-Z]+)", line)
83+
if match and match.group(1):
84+
benchmark_name = match.group(1)
85+
# find where to insert the new benchmark in the right alphabetical
86+
# order.
87+
if (name < benchmark_name and previous_benchmark_name is None or
88+
name < benchmark_name and name > previous_benchmark_name):
89+
if read_test_dependencies:
90+
file_new_contents.append('import ' + name + '\n' + line)
91+
else:
92+
# all test dependencies are first specified, so from now
93+
# on we can look where to insert the new benchmark.
94+
read_test_dependencies = True
95+
file_new_contents.append(line)
96+
else:
97+
file_new_contents.append(line)
98+
previous_benchmark_name = benchmark_name
99+
else:
100+
file_new_contents.append(line)
101+
with open(relative_path, 'w') as f:
102+
for line in file_new_contents:
103+
f.write(line)
104+
105+
106+
def add_register_benchmark(name):
107+
"""Adds an `import` statement to the `main.swift` file for the new
108+
benchmark.
109+
"""
110+
relative_path = create_relative_path('../utils/main.swift')
111+
112+
file_contents = []
113+
with open(relative_path, 'r') as f:
114+
file_contents = f.readlines()
115+
116+
file_new_contents = insert_line_alphabetically(
117+
name,
118+
'registerBenchmark(' + name + ')\n',
119+
file_contents,
120+
r"registerBenchmark\(([a-zA-Z]+)\)"
121+
)
122+
with open(relative_path, 'w') as f:
123+
for line in file_new_contents:
124+
f.write(line)
125+
126+
127+
def insert_line_alphabetically(name, new_line, lines, regex):
128+
"""Iterates through the given lines and executes the regex on each line to
129+
find where the new benchmark should be inserted with the given `new_line`.
130+
"""
131+
# the name of the previous seen benchmark in order to insert the new
132+
# one at the correct position
133+
previous_benchmark_name = None
134+
# the new contents of the file
135+
updated_lines = []
136+
for line in lines:
137+
# apply regex and get name of benchmark on this line
138+
match = re.search(regex, line)
139+
if match and match.group(1):
140+
benchmark_name = match.group(1)
141+
# check if we're at the line where we have to insert the new
142+
# benchmark in the correct alphabetical order
143+
if (name < benchmark_name and previous_benchmark_name is None or
144+
name < benchmark_name and name > previous_benchmark_name):
145+
updated_lines.append(new_line + line)
146+
else:
147+
updated_lines.append(line)
148+
previous_benchmark_name = benchmark_name
149+
else:
150+
updated_lines.append(line)
151+
return updated_lines
152+
153+
154+
def create_relative_path(file_path):
155+
return os.path.join(os.path.dirname(__file__), file_path)
156+
157+
158+
if __name__ == "__main__":
159+
main()

benchmark/scripts/run_smoke_bench

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def test_performance(opt_level, old_dir, new_dir, threshold, num_samples,
185185
tests = TestComparator(results[0], results[1], threshold)
186186
changed = tests.decreased + tests.increased
187187

188-
while len(changed) > 0 and unchanged_length_count < 5:
188+
while len(changed) > 0 and unchanged_length_count < 10:
189189
i += 1
190190
if VERBOSE:
191191
log(' test again: ' + str([test.name for test in changed]))
@@ -205,25 +205,6 @@ def test_performance(opt_level, old_dir, new_dir, threshold, num_samples,
205205
threshold * 1.4, output_file, *results)
206206

207207

208-
def get_results(bench_dir, opt_level, num_samples, to_test):
209-
try:
210-
exe = os.path.join(bench_dir, 'bin', 'Benchmark_' + opt_level)
211-
args = [exe, '--num-samples=' + str(num_samples),
212-
'--sample-time=0.0025']
213-
if to_test:
214-
args += to_test
215-
env = {'DYLD_LIBRARY_PATH': os.path.join(bench_dir, 'lib', 'swift',
216-
'macos'),
217-
'SWIFT_DETERMINISTIC_HASHING': '1'}
218-
output = subprocess.check_output(args, env=env)
219-
except subprocess.CalledProcessError as e:
220-
sys.stderr.write(e.output)
221-
sys.stderr.flush()
222-
return sys.exit(e.returncode)
223-
else:
224-
return output
225-
226-
227208
def report_code_size(opt_level, old_dir, new_dir, platform, output_file):
228209
if opt_level == 'swiftlibs':
229210
files = glob.glob(os.path.join(old_dir, 'lib', 'swift', platform,

0 commit comments

Comments
 (0)