Skip to content

Commit ff93177

Browse files
committed
Merge branch 'master_2' into tensorflow
2 parents e936fb9 + 1a1f731 commit ff93177

File tree

178 files changed

+1418
-7356
lines changed

Some content is hidden

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

178 files changed

+1418
-7356
lines changed

docs/Diagnostics.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,19 @@ Most diagnostics have no reason to change behavior under editor mode. An example
104104
- `%error` - Represents a branch in a `%select` that should never be taken. In debug builds of the compiler this produces an assertion failure.
105105

106106
- `%%` - Emits a literal percent sign.
107+
108+
### Diagnostic Verifier ###
109+
110+
(This section is specific to the Swift compiler's diagnostic engine.)
111+
112+
If the `-verify` frontend flag is used, the Swift compiler will check emitted diagnostics against specially formatted comments in the source. This feature is used extensively throughout the test suite to ensure diagnostics are emitted with the correct message and source location.
113+
114+
An expected diagnostic is denoted by a comment which begins with `expected-error`, `expected-warning`, `expected-note`, or `expected-remark`. It is followed by:
115+
116+
- (Optional) Location information. By default, the comment will match any diagnostic emitted on the same line. However, it's possible to override this behavior and/or specify column information as well. `// expected-error@-1 ...` looks for an error on the previous line, `// expected-warning@+1:3 ...` looks for a warning on the next line at the third column, and `// expected-note@:7 ...` looks for a note on the same line at the seventh column.
117+
118+
- (Optional) A match count which specifies how many times the diagnostic is expected to appear. This may be a positive integer or `*`, which allows for zero or more matches. The match count must be surrounded by whitespace if present. For example, `// expected-error 2 ...` looks for two matching errors, and `// expected-warning * ...` looks for any number of matching warnings.
119+
120+
- (Required) The expected error message. The message should be enclosed in double curly braces and should not include the `error:`/`warning:`/`note:`/`remark:` prefix. For example, `// expected-error {{invalid redeclaration of 'y'}}` would match an error with that message on the same line. The expected message does not need to match the emitted message verbatim. As long as the expected message is a substring of the original message, they will match.
121+
122+
- (Optional) Expected fix-its. These are each enclosed in double curly braces and appear after the expected message. An expected fix-it consists of a column range followed by the text it's expected to be replaced with. For example, `let r : Int i = j // expected-error{{consecutive statements}} {{12-12=;}}` will match a fix-it attached to the consecutive statements error which inserts a semicolon at column 12, just after the 't' in 'Int'. The special {{none}} specifier is also supported, which will cause the diagnostic match to fail if unexpected fix-its are produced.

docs/Testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ code for the target that is not the build machine:
232232

233233
* ``%target-typecheck-verify-swift``: parse and type check the current Swift file
234234
for the target platform and verify diagnostics, like ``swift -frontend -typecheck -verify
235-
%s``.
235+
%s``. For further explanation of `-verify` mode, see [Diagnostics.md](Diagnostics.md).
236236

237237
Use this substitution for testing semantic analysis in the compiler.
238238

include/swift/AST/ASTNode.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ namespace swift {
3636
enum class DeclKind : uint8_t;
3737
enum class StmtKind;
3838

39-
struct ASTNode : public llvm::PointerUnion3<Expr*, Stmt*, Decl*> {
39+
struct ASTNode : public llvm::PointerUnion<Expr*, Stmt*, Decl*> {
4040
// Inherit the constructors from PointerUnion.
41-
using PointerUnion3::PointerUnion3;
42-
41+
using PointerUnion::PointerUnion;
42+
4343
SourceRange getSourceRange() const;
4444

4545
/// Return the location of the start of the statement.

include/swift/AST/Decl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4834,7 +4834,7 @@ class VarDecl : public AbstractStorageDecl {
48344834
};
48354835

48364836
protected:
4837-
PointerUnion3<PatternBindingDecl *, Stmt *, VarDecl *> Parent;
4837+
PointerUnion<PatternBindingDecl *, Stmt *, VarDecl *> Parent;
48384838

48394839
VarDecl(DeclKind kind, bool isStatic, Introducer introducer,
48404840
bool issCaptureList, SourceLoc nameLoc, Identifier name,

include/swift/AST/DiagnosticsClangImporter.def

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@ WARNING(implicit_bridging_header_imported_from_module,none,
9191
"is deprecated and will be removed in a later version of Swift",
9292
(StringRef, Identifier))
9393

94-
WARNING(clang_vfs_overlay_is_ignored,none,
95-
"ignoring '-ivfsoverlay' options provided to '-Xcc' in favor of "
96-
"'-vfsoverlay'", ())
97-
9894
#ifndef DIAG_NO_UNDEF
9995
# if defined(DIAG)
10096
# undef DIAG

include/swift/AST/GenericSignatureBuilder.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ class GenericSignatureBuilder {
9292
class ResolvedType;
9393

9494
using UnresolvedRequirementRHS =
95-
llvm::PointerUnion3<Type, PotentialArchetype *, LayoutConstraint>;
95+
llvm::PointerUnion<Type, PotentialArchetype *, LayoutConstraint>;
9696

9797
using RequirementRHS =
98-
llvm::PointerUnion3<Type, PotentialArchetype *, LayoutConstraint>;
98+
llvm::PointerUnion<Type, PotentialArchetype *, LayoutConstraint>;
9999

100100
/// The location of a requirement as written somewhere in the source.
101101
typedef llvm::PointerUnion<const TypeRepr *, const RequirementRepr *>
@@ -1373,8 +1373,8 @@ class GenericSignatureBuilder::FloatingRequirementSource {
13731373
} kind;
13741374

13751375
using Storage =
1376-
llvm::PointerUnion3<const RequirementSource *, const TypeRepr *,
1377-
const RequirementRepr *>;
1376+
llvm::PointerUnion<const RequirementSource *, const TypeRepr *,
1377+
const RequirementRepr *>;
13781378

13791379
Storage storage;
13801380

include/swift/AST/ModuleLoader.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
#include "llvm/ADT/SmallSet.h"
2525
#include "llvm/ADT/TinyPtrVector.h"
2626

27+
namespace llvm {
28+
class FileCollector;
29+
}
30+
2731
namespace clang {
2832
class DependencyCollector;
2933
}
@@ -54,8 +58,9 @@ enum class Bridgeability : unsigned {
5458
class DependencyTracker {
5559
std::shared_ptr<clang::DependencyCollector> clangCollector;
5660
public:
57-
58-
explicit DependencyTracker(bool TrackSystemDeps);
61+
explicit DependencyTracker(
62+
bool TrackSystemDeps,
63+
std::shared_ptr<llvm::FileCollector> FileCollector = {});
5964

6065
/// Adds a file as a dependency.
6166
///

include/swift/AST/TypeCheckRequests.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,9 @@ struct WhereClauseOwner {
367367

368368
/// The source of the where clause, which can be a generic parameter list
369369
/// or a declaration that can have a where clause.
370-
llvm::PointerUnion4<GenericParamList *, Decl *, SpecializeAttr *,
371-
// SWIFT_ENABLE_TENSORFLOW
372-
DifferentiableAttr *>
370+
llvm::PointerUnion<GenericParamList *, Decl *, SpecializeAttr *,
371+
// SWIFT_ENABLE_TENSORFLOW
372+
DifferentiableAttr *>
373373
source;
374374

375375
WhereClauseOwner(Decl *decl);

include/swift/Basic/LLVM.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ namespace llvm {
4242
template<typename T> class MutableArrayRef;
4343
template<typename T> class TinyPtrVector;
4444
template<typename T> class Optional;
45-
template <typename PT1, typename PT2> class PointerUnion;
46-
template <typename PT1, typename PT2, typename PT3> class PointerUnion3;
45+
template <typename ...PTs> class PointerUnion;
4746
class SmallBitVector;
4847

4948
// Other common classes.
@@ -68,7 +67,6 @@ namespace swift {
6867
using llvm::None;
6968
using llvm::Optional;
7069
using llvm::PointerUnion;
71-
using llvm::PointerUnion3;
7270
using llvm::SmallBitVector;
7371
using llvm::SmallPtrSet;
7472
using llvm::SmallPtrSetImpl;

include/swift/ClangImporter/ClangImporter.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
namespace llvm {
2525
class Triple;
26+
class FileCollector;
2627
template<typename Fn> class function_ref;
2728
}
2829

@@ -149,7 +150,8 @@ class ClangImporter final : public ClangModuleLoader {
149150
/// Create a new clang::DependencyCollector customized to
150151
/// ClangImporter's specific uses.
151152
static std::shared_ptr<clang::DependencyCollector>
152-
createDependencyCollector(bool TrackSystemDeps);
153+
createDependencyCollector(bool TrackSystemDeps,
154+
std::shared_ptr<llvm::FileCollector> FileCollector);
153155

154156
/// Append visible module names to \p names. Note that names are possibly
155157
/// duplicated, and not guaranteed to be ordered in any way.

include/swift/ClangImporter/ClangImporterOptions.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,6 @@ class ClangImporterOptions {
9898
/// When set, don't enforce warnings with -Werror.
9999
bool DebuggerSupport = false;
100100

101-
/// When set, clobber the Clang instance's virtual file system with the Swift
102-
/// virtual file system.
103-
bool ForceUseSwiftVirtualFileSystem = false;
104-
105101
// SWIFT_ENABLE_TENSORFLOW
106102
/// When set, clang writes its output files (module caches) to this instead
107103
/// of to the real filesystem.

include/swift/LLVMPasses/Passes.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,14 @@ namespace swift {
3030
const llvm::PreservedAnalyses &) { return false; }
3131

3232
using AAResultBase::getModRefInfo;
33-
llvm::ModRefInfo getModRefInfo(llvm::ImmutableCallSite CS,
34-
const llvm::MemoryLocation &Loc);
33+
llvm::ModRefInfo getModRefInfo(const llvm::CallBase *Call,
34+
const llvm::MemoryLocation &Loc) {
35+
llvm::AAQueryInfo AAQI;
36+
return getModRefInfo(Call, Loc, AAQI);
37+
}
38+
llvm::ModRefInfo getModRefInfo(const llvm::CallBase *Call,
39+
const llvm::MemoryLocation &Loc,
40+
llvm::AAQueryInfo &AAQI);
3541
};
3642

3743
class SwiftAAWrapperPass : public llvm::ImmutablePass {

include/swift/Parse/ASTGen.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "swift/AST/ASTContext.h"
1717
#include "swift/AST/Decl.h"
1818
#include "swift/AST/Expr.h"
19+
#include "swift/AST/TypeRepr.h"
1920
#include "swift/Parse/PersistentParserState.h"
2021
#include "swift/Syntax/SyntaxNodes.h"
2122
#include "llvm/ADT/DenseMap.h"
@@ -46,6 +47,30 @@ class ASTGen {
4647

4748
SourceLoc generate(const syntax::TokenSyntax &Tok, const SourceLoc Loc);
4849

50+
SourceLoc generateIdentifierDeclName(const syntax::TokenSyntax &Tok,
51+
const SourceLoc, Identifier &Identifier);
52+
53+
public:
54+
//===--------------------------------------------------------------------===//
55+
// Decls.
56+
57+
Decl *generate(const syntax::DeclSyntax &Decl, const SourceLoc Loc);
58+
TypeDecl *generate(const syntax::AssociatedtypeDeclSyntax &Decl,
59+
const SourceLoc Loc);
60+
61+
TrailingWhereClause *generate(const syntax::GenericWhereClauseSyntax &syntax,
62+
const SourceLoc Loc);
63+
MutableArrayRef<TypeLoc>
64+
generate(const syntax::TypeInheritanceClauseSyntax &syntax,
65+
const SourceLoc Loc, bool allowClassRequirement);
66+
67+
private:
68+
DeclAttributes
69+
generateDeclAttributes(const syntax::DeclSyntax &D,
70+
const Optional<syntax::AttributeListSyntax> &attrs,
71+
const Optional<syntax::ModifierListSyntax> &modifiers,
72+
SourceLoc Loc, bool includeComments);
73+
4974
public:
5075
//===--------------------------------------------------------------------===//
5176
// Expressions.
@@ -100,6 +125,8 @@ class ASTGen {
100125
const SourceLoc Loc);
101126
TypeRepr *generate(const syntax::ImplicitlyUnwrappedOptionalTypeSyntax &Type,
102127
const SourceLoc Loc);
128+
TypeRepr *generate(const syntax::ClassRestrictionTypeSyntax &Type,
129+
const SourceLoc Loc);
103130
TypeRepr *generate(const syntax::CodeCompletionTypeSyntax &Type,
104131
const SourceLoc Loc);
105132
TypeRepr *generate(const syntax::UnknownTypeSyntax &Type,

include/swift/Parse/LibSyntaxGenerator.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@ class LibSyntaxGenerator {
3838
assert(Node.isDeferredToken());
3939

4040
auto Kind = Node.getTokenKind();
41-
auto Range = Node.getDeferredTokenRangeWithTrivia();
41+
auto Range = Node.getDeferredTokenRange();
4242
auto LeadingTriviaPieces = Node.getDeferredLeadingTriviaPieces();
4343
auto TrailingTriviaPieces = Node.getDeferredTrailingTriviaPieces();
4444

4545
auto Recorded = Recorder.recordToken(Kind, Range, LeadingTriviaPieces,
4646
TrailingTriviaPieces);
47-
auto Raw = static_cast<RawSyntax *>(Recorded.takeOpaqueNode());
47+
RC<RawSyntax> Raw{static_cast<RawSyntax *>(Recorded.takeOpaqueNode())};
48+
Raw->Release(); // -1 since it's transfer of ownership.
4849
return make<TokenSyntax>(Raw);
4950
}
5051

@@ -55,7 +56,7 @@ class LibSyntaxGenerator {
5556
auto Children = Node.getDeferredChildren();
5657

5758
auto Recorded = Recorder.recordRawSyntax(Kind, Children);
58-
RC<RawSyntax> Raw {static_cast<RawSyntax *>(Recorded.takeOpaqueNode()) };
59+
RC<RawSyntax> Raw{static_cast<RawSyntax *>(Recorded.takeOpaqueNode())};
5960
Raw->Release(); // -1 since it's transfer of ownership.
6061
return make<SyntaxNode>(Raw);
6162
}

include/swift/Parse/Parser.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#include "llvm/ADT/SetVector.h"
4141

4242
namespace llvm {
43-
template <typename PT1, typename PT2, typename PT3> class PointerUnion3;
43+
template <typename... PTs> class PointerUnion;
4444
}
4545

4646
namespace swift {
@@ -1011,12 +1011,23 @@ class Parser {
10111011
bool delayParsingDeclList(SourceLoc LBLoc, SourceLoc &RBLoc,
10121012
IterableDeclContext *IDC);
10131013

1014+
ParsedSyntaxResult<ParsedTypeInheritanceClauseSyntax>
1015+
parseTypeInheritanceClauseSyntax(bool allowClassRequirement,
1016+
bool allowAnyObject);
1017+
1018+
ParsedSyntaxResult<ParsedDeclSyntax>
1019+
parseDeclAssociatedTypeSyntax(ParseDeclOptions flags,
1020+
Optional<ParsedAttributeListSyntax> attrs,
1021+
Optional<ParsedModifierListSyntax> modifiers);
1022+
10141023
ParserResult<TypeDecl> parseDeclTypeAlias(ParseDeclOptions Flags,
1015-
DeclAttributes &Attributes);
1024+
DeclAttributes &Attributes,
1025+
SourceLoc leadingLoc);
10161026

10171027
ParserResult<TypeDecl> parseDeclAssociatedType(ParseDeclOptions Flags,
1018-
DeclAttributes &Attributes);
1019-
1028+
DeclAttributes &Attributes,
1029+
SourceLoc leadingLoc);
1030+
10201031
/// Parse a #if ... #endif directive.
10211032
/// Delegate callback function to parse elements in the blocks.
10221033
ParserResult<IfConfigDecl> parseIfConfig(
@@ -1127,7 +1138,7 @@ class Parser {
11271138

11281139
ParserResult<ImportDecl> parseDeclImport(ParseDeclOptions Flags,
11291140
DeclAttributes &Attributes);
1130-
ParserStatus parseInheritance(SmallVectorImpl<TypeLoc> &Inherited,
1141+
ParserStatus parseInheritance(MutableArrayRef<TypeLoc> &Inherited,
11311142
bool allowClassRequirement,
11321143
bool allowAnyObject);
11331144
ParserStatus parseDeclItem(bool &PreviousHadSemi,

include/swift/Parse/SyntaxParsingContext.h

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -279,17 +279,9 @@ class alignas(1 << SyntaxAlignInBits) SyntaxParsingContext {
279279
}
280280

281281
/// Returns the topmost Syntax node.
282-
template <typename SyntaxNode> SyntaxNode topNode() {
283-
ParsedRawSyntaxNode &TopNode = getStorage().back();
284-
if (TopNode.isRecorded()) {
285-
OpaqueSyntaxNode OpaqueNode = TopNode.getOpaqueNode();
286-
return getSyntaxCreator().getLibSyntaxNodeFor<SyntaxNode>(OpaqueNode);
287-
}
288-
return getSyntaxCreator().createNode<SyntaxNode>(TopNode.copyDeferred());
289-
}
282+
template <typename SyntaxNode> SyntaxNode topNode();
290283

291-
template <typename SyntaxNode>
292-
llvm::Optional<SyntaxNode> popIf() {
284+
template <typename SyntaxNode> llvm::Optional<SyntaxNode> popIf() {
293285
auto &Storage = getStorage();
294286
if (Storage.size() <= Offset)
295287
return llvm::None;
@@ -376,5 +368,24 @@ class alignas(1 << SyntaxAlignInBits) SyntaxParsingContext {
376368
"Only meant for use in the debugger");
377369
};
378370

371+
template <typename SyntaxNode>
372+
inline SyntaxNode SyntaxParsingContext::topNode() {
373+
ParsedRawSyntaxNode &TopNode = getStorage().back();
374+
if (TopNode.isRecorded()) {
375+
OpaqueSyntaxNode OpaqueNode = TopNode.getOpaqueNode();
376+
return getSyntaxCreator().getLibSyntaxNodeFor<SyntaxNode>(OpaqueNode);
377+
}
378+
return getSyntaxCreator().createNode<SyntaxNode>(TopNode.copyDeferred());
379+
}
380+
381+
template <> inline TokenSyntax SyntaxParsingContext::topNode<TokenSyntax>() {
382+
ParsedRawSyntaxNode &TopNode = getStorage().back();
383+
if (TopNode.isRecorded()) {
384+
OpaqueSyntaxNode OpaqueNode = TopNode.getOpaqueNode();
385+
return getSyntaxCreator().getLibSyntaxNodeFor<TokenSyntax>(OpaqueNode);
386+
}
387+
return getSyntaxCreator().createToken(TopNode.copyDeferred());
388+
}
389+
379390
} // namespace swift
380391
#endif // SWIFT_SYNTAX_PARSING_CONTEXT_H

include/swift/SILOptimizer/Analysis/LoopRegionAnalysis.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ class LoopRegion {
384384
private:
385385
/// A pointer to one of a Loop, Basic Block, or Function represented by this
386386
/// region.
387-
llvm::PointerUnion3<FunctionTy *, LoopTy *, BlockTy *> Ptr;
387+
llvm::PointerUnion<FunctionTy *, LoopTy *, BlockTy *> Ptr;
388388

389389
/// The ID of this region.
390390
unsigned ID;

include/swift/Syntax/Syntax.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class Syntax {
8383
SyntaxKind getKind() const;
8484

8585
/// Get the shared raw syntax.
86-
RC<RawSyntax> getRaw() const;
86+
const RC<RawSyntax> &getRaw() const;
8787

8888
/// Get an ID for this node that is stable across incremental parses
8989
SyntaxNodeId getId() const { return getRaw()->getId(); }

include/swift/Syntax/SyntaxData.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class SyntaxData final
186186
CursorIndex IndexInParent = 0);
187187

188188
/// Returns the raw syntax node for this syntax node.
189-
const RC<RawSyntax> getRaw() const {
189+
const RC<RawSyntax> &getRaw() const {
190190
return Raw;
191191
}
192192

lib/AST/Builtins.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,6 +1481,7 @@ Type IntrinsicTypeDecoder::decodeImmediate() {
14811481
case IITDescriptor::HalfVecArgument:
14821482
case IITDescriptor::VarArg:
14831483
case IITDescriptor::Token:
1484+
case IITDescriptor::VecElementArgument:
14841485
case IITDescriptor::VecOfAnyPtrsToElt:
14851486
// These types cannot be expressed in swift yet.
14861487
return Type();

lib/AST/Decl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5164,6 +5164,10 @@ bool VarDecl::isSettable(const DeclContext *UseDC,
51645164
if (!isLet())
51655165
return supportsMutation();
51665166

5167+
// Debugger expression 'let's are initialized through a side-channel.
5168+
if (isDebuggerVar())
5169+
return false;
5170+
51675171
// We have a 'let'; we must be checking settability from a specific
51685172
// DeclContext to go on further.
51695173
if (UseDC == nullptr)

0 commit comments

Comments
 (0)