Skip to content

Commit 2021dd5

Browse files
author
Max Moiseev
committed
Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines
2 parents 8af04c8 + 41fe791 commit 2021dd5

File tree

968 files changed

+5028
-2057
lines changed

Some content is hidden

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

968 files changed

+5028
-2057
lines changed

CMakeLists.txt

+6-1
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,12 @@ if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
412412
endif()
413413

414414
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
415-
configure_sdk_unix(FREEBSD "FreeBSD" "freebsd" "freebsd" "x86_64" "x86_64-freebsd10")
415+
# FIXME: Using the host OS version won't produce correct results for
416+
# cross-compilation.
417+
string(REPLACE "[-].*" "" FREEBSD_SYSTEM_VERSION ${CMAKE_SYSTEM_VERSION})
418+
message(STATUS "FreeBSD Version: ${FREEBSD_SYSTEM_VERSION}")
419+
configure_sdk_unix(FREEBSD "FreeBSD" "freebsd" "freebsd" "x86_64"
420+
"x86_64-unknown-freebsd${FREEBSD_SYSTEM_VERSION}")
416421

417422
set(CMAKE_EXECUTABLE_FORMAT "ELF")
418423

docs/Failable Initializers.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ a new hidden stored property to each class that directly defines failing
173173
initializers. The bit is set if this slice of the instance has been
174174
initialized.
175175

176-
Note that unlike partailDeinit, if a class does not have failing initializers,
176+
Note that unlike partialDeinit, if a class does not have failing initializers,
177177
it does not need this bit, even if its initializer delegates to a failing
178178
initializer in a superclass.
179179

include/swift/AST/ArchetypeBuilder.h

+6
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,12 @@ class ArchetypeBuilder {
218218
/// \returns true if an error occurred, false otherwise.
219219
bool addGenericParameter(GenericTypeParamDecl *GenericParam);
220220

221+
/// Add the requirements placed on the given abstract type parameter
222+
/// to the given potential archetype.
223+
///
224+
/// \returns true if an error occurred, false otherwise.
225+
bool addGenericParameterRequirements(GenericTypeParamDecl *GenericParam);
226+
221227
/// \brief Add a new generic parameter for which there may be requirements.
222228
///
223229
/// \returns true if an error occurred, false otherwise.

include/swift/AST/Decl.h

+13-4
Original file line numberDiff line numberDiff line change
@@ -2871,9 +2871,6 @@ class NominalTypeDecl : public TypeDecl, public DeclContext,
28712871
return GenericSig;
28722872
}
28732873

2874-
/// Mark generic type signature as invalid.
2875-
void markInvalidGenericSignature();
2876-
28772874
/// getDeclaredType - Retrieve the type declared by this entity.
28782875
Type getDeclaredType() const { return DeclaredTy; }
28792876

@@ -4371,6 +4368,7 @@ class AbstractFunctionDecl : public ValueDecl, public DeclContext {
43714368
};
43724369

43734370
GenericParamList *GenericParams;
4371+
GenericSignature *GenericSig;
43744372

43754373
CaptureInfo Captures;
43764374

@@ -4379,7 +4377,7 @@ class AbstractFunctionDecl : public ValueDecl, public DeclContext {
43794377
GenericParamList *GenericParams)
43804378
: ValueDecl(Kind, Parent, Name, NameLoc),
43814379
DeclContext(DeclContextKind::AbstractFunctionDecl, Parent),
4382-
Body(nullptr), GenericParams(nullptr) {
4380+
Body(nullptr), GenericParams(nullptr), GenericSig(nullptr) {
43834381
setBodyKind(BodyKind::None);
43844382
setGenericParams(GenericParams);
43854383
AbstractFunctionDeclBits.NumParamPatterns = NumParamPatterns;
@@ -4396,6 +4394,17 @@ class AbstractFunctionDecl : public ValueDecl, public DeclContext {
43964394
}
43974395

43984396
void setGenericParams(GenericParamList *GenericParams);
4397+
4398+
public:
4399+
void setGenericSignature(GenericSignature *GenericSig) {
4400+
assert(!this->GenericSig && "already have signature?");
4401+
this->GenericSig = GenericSig;
4402+
}
4403+
4404+
GenericSignature *getGenericSignature() const {
4405+
return GenericSig;
4406+
}
4407+
43994408
public:
44004409
// FIXME: Hack that provides names with keyword arguments for accessors.
44014410
DeclName getEffectiveFullName() const;

include/swift/AST/DeclContext.h

+4
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,10 @@ class alignas(1 << DeclContextAlignInBits) DeclContext {
359359

360360
/// Determine whether the innermost context is generic.
361361
bool isInnermostContextGeneric() const;
362+
363+
/// Determine whether the innermost context is either a generic type context,
364+
/// or a concrete type nested inside a generic type context.
365+
bool isGenericTypeContext() const;
362366

363367
/// Returns true if lookups within this context could affect downstream files.
364368
///

include/swift/AST/Expr.h

-3
Original file line numberDiff line numberDiff line change
@@ -931,9 +931,6 @@ class DeclRefExpr : public Expr {
931931
return DOrSpecialized.get<ConcreteDeclRef>();
932932
}
933933

934-
/// Set the declaration.
935-
void setDeclRef(ConcreteDeclRef ref);
936-
937934
void setSpecialized();
938935

939936
/// \brief Determine whether this declaration reference was immediately

include/swift/AST/IRGenOptions.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ class IRGenOptions {
126126
/// Whether we should embed the bitcode file.
127127
IRGenEmbedMode EmbedMode : 2;
128128

129+
/// For resilient access to super's members for testing.
130+
unsigned ForceResilientSuperDispatch: 1;
131+
129132
/// List of backend command-line options for -embed-bitcode.
130133
std::vector<uint8_t> CmdArgs;
131134

@@ -135,7 +138,9 @@ class IRGenOptions {
135138
DisableLLVMARCOpts(false), DisableLLVMSLPVectorizer(false),
136139
DisableFPElim(true), Playground(false),
137140
EmitStackPromotionChecks(false), GenerateProfile(false),
138-
EmbedMode(IRGenEmbedMode::None) {}
141+
EmbedMode(IRGenEmbedMode::None),
142+
ForceResilientSuperDispatch(false)
143+
{}
139144

140145
/// Gets the name of the specified output filename.
141146
/// If multiple files are specified, the last one is returned.

include/swift/Basic/STLExtras.h

+15
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,21 @@ void sortUnique(
558558
C.erase(std::unique(C.begin(), C.end()), C.end());
559559
}
560560

561+
/// Sorts and then uniques a container with random access iterators and an erase
562+
/// method that removes a range specified by random access iterators.
563+
template <typename Container, typename Comparator>
564+
void sortUnique(
565+
Container &C,
566+
Comparator Cmp,
567+
typename std::enable_if<
568+
std::is_same<typename std::iterator_traits<
569+
typename Container::iterator>::iterator_category,
570+
std::random_access_iterator_tag>::value,
571+
void>::type * = nullptr) {
572+
std::sort(C.begin(), C.end(), Cmp);
573+
C.erase(std::unique(C.begin(), C.end()), C.end());
574+
}
575+
561576
} // end namespace swift
562577

563578
#endif

include/swift/ClangImporter/ClangImporterOptions.h

-4
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ class ClangImporterOptions {
5353
/// generation.
5454
bool DetailedPreprocessingRecord = false;
5555

56-
/// If true, matched getter-like and setter-like methods will be imported as
57-
/// properties.
58-
bool InferImplicitProperties = false;
59-
6056
/// If true, Clang diagnostics will be dumped to stderr using Clang's
6157
/// diagnostic printer as well as being passed to Swift's diagnostic engine.
6258
bool DumpClangDiagnostics = false;

include/swift/Option/FrontendOptions.td

+7-4
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ def emit_verbose_sil : Flag<["-"], "emit-verbose-sil">,
190190
def use_native_super_method : Flag<["-"], "use-native-super-method">,
191191
HelpText<"Use super_method for super calls in native classes">;
192192

193+
def force_resilient_super_dispatch: Flag<["-"], "force-resilient-super-dispatch">,
194+
HelpText<"Assume all super member accesses are resilient">;
195+
193196
def disable_self_type_mangling : Flag<["-"], "disable-self-type-mangling">,
194197
HelpText<"Disable including Self type in method type manglings">;
195198

@@ -200,10 +203,6 @@ def disable_availability_checking : Flag<["-"],
200203
"disable-availability-checking">,
201204
HelpText<"Disable checking for potentially unavailable APIs">;
202205

203-
def enable_objc_implicit_properties :
204-
Flag<["-"], "enable-objc-implicit-properties">,
205-
HelpText<"Import Objective-C \"implicit properties\" as properties">;
206-
207206
def enable_omit_needless_words :
208207
Flag<["-"], "enable-omit-needless-words">,
209208
HelpText<"Omit needless words when importing Objective-C names">;
@@ -212,6 +211,10 @@ def enable_infer_default_arguments :
212211
Flag<["-"], "enable-infer-default-arguments">,
213212
HelpText<"Infer default arguments for imported parameters">;
214213

214+
def enable_swift_name_lookup_tables :
215+
Flag<["-"], "enable-swift-name-lookup-tables">,
216+
HelpText<"Enable Swift name lookup tables in the Clang importer">;
217+
215218
def warn_omit_needless_words :
216219
Flag<["-"], "Womit-needless-words">,
217220
HelpText<"Warn about needless words in names">;

include/swift/SIL/DebugUtils.h

+2
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ inline SILInstruction *getSingleNonDebugUser(const V &value) {
164164
auto Range = getNonDebugUses(value);
165165
auto I = Range.begin(), E = Range.end();
166166
if (I == E) return nullptr;
167+
if (std::next(I) != E)
168+
return nullptr;
167169
return I->getUser();
168170
}
169171

include/swift/SIL/LoopInfo.h

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ class SILLoop : public llvm::LoopBase<SILBasicBlock, SILLoop> {
4646
return make_range(begin(), end());
4747
}
4848

49+
/// Check whether it is safe to duplicate this instruction when duplicating
50+
/// this loop by unrolling or versioning.
51+
bool canDuplicate(SILInstruction *Inst) const;
52+
4953
private:
5054
friend class llvm::LoopInfoBase<SILBasicBlock, SILLoop>;
5155

include/swift/SIL/SILBasicBlock.h

+32-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#ifndef SWIFT_SIL_BASICBLOCK_H
1818
#define SWIFT_SIL_BASICBLOCK_H
1919

20+
#include "swift/Basic/Range.h"
2021
#include "swift/SIL/SILInstruction.h"
2122

2223
namespace llvm {
@@ -234,10 +235,31 @@ public llvm::ilist_node<SILBasicBlock>, public SILAllocated<SILBasicBlock> {
234235

235236
/// \brief Returns true if \p BB is a successor of this block.
236237
bool isSuccessor(SILBasicBlock *BB) const {
237-
for (auto &Succ : getSuccessors())
238-
if (Succ.getBB() == BB)
239-
return true;
240-
return false;
238+
auto Range = getSuccessorBlocks();
239+
return any_of(Range, [&BB](const SILBasicBlock *SuccBB) -> bool {
240+
return BB == SuccBB;
241+
});
242+
}
243+
244+
using SuccessorBlockListTy =
245+
TransformRange<SuccessorListTy,
246+
std::function<SILBasicBlock *(const SILSuccessor &)>>;
247+
using ConstSuccessorBlockListTy =
248+
TransformRange<ConstSuccessorListTy,
249+
std::function<const SILBasicBlock *(const SILSuccessor &)>>;
250+
251+
/// Return the range of SILBasicBlocks that are successors of this block.
252+
SuccessorBlockListTy getSuccessorBlocks() {
253+
using FuncTy = std::function<SILBasicBlock *(const SILSuccessor &)>;
254+
FuncTy F(&SILSuccessor::getBB);
255+
return makeTransformRange(getSuccessors(), F);
256+
}
257+
258+
/// Return the range of SILBasicBlocks that are successors of this block.
259+
ConstSuccessorBlockListTy getSuccessorBlocks() const {
260+
using FuncTy = std::function<const SILBasicBlock *(const SILSuccessor &)>;
261+
FuncTy F(&SILSuccessor::getBB);
262+
return makeTransformRange(getSuccessors(), F);
241263
}
242264

243265
using pred_iterator = SILSuccessorIterator;
@@ -250,6 +272,12 @@ public llvm::ilist_node<SILBasicBlock>, public SILAllocated<SILBasicBlock> {
250272
return {pred_begin(), pred_end() };
251273
}
252274

275+
bool isPredecessor(SILBasicBlock *BB) const {
276+
return any_of(getPreds(), [&BB](const SILBasicBlock *PredBB) -> bool {
277+
return BB == PredBB;
278+
});
279+
}
280+
253281
SILBasicBlock *getSinglePredecessor() {
254282
if (pred_empty() || std::next(pred_begin()) != pred_end())
255283
return nullptr;

include/swift/SIL/SILCloner.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ SILCloner<ImplClass>::visitSILBasicBlock(SILBasicBlock* BB) {
366366
// Iterate over successors to do the depth-first search.
367367
for (auto &Succ : BB->getSuccessors()) {
368368
auto BBI = BBMap.find(Succ);
369-
// Only visit a successor that has not already been visisted.
369+
// Only visit a successor that has not already been visited.
370370
if (BBI == BBMap.end()) {
371371
// Map the successor to a new BB.
372372
auto MappedBB = new (F.getModule()) SILBasicBlock(&F);

include/swift/SIL/SILFunction.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class SILFunction
108108
/// functions into the thunk.
109109
unsigned Thunk : 2;
110110

111-
/// The visiblity of the parent class, if this is a method which is contained
111+
/// The visibility of the parent class, if this is a method which is contained
112112
/// in the vtable of that class.
113113
unsigned ClassVisibility : 2;
114114

@@ -300,7 +300,7 @@ class SILFunction
300300

301301
/// Get's the effective linkage which is used to derive the llvm linkage.
302302
/// Usually this is the same as getLinkage(), except in one case: if this
303-
/// function is a method in a class which has higher visiblity than the
303+
/// function is a method in a class which has higher visibility than the
304304
/// method itself, the function can be referenced from vtables of derived
305305
/// classes in other compilation units.
306306
SILLinkage getEffectiveSymbolLinkage() const {

include/swift/SILOptimizer/Analysis/ClassHierarchyAnalysis.h

+4-5
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
#include "llvm/ADT/DenseMap.h"
2222
#include "llvm/Support/Debug.h"
2323

24-
using namespace llvm;
25-
2624
namespace swift {
2725

2826
class SILModule;
@@ -32,7 +30,8 @@ class ClassHierarchyAnalysis : public SILAnalysis {
3230
typedef SmallVector<ClassDecl *, 8> ClassList;
3331
typedef SmallPtrSet<ClassDecl *, 32> ClassSet;
3432
typedef SmallVector<NominalTypeDecl *, 8> NominalTypeList;
35-
typedef DenseMap<ProtocolDecl *, NominalTypeList> ProtocolImplementations;
33+
typedef llvm::DenseMap<ProtocolDecl *, NominalTypeList>
34+
ProtocolImplementations;
3635

3736
ClassHierarchyAnalysis(SILModule *Mod)
3837
: SILAnalysis(AnalysisKind::ClassHierarchy), M(Mod) {
@@ -101,10 +100,10 @@ class ClassHierarchyAnalysis : public SILAnalysis {
101100
SILModule *M;
102101

103102
/// A cache that maps a class to all of its known direct subclasses.
104-
DenseMap<ClassDecl*, ClassList> DirectSubclassesCache;
103+
llvm::DenseMap<ClassDecl*, ClassList> DirectSubclassesCache;
105104

106105
/// A cache that maps a class to all of its known indirect subclasses.
107-
DenseMap<ClassDecl*, ClassList> IndirectSubclassesCache;
106+
llvm::DenseMap<ClassDecl*, ClassList> IndirectSubclassesCache;
108107

109108
/// A cache that maps a protocol to all of its known implementations.
110109
ProtocolImplementations ProtocolImplementationsCache;

include/swift/SILOptimizer/Analysis/LoopRegionAnalysis.h

+12
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,10 @@ class LoopRegion {
399399
/// Subregions array by the RPO number of its header.
400400
llvm::SmallVector<std::pair<unsigned, unsigned>, 2> Subloops;
401401

402+
/// A list of subregions with non-local successors. This is the actual ID
403+
/// of the subregion since we do not care about any ordering.
404+
llvm::SmallVector<unsigned, 2> ExitingSubregions;
405+
402406
subregion_iterator begin() const {
403407
return subregion_iterator(Subregions.begin(), &Subloops);
404408
}
@@ -498,6 +502,14 @@ class LoopRegion {
498502
return std::find(subregion_begin(), End, R->getID()) != End;
499503
}
500504

505+
/// Returns an ArrayRef containing IDs of the exiting subregions of this
506+
/// region. The exit regions associated with the exiting subregions are the
507+
/// end points of the non-local edges. This asserts if this is a region
508+
/// representing a block.
509+
ArrayRef<unsigned> getExitingSubregions() const {
510+
return getSubregionData().ExitingSubregions;
511+
}
512+
501513
using pred_const_iterator = decltype(Preds)::const_iterator;
502514
pred_const_iterator pred_begin() const { return Preds.begin(); }
503515
pred_const_iterator pred_end() const { return Preds.end(); }

include/swift/SILOptimizer/PassManager/PassManager.h

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ namespace swift {
2626
class SILFunction;
2727
class SILFunctionTransform;
2828
class SILModule;
29+
class SILModuleTransform;
2930
class SILOptions;
3031
class SILTransform;
3132

@@ -156,6 +157,10 @@ class SILPassManager {
156157

157158
typedef llvm::ArrayRef<SILFunctionTransform *> PassList;
158159
private:
160+
/// Run the SIL module transform \p SMT over all the functions in
161+
/// the module.
162+
void runModulePass(SILModuleTransform *SMT);
163+
159164
/// Run the passes in \p FuncTransforms. Return true
160165
/// if the pass manager requested to stop the execution
161166
/// of the optimization cycle (this is a debug feature).

include/swift/SILOptimizer/PassManager/Passes.def

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ PASS(AllocBoxToStack, "allocbox-to-stack",
3838
"Promote heap allocations to stack allocations")
3939
PASS(ArrayCountPropagation, "array-count-propagation",
4040
"Propagate the count of arrays")
41+
PASS(ArrayElementPropagation, "array-element-propagation",
42+
"Propagate the value of array elements")
4143
PASS(BasicCalleePrinter, "basic-callee-printer",
4244
"Construct basic callee analysis and use it to print callees "
4345
"for testing purposes")
@@ -130,6 +132,8 @@ PASS(LoopRegionViewCFG, "loop-region-view-cfg",
130132
"Construct the loop region data structure and dump its contents as a pdf cfg")
131133
PASS(LoopRotate, "loop-rotate",
132134
"Rotate loops")
135+
PASS(LoopUnroll, "loop-unroll",
136+
"Unroll loops")
133137
PASS(LowerAggregateInstrs, "lower-aggregate-instrs",
134138
"Lower aggregate instructions to scalar instructions")
135139
PASS(MandatoryInlining, "mandatory-inlining",

0 commit comments

Comments
 (0)