Skip to content

Commit 0c03034

Browse files
authored
---
yaml --- r: 343213 b: refs/heads/master-rebranch c: ec3975a h: refs/heads/master i: 343211: 5284708
1 parent 89abb8f commit 0c03034

File tree

95 files changed

+3291
-4253
lines changed

Some content is hidden

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

95 files changed

+3291
-4253
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-02-a: ddd2b2976aa9bfde5f20fe37f6bd2
14551455
refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-03-a: 171cc166f2abeb5ca2a4003700a8a78a108bd300
14561456
refs/heads/benlangmuir-patch-1: baaebaf39d52f3bf36710d4fe40cf212e996b212
14571457
refs/heads/i-do-redeclare: 8c4e6d5de5c1e3f0a2cedccf319df713ea22c48e
1458-
refs/heads/master-rebranch: 108a02f02bddddff8e910e99cf72d90fd0c69e39
1458+
refs/heads/master-rebranch: ec3975a977f04810d8208bae491826cfb76f909e
14591459
refs/heads/rdar-53901732: 9bd06af3284e18a109cdbf9aa59d833b24eeca7b
14601460
refs/heads/revert-26776-subst-always-returns-a-type: 1b8e18fdd391903a348970a4c848995d4cdd789c
14611461
refs/heads/tensorflow-merge: 8b854f62f80d4476cb383d43c4aac2001dde3cec

branches/master-rebranch/include/swift/AST/ASTContext.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ namespace swift {
112112

113113
enum class KnownProtocolKind : uint8_t;
114114

115+
namespace namelookup {
116+
class ImportCache;
117+
}
118+
115119
namespace syntax {
116120
class SyntaxArena;
117121
}
@@ -683,7 +687,9 @@ class ASTContext final {
683687
/// If there is no Clang module loader, returns a null pointer.
684688
/// The loader is owned by the AST context.
685689
ClangModuleLoader *getDWARFModuleLoader() const;
686-
690+
691+
namelookup::ImportCache &getImportCache() const;
692+
687693
/// Asks every module loader to verify the ASTs it has loaded.
688694
///
689695
/// Does nothing in non-asserts (NDEBUG) builds.

branches/master-rebranch/include/swift/AST/Builtins.def

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,14 @@ BUILTIN_MISC_OPERATION(Strideof, "strideof", "n", Special)
418418
/// IsPOD has type T.Type -> Bool
419419
BUILTIN_MISC_OPERATION(IsPOD, "ispod", "n", Special)
420420

421+
/// IsConcrete has type (T.Type) -> Bool
422+
///
423+
/// If the meta type T is concrete, we can always transform this to `true` at
424+
/// any time in SIL. If it's generic, then we lower it to `false` right before
425+
/// IRGen in IRGenPrepare. This allows for the optimizer to specialize this at
426+
/// -O and eliminate conditional code.
427+
BUILTIN_MISC_OPERATION(IsConcrete, "isConcrete", "n", Special)
428+
421429
/// IsBitwiseTakable has type T.Type -> Bool
422430
BUILTIN_MISC_OPERATION(IsBitwiseTakable, "isbitwisetakable", "n", Special)
423431

branches/master-rebranch/include/swift/AST/DiagnosticsModuleDiffer.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ ERROR(decl_new_witness_table_entry,none,"%0 now requires %select{|no}1 new witne
9696

9797
ERROR(new_decl_without_intro,none,"%0 is a new API without @available attribute", (StringRef))
9898

99+
ERROR(objc_name_change,none,"%0 has ObjC name change from %1 to %2", (StringRef, StringRef, StringRef))
100+
99101
#ifndef DIAG_NO_UNDEF
100102
# if defined(DIAG)
101103
# undef DIAG
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
//===--- ImportCache.h - Caching the import graph ---------------*- C++ -*-===//
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+
// This file defines interfaces for querying the module import graph in an
14+
// efficient manner.
15+
//
16+
//===----------------------------------------------------------------------===//
17+
18+
#ifndef SWIFT_AST_IMPORT_CACHE_H
19+
#define SWIFT_AST_IMPORT_CACHE_H
20+
21+
#include "swift/AST/Module.h"
22+
#include "llvm/ADT/DenseMap.h"
23+
#include "llvm/ADT/FoldingSet.h"
24+
25+
namespace swift {
26+
class DeclContext;
27+
28+
namespace namelookup {
29+
30+
/// An object describing a set of modules visible from a DeclContext.
31+
///
32+
/// This consists of two arrays of modules; the top-level imports and the
33+
/// transitive imports.
34+
///
35+
/// The top-level imports contains all public imports of the parent module
36+
/// of 'dc', together with any private imports in the source file containing
37+
/// 'dc', if there is one.
38+
///
39+
/// The transitive imports contains all public imports reachable from the
40+
/// set of top-level imports.
41+
///
42+
/// Both sets only contain unique elements. The top-level imports always
43+
/// include the parent module of 'dc' explicitly.
44+
///
45+
/// The set of transitive imports does not contain any elements found in
46+
/// the top-level imports.
47+
///
48+
/// The Swift standard library module is not included in either set unless
49+
/// it was explicitly imported (or re-exported).
50+
class ImportSet final :
51+
public llvm::FoldingSetNode,
52+
private llvm::TrailingObjects<ImportSet, ModuleDecl::ImportedModule> {
53+
friend TrailingObjects;
54+
friend ImportCache;
55+
56+
unsigned NumTopLevelImports;
57+
unsigned NumTransitiveImports;
58+
59+
ImportSet(ArrayRef<ModuleDecl::ImportedModule> topLevelImports,
60+
ArrayRef<ModuleDecl::ImportedModule> transitiveImports);
61+
62+
ImportSet(const ImportSet &) = delete;
63+
void operator=(const ImportSet &) = delete;
64+
65+
public:
66+
void Profile(llvm::FoldingSetNodeID &ID) {
67+
Profile(ID, getTopLevelImports());
68+
}
69+
static void Profile(
70+
llvm::FoldingSetNodeID &ID,
71+
ArrayRef<ModuleDecl::ImportedModule> topLevelImports);
72+
73+
size_t numTrailingObjects(OverloadToken<ModuleDecl::ImportedModule>) const {
74+
return NumTopLevelImports + NumTransitiveImports;
75+
}
76+
77+
ArrayRef<ModuleDecl::ImportedModule> getTopLevelImports() const {
78+
return {getTrailingObjects<ModuleDecl::ImportedModule>(),
79+
NumTopLevelImports};
80+
}
81+
82+
ArrayRef<ModuleDecl::ImportedModule> getTransitiveImports() const {
83+
return {getTrailingObjects<ModuleDecl::ImportedModule>() +
84+
NumTopLevelImports,
85+
NumTransitiveImports};
86+
}
87+
88+
ArrayRef<ModuleDecl::ImportedModule> getAllImports() const {
89+
return {getTrailingObjects<ModuleDecl::ImportedModule>(),
90+
NumTopLevelImports + NumTransitiveImports};
91+
}
92+
};
93+
94+
class alignas(ModuleDecl::ImportedModule) ImportCache {
95+
ImportCache(const ImportCache &) = delete;
96+
void operator=(const ImportCache &) = delete;
97+
98+
llvm::FoldingSet<ImportSet> ImportSets;
99+
llvm::DenseMap<const DeclContext *, ImportSet *> ImportSetForDC;
100+
llvm::DenseMap<std::tuple<const ModuleDecl *,
101+
const DeclContext *>,
102+
ArrayRef<ModuleDecl::AccessPathTy>> VisibilityCache;
103+
llvm::DenseMap<std::tuple<const ModuleDecl *,
104+
const ModuleDecl *,
105+
const DeclContext *>,
106+
ArrayRef<ModuleDecl::AccessPathTy>> ShadowCache;
107+
108+
ModuleDecl::AccessPathTy EmptyAccessPath;
109+
110+
ArrayRef<ModuleDecl::AccessPathTy> allocateArray(
111+
ASTContext &ctx,
112+
SmallVectorImpl<ModuleDecl::AccessPathTy> &results);
113+
114+
ImportSet &getImportSet(ASTContext &ctx,
115+
ArrayRef<ModuleDecl::ImportedModule> topLevelImports);
116+
117+
public:
118+
ImportCache() {}
119+
120+
/// Returns an object descripting all modules transtiively imported
121+
/// from 'dc'.
122+
ImportSet &getImportSet(const DeclContext *dc);
123+
124+
/// Returns all access paths into 'mod' that are visible from 'dc',
125+
/// including transitively, via re-exports.
126+
ArrayRef<ModuleDecl::AccessPathTy>
127+
getAllVisibleAccessPaths(const ModuleDecl *mod, const DeclContext *dc);
128+
129+
bool isImportedBy(const ModuleDecl *mod,
130+
const DeclContext *dc) {
131+
return !getAllVisibleAccessPaths(mod, dc).empty();
132+
}
133+
134+
/// Determines if 'mod' is visible from 'dc' as a result of a scoped import.
135+
/// Note that if 'mod' was not imported from 'dc' at all, this also returns
136+
/// false.
137+
bool isScopedImport(const ModuleDecl *mod, DeclBaseName name,
138+
const DeclContext *dc) {
139+
auto accessPaths = getAllVisibleAccessPaths(mod, dc);
140+
for (auto accessPath : accessPaths) {
141+
if (accessPath.empty())
142+
continue;
143+
if (ModuleDecl::matchesAccessPath(accessPath, name))
144+
return true;
145+
}
146+
147+
return false;
148+
}
149+
150+
/// Returns all access paths in 'mod' that are visible from 'dc' if we
151+
/// subtract imports of 'other'.
152+
ArrayRef<ModuleDecl::AccessPathTy>
153+
getAllAccessPathsNotShadowedBy(const ModuleDecl *mod,
154+
const ModuleDecl *other,
155+
const DeclContext *dc);
156+
157+
/// Returns 'true' if a declaration named 'name' defined in 'other' shadows
158+
/// defined in 'mod', because no access paths can find 'name' in 'mod' from
159+
/// 'dc' if we ignore imports of 'other'.
160+
bool isShadowedBy(const ModuleDecl *mod,
161+
const ModuleDecl *other,
162+
DeclBaseName name,
163+
const DeclContext *dc) {
164+
auto accessPaths = getAllAccessPathsNotShadowedBy(mod, other, dc);
165+
return llvm::none_of(accessPaths,
166+
[&](ModuleDecl::AccessPathTy accessPath) {
167+
return ModuleDecl::matchesAccessPath(accessPath, name);
168+
});
169+
}
170+
171+
/// Qualified lookup into types uses a slightly different check that does not
172+
/// take access paths into account.
173+
bool isShadowedBy(const ModuleDecl *mod,
174+
const ModuleDecl *other,
175+
const DeclContext *dc) {
176+
auto accessPaths = getAllAccessPathsNotShadowedBy(mod, other, dc);
177+
return accessPaths.empty();
178+
}
179+
180+
/// This is a hack to cope with main file parsing and REPL parsing, where
181+
/// we can add ImportDecls after name binding.
182+
void clear() {
183+
ImportSetForDC.clear();
184+
}
185+
};
186+
187+
} // namespace namelookup
188+
189+
} // namespace swift
190+
191+
#endif

branches/master-rebranch/include/swift/AST/NameLookup.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,11 @@ bool removeOverriddenDecls(SmallVectorImpl<ValueDecl*> &decls);
378378
/// other declarations in that set.
379379
///
380380
/// \param decls The set of declarations being considered.
381-
/// \param curModule The current module.
381+
/// \param dc The DeclContext from which the lookup was performed.
382382
///
383383
/// \returns true if any shadowed declarations were removed.
384384
bool removeShadowedDecls(SmallVectorImpl<ValueDecl*> &decls,
385-
const ModuleDecl *curModule);
385+
const DeclContext *dc);
386386

387387
/// Finds decls visible in the given context and feeds them to the given
388388
/// VisibleDeclConsumer. If the current DeclContext is nested in a function,

branches/master-rebranch/include/swift/Basic/LangOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ namespace swift {
259259
bool WarnIfASTScopeLookup = false;
260260

261261
/// Build the ASTScope tree lazily
262-
bool LazyASTScopes = false;
262+
bool LazyASTScopes = true;
263263

264264
/// Whether to use the import as member inference system
265265
///

branches/master-rebranch/include/swift/Basic/Statistics.def

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,19 @@ FRONTEND_STATISTIC(AST, NumBraceStmtASTScopeExpansions)
175175
/// Number of ASTScope lookups
176176
FRONTEND_STATISTIC(AST, NumASTScopeLookups)
177177

178+
/// Number of lookups of the cached import graph for a module or
179+
/// source file.
180+
FRONTEND_STATISTIC(AST, ImportSetFoldHit)
181+
FRONTEND_STATISTIC(AST, ImportSetFoldMiss)
182+
183+
FRONTEND_STATISTIC(AST, ImportSetCacheHit)
184+
FRONTEND_STATISTIC(AST, ImportSetCacheMiss)
185+
186+
FRONTEND_STATISTIC(AST, ModuleVisibilityCacheHit)
187+
FRONTEND_STATISTIC(AST, ModuleVisibilityCacheMiss)
188+
189+
FRONTEND_STATISTIC(AST, ModuleShadowCacheHit)
190+
FRONTEND_STATISTIC(AST, ModuleShadowCacheMiss)
178191

179192
/// Number of full function bodies parsed.
180193
FRONTEND_STATISTIC(Parse, NumFunctionsParsed)

branches/master-rebranch/include/swift/Frontend/Frontend.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ class CompilerInvocation {
297297
/// Called from lldb, see rdar://53971116
298298
void disableASTScopeLookup() {
299299
LangOpts.EnableASTScopeLookup = false;
300-
LangOpts.LazyASTScopes = false;
301300
}
302301

303302
CodeCompletionCallbacksFactory *getCodeCompletionFactory() const {

branches/master-rebranch/include/swift/IDE/DigesterEnums.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ KEY_STRING(IntroiOS, intro_iOS)
151151
KEY_STRING(IntrotvOS, intro_tvOS)
152152
KEY_STRING(IntrowatchOS, intro_watchOS)
153153
KEY_STRING(Introswift, intro_swift)
154+
KEY_STRING(ObjCName, objc_name)
154155

155156
KEY_STRING_ARR(SuperclassNames, superclassNames)
156157
KEY_STRING_ARR(ToolArgs, tool_arguments)

branches/master-rebranch/include/swift/Index/IndexSymbol.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ struct IndexSymbol : IndexRelation {
6666
SmallVector<IndexRelation, 3> Relations;
6767
unsigned line = 0;
6868
unsigned column = 0;
69+
Optional<unsigned> offset;
6970

7071
IndexSymbol() = default;
7172

branches/master-rebranch/include/swift/SIL/MemoryLifetime.h

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ class MemoryLocations {
183183
return &locations[index];
184184
}
185185

186+
/// Registers an address projection instruction for a location.
187+
void registerProjection(SingleValueInstruction *projection, unsigned locIdx) {
188+
addr2LocIdx[projection] = locIdx;
189+
}
190+
186191
/// Sets the location bits os \p addr in \p bits, if \p addr is associated
187192
/// with a location.
188193
void setBits(Bits &bits, SILValue addr) {
@@ -341,13 +346,29 @@ class MemoryDataflow {
341346
/// Calculates the BlockState::exitReachable flags.
342347
void exitReachableAnalysis();
343348

349+
using JoinOperation = std::function<void (Bits &dest, const Bits &src)>;
350+
344351
/// Derives the block exit sets from the entry sets by applying the gen and
345352
/// kill sets.
346-
void solveDataflowForward();
353+
/// At control flow joins, the \p join operation is applied.
354+
void solveForward(JoinOperation join);
355+
356+
/// Calls solveForward() with a bit-intersection as join operation.
357+
void solveForwardWithIntersect();
358+
359+
/// Calls solveForward() with a bit-union as join operation.
360+
void solveForwardWithUnion();
347361

348362
/// Derives the block entry sets from the exit sets by applying the gen and
349363
/// kill sets.
350-
void solveDataflowBackward();
364+
/// At control flow joins, the \p join operation is applied.
365+
void solveBackward(JoinOperation join);
366+
367+
/// Calls solveBackward() with a bit-intersection as join operation.
368+
void solveBackwardWithIntersect();
369+
370+
/// Calls solveBackward() with a bit-union as join operation.
371+
void solveBackwardWithUnion();
351372

352373
/// Debug dump the MemoryLifetime internals.
353374
void dump() const;

branches/master-rebranch/include/swift/SIL/SILInstruction.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3240,6 +3240,9 @@ class LoadInst
32403240
return LoadOwnershipQualifier(
32413241
SILInstruction::Bits.LoadInst.OwnershipQualifier);
32423242
}
3243+
void setOwnershipQualifier(LoadOwnershipQualifier qualifier) {
3244+
SILInstruction::Bits.LoadInst.OwnershipQualifier = unsigned(qualifier);
3245+
}
32433246
};
32443247

32453248
// *NOTE* When serializing, we can only represent up to 4 values here. If more
@@ -3279,6 +3282,9 @@ class StoreInst
32793282
return StoreOwnershipQualifier(
32803283
SILInstruction::Bits.StoreInst.OwnershipQualifier);
32813284
}
3285+
void setOwnershipQualifier(StoreOwnershipQualifier qualifier) {
3286+
SILInstruction::Bits.StoreInst.OwnershipQualifier = unsigned(qualifier);
3287+
}
32823288
};
32833289

32843290
class EndBorrowInst;

branches/master-rebranch/include/swift/SILOptimizer/PassManager/Passes.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ PASS(DeadObjectElimination, "deadobject-elim",
132132
"Dead Object Elimination for Classes with Trivial Destruction")
133133
PASS(DefiniteInitialization, "definite-init",
134134
"Definite Initialization for Diagnostics")
135+
PASS(DestroyHoisting, "destroy-hoisting",
136+
"Hoisting of value destroys")
135137
PASS(Devirtualizer, "devirtualizer",
136138
"Indirect Call Devirtualization")
137139
PASS(DiagnoseInfiniteRecursion, "diagnose-infinite-recursion",

0 commit comments

Comments
 (0)