Skip to content

Commit 7b90628

Browse files
authored
Merge pull request swiftlang#27922 from CodaFi/bitflip
isInvalid() Is Finally Semantic
2 parents a5b8c64 + 0267384 commit 7b90628

Some content is hidden

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

53 files changed

+148
-208
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).

lib/AST/ASTMangler.cpp

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

23682368
auto &C = decl->getASTContext();
2369-
if (!decl->getInterfaceType() || decl->getInterfaceType()->is<ErrorType>()) {
2369+
if (decl->isInvalid()) {
23702370
if (isa<AbstractFunctionDecl>(decl))
23712371
return CanFunctionType::get({AnyFunctionType::Param(C.TheErrorType)},
23722372
C.TheErrorType);

lib/AST/ASTPrinter.cpp

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

28732873

28742874
auto params = ArrayRef<AnyFunctionType::Param>();
2875-
if (elt->hasInterfaceType() && !elt->getInterfaceType()->hasError()) {
2875+
if (elt->hasInterfaceType() && !elt->isInvalid()) {
28762876
// Walk to the params of the associated values.
28772877
// (EnumMetaType) -> (AssocValues) -> Enum
28782878
params = elt->getInterfaceType()->castTo<AnyFunctionType>()
@@ -2969,7 +2969,7 @@ void PrintAST::visitSubscriptDecl(SubscriptDecl *decl) {
29692969
}, [&] { // Parameters
29702970
printGenericDeclGenericParams(decl);
29712971
auto params = ArrayRef<AnyFunctionType::Param>();
2972-
if (decl->hasInterfaceType() && !decl->getInterfaceType()->hasError()) {
2972+
if (decl->hasInterfaceType() && !decl->isInvalid()) {
29732973
// Walk to the params of the subscript's indices.
29742974
params = decl->getInterfaceType()->castTo<AnyFunctionType>()->getParams();
29752975
}

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
}

lib/AST/Module.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,15 @@ void SourceLookupCache::addToUnqualifiedLookupCache(Range decls,
212212
if (!NTD->hasUnparsedMembers() || NTD->maybeHasOperatorDeclarations())
213213
addToUnqualifiedLookupCache(NTD->getMembers(), true);
214214

215-
// Avoid populating the cache with the members of invalid extension
216-
// declarations. These members can be used to point validation inside of
217-
// a malformed context.
218-
if (D->isInvalid()) continue;
215+
if (auto *ED = dyn_cast<ExtensionDecl>(D)) {
216+
// Avoid populating the cache with the members of invalid extension
217+
// declarations. These members can be used to point validation inside of
218+
// a malformed context.
219+
if (ED->isInvalid()) continue;
219220

220-
if (auto *ED = dyn_cast<ExtensionDecl>(D))
221221
if (!ED->hasUnparsedMembers() || ED->maybeHasOperatorDeclarations())
222222
addToUnqualifiedLookupCache(ED->getMembers(), true);
223+
}
223224
}
224225
}
225226

lib/AST/NameLookup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void DebuggerClient::anchor() {}
6969
void AccessFilteringDeclConsumer::foundDecl(
7070
ValueDecl *D, DeclVisibilityKind reason,
7171
DynamicLookupInfo dynamicLookupInfo) {
72-
if (D->isInvalid())
72+
if (D->hasInterfaceType() && D->isInvalid())
7373
return;
7474
if (!D->isAccessibleFrom(DC))
7575
return;

lib/AST/TypeCheckRequests.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,9 +1020,6 @@ void InterfaceTypeRequest::cacheResult(Type type) const {
10201020
assert(!type->hasTypeVariable() && "Type variable in interface type");
10211021
assert(!type->is<InOutType>() && "Interface type must be materializable");
10221022
assert(!type->hasArchetype() && "Archetype in interface type");
1023-
1024-
if (type->hasError())
1025-
decl->setInvalid();
10261023
}
10271024
decl->TypeAndAccess.setPointer(type);
10281025
}

lib/AST/USRGeneration.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,6 @@ swift::USRGenerationRequest::evaluate(Evaluator &evaluator,
258258
llvm::Expected<std::string>
259259
swift::MangleLocalTypeDeclRequest::evaluate(Evaluator &evaluator,
260260
const TypeDecl *D) const {
261-
if (!D->getInterfaceType())
262-
return std::string();
263-
264261
if (isa<ModuleDecl>(D))
265262
return std::string(); // Ignore.
266263

lib/IDE/CodeCompletion.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2431,8 +2431,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
24312431
addTypeAnnotation(Builder, AFT->getResult());
24322432
};
24332433

2434-
if (!AFD || !AFD->getInterfaceType() ||
2435-
!AFD->getInterfaceType()->is<AnyFunctionType>()) {
2434+
if (!AFD || !AFD->getInterfaceType()->is<AnyFunctionType>()) {
24362435
// Probably, calling closure type expression.
24372436
foundFunction(AFT);
24382437
addPattern();

0 commit comments

Comments
 (0)