Skip to content

Commit 9b53efd

Browse files
author
Max Moiseev
committed
Merge branch 'master' into new-integer-protocols
2 parents 4018472 + 8ca5ec9 commit 9b53efd

File tree

380 files changed

+10140
-4535
lines changed

Some content is hidden

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

380 files changed

+10140
-4535
lines changed

.flake8

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ filename = *.py,
1919
./utils/line-directive,
2020
./utils/swift_build_support/tests/mock-distcc,
2121
./docs/scripts/ns-html2rst,
22-
.utils/PathSanitizingFileCheck,
23-
./utils/python-lint,
22+
./utils/PathSanitizingFileCheck,
2423
./utils/recursive-lipo,
2524
./utils/round-trip-syntax-test,
2625
./utils/rth,
@@ -29,4 +28,4 @@ filename = *.py,
2928
./utils/submit-benchmark-results,
3029
./utils/update-checkout,
3130
./utils/viewcfg,
32-
./utils/symbolicate-linux-fatal
31+
./utils/symbolicate-linux-fatal,

benchmark/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ set(SWIFT_BENCH_MODULES
4444
single-source/DictionaryLiteral
4545
single-source/DictionaryRemove
4646
single-source/DictionarySwap
47+
single-source/DropFirst
4748
single-source/DropLast
49+
single-source/DropWhile
4850
single-source/ErrorHandling
4951
single-source/ExistentialPerformance
5052
single-source/Fibonacci
@@ -79,6 +81,8 @@ set(SWIFT_BENCH_MODULES
7981
single-source/PolymorphicCalls
8082
single-source/PopFront
8183
single-source/PopFrontGeneric
84+
single-source/Prefix
85+
single-source/PrefixWhile
8286
single-source/Prims
8387
single-source/ProtocolDispatch
8488
single-source/ProtocolDispatch2

benchmark/scripts/Benchmark_RuntimeLeaksRunner.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class LeaksRunnerBenchmarkDriver(perf_test_driver.BenchmarkDriver):
9494
raise RuntimeError("Expected one line of output")
9595
if result != 0:
9696
raise RuntimeError("Process segfaulted")
97-
except:
97+
except Exception:
9898
sys.stderr.write("Child Process Failed! (%s,%s)\n" % (
9999
data['path'], data['test_name']))
100100
sys.stderr.flush()
@@ -110,7 +110,7 @@ class LeaksRunnerBenchmarkDriver(perf_test_driver.BenchmarkDriver):
110110

111111
total_count = d['objc_count'] + d['swift_count']
112112
return total_count
113-
except:
113+
except Exception:
114114
tmp = (data['path'], data['test_name'])
115115
sys.stderr.write("Failed parse output! (%s,%s)\n" % tmp)
116116
sys.stderr.flush()

benchmark/scripts/generate_harness/generate_harness.py

+46-21
Original file line numberDiff line numberDiff line change
@@ -12,43 +12,75 @@
1212
#
1313
# ===---------------------------------------------------------------------===//
1414

15-
# Generate CMakeLists.txt and utils/main.swift from templates.
15+
# Generate boilerplate, CMakeLists.txt and utils/main.swift from templates.
1616

1717
from __future__ import print_function
1818

19-
import glob
19+
import argparse
2020
import os
2121
import re
22+
import subprocess
2223

2324
import jinja2
2425

2526
script_dir = os.path.dirname(os.path.realpath(__file__))
2627
perf_dir = os.path.realpath(os.path.join(script_dir, '../..'))
28+
gyb = os.path.realpath(os.path.join(perf_dir, '../utils/gyb'))
2729
single_source_dir = os.path.join(perf_dir, 'single-source')
2830
multi_source_dir = os.path.join(perf_dir, 'multi-source')
31+
parser = argparse.ArgumentParser()
32+
parser.add_argument("--output-dir",
33+
help="Output directory (for validation test)",
34+
default=perf_dir)
35+
args = parser.parse_args()
36+
output_dir = args.output_dir
2937

3038
template_map = {
31-
'CMakeLists.txt_template': os.path.join(perf_dir, 'CMakeLists.txt'),
32-
'main.swift_template': os.path.join(perf_dir, 'utils/main.swift')
39+
'CMakeLists.txt_template': os.path.join(output_dir, 'CMakeLists.txt'),
40+
'main.swift_template': os.path.join(output_dir, 'utils/main.swift')
3341
}
3442
ignored_run_funcs = ["Ackermann", "Fibonacci"]
3543

3644
template_loader = jinja2.FileSystemLoader(searchpath="/")
3745
template_env = jinja2.Environment(loader=template_loader, trim_blocks=True,
3846
lstrip_blocks=True)
3947

48+
49+
def all_files(directory, extension): # matching: [directory]/**/*[extension]
50+
return [
51+
os.path.join(root, f)
52+
for root, _, files in os.walk(directory)
53+
for f in files if f.endswith(extension)
54+
]
55+
56+
57+
def will_write(filename): # ensure path to file exists before writing
58+
print(filename)
59+
output_path = os.path.split(filename)[0]
60+
if not os.path.exists(output_path):
61+
os.makedirs(output_path)
62+
63+
4064
if __name__ == '__main__':
65+
# Generate Your Boilerplate
66+
gyb_files = all_files(perf_dir, '.gyb')
67+
for f in gyb_files:
68+
relative_path = os.path.relpath(f[:-4], perf_dir)
69+
out_file = os.path.join(output_dir, relative_path)
70+
will_write(out_file)
71+
subprocess.call([gyb, '--line-directive', '', '-o', out_file, f])
72+
4173
# CMakeList single-source
42-
test_files = glob.glob(os.path.join(single_source_dir, '*.swift'))
74+
test_files = all_files(single_source_dir, '.swift')
4375
tests = sorted(os.path.basename(x).split('.')[0] for x in test_files)
4476

4577
# CMakeList multi-source
4678
class MultiSourceBench(object):
47-
4879
def __init__(self, path):
4980
self.name = os.path.basename(path)
5081
self.files = [x for x in os.listdir(path)
5182
if x.endswith('.swift')]
83+
5284
if os.path.isdir(multi_source_dir):
5385
multisource_benches = [
5486
MultiSourceBench(os.path.join(multi_source_dir, x))
@@ -67,26 +99,19 @@ def get_run_funcs(filepath):
6799
matches = re.findall(r'func run_(.*?)\(', content)
68100
return filter(lambda x: x not in ignored_run_funcs, matches)
69101

70-
def find_run_funcs(dirs):
71-
ret_run_funcs = []
72-
for d in dirs:
73-
for root, _, files in os.walk(d):
74-
for name in filter(lambda x: x.endswith('.swift'), files):
75-
run_funcs = get_run_funcs(os.path.join(root, name))
76-
ret_run_funcs.extend(run_funcs)
77-
return ret_run_funcs
78-
run_funcs = sorted(
79-
[(x, x)
80-
for x in find_run_funcs([single_source_dir, multi_source_dir])],
81-
key=lambda x: x[0]
82-
)
102+
def find_run_funcs():
103+
swift_files = all_files(perf_dir, '.swift')
104+
return [func for f in swift_files for func in get_run_funcs(f)]
105+
106+
run_funcs = [(f, f) for f in sorted(find_run_funcs())]
83107

84108
# Replace originals with files generated from templates
85109
for template_file in template_map:
86110
template_path = os.path.join(script_dir, template_file)
87111
template = template_env.get_template(template_path)
88-
print(template_map[template_file])
89-
open(template_map[template_file], 'w').write(
112+
out_file = template_map[template_file]
113+
will_write(out_file)
114+
open(out_file, 'w').write(
90115
template.render(tests=tests,
91116
multisource_benches=multisource_benches,
92117
imports=imports,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
# This script is invoked by `lit` on all smoke test runs from the
3+
# validation-test/benchmark/generate-harness.test-sh.
4+
# It ensures that the files checked in the benchmark suite that are generated
5+
# from templates always match what would be regenerated if one
6+
# re-ran the relevant scripts. This is to catch accidental manual edits.
7+
8+
SWIFT_SRC_DIR="$1"
9+
BENCHMARK_DIR="${SWIFT_SRC_DIR}/benchmark"
10+
SCRIPT_DIR="${BENCHMARK_DIR}/scripts"
11+
TEMP_DIR="$2"
12+
13+
"${SCRIPT_DIR}/generate_harness/generate_harness.py" "--output-dir=${TEMP_DIR}"
14+
for f in $(cd "${TEMP_DIR}" && find ./ -type f); do
15+
diff "${TEMP_DIR}/${f}" "${BENCHMARK_DIR}/${f}"
16+
if [[ $? -ne 0 ]]; then
17+
exit 1
18+
fi
19+
done

benchmark/single-source/CString.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- CString.swift -------------------------------------------------===//
1+
//===--- CString.swift ----------------------------------------------------===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
+193
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
//===--- DropFirst.swift --------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 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+
////////////////////////////////////////////////////////////////////////////////
14+
// WARNING: This file is manually generated from .gyb template and should not
15+
// be directly modified. Instead, make changes to DropFirst.swift.gyb and run
16+
// scripts/generate_harness/generate_harness.py to regenerate this file.
17+
////////////////////////////////////////////////////////////////////////////////
18+
19+
import TestsUtils
20+
21+
let sequenceCount = 4096
22+
let dropCount = 1024
23+
let suffixCount = sequenceCount - dropCount
24+
let sumCount = suffixCount * (2 * sequenceCount - suffixCount - 1) / 2
25+
26+
@inline(never)
27+
public func run_DropFirstCountableRange(_ N: Int) {
28+
let s = 0..<sequenceCount
29+
for _ in 1...20*N {
30+
var result = 0
31+
for element in s.dropFirst(dropCount) {
32+
result += element
33+
}
34+
CheckResults(result == sumCount,
35+
"IncorrectResults in DropFirstCountableRange: \(result) != \(sumCount)")
36+
}
37+
}
38+
@inline(never)
39+
public func run_DropFirstSequence(_ N: Int) {
40+
let s = sequence(first: 0) { $0 < sequenceCount - 1 ? $0 &+ 1 : nil }
41+
for _ in 1...20*N {
42+
var result = 0
43+
for element in s.dropFirst(dropCount) {
44+
result += element
45+
}
46+
CheckResults(result == sumCount,
47+
"IncorrectResults in DropFirstSequence: \(result) != \(sumCount)")
48+
}
49+
}
50+
@inline(never)
51+
public func run_DropFirstAnySequence(_ N: Int) {
52+
let s = AnySequence(sequence(first: 0) { $0 < sequenceCount - 1 ? $0 &+ 1 : nil })
53+
for _ in 1...20*N {
54+
var result = 0
55+
for element in s.dropFirst(dropCount) {
56+
result += element
57+
}
58+
CheckResults(result == sumCount,
59+
"IncorrectResults in DropFirstAnySequence: \(result) != \(sumCount)")
60+
}
61+
}
62+
@inline(never)
63+
public func run_DropFirstAnySeqCntRange(_ N: Int) {
64+
let s = AnySequence(0..<sequenceCount)
65+
for _ in 1...20*N {
66+
var result = 0
67+
for element in s.dropFirst(dropCount) {
68+
result += element
69+
}
70+
CheckResults(result == sumCount,
71+
"IncorrectResults in DropFirstAnySeqCntRange: \(result) != \(sumCount)")
72+
}
73+
}
74+
@inline(never)
75+
public func run_DropFirstAnySeqCRangeIter(_ N: Int) {
76+
let s = AnySequence((0..<sequenceCount).makeIterator())
77+
for _ in 1...20*N {
78+
var result = 0
79+
for element in s.dropFirst(dropCount) {
80+
result += element
81+
}
82+
CheckResults(result == sumCount,
83+
"IncorrectResults in DropFirstAnySeqCRangeIter: \(result) != \(sumCount)")
84+
}
85+
}
86+
@inline(never)
87+
public func run_DropFirstAnyCollection(_ N: Int) {
88+
let s = AnyCollection(0..<sequenceCount)
89+
for _ in 1...20*N {
90+
var result = 0
91+
for element in s.dropFirst(dropCount) {
92+
result += element
93+
}
94+
CheckResults(result == sumCount,
95+
"IncorrectResults in DropFirstAnyCollection: \(result) != \(sumCount)")
96+
}
97+
}
98+
@inline(never)
99+
public func run_DropFirstArray(_ N: Int) {
100+
let s = Array(0..<sequenceCount)
101+
for _ in 1...20*N {
102+
var result = 0
103+
for element in s.dropFirst(dropCount) {
104+
result += element
105+
}
106+
CheckResults(result == sumCount,
107+
"IncorrectResults in DropFirstArray: \(result) != \(sumCount)")
108+
}
109+
}
110+
@inline(never)
111+
public func run_DropFirstCountableRangeLazy(_ N: Int) {
112+
let s = (0..<sequenceCount).lazy
113+
for _ in 1...20*N {
114+
var result = 0
115+
for element in s.dropFirst(dropCount) {
116+
result += element
117+
}
118+
CheckResults(result == sumCount,
119+
"IncorrectResults in DropFirstCountableRangeLazy: \(result) != \(sumCount)")
120+
}
121+
}
122+
@inline(never)
123+
public func run_DropFirstSequenceLazy(_ N: Int) {
124+
let s = (sequence(first: 0) { $0 < sequenceCount - 1 ? $0 &+ 1 : nil }).lazy
125+
for _ in 1...20*N {
126+
var result = 0
127+
for element in s.dropFirst(dropCount) {
128+
result += element
129+
}
130+
CheckResults(result == sumCount,
131+
"IncorrectResults in DropFirstSequenceLazy: \(result) != \(sumCount)")
132+
}
133+
}
134+
@inline(never)
135+
public func run_DropFirstAnySequenceLazy(_ N: Int) {
136+
let s = (AnySequence(sequence(first: 0) { $0 < sequenceCount - 1 ? $0 &+ 1 : nil })).lazy
137+
for _ in 1...20*N {
138+
var result = 0
139+
for element in s.dropFirst(dropCount) {
140+
result += element
141+
}
142+
CheckResults(result == sumCount,
143+
"IncorrectResults in DropFirstAnySequenceLazy: \(result) != \(sumCount)")
144+
}
145+
}
146+
@inline(never)
147+
public func run_DropFirstAnySeqCntRangeLazy(_ N: Int) {
148+
let s = (AnySequence(0..<sequenceCount)).lazy
149+
for _ in 1...20*N {
150+
var result = 0
151+
for element in s.dropFirst(dropCount) {
152+
result += element
153+
}
154+
CheckResults(result == sumCount,
155+
"IncorrectResults in DropFirstAnySeqCntRangeLazy: \(result) != \(sumCount)")
156+
}
157+
}
158+
@inline(never)
159+
public func run_DropFirstAnySeqCRangeIterLazy(_ N: Int) {
160+
let s = (AnySequence((0..<sequenceCount).makeIterator())).lazy
161+
for _ in 1...20*N {
162+
var result = 0
163+
for element in s.dropFirst(dropCount) {
164+
result += element
165+
}
166+
CheckResults(result == sumCount,
167+
"IncorrectResults in DropFirstAnySeqCRangeIterLazy: \(result) != \(sumCount)")
168+
}
169+
}
170+
@inline(never)
171+
public func run_DropFirstAnyCollectionLazy(_ N: Int) {
172+
let s = (AnyCollection(0..<sequenceCount)).lazy
173+
for _ in 1...20*N {
174+
var result = 0
175+
for element in s.dropFirst(dropCount) {
176+
result += element
177+
}
178+
CheckResults(result == sumCount,
179+
"IncorrectResults in DropFirstAnyCollectionLazy: \(result) != \(sumCount)")
180+
}
181+
}
182+
@inline(never)
183+
public func run_DropFirstArrayLazy(_ N: Int) {
184+
let s = (Array(0..<sequenceCount)).lazy
185+
for _ in 1...20*N {
186+
var result = 0
187+
for element in s.dropFirst(dropCount) {
188+
result += element
189+
}
190+
CheckResults(result == sumCount,
191+
"IncorrectResults in DropFirstArrayLazy: \(result) != \(sumCount)")
192+
}
193+
}

0 commit comments

Comments
 (0)