Skip to content

Commit cb5fd7f

Browse files
committed
Merge branch 'master' into extend-operator-designated-type
2 parents d8c826d + 8d37c79 commit cb5fd7f

File tree

104 files changed

+2197
-2961
lines changed

Some content is hidden

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

104 files changed

+2197
-2961
lines changed

benchmark/single-source/NSStringConversion.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public func run_NSStringConversion(_ N: Int) {
2323
#if _runtime(_ObjC)
2424
let test:NSString = NSString(cString: "test", encoding: String.Encoding.ascii.rawValue)!
2525
for _ in 1...N * 10000 {
26-
_ = test as String
26+
blackHole(identity(test) as String)
2727
}
2828
#endif
2929
}

include/swift/AST/ASTContext.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,12 +400,35 @@ class ASTContext final {
400400
/// Set a new stats reporter.
401401
void setStatsReporter(UnifiedStatsReporter *stats);
402402

403+
/// Creates a new lazy resolver by passing the ASTContext and the other
404+
/// given arguments to a newly-allocated instance of \c ResolverType.
405+
///
406+
/// \returns true if a new lazy resolver was created, false if there was
407+
/// already a lazy resolver registered.
408+
template<typename ResolverType, typename ... Args>
409+
bool createLazyResolverIfMissing(Args && ...args) {
410+
if (getLazyResolver())
411+
return false;
412+
413+
setLazyResolver(new ResolverType(*this, std::forward<Args>(args)...));
414+
return true;
415+
}
416+
417+
/// Remove the lazy resolver, if there is one.
418+
///
419+
/// FIXME: We probably don't ever want to do this.
420+
void removeLazyResolver() {
421+
setLazyResolver(nullptr);
422+
}
423+
403424
/// Retrieve the lazy resolver for this context.
404425
LazyResolver *getLazyResolver() const;
405426

427+
private:
406428
/// Set the lazy resolver for this context.
407429
void setLazyResolver(LazyResolver *resolver);
408430

431+
public:
409432
/// Add a lazy parser for resolving members later.
410433
void addLazyParser(LazyMemberParser *parser);
411434

include/swift/AST/AttrKind.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ enum class Associativity : uint8_t {
4040
Right
4141
};
4242

43+
/// Returns the in-source spelling of the given associativity.
44+
StringRef getAssociativitySpelling(Associativity value);
45+
4346
/// The kind of unary operator, if any.
4447
enum class UnaryOperatorKind : uint8_t {
4548
None,

include/swift/AST/Builtins.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ BUILTIN_UNARY_OPERATION(FNeg, "fneg", "n", FloatOrVector)
114114
// It has only an effect if the argument is a load or call.
115115
// TODO: consider printing a warning if it is not used on a load or call.
116116
BUILTIN_UNARY_OPERATION(AssumeNonNegative, "assumeNonNegative", "n", Integer)
117+
// It only works on i1.
118+
BUILTIN_UNARY_OPERATION(AssumeTrue, "assume", "", Integer)
117119

118120
#undef BUILTIN_UNARY_OPERATION
119121

include/swift/AST/Module.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,12 @@ class ModuleDecl : public DeclContext, public TypeDecl {
431431
/// The order of the results is not guaranteed to be meaningful.
432432
void getLocalTypeDecls(SmallVectorImpl<TypeDecl*> &Results) const;
433433

434+
/// Finds all precedence group decls of this module.
435+
///
436+
/// This does a simple local lookup, not recursively looking through imports.
437+
/// The order of the results is not guaranteed to be meaningful.
438+
void getPrecedenceGroups(SmallVectorImpl<PrecedenceGroupDecl*> &Results) const;
439+
434440
/// Finds all top-level decls that should be displayed to a client of this
435441
/// module.
436442
///
@@ -690,6 +696,13 @@ class FileUnit : public DeclContext {
690696
virtual void getTopLevelDecls(SmallVectorImpl<Decl*> &results) const {}
691697

692698

699+
/// Finds all precedence group decls in this file.
700+
///
701+
/// This does a simple local lookup, not recursively looking through imports.
702+
/// The order of the results is not guaranteed to be meaningful.
703+
virtual void
704+
getPrecedenceGroups(SmallVectorImpl<PrecedenceGroupDecl*> &Results) const {}
705+
693706
/// Finds all local type decls in this file.
694707
///
695708
/// This does a simple local lookup, not recursively looking through imports.
@@ -985,6 +998,9 @@ class SourceFile final : public FileUnit {
985998

986999
virtual void getTopLevelDecls(SmallVectorImpl<Decl*> &results) const override;
9871000

1001+
virtual void
1002+
getPrecedenceGroups(SmallVectorImpl<PrecedenceGroupDecl*> &results) const override;
1003+
9881004
virtual void
9891005
getLocalTypeDecls(SmallVectorImpl<TypeDecl*> &results) const override;
9901006

include/swift/Driver/Compilation.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,6 @@ class Compilation {
180180
/// by \c BatchCount.
181181
const Optional<unsigned> BatchSizeLimit;
182182

183-
/// In order to test repartitioning, set to true if
184-
/// -driver-force-one-batch-repartition is present.
185-
const bool ForceOneBatchRepartition = false;
186-
187183
/// True if temporary files should not be deleted.
188184
const bool SaveTemps;
189185

@@ -236,7 +232,6 @@ class Compilation {
236232
unsigned BatchSeed = 0,
237233
Optional<unsigned> BatchCount = None,
238234
Optional<unsigned> BatchSizeLimit = None,
239-
bool ForceOneBatchRepartition = false,
240235
bool SaveTemps = false,
241236
bool ShowDriverTimeCompilation = false,
242237
std::unique_ptr<UnifiedStatsReporter> Stats = nullptr);
@@ -298,8 +293,6 @@ class Compilation {
298293
return EnableBatchMode;
299294
}
300295

301-
bool getForceOneBatchRepartition() const { return ForceOneBatchRepartition; }
302-
303296
bool getContinueBuildingAfterErrors() const {
304297
return ContinueBuildingAfterErrors;
305298
}

include/swift/IDE/CodeCompletion.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ enum class CompletionKind {
508508
PlatformConditon,
509509
AfterIfStmtElse,
510510
GenericParams,
511+
PrecedenceGroup,
511512
};
512513

513514
/// \brief A single code completion result.
@@ -891,7 +892,8 @@ void lookupCodeCompletionResultsFromModule(CodeCompletionResultSink &targetSink,
891892
/// restricting by \p onlyTypes.
892893
void copyCodeCompletionResults(CodeCompletionResultSink &targetSink,
893894
CodeCompletionResultSink &sourceSink,
894-
bool onlyTypes);
895+
bool onlyTypes,
896+
bool onlyPrecedenceGroups);
895897

896898
} // end namespace ide
897899
} // end namespace swift

include/swift/IDE/CodeCompletionCache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ struct RequestedCachedModule {
9595
CodeCompletionCache::Key Key;
9696
const ModuleDecl *TheModule;
9797
bool OnlyTypes;
98+
bool OnlyPrecedenceGroups;
9899
};
99100

100101
} // end namespace ide

include/swift/Option/Options.td

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,6 @@ def driver_batch_count : Separate<["-"], "driver-batch-count">,
116116
def driver_batch_size_limit : Separate<["-"], "driver-batch-size-limit">,
117117
InternalDebugOpt,
118118
HelpText<"Use the given number as the upper limit on dynamic batch-mode partition size">;
119-
def driver_force_one_batch_repartition : Flag<["-"], "driver-force-one-batch-repartition">,
120-
InternalDebugOpt,
121-
HelpText<"Force one batch repartitioning for testing">;
122119

123120
def driver_force_response_files : Flag<["-"], "driver-force-response-files">,
124121
InternalDebugOpt,

include/swift/Parse/CodeCompletionCallbacks.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ class CodeCompletionCallbacks {
183183
/// @available.
184184
virtual void completeDeclAttrParam(DeclAttrKind DK, int Index) = 0;
185185

186+
/// Complete within a precedence group decl or after a colon in an
187+
/// operator decl.
188+
virtual void completeInPrecedenceGroup(SyntaxKind SK) = 0;
189+
186190
/// Complete the platform names inside #available statements.
187191
virtual void completePoundAvailablePlatform() = 0;
188192

include/swift/Parse/SyntaxParsingContext.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,8 @@ class alignas(1 << SyntaxAlignInBits) SyntaxParsingContext {
331331
/// are supported. See the implementation.
332332
void createNodeInPlace(SyntaxKind Kind);
333333

334-
/// Squshing nodes from the back of the pending syntax list to a given syntax
335-
/// collection kind. If there're no nodes can fit into the collection kind,
334+
/// Squashing nodes from the back of the pending syntax list to a given syntax
335+
/// collection kind. If there're no nodes that can fit into the collection kind,
336336
/// this function does nothing. Otherwise, it creates a collection node in place
337337
/// to contain all sequential suitable nodes from back.
338338
void collectNodesInPlace(SyntaxKind ColletionKind);

include/swift/SIL/OwnershipUtils.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define SWIFT_SIL_OWNERSHIPUTILS_H
1515

1616
#include "swift/Basic/LLVM.h"
17+
#include "swift/SIL/SILValue.h"
1718
#include "llvm/ADT/SmallPtrSet.h"
1819
#include "llvm/ADT/SmallVector.h"
1920

@@ -101,6 +102,22 @@ bool valueHasLinearLifetime(SILValue value,
101102
DeadEndBlocks &deadEndBlocks,
102103
ownership::ErrorBehaviorKind errorBehavior);
103104

105+
/// Returns true if v is an address or trivial.
106+
bool isValueAddressOrTrivial(SILValue v, SILModule &m);
107+
108+
/// These operations forward both owned and guaranteed ownership.
109+
bool isOwnershipForwardingValueKind(SILNodeKind kind);
110+
111+
/// These operations forward guaranteed ownership, but don't necessarily forward
112+
/// owned values.
113+
bool isGuaranteedForwardingValueKind(SILNodeKind kind);
114+
115+
bool isGuaranteedForwardingValue(SILValue value);
116+
117+
bool isGuaranteedForwardingInst(SILInstruction *i);
118+
119+
bool isOwnershipForwardingInst(SILInstruction *i);
120+
104121
} // namespace swift
105122

106123
#endif

include/swift/Sema/IDETypeChecking.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ namespace swift {
3030
class ExtensionDecl;
3131
class ProtocolDecl;
3232
class Type;
33+
class TypeChecker;
3334
class DeclContext;
3435
class ConcreteDeclRef;
3536
class ValueDecl;
@@ -123,11 +124,11 @@ namespace swift {
123124
/// \returns true on success, false on error.
124125
bool typeCheckTopLevelCodeDecl(TopLevelCodeDecl *TLCD);
125126

126-
/// A unique_ptr for LazyResolver that can perform additional cleanup.
127-
using OwnedResolver = std::unique_ptr<LazyResolver, void(*)(LazyResolver*)>;
128-
129-
/// Creates a lazy type resolver for use in lookups.
130-
OwnedResolver createLazyResolver(ASTContext &Ctx);
127+
/// Creates a type checker instance on the given AST context, if it
128+
/// doesn't already have one.
129+
///
130+
/// \returns a reference to the type checker instance.
131+
TypeChecker &createTypeChecker(ASTContext &Ctx);
131132

132133
struct ExtensionInfo {
133134
// The extension with the declarations to apply.

include/swift/Serialization/ModuleFile.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,9 @@ class ModuleFile
738738
/// Adds all top-level decls to the given vector.
739739
void getTopLevelDecls(SmallVectorImpl<Decl*> &Results);
740740

741+
/// Adds all precedence groups to the given vector.
742+
void getPrecedenceGroups(SmallVectorImpl<PrecedenceGroupDecl*> &Results);
743+
741744
/// Adds all local type decls to the given vector.
742745
void getLocalTypeDecls(SmallVectorImpl<TypeDecl*> &Results);
743746

include/swift/Serialization/SerializedModuleLoader.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ class SerializedASTFile final : public LoadedFile {
175175

176176
virtual void getTopLevelDecls(SmallVectorImpl<Decl*> &results) const override;
177177

178+
virtual void
179+
getPrecedenceGroups(SmallVectorImpl<PrecedenceGroupDecl*> &Results) const override;
180+
178181
virtual void
179182
getLocalTypeDecls(SmallVectorImpl<TypeDecl*> &results) const override;
180183

lib/AST/ASTContext.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,8 @@ FOR_KNOWN_FOUNDATION_TYPES(CACHE_FOUNDATION_DECL)
428428
ASTContext::Implementation::Implementation()
429429
: IdentifierTable(Allocator), TheSyntaxArena(new SyntaxArena()) {}
430430
ASTContext::Implementation::~Implementation() {
431+
delete Resolver;
432+
431433
for (auto &cleanup : Cleanups)
432434
cleanup();
433435
}
@@ -579,13 +581,10 @@ LazyResolver *ASTContext::getLazyResolver() const {
579581

580582
/// Set the lazy resolver for this context.
581583
void ASTContext::setLazyResolver(LazyResolver *resolver) {
582-
if (resolver) {
583-
assert(getImpl().Resolver == nullptr && "already have a resolver");
584-
getImpl().Resolver = resolver;
585-
} else {
586-
assert(getImpl().Resolver != nullptr && "no resolver to remove");
587-
getImpl().Resolver = resolver;
588-
}
584+
if (auto existing = getImpl().Resolver)
585+
delete existing;
586+
587+
getImpl().Resolver = resolver;
589588
}
590589

591590
void ASTContext::addLazyParser(LazyMemberParser *lazyParser) {

lib/AST/Decl.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6062,6 +6062,15 @@ SourceRange DestructorDecl::getSourceRange() const {
60626062
return { getDestructorLoc(), getBody()->getEndLoc() };
60636063
}
60646064

6065+
StringRef swift::getAssociativitySpelling(Associativity value) {
6066+
switch (value) {
6067+
case Associativity::None: return "none";
6068+
case Associativity::Left: return "left";
6069+
case Associativity::Right: return "right";
6070+
}
6071+
llvm_unreachable("Unhandled Associativity in switch.");
6072+
}
6073+
60656074
PrecedenceGroupDecl *
60666075
PrecedenceGroupDecl::create(DeclContext *dc,
60676076
SourceLoc precedenceGroupLoc,

lib/AST/Module.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,20 @@ void SourceFile::getTopLevelDecls(SmallVectorImpl<Decl*> &Results) const {
547547
Results.append(Decls.begin(), Decls.end());
548548
}
549549

550+
void ModuleDecl::getPrecedenceGroups(
551+
SmallVectorImpl<PrecedenceGroupDecl*> &Results) const {
552+
FORWARD(getPrecedenceGroups, (Results));
553+
}
554+
555+
void SourceFile::getPrecedenceGroups(
556+
SmallVectorImpl<PrecedenceGroupDecl*> &Results) const {
557+
for (auto pair : PrecedenceGroups) {
558+
if (pair.second.getPointer() && pair.second.getInt()) {
559+
Results.push_back(pair.second.getPointer());
560+
}
561+
}
562+
}
563+
550564
void SourceFile::getLocalTypeDecls(SmallVectorImpl<TypeDecl*> &Results) const {
551565
Results.append(LocalTypeDecls.begin(), LocalTypeDecls.end());
552566
}

lib/AST/ProtocolConformance.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,8 @@ NormalProtocolConformance::populateSignatureConformances() {
578578

579579
// Allocate the buffer of conformance requirements.
580580
auto &ctx = self->getProtocol()->getASTContext();
581-
buffer = ctx.AllocateUninitialized<ProtocolConformanceRef>(numConformanceRequirements);
581+
buffer = ctx.AllocateUninitialized<ProtocolConformanceRef>(
582+
numConformanceRequirements);
582583

583584
// Skip over any non-conformance requirements in the requirement
584585
// signature.
@@ -600,11 +601,20 @@ NormalProtocolConformance::populateSignatureConformances() {
600601
other.owning = false;
601602
}
602603

604+
~Writer() {
605+
if (!owning)
606+
return;
607+
while (!requirementSignature.empty())
608+
(*this)(ProtocolConformanceRef::forInvalid());
609+
}
610+
603611
void operator()(ProtocolConformanceRef conformance){
604612
// Make sure we have the right conformance.
605613
assert(!requirementSignature.empty() && "Too many conformances?");
606-
assert(conformance.getRequirement() ==
607-
requirementSignature.front().getSecondType()->castTo<ProtocolType>()->getDecl());
614+
assert(conformance.isInvalid() ||
615+
conformance.getRequirement() ==
616+
requirementSignature.front().getSecondType()
617+
->castTo<ProtocolType>()->getDecl());
608618
assert((!conformance.isConcrete() ||
609619
!conformance.getConcrete()->getType()->hasArchetype()) &&
610620
"signature conformances must use interface types");

0 commit comments

Comments
 (0)