Skip to content

Commit 77a8b1b

Browse files
Merge pull request swiftlang#209 from swiftwasm/master
[pull] swiftwasm from master
2 parents 4e01560 + b1fc252 commit 77a8b1b

File tree

206 files changed

+5131
-3727
lines changed

Some content is hidden

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

206 files changed

+5131
-3727
lines changed

benchmark/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ set(SWIFT_BENCH_MODULES
6262
single-source/Combos
6363
single-source/DataBenchmarks
6464
single-source/DeadArray
65+
single-source/DevirtualizeProtocolComposition
6566
single-source/DictOfArraysToArrayOfDicts
6667
single-source/DictTest
6768
single-source/DictTest2
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//===--- DevirtualizeProtocolComposition.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 DevirtualizeProtocolComposition = [
16+
BenchmarkInfo(name: "DevirtualizeProtocolComposition", runFunction: run_DevirtualizeProtocolComposition, tags: [.validation, .api]),
17+
]
18+
19+
protocol Pingable { func ping() -> Int; func pong() -> Int}
20+
21+
public class Game<T> {
22+
func length() -> Int { return 10 }
23+
}
24+
25+
public class PingPong: Game<String> { }
26+
27+
extension PingPong : Pingable {
28+
func ping() -> Int { return 1 }
29+
func pong() -> Int { return 2 }
30+
}
31+
32+
func playGame<T>(_ x: Game<T> & Pingable) -> Int {
33+
var sum = 0
34+
for _ in 0..<x.length() {
35+
sum += x.ping() + x.pong()
36+
}
37+
return sum
38+
}
39+
40+
@inline(never)
41+
public func run_DevirtualizeProtocolComposition(N: Int) {
42+
for _ in 0..<N * 20_000 {
43+
blackHole(playGame(PingPong()))
44+
}
45+
}

benchmark/utils/main.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import Codable
5050
import Combos
5151
import DataBenchmarks
5252
import DeadArray
53+
import DevirtualizeProtocolComposition
5354
import DictOfArraysToArrayOfDicts
5455
import DictTest
5556
import DictTest2
@@ -231,6 +232,7 @@ registerBenchmark(Combos)
231232
registerBenchmark(ClassArrayGetter)
232233
registerBenchmark(DataBenchmarks)
233234
registerBenchmark(DeadArray)
235+
registerBenchmark(DevirtualizeProtocolComposition)
234236
registerBenchmark(DictOfArraysToArrayOfDicts)
235237
registerBenchmark(Dictionary)
236238
registerBenchmark(Dictionary2)

docs/OptimizationTips.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,38 @@ protocols as class-only protocols to get better runtime performance.
544544

545545
.. https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Protocols.html
546546
547+
The Cost of Let/Var when Captured by Escaping Closures
548+
======================================================
549+
550+
While one may think that the distinction in between let/var is just
551+
about language semantics, there are also performance
552+
considerations. Remember that any time one creates a binding for a
553+
closure, one is forcing the compiler to emit an escaping closure,
554+
e.x.:
555+
556+
::
557+
558+
let f: () -> () = { ... } // Escaping closure
559+
// Contrasted with:
560+
({ ... })() // Non Escaping closure
561+
x.map { ... } // Non Escaping closure
562+
563+
When a var is captured by an escaping closure, the compiler must
564+
allocate a heap box to store the var so that both the closure
565+
creator/closure can read/write to the value. This even includes
566+
situations where the underlying type of the captured binding is
567+
trivial! In contrast, when captured a `let` is captured by value. As
568+
such, the compiler stores a copy of the value directly into the
569+
closure's storage without needing a box.
570+
571+
Advice: Pass var as an `inout` if closure not actually escaping
572+
---------------------------------------------------------------
573+
574+
If one is using an escaping closure for expressivity purposes, but is
575+
actually using a closure locally, pass vars as inout parameters
576+
instead of by using captures. The inout will ensure that a heap box is
577+
not allocated for the variables and avoid any retain/release traffic
578+
from the heap box being passed around.
547579

548580
Unsupported Optimization Attributes
549581
===================================

docs/TypeChecker.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,4 +985,3 @@ The things in the queue yet to be ported are:
985985

986986
- Missing explicit ``Self.`` and ``self.``
987987
- Logic related to overload candidate ranking (``CalleeCandidateInfo``)
988-
- ``diagnoseParameterErrors``

include/swift/AST/DiagnosticsSIL.def

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -447,12 +447,12 @@ ERROR(constexpr_imported_func_not_onone, none, "imported constant evaluable "
447447

448448
ERROR(non_physical_addressof,none,
449449
"addressof only works with purely physical lvalues; "
450-
"use `withUnsafePointer` or `withUnsafeBytes` unless you're implementing "
451-
"`withUnsafePointer` or `withUnsafeBytes`", ())
450+
"use 'withUnsafePointer' or 'withUnsafeBytes' unless you're implementing "
451+
"'withUnsafePointer' or 'withUnsafeBytes'", ())
452452
ERROR(non_borrowed_indirect_addressof,none,
453453
"addressof only works with borrowable in-memory rvalues; "
454-
"use `withUnsafePointer` or `withUnsafeBytes` unless you're implementing "
455-
"`withUnsafePointer` or `withUnsafeBytes`", ())
454+
"use 'withUnsafePointer' or 'withUnsafeBytes' unless you're implementing "
455+
"'withUnsafePointer' or 'withUnsafeBytes'", ())
456456

457457
REMARK(opt_remark_passed, none, "%0", (StringRef))
458458
REMARK(opt_remark_missed, none, "%0", (StringRef))

include/swift/AST/DiagnosticsSema.def

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,9 @@ ERROR(argument_out_of_order_unnamed_named,none,
11331133
ERROR(argument_out_of_order_unnamed_unnamed,none,
11341134
"unnamed argument #%0 must precede unnamed argument #%1",
11351135
(unsigned, unsigned))
1136+
ERROR(argument_out_of_order_binary_op,none,
1137+
"operator argument #%0 must precede operator argument #%1",
1138+
(unsigned, unsigned))
11361139
NOTE(candidate_expected_different_labels,none,
11371140
"incorrect labels for candidate (have: '%0', expected: '%1')",
11381141
(StringRef, StringRef))
@@ -4843,10 +4846,10 @@ ERROR(property_wrapper_type_not_usable_from_inline,none,
48434846
"must be '@usableFromInline' or public",
48444847
(bool, bool))
48454848
WARNING(property_wrapper_wrapperValue,none,
4846-
"property wrapper's `wrapperValue` property should be renamed to "
4849+
"property wrapper's 'wrapperValue' property should be renamed to "
48474850
"'projectedValue'; use of 'wrapperValue' is deprecated", ())
48484851
WARNING(property_wrapper_init_initialValue,none,
4849-
"property wrapper's `init(initialValue:)` should be renamed "
4852+
"property wrapper's 'init(initialValue:)' should be renamed "
48504853
"to 'init(wrappedValue:)'; use of 'init(initialValue:)' is deprecated",
48514854
())
48524855
ERROR(property_wrapper_projection_value_missing,none,

include/swift/AST/IRGenOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ class IRGenOptions {
262262
EnableAnonymousContextMangledNames(false), ForcePublicLinkage(false),
263263
LazyInitializeClassMetadata(false),
264264
LazyInitializeProtocolConformances(false), DisableLegacyTypeInfo(false),
265-
PrespecializeGenericMetadata(true), UseIncrementalLLVMCodeGen(true),
265+
PrespecializeGenericMetadata(false), UseIncrementalLLVMCodeGen(true),
266266
UseSwiftCall(false), GenerateProfile(false),
267267
EnableDynamicReplacementChaining(false),
268268
DisableRoundTripDebugTypes(false), DisableDebuggerShadowCopies(false),

include/swift/AST/SourceFile.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,6 @@ class SourceFile final : public FileUnit {
257257

258258
bool isImportedImplementationOnly(const ModuleDecl *module) const;
259259

260-
/// This is a hack for 'main' file parsing and the integrated REPL.
261-
///
262-
/// FIXME: Refactor main file parsing to not pump the parser incrementally.
263-
/// FIXME: Remove the integrated REPL.
264-
void clearLookupCache();
265-
266260
void cacheVisibleDecls(SmallVectorImpl<ValueDecl *> &&globals) const;
267261
const SmallVectorImpl<ValueDecl *> &getCachedVisibleDecls() const;
268262

include/swift/AST/Types.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2780,7 +2780,8 @@ class AnyFunctionType : public TypeBase {
27802780
Identifier l = Identifier(),
27812781
ParameterTypeFlags f = ParameterTypeFlags())
27822782
: Ty(t), Label(l), Flags(f) {
2783-
assert(!t || !t->is<InOutType>() && "set flags instead");
2783+
assert(t && "param type must be non-null");
2784+
assert(!t->is<InOutType>() && "set flags instead");
27842785
}
27852786

27862787
private:

0 commit comments

Comments
 (0)