Skip to content

Commit 738f232

Browse files
committed
Merge tag 'swift-DEVELOPMENT-SNAPSHOT-2019-10-31-a' into tensorflow-merge
Tag build swift-DEVELOPMENT-SNAPSHOT-2019-10-31-a
2 parents 2f1306e + d3461e1 commit 738f232

File tree

109 files changed

+1599
-1730
lines changed

Some content is hidden

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

109 files changed

+1599
-1730
lines changed

include/swift/AST/Decl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -807,10 +807,10 @@ class alignas(1 << DeclAlignInBits) Decl {
807807
bool walk(ASTWalker &walker);
808808

809809
/// Return whether this declaration has been determined invalid.
810-
bool isInvalid() const { return Bits.Decl.Invalid; }
810+
bool isInvalid() const;
811811

812812
/// Mark this declaration invalid.
813-
void setInvalid(bool isInvalid = true) { Bits.Decl.Invalid = isInvalid; }
813+
void setInvalid();
814814

815815
/// Determine whether this declaration was implicitly generated by the
816816
/// compiler (rather than explicitly written in source code).

include/swift/AST/DiagnosticConsumer.h

Lines changed: 19 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ struct DiagnosticInfo {
4545
DiagnosticKind Kind;
4646
StringRef FormatString;
4747
ArrayRef<DiagnosticArgument> FormatArgs;
48+
49+
/// Only used when directing diagnostics to different outputs.
50+
/// In batch mode a diagnostic may be
51+
/// located in a non-primary file, but there will be no .dia file for a
52+
/// non-primary. If valid, this argument contains a location within a buffer
53+
/// that corresponds to a primary input. The .dia file for that primary can be
54+
/// used for the diagnostic, as if it had occurred at this location.
4855
SourceLoc BufferIndirectlyCausingDiagnostic;
4956

5057
/// DiagnosticInfo of notes which are children of this diagnostic, if any
@@ -109,29 +116,9 @@ class DiagnosticConsumer {
109116
/// \param SM The source manager associated with the source locations in
110117
/// this diagnostic.
111118
///
112-
/// \param Loc The source location associated with this diagnostic. This
113-
/// location may be invalid, if the diagnostic is not directly related to
114-
/// the source (e.g., if it comes from command-line parsing).
115-
///
116-
/// \param Kind The severity of the diagnostic (error, warning, note).
117-
///
118-
/// \param FormatArgs The diagnostic format string arguments.
119-
///
120-
/// \param Info Extra information associated with the diagnostic.
121-
///
122-
/// \param bufferIndirectlyCausingDiagnostic Only used when directing
123-
/// diagnostics to different outputs.
124-
/// In batch mode a diagnostic may be
125-
/// located in a non-primary file, but there will be no .dia file for a
126-
/// non-primary. If valid, this argument contains a location within a buffer
127-
/// that corresponds to a primary input. The .dia file for that primary can be
128-
/// used for the diagnostic, as if it had occurred at this location.
129-
virtual void
130-
handleDiagnostic(SourceManager &SM, SourceLoc Loc, DiagnosticKind Kind,
131-
StringRef FormatString,
132-
ArrayRef<DiagnosticArgument> FormatArgs,
133-
const DiagnosticInfo &Info,
134-
SourceLoc bufferIndirectlyCausingDiagnostic) = 0;
119+
/// \param Info Information describing the diagnostic.
120+
virtual void handleDiagnostic(SourceManager &SM,
121+
const DiagnosticInfo &Info) = 0;
135122

136123
/// \returns true if an error occurred while finishing-up.
137124
virtual bool finishProcessing() { return false; }
@@ -149,11 +136,7 @@ class DiagnosticConsumer {
149136
/// DiagnosticConsumer that discards all diagnostics.
150137
class NullDiagnosticConsumer : public DiagnosticConsumer {
151138
public:
152-
void handleDiagnostic(SourceManager &SM, SourceLoc Loc, DiagnosticKind Kind,
153-
StringRef FormatString,
154-
ArrayRef<DiagnosticArgument> FormatArgs,
155-
const DiagnosticInfo &Info,
156-
SourceLoc bufferIndirectlyCausingDiagnostic) override;
139+
void handleDiagnostic(SourceManager &SM, const DiagnosticInfo &Info) override;
157140
};
158141

159142
/// DiagnosticConsumer that forwards diagnostics to the consumers of
@@ -162,11 +145,7 @@ class ForwardingDiagnosticConsumer : public DiagnosticConsumer {
162145
DiagnosticEngine &TargetEngine;
163146
public:
164147
ForwardingDiagnosticConsumer(DiagnosticEngine &Target);
165-
void handleDiagnostic(SourceManager &SM, SourceLoc Loc, DiagnosticKind Kind,
166-
StringRef FormatString,
167-
ArrayRef<DiagnosticArgument> FormatArgs,
168-
const DiagnosticInfo &Info,
169-
SourceLoc bufferIndirectlyCausingDiagnostic) override;
148+
void handleDiagnostic(SourceManager &SM, const DiagnosticInfo &Info) override;
170149
};
171150

172151
/// DiagnosticConsumer that funnels diagnostics in certain files to
@@ -228,18 +207,13 @@ class FileSpecificDiagnosticConsumer : public DiagnosticConsumer {
228207
std::unique_ptr<DiagnosticConsumer> consumer)
229208
: inputFileName(inputFileName), consumer(std::move(consumer)) {}
230209

231-
void handleDiagnostic(SourceManager &SM, SourceLoc Loc, DiagnosticKind Kind,
232-
StringRef FormatString,
233-
ArrayRef<DiagnosticArgument> FormatArgs,
234-
const DiagnosticInfo &Info,
235-
const SourceLoc bufferIndirectlyCausingDiagnostic) {
210+
void handleDiagnostic(SourceManager &SM, const DiagnosticInfo &Info) {
236211
if (!getConsumer())
237212
return;
238-
hasAnErrorBeenConsumed |= Kind == DiagnosticKind::Error;
239-
getConsumer()->handleDiagnostic(SM, Loc, Kind, FormatString, FormatArgs,
240-
Info, bufferIndirectlyCausingDiagnostic);
213+
hasAnErrorBeenConsumed |= Info.Kind == DiagnosticKind::Error;
214+
getConsumer()->handleDiagnostic(SM, Info);
241215
}
242-
216+
243217
void informDriverOfIncompleteBatchModeCompilation() {
244218
if (!hasAnErrorBeenConsumed && getConsumer())
245219
getConsumer()->informDriverOfIncompleteBatchModeCompilation();
@@ -324,11 +298,7 @@ class FileSpecificDiagnosticConsumer : public DiagnosticConsumer {
324298
SmallVectorImpl<Subconsumer> &consumers);
325299

326300
public:
327-
void handleDiagnostic(SourceManager &SM, SourceLoc Loc, DiagnosticKind Kind,
328-
StringRef FormatString,
329-
ArrayRef<DiagnosticArgument> FormatArgs,
330-
const DiagnosticInfo &Info,
331-
SourceLoc bufferIndirectlyCausingDiagnostic) override;
301+
void handleDiagnostic(SourceManager &SM, const DiagnosticInfo &Info) override;
332302

333303
bool finishProcessing() override;
334304

@@ -348,12 +318,10 @@ class FileSpecificDiagnosticConsumer : public DiagnosticConsumer {
348318
subconsumerForLocation(SourceManager &SM, SourceLoc loc);
349319

350320
Optional<FileSpecificDiagnosticConsumer::Subconsumer *>
351-
findSubconsumer(SourceManager &SM, SourceLoc loc, DiagnosticKind Kind,
352-
SourceLoc bufferIndirectlyCausingDiagnostic);
321+
findSubconsumer(SourceManager &SM, const DiagnosticInfo &Info);
353322

354323
Optional<FileSpecificDiagnosticConsumer::Subconsumer *>
355-
findSubconsumerForNonNote(SourceManager &SM, SourceLoc loc,
356-
SourceLoc bufferIndirectlyCausingDiagnostic);
324+
findSubconsumerForNonNote(SourceManager &SM, const DiagnosticInfo &Info);
357325
};
358326

359327
} // end namespace swift

include/swift/AST/TypeCheckRequests.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,6 +1634,26 @@ class SynthesizeDefaultInitRequest
16341634
bool isCached() const { return true; }
16351635
};
16361636

1637+
class CompareDeclSpecializationRequest
1638+
: public SimpleRequest<CompareDeclSpecializationRequest,
1639+
bool(DeclContext *, ValueDecl *, ValueDecl *, bool),
1640+
CacheKind::Cached> {
1641+
public:
1642+
using SimpleRequest::SimpleRequest;
1643+
1644+
private:
1645+
friend SimpleRequest;
1646+
1647+
// Evaluation.
1648+
llvm::Expected<bool> evaluate(Evaluator &evaluator, DeclContext *DC,
1649+
ValueDecl *VD1, ValueDecl *VD2,
1650+
bool dynamic) const;
1651+
1652+
public:
1653+
// Caching.
1654+
bool isCached() const { return true; }
1655+
};
1656+
16371657
// Allow AnyValue to compare two Type values, even though Type doesn't
16381658
// support ==.
16391659
template<>

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ SWIFT_REQUEST(TypeChecker, AttachedPropertyWrappersRequest,
2929
NoLocationInfo)
3030
SWIFT_REQUEST(TypeChecker, ClassAncestryFlagsRequest,
3131
AncestryFlags(ClassDecl *), Cached, NoLocationInfo)
32+
SWIFT_REQUEST(TypeChecker, CompareDeclSpecializationRequest,
33+
bool (DeclContext *, ValueDecl *, ValueDecl *, bool), Cached,
34+
NoLocationInfo)
3235
SWIFT_REQUEST(TypeChecker, DefaultDefinitionTypeRequest,
3336
Type(AssociatedTypeDecl *), Cached, NoLocationInfo)
3437
SWIFT_REQUEST(TypeChecker, DefaultTypeRequest,

include/swift/Frontend/PrintingDiagnosticConsumer.h

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,8 @@ class PrintingDiagnosticConsumer : public DiagnosticConsumer {
3535
PrintingDiagnosticConsumer(llvm::raw_ostream &stream = llvm::errs()) :
3636
Stream(stream) { }
3737

38-
virtual void
39-
handleDiagnostic(SourceManager &SM, SourceLoc Loc, DiagnosticKind Kind,
40-
StringRef FormatString,
41-
ArrayRef<DiagnosticArgument> FormatArgs,
42-
const DiagnosticInfo &Info,
43-
SourceLoc bufferIndirectlyCausingDiagnostic) override;
38+
virtual void handleDiagnostic(SourceManager &SM,
39+
const DiagnosticInfo &Info) override;
4440

4541
void forceColors() {
4642
ForceColors = true;
@@ -52,11 +48,7 @@ class PrintingDiagnosticConsumer : public DiagnosticConsumer {
5248
}
5349

5450
private:
55-
void printDiagnostic(SourceManager &SM, SourceLoc Loc, DiagnosticKind Kind,
56-
StringRef FormatString,
57-
ArrayRef<DiagnosticArgument> FormatArgs,
58-
const DiagnosticInfo &Info,
59-
SourceLoc bufferIndirectlyCausingDiagnostic);
51+
void printDiagnostic(SourceManager &SM, const DiagnosticInfo &Info);
6052
};
6153

6254
}

include/swift/Migrator/FixitApplyDiagnosticConsumer.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,7 @@ class FixitApplyDiagnosticConsumer final
6262
/// output stream.
6363
void printResult(llvm::raw_ostream &OS) const;
6464

65-
void handleDiagnostic(SourceManager &SM, SourceLoc Loc, DiagnosticKind Kind,
66-
StringRef FormatString,
67-
ArrayRef<DiagnosticArgument> FormatArgs,
68-
const DiagnosticInfo &Info,
69-
SourceLoc bufferIndirectlyCausingDiagnostic) override;
65+
void handleDiagnostic(SourceManager &SM, const DiagnosticInfo &Info) override;
7066

7167
unsigned getNumFixitsApplied() const {
7268
return NumFixitsApplied;

include/swift/Migrator/FixitFilter.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ namespace migrator {
2525

2626
struct FixitFilter {
2727
/// Returns true if the fix-it should be applied.
28-
bool shouldTakeFixit(const DiagnosticKind Kind,
29-
const DiagnosticInfo &Info) const {
28+
bool shouldTakeFixit(const DiagnosticInfo &Info) const {
3029
// Do not add a semi or comma as it is wrong in most cases during migration
3130
if (Info.ID == diag::statement_same_line_without_semi.ID ||
3231
Info.ID == diag::declaration_same_line_without_semi.ID ||
@@ -114,7 +113,7 @@ struct FixitFilter {
114113
return false;
115114
}
116115

117-
if (Kind == DiagnosticKind::Error)
116+
if (Info.Kind == DiagnosticKind::Error)
118117
return true;
119118

120119
// Fixits from warnings/notes that should be applied.

lib/AST/ASTMangler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2461,7 +2461,7 @@ CanType ASTMangler::getDeclTypeForMangling(
24612461
parentGenericSig = GenericSignature();
24622462

24632463
auto &C = decl->getASTContext();
2464-
if (!decl->getInterfaceType() || decl->getInterfaceType()->is<ErrorType>()) {
2464+
if (decl->isInvalid()) {
24652465
if (isa<AbstractFunctionDecl>(decl))
24662466
return CanFunctionType::get({AnyFunctionType::Param(C.TheErrorType)},
24672467
C.TheErrorType);

lib/AST/ASTPrinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2875,7 +2875,7 @@ void PrintAST::printEnumElement(EnumElementDecl *elt) {
28752875

28762876

28772877
auto params = ArrayRef<AnyFunctionType::Param>();
2878-
if (elt->hasInterfaceType() && !elt->getInterfaceType()->hasError()) {
2878+
if (elt->hasInterfaceType() && !elt->isInvalid()) {
28792879
// Walk to the params of the associated values.
28802880
// (EnumMetaType) -> (AssocValues) -> Enum
28812881
params = elt->getInterfaceType()->castTo<AnyFunctionType>()
@@ -2972,7 +2972,7 @@ void PrintAST::visitSubscriptDecl(SubscriptDecl *decl) {
29722972
}, [&] { // Parameters
29732973
printGenericDeclGenericParams(decl);
29742974
auto params = ArrayRef<AnyFunctionType::Param>();
2975-
if (decl->hasInterfaceType() && !decl->getInterfaceType()->hasError()) {
2975+
if (decl->hasInterfaceType() && !decl->isInvalid()) {
29762976
// Walk to the params of the subscript's indices.
29772977
params = decl->getInterfaceType()->castTo<AnyFunctionType>()->getParams();
29782978
}

lib/AST/AccessRequests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ AccessLevelRequest::evaluate(Evaluator &evaluator, ValueDecl *D) const {
8181
// Special case for dtors and enum elements: inherit from container
8282
if (D->getKind() == DeclKind::Destructor ||
8383
D->getKind() == DeclKind::EnumElement) {
84-
if (D->isInvalid()) {
84+
if (D->hasInterfaceType() && D->isInvalid()) {
8585
return AccessLevel::Private;
8686
} else {
8787
auto container = cast<NominalTypeDecl>(D->getDeclContext());

lib/AST/Decl.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,77 @@ DeclContext *Decl::getInnermostDeclContext() const {
376376
return getDeclContext();
377377
}
378378

379+
bool Decl::isInvalid() const {
380+
switch (getKind()) {
381+
#define VALUE_DECL(ID, PARENT)
382+
#define DECL(ID, PARENT) \
383+
case DeclKind::ID:
384+
#include "swift/AST/DeclNodes.def"
385+
return Bits.Decl.Invalid;
386+
case DeclKind::Param: {
387+
// Parameters are special because closure parameters may not have type
388+
// annotations. In which case, the interface type request returns
389+
// ErrorType. Therefore, consider parameters with implicit types to always
390+
// be valid.
391+
auto *PD = cast<ParamDecl>(this);
392+
if (!PD->getTypeRepr() && !PD->hasInterfaceType())
393+
return false;
394+
}
395+
LLVM_FALLTHROUGH;
396+
case DeclKind::Enum:
397+
case DeclKind::Struct:
398+
case DeclKind::Class:
399+
case DeclKind::Protocol:
400+
case DeclKind::OpaqueType:
401+
case DeclKind::TypeAlias:
402+
case DeclKind::GenericTypeParam:
403+
case DeclKind::AssociatedType:
404+
case DeclKind::Module:
405+
case DeclKind::Var:
406+
case DeclKind::Subscript:
407+
case DeclKind::Constructor:
408+
case DeclKind::Destructor:
409+
case DeclKind::Func:
410+
case DeclKind::Accessor:
411+
case DeclKind::EnumElement:
412+
return cast<ValueDecl>(this)->getInterfaceType()->hasError();
413+
}
414+
415+
llvm_unreachable("Unknown decl kind");
416+
}
417+
418+
void Decl::setInvalid() {
419+
switch (getKind()) {
420+
#define VALUE_DECL(ID, PARENT)
421+
#define DECL(ID, PARENT) \
422+
case DeclKind::ID:
423+
#include "swift/AST/DeclNodes.def"
424+
Bits.Decl.Invalid = true;
425+
return;
426+
case DeclKind::Enum:
427+
case DeclKind::Struct:
428+
case DeclKind::Class:
429+
case DeclKind::Protocol:
430+
case DeclKind::OpaqueType:
431+
case DeclKind::TypeAlias:
432+
case DeclKind::GenericTypeParam:
433+
case DeclKind::AssociatedType:
434+
case DeclKind::Module:
435+
case DeclKind::Var:
436+
case DeclKind::Param:
437+
case DeclKind::Subscript:
438+
case DeclKind::Constructor:
439+
case DeclKind::Destructor:
440+
case DeclKind::Func:
441+
case DeclKind::Accessor:
442+
case DeclKind::EnumElement:
443+
cast<ValueDecl>(this)->setInterfaceType(ErrorType::get(getASTContext()));
444+
return;
445+
}
446+
447+
llvm_unreachable("Unknown decl kind");
448+
}
449+
379450
void Decl::setDeclContext(DeclContext *DC) {
380451
Context = DC;
381452
}

0 commit comments

Comments
 (0)