Skip to content

Commit 2ba4516

Browse files
Resolving conflict with master
2 parents a90789b + 09847e6 commit 2ba4516

File tree

211 files changed

+1467
-593
lines changed

Some content is hidden

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

211 files changed

+1467
-593
lines changed

CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,6 @@ option(SWIFT_STDLIB_USE_NONATOMIC_RC
327327
"Build the standard libraries and overlays with nonatomic reference count operations enabled"
328328
FALSE)
329329

330-
option(SWIFT_STDLIB_ENABLE_SIL_OWNERSHIP
331-
"Build the standard libraries and overlays with sil ownership enabled."
332-
FALSE)
333-
334330
option(SWIFT_ENABLE_RUNTIME_FUNCTION_COUNTERS
335331
"Enable runtime function counters and expose the API."
336332
FALSE)

benchmark/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ set(SWIFT_BENCH_MODULES
134134
single-source/RandomValues
135135
single-source/RangeAssignment
136136
single-source/RangeIteration
137+
single-source/RangeOverlaps
137138
single-source/RangeReplaceableCollectionPlusDefault
138139
single-source/RecursiveOwnedParameter
139140
single-source/ReduceInto

benchmark/cmake/modules/AddSwiftBenchmarkSuite.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ function (swift_benchmark_compile_archopts)
314314

315315
set(common_options
316316
"-c"
317+
"-Xfrontend" "-verify-sil-ownership"
317318
"-target" "${target}"
318319
"-${BENCH_COMPILE_ARCHOPTS_OPT}" ${PAGE_ALIGNMENT_OPTION})
319320

@@ -343,6 +344,7 @@ function (swift_benchmark_compile_archopts)
343344

344345
set(common_options_driver
345346
"-c"
347+
"-Xfrontend" "-verify-sil-ownership"
346348
"-target" "${target}"
347349
"-${driver_opt}")
348350

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
//===--- RangeOverlaps.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 RangeOverlaps = [
16+
BenchmarkInfo(
17+
name: "RangeOverlapsRange",
18+
runFunction: run_RangeOverlapsRange,
19+
tags: [.validation, .api],
20+
setUpFunction: buildRanges),
21+
BenchmarkInfo(
22+
name: "RangeOverlapsClosedRange",
23+
runFunction: run_RangeOverlapsClosedRange,
24+
tags: [.validation, .api],
25+
setUpFunction: buildRanges),
26+
BenchmarkInfo(
27+
name: "ClosedRangeOverlapsClosedRange",
28+
runFunction: run_ClosedRangeOverlapsClosedRange,
29+
tags: [.validation, .api],
30+
setUpFunction: buildRanges)
31+
]
32+
33+
private func buildRanges() {
34+
blackHole(ranges)
35+
blackHole(closedRanges)
36+
}
37+
38+
private let ranges: [Range<Int>] = (-8...8).flatMap { a in (0...16).map { l in a..<(a+l) } }
39+
private let closedRanges: [ClosedRange<Int>] = (-8...8).flatMap { a in (0...16).map { l in a...(a+l) } }
40+
41+
@inline(never)
42+
public func run_RangeOverlapsRange(_ N: Int) {
43+
var check: UInt64 = 0
44+
for _ in 0..<N {
45+
for lhs in ranges {
46+
for rhs in ranges {
47+
if lhs.overlaps(rhs) { check += 1 }
48+
}
49+
}
50+
}
51+
CheckResults(check == 47872 * UInt64(N))
52+
}
53+
54+
@inline(never)
55+
public func run_RangeOverlapsClosedRange(_ N: Int) {
56+
var check: UInt64 = 0
57+
for _ in 0..<N {
58+
for lhs in ranges {
59+
for rhs in closedRanges {
60+
if lhs.overlaps(rhs) { check += 1 }
61+
}
62+
}
63+
}
64+
CheckResults(check == 51680 * UInt64(N))
65+
}
66+
67+
@inline(never)
68+
public func run_ClosedRangeOverlapsClosedRange(_ N: Int) {
69+
var check: UInt64 = 0
70+
for _ in 0..<N {
71+
for lhs in closedRanges {
72+
for rhs in closedRanges {
73+
if lhs.overlaps(rhs) { check += 1 }
74+
}
75+
}
76+
}
77+
CheckResults(check == 55777 * UInt64(N))
78+
}

benchmark/utils/main.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ import RandomShuffle
127127
import RandomValues
128128
import RangeAssignment
129129
import RangeIteration
130+
import RangeOverlaps
130131
import RangeReplaceableCollectionPlusDefault
131132
import RecursiveOwnedParameter
132133
import ReduceInto
@@ -298,6 +299,7 @@ registerBenchmark(RandomShuffle)
298299
registerBenchmark(RandomValues)
299300
registerBenchmark(RangeAssignment)
300301
registerBenchmark(RangeIteration)
302+
registerBenchmark(RangeOverlaps)
301303
registerBenchmark(RangeReplaceableCollectionPlusDefault)
302304
registerBenchmark(RecursiveOwnedParameter)
303305
registerBenchmark(ReduceInto)

cmake/modules/SwiftSharedCMakeConfig.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ macro(swift_common_standalone_build_config_llvm product)
6363
endif()
6464

6565
if(CMAKE_CROSSCOMPILING)
66-
set(LLVM_NATIVE_BUILD "${LLVM_BINARY_DIR}/NATIVE")
67-
if(NOT EXISTS "${LLVM_NATIVE_BUILD}")
66+
set(LLVM_NATIVE_BUILD_DIR "${LLVM_BINARY_DIR}/NATIVE")
67+
if(NOT EXISTS "${LLVM_NATIVE_BUILD_DIR}")
6868
message(FATAL_ERROR
6969
"Attempting to cross-compile swift standalone but no native LLVM build
7070
found. Please cross-compile LLVM as well.")

cmake/modules/SwiftSource.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ function(_compile_swift_files
236236
endif()
237237

238238
if(SWIFTFILE_IS_STDLIB)
239-
list(APPEND swift_flags "-Xfrontend" "-enable-sil-ownership")
239+
list(APPEND swift_flags "-Xfrontend" "-verify-sil-ownership")
240240
list(APPEND swift_flags "-Xfrontend" "-enable-mandatory-semantic-arc-opts")
241241
endif()
242242

docs/StandardLibraryProgrammersManual.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ Optionals can be unwrapped with `!`, which triggers a trap on nil. Alternatively
5353

5454
### Builtins
5555

56-
#### `_fastPath` and `_slowPath` (also, `_branchHint`)
56+
#### `_fastPath` and `_slowPath`
5757

5858
`_fastPath` returns its argument, wrapped in a Builtin.expect. This informs the optimizer that the vast majority of the time, the branch will be taken (i.e. the then branch is “hot”). The SIL optimizer may alter heuristics for anything dominated by the then branch. But the real performance impact comes from the fact that the SIL optimizer will consider anything dominated by the else branch to be infrequently executed (i.e. “cold”). This means that transformations that may increase code size have very conservative heuristics to keep the rarely executed code small.
5959

6060
The probabilities are passed through to LLVM as branch weight metadata, to leverage LLVM’s use of GCC style builtin_expect knowledge (e.g. for code layout and low-level inlining).
6161

6262
`_fastPath` probabilities are compounding, see the example below. For this reason, it can actually degrade performance in non-intuitive ways as it marks all other code (including subsequent `_fastPath`s) as being cold. Consider `_fastPath` as basically spraying the rest of the code with a Mr. Freeze-style ice gun.
6363

64-
`_slowPath` is the same as `_fastPath`, just with the branches swapped. Both are just wrappers around `_branchHint`, which is otherwise never called directly.
64+
`_slowPath` is the same as `_fastPath`, just with the branches swapped.
6565

6666
*Example:*
6767

@@ -84,8 +84,6 @@ if _fastPath(...) {
8484
return
8585
```
8686

87-
*NOTE: these are due for a rename and possibly a redesign. They conflate multiple notions that don’t match the average standard library programmer’s intuition.*
88-
8987

9088
#### `_onFastPath`
9189

include/swift/AST/Decl.h

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4552,6 +4552,8 @@ class AbstractStorageDecl : public ValueDecl {
45524552
/// True if any of the accessors to the storage is private or fileprivate.
45534553
bool hasPrivateAccessor() const;
45544554

4555+
bool hasDidSetOrWillSetDynamicReplacement() const;
4556+
45554557
// Implement isa/cast/dyncast/etc.
45564558
static bool classof(const Decl *D) {
45574559
return D->getKind() >= DeclKind::First_AbstractStorageDecl &&
@@ -4577,7 +4579,7 @@ class VarDecl : public AbstractStorageDecl {
45774579
};
45784580

45794581
protected:
4580-
llvm::PointerUnion<PatternBindingDecl*, Stmt*> ParentPattern;
4582+
PointerUnion3<PatternBindingDecl *, Stmt *, VarDecl *> Parent;
45814583

45824584
VarDecl(DeclKind Kind, bool IsStatic, Specifier Sp, bool IsCaptureList,
45834585
SourceLoc NameLoc, Identifier Name, DeclContext *DC)
@@ -4648,12 +4650,15 @@ class VarDecl : public AbstractStorageDecl {
46484650
/// Return the parent pattern binding that may provide an initializer for this
46494651
/// VarDecl. This returns null if there is none associated with the VarDecl.
46504652
PatternBindingDecl *getParentPatternBinding() const {
4651-
return ParentPattern.dyn_cast<PatternBindingDecl *>();
4653+
if (!Parent)
4654+
return nullptr;
4655+
return Parent.dyn_cast<PatternBindingDecl *>();
46524656
}
46534657
void setParentPatternBinding(PatternBindingDecl *PBD) {
4654-
ParentPattern = PBD;
4658+
assert(PBD);
4659+
Parent = PBD;
46554660
}
4656-
4661+
46574662
/// Return the Pattern involved in initializing this VarDecl. However, recall
46584663
/// that the Pattern may be involved in initializing more than just this one
46594664
/// vardecl. For example, if this is a VarDecl for "x", the pattern may be
@@ -4664,16 +4669,53 @@ class VarDecl : public AbstractStorageDecl {
46644669
/// returns null.
46654670
///
46664671
Pattern *getParentPattern() const;
4667-
4672+
46684673
/// Return the statement that owns the pattern associated with this VarDecl,
46694674
/// if one exists.
4675+
///
4676+
/// NOTE: After parsing and before type checking, all VarDecls from
4677+
/// CaseLabelItem's Patterns return their CaseStmt. After type checking, we
4678+
/// will have constructed the CaseLabelItem VarDecl linked list implying this
4679+
/// will return nullptr. After type checking, if one wishes to find a parent
4680+
/// pattern of a VarDecl of a CaseStmt, \see getRecursiveParentPatternStmt
4681+
/// instead.
46704682
Stmt *getParentPatternStmt() const {
4671-
return ParentPattern.dyn_cast<Stmt*>();
4683+
if (!Parent)
4684+
return nullptr;
4685+
return Parent.dyn_cast<Stmt *>();
46724686
}
4673-
void setParentPatternStmt(Stmt *S) {
4674-
ParentPattern = S;
4687+
4688+
void setParentPatternStmt(Stmt *s) {
4689+
assert(s);
4690+
Parent = s;
4691+
}
4692+
4693+
/// Look for the parent pattern stmt of this var decl, recursively
4694+
/// looking through var decl pointers and then through any
4695+
/// fallthroughts.
4696+
Stmt *getRecursiveParentPatternStmt() const;
4697+
4698+
/// Returns the var decl that this var decl is an implicit reference to if
4699+
/// such a var decl exists.
4700+
VarDecl *getParentVarDecl() const {
4701+
if (!Parent)
4702+
return nullptr;
4703+
return Parent.dyn_cast<VarDecl *>();
4704+
}
4705+
4706+
/// Set \p v to be the pattern produced VarDecl that is the parent of this
4707+
/// var decl.
4708+
void setParentVarDecl(VarDecl *v) {
4709+
assert(v);
4710+
Parent = v;
46754711
}
46764712

4713+
/// If this is a VarDecl that does not belong to a CaseLabelItem's pattern,
4714+
/// return this. Otherwise, this VarDecl must belong to a CaseStmt's
4715+
/// CaseLabelItem. In that case, return the first case label item of the first
4716+
/// case stmt in a sequence of case stmts that fallthrough into each other.
4717+
VarDecl *getCanonicalVarDecl() const;
4718+
46774719
/// True if the global stored property requires lazy initialization.
46784720
bool isLazilyInitializedGlobal() const;
46794721

include/swift/AST/SILOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class SILOptions {
112112
std::string SILOutputFileNameForDebugging;
113113

114114
/// If set to true, compile with the SIL Ownership Model enabled.
115-
bool EnableSILOwnership = false;
115+
bool VerifySILOwnership = false;
116116

117117
/// Assume that code will be executed in a single-threaded environment.
118118
bool AssumeSingleThreaded = false;

include/swift/Basic/LLVM.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ namespace llvm {
4343
template<typename T> class TinyPtrVector;
4444
template<typename T> class Optional;
4545
template <typename PT1, typename PT2> class PointerUnion;
46+
template <typename PT1, typename PT2, typename PT3> class PointerUnion3;
4647
class SmallBitVector;
4748

4849
// Other common classes.
@@ -62,22 +63,23 @@ namespace swift {
6263
using llvm::cast_or_null;
6364

6465
// Containers.
66+
using llvm::ArrayRef;
67+
using llvm::MutableArrayRef;
6568
using llvm::None;
6669
using llvm::Optional;
67-
using llvm::SmallPtrSetImpl;
70+
using llvm::PointerUnion;
71+
using llvm::PointerUnion3;
72+
using llvm::SmallBitVector;
6873
using llvm::SmallPtrSet;
74+
using llvm::SmallPtrSetImpl;
75+
using llvm::SmallSetVector;
6976
using llvm::SmallString;
70-
using llvm::StringRef;
71-
using llvm::StringLiteral;
72-
using llvm::Twine;
73-
using llvm::SmallVectorImpl;
7477
using llvm::SmallVector;
75-
using llvm::ArrayRef;
76-
using llvm::MutableArrayRef;
78+
using llvm::SmallVectorImpl;
79+
using llvm::StringLiteral;
80+
using llvm::StringRef;
7781
using llvm::TinyPtrVector;
78-
using llvm::PointerUnion;
79-
using llvm::SmallSetVector;
80-
using llvm::SmallBitVector;
82+
using llvm::Twine;
8183

8284
// Other common classes.
8385
using llvm::APFloat;

include/swift/Frontend/FrontendOptions.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,6 @@ class FrontendOptions {
220220
/// (if asked to emit SIL).
221221
bool EmitVerboseSIL = false;
222222

223-
/// If set, find and import parseable modules from .swiftinterface files.
224-
bool EnableParseableModuleInterface = false;
225-
226223
/// If set, this module is part of a mixed Objective-C/Swift framework, and
227224
/// the Objective-C half should implicitly be visible to the Swift sources.
228225
bool ImportUnderlyingModule = false;

include/swift/Option/FrontendOptions.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ def emit_pch : Flag<["-"], "emit-pch">,
299299
def pch_disable_validation : Flag<["-"], "pch-disable-validation">,
300300
HelpText<"Disable validating the persistent PCH">;
301301

302-
def enable_sil_ownership : Flag<["-"], "enable-sil-ownership">,
303-
HelpText<"Enable the SIL Ownership Model">;
302+
def verify_sil_ownership : Flag<["-"], "verify-sil-ownership">,
303+
HelpText<"Verify ownership invariants during SIL Verification ">;
304304

305305
def enable_mandatory_semantic_arc_opts : Flag<["-"], "enable-mandatory-semantic-arc-opts">,
306306
HelpText<"Enable the mandatory semantic arc optimizer">;

include/swift/Option/Options.td

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,6 @@ def emit_parseable_module_interface_path :
346346
Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild,
347347
ArgumentIsPath]>,
348348
MetaVarName<"<path>">, HelpText<"Output parseable interface file to <path>">;
349-
def enable_parseable_module_interface :
350-
Flag<["-"], "enable-parseable-module-interface">,
351-
Flags<[FrontendOption, HelpHidden, NoInteractiveOption,
352-
DoesNotAffectIncrementalBuild]>,
353-
HelpText<"Accept parseable .swiftinterface form of modules">;
354349

355350
def emit_objc_header : Flag<["-"], "emit-objc-header">,
356351
Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild]>,

include/swift/Parse/Parser.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,22 @@ class Parser {
230230
// Cut off parsing by acting as if we reached the end-of-file.
231231
Tok.setKind(tok::eof);
232232
}
233-
233+
234+
/// Use this to assert that the parser has advanced the lexing location, e.g.
235+
/// before a specific parser function has returned.
236+
class AssertParserMadeProgressBeforeLeavingScopeRAII {
237+
Parser &P;
238+
SourceLoc InitialLoc;
239+
public:
240+
AssertParserMadeProgressBeforeLeavingScopeRAII(Parser &parser) : P(parser) {
241+
InitialLoc = P.Tok.getLoc();
242+
}
243+
~AssertParserMadeProgressBeforeLeavingScopeRAII() {
244+
assert(InitialLoc != P.Tok.getLoc() &&
245+
"parser did not make progress, this can result in infinite loop");
246+
}
247+
};
248+
234249
/// A RAII object for temporarily changing CurDeclContext.
235250
class ContextChange {
236251
protected:

0 commit comments

Comments
 (0)