Skip to content

Commit 0089ad4

Browse files
authored
Merge pull request #6 from apple/master
merge
2 parents 7fb16b8 + e43ff71 commit 0089ad4

File tree

514 files changed

+11442
-7867
lines changed

Some content is hidden

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

514 files changed

+11442
-7867
lines changed

CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,12 @@ set(CLANG_COMPILER_VERSION "" CACHE STRING
129129
"The internal version of the Clang compiler")
130130

131131
# Indicate whether Swift should attempt to use the lld linker.
132-
set(SWIFT_ENABLE_LLD_LINKER FALSE CACHE BOOL
132+
set(SWIFT_ENABLE_LLD_LINKER TRUE CACHE BOOL
133133
"Enable using the lld linker when available")
134134

135135
# Indicate whether Swift should attempt to use the gold linker.
136136
# This is not used on Darwin.
137-
set(SWIFT_ENABLE_GOLD_LINKER FALSE CACHE BOOL
137+
set(SWIFT_ENABLE_GOLD_LINKER TRUE CACHE BOOL
138138
"Enable using the gold linker when available")
139139

140140
set(SWIFT_SDKS "" CACHE STRING
@@ -300,6 +300,10 @@ option(SWIFT_ENABLE_GUARANTEED_NORMAL_ARGUMENTS
300300
"Build the standard libraries, overlays, and runtime with normal arguments at +0"
301301
FALSE)
302302

303+
option(SWIFT_ENABLE_RUNTIME_FUNCTION_COUNTERS
304+
"Enable runtime function counters and expose the API."
305+
FALSE)
306+
303307
#
304308
# End of user-configurable options.
305309
#

benchmark/scripts/Benchmark_RuntimeLeaksRunner.in

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,29 +81,35 @@ class LeaksRunnerBenchmarkDriver(perf_test_driver.BenchmarkDriver):
8181
def prepare_input(self, name):
8282
return {'num_samples': self.num_samples, 'num_iters': self.num_iters}
8383

84+
def run_test_inner(self, data, num_iters):
85+
p = subprocess.Popen([
86+
data['path'],
87+
"--num-samples={}".format(data['num_samples']),
88+
"--num-iters={}".format(num_iters), data['test_name']],
89+
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
90+
error_out = p.communicate()[1].split("\n")
91+
result = p.returncode
92+
if result is None:
93+
raise RuntimeError("Expected one line of output")
94+
if result != 0:
95+
raise RuntimeError("Process segfaulted")
96+
return error_out
97+
8498
def run_test(self, data, num_iters):
8599
try:
86-
p = subprocess.Popen([
87-
data['path'],
88-
"--num-samples={}".format(data['num_samples']),
89-
"--num-iters={}".format(num_iters), data['test_name']],
90-
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
91-
error_out = p.communicate()[1].split("\n")
92-
result = p.returncode
93-
if result is None:
94-
raise RuntimeError("Expected one line of output")
95-
if result != 0:
96-
raise RuntimeError("Process segfaulted")
97-
except Exception:
98-
sys.stderr.write("Child Process Failed! (%s,%s)\n" % (
99-
data['path'], data['test_name']))
100+
args = [data, num_iters]
101+
result = perf_test_driver.run_with_timeout(self.run_test_inner,
102+
args)
103+
except Exception, e:
104+
sys.stderr.write("Child Process Failed! (%s,%s). Error: %s\n" % (
105+
data['path'], data['test_name'], e))
100106
sys.stderr.flush()
101107
return None
102108

103109
try:
104110
# We grab the second line since swift globals get lazily created in
105111
# the first iteration.
106-
d = json.loads(error_out[1])
112+
d = json.loads(result[1])
107113
d['objc_objects'] = [x for x in d['objc_objects']
108114
if x not in IGNORABLE_GLOBAL_OBJC_CLASSES]
109115
d['objc_count'] = len(d['objc_objects'])

benchmark/scripts/perf_test_driver/perf_test_driver.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,24 @@ def print_data(self, max_test_len):
5757
print(fmt.format(self.get_name(), self.get_result()))
5858

5959

60+
def run_with_timeout(func, args):
61+
# We timeout after 10 minutes.
62+
timeout_seconds = 10 * 60
63+
64+
# We just use this to create a timeout since we use an older python. Once
65+
# we update to use python >= 3.3, use the timeout API on communicate
66+
# instead.
67+
import multiprocessing.dummy
68+
fakeThreadPool = multiprocessing.dummy.Pool(1)
69+
try:
70+
result = fakeThreadPool.apply_async(func, args=args)
71+
return result.get(timeout_seconds)
72+
except multiprocessing.TimeoutError:
73+
fakeThreadPool.terminate()
74+
raise RuntimeError("Child process aborted due to timeout. "
75+
"Timeout: %s seconds" % timeout_seconds)
76+
77+
6078
def _unwrap_self(args):
6179
return type(args[0]).process_input(*args)
6280

benchmark/single-source/Combos.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public func run_Combos(_ N: Int) {
1818
var combos = [[Character]]()
1919

2020
for _ in 1...10*N {
21-
combos = combinations("ABCDEFGHIJ".characters, "0123456789".characters).map {
21+
combos = combinations("ABCDEFGHIJ", "0123456789").map {
2222
return [$0] + [$1]
2323
}
2424

benchmark/single-source/LuhnAlgoEager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ let combineDoubleDigits = {
220220
// removing lazy at start of pipeline
221221
// switches to array-based version
222222
let eagerchecksum = { (ccnum: String) -> Bool in
223-
ccnum.characters//.lazy
223+
ccnum //.lazy
224224
|> { $0.reversed().lazy }
225225
|> { mapSome($0, charToInt) }
226226
|> { mapEveryN($0, 2, double) }

benchmark/single-source/LuhnAlgoLazy.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ let combineDoubleDigits = {
219219

220220
// first, the lazy version of checksum calcuation
221221
let lazychecksum = { (ccnum: String) -> Bool in
222-
ccnum.characters.lazy
222+
ccnum.lazy
223223
|> reverse
224224
|> { mapSome($0, charToInt) }
225225
|> { mapEveryN($0, 2, double) }

benchmark/single-source/NibbleSort.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ struct NibbleCollection: RandomAccessCollection, MutableCollection {
3838
let startIndex: UInt64 = 0
3939
let endIndex: UInt64 = 16
4040

41-
subscript(bounds: Range<Index>)
42-
-> MutableRandomAccessSlice<NibbleCollection> {
41+
subscript(bounds: Range<Index>) -> Slice<NibbleCollection> {
4342
get {
4443
fatalError("Should not be called. Added here to please the type checker")
4544
}

benchmark/single-source/StringRemoveDupes.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ public func run_StringRemoveDupes(_ N: Int) {
2424
for _ in 1...10*N {
2525
s = text.removeDuplicates()
2626

27-
if s.characters.count != textLengthRef {
27+
if s.count != textLengthRef {
2828
break
2929
}
3030
}
3131

32-
CheckResults(s.characters.count == textLengthRef)
32+
CheckResults(s.count == textLengthRef)
3333
}
3434

3535
// removes all but first occurrence from a sequence, returning an array.
@@ -46,6 +46,6 @@ func uniq<S: Sequence,
4646
// all duplicates removed
4747
extension String {
4848
func removeDuplicates() -> String {
49-
return String(uniq(self.characters))
49+
return String(uniq(self))
5050
}
5151
}

cmake/modules/AddSwift.cmake

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,10 @@ function(_add_variant_c_compile_flags)
255255
else()
256256
list(APPEND result "-DNDEBUG")
257257
endif()
258+
259+
if(SWIFT_ENABLE_RUNTIME_FUNCTION_COUNTERS)
260+
list(APPEND result "-DSWIFT_ENABLE_RUNTIME_FUNCTION_COUNTERS")
261+
endif()
258262

259263
if(CFLAGS_ANALYZE_CODE_COVERAGE)
260264
list(APPEND result "-fprofile-instr-generate"
@@ -316,6 +320,10 @@ function(_add_variant_swift_compile_flags
316320
if (SWIFT_ENABLE_GUARANTEED_NORMAL_ARGUMENTS)
317321
list(APPEND result "-Xfrontend" "-enable-guaranteed-normal-arguments")
318322
endif()
323+
324+
if(SWIFT_ENABLE_RUNTIME_FUNCTION_COUNTERS)
325+
list(APPEND result "-D" "SWIFT_ENABLE_RUNTIME_FUNCTION_COUNTERS")
326+
endif()
319327

320328
set("${result_var_name}" "${result}" PARENT_SCOPE)
321329
endfunction()
@@ -396,14 +404,15 @@ function(_add_variant_link_flags)
396404
endif()
397405

398406
if(NOT SWIFT_COMPILER_IS_MSVC_LIKE)
399-
if(SWIFT_ENABLE_GOLD_LINKER AND
400-
"${SWIFT_SDK_${LFLAGS_SDK}_OBJECT_FORMAT}" STREQUAL "ELF")
401-
list(APPEND result "-fuse-ld=gold")
402-
endif()
403-
if(SWIFT_ENABLE_LLD_LINKER OR
407+
find_program(LDLLD_PATH "ld.lld")
408+
# Strangely, macOS finds lld and then can't find it when using -fuse-ld=
409+
if((SWIFT_ENABLE_LLD_LINKER AND LDLLD_PATH AND NOT APPLE) OR
404410
("${LFLAGS_SDK}" STREQUAL "WINDOWS" AND
405411
NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "WINDOWS"))
406412
list(APPEND result "-fuse-ld=lld")
413+
elseif(SWIFT_ENABLE_GOLD_LINKER AND
414+
"${SWIFT_SDK_${LFLAGS_SDK}_OBJECT_FORMAT}" STREQUAL "ELF")
415+
list(APPEND result "-fuse-ld=gold")
407416
endif()
408417
endif()
409418

@@ -1692,12 +1701,14 @@ function(add_swift_library name)
16921701
set(codesign_arg CODESIGN)
16931702
endif()
16941703
precondition(THIN_INPUT_TARGETS)
1695-
_add_swift_lipo_target(
1696-
SDK ${sdk}
1697-
TARGET ${lipo_target}
1698-
OUTPUT ${UNIVERSAL_LIBRARY_NAME}
1699-
${codesign_arg}
1700-
${THIN_INPUT_TARGETS})
1704+
_add_swift_lipo_target(SDK
1705+
${sdk}
1706+
TARGET
1707+
${lipo_target}
1708+
OUTPUT
1709+
${UNIVERSAL_LIBRARY_NAME}
1710+
${codesign_arg}
1711+
${THIN_INPUT_TARGETS})
17011712

17021713
# Cache universal libraries for dependency purposes
17031714
set(UNIVERSAL_LIBRARY_NAMES_${SWIFT_SDK_${sdk}_LIB_SUBDIR}
@@ -1743,11 +1754,13 @@ function(add_swift_library name)
17431754
"${name}-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-static")
17441755
set(UNIVERSAL_LIBRARY_NAME
17451756
"${SWIFTSTATICLIB_DIR}/${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${name}${CMAKE_STATIC_LIBRARY_SUFFIX}")
1746-
_add_swift_lipo_target(
1747-
SDK ${sdk}
1748-
TARGET ${lipo_target_static}
1749-
OUTPUT "${UNIVERSAL_LIBRARY_NAME}"
1750-
${THIN_INPUT_TARGETS_STATIC})
1757+
_add_swift_lipo_target(SDK
1758+
${sdk}
1759+
TARGET
1760+
${lipo_target_static}
1761+
OUTPUT
1762+
"${UNIVERSAL_LIBRARY_NAME}"
1763+
${THIN_INPUT_TARGETS_STATIC})
17511764
swift_install_in_component("${SWIFTLIB_INSTALL_IN_COMPONENT}"
17521765
FILES "${UNIVERSAL_LIBRARY_NAME}"
17531766
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift_static/${resource_dir_sdk_subdir}"
@@ -1760,14 +1773,18 @@ function(add_swift_library name)
17601773
# Add Swift standard library targets as dependencies to the top-level
17611774
# convenience target.
17621775
if(SWIFTLIB_TARGET_LIBRARY)
1776+
set(FILTERED_UNITTESTS
1777+
swiftStdlibCollectionUnittest
1778+
swiftStdlibUnicodeUnittest)
1779+
17631780
foreach(arch ${SWIFT_SDK_${sdk}_ARCHITECTURES})
17641781
set(VARIANT_SUFFIX "-${SWIFT_SDK_${sdk}_LIB_SUBDIR}-${arch}")
1765-
if(TARGET "swift-stdlib${VARIANT_SUFFIX}" AND TARGET "swift-test-stdlib${VARIANT_SUFFIX}")
1782+
if(TARGET "swift-stdlib${VARIANT_SUFFIX}" AND
1783+
TARGET "swift-test-stdlib${VARIANT_SUFFIX}")
17661784
add_dependencies("swift-stdlib${VARIANT_SUFFIX}"
17671785
${lipo_target}
17681786
${lipo_target_static})
1769-
if((NOT "${name}" STREQUAL "swiftStdlibCollectionUnittest") AND
1770-
(NOT "${name}" STREQUAL "swiftStdlibUnicodeUnittest"))
1787+
if(NOT "${name}" IN_LIST FILTERED_UNITTESTS)
17711788
add_dependencies("swift-test-stdlib${VARIANT_SUFFIX}"
17721789
${lipo_target}
17731790
${lipo_target_static})

cmake/modules/AddSwiftUnittests.cmake

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,16 @@ function(add_swift_unittest test_dirname)
4747
LINK_FLAGS " -latomic")
4848
endif()
4949

50-
if(SWIFT_ENABLE_GOLD_LINKER AND
50+
find_program(LDLLD_PATH "ld.lld")
51+
# Strangely, macOS finds lld and then can't find it when using -fuse-ld=
52+
if(SWIFT_ENABLE_LLD_LINKER AND LDLLD_PATH AND NOT APPLE)
53+
set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY
54+
LINK_FLAGS " -fuse-ld=lld")
55+
elseif(SWIFT_ENABLE_GOLD_LINKER AND
5156
"${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_OBJECT_FORMAT}" STREQUAL "ELF")
5257
set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY
5358
LINK_FLAGS " -fuse-ld=gold")
5459
endif()
55-
if(SWIFT_ENABLE_LLD_LINKER)
56-
set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY
57-
LINK_FLAGS " -fuse-ld=lld")
58-
endif()
5960

6061
if(SWIFT_ANALYZE_CODE_COVERAGE)
6162
set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY

0 commit comments

Comments
 (0)