Skip to content

Commit b135928

Browse files
committed
Drop CheckingWithValidSignature from the validation state machine
Now that the generic signature is computable on demand, this predicate is doubly useless. All of the callers intended to ask "hasInterfaceType" anyways.
1 parent ae60618 commit b135928

17 files changed

+34
-70
lines changed

include/swift/AST/Decl.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ class alignas(1 << DeclAlignInBits) Decl {
279279
enum class ValidationState {
280280
Unchecked,
281281
Checking,
282-
CheckingWithValidSignature,
283282
Checked,
284283
};
285284

@@ -850,19 +849,11 @@ class alignas(1 << DeclAlignInBits) Decl {
850849
case ValidationState::Checked:
851850
return false;
852851
case ValidationState::Checking:
853-
case ValidationState::CheckingWithValidSignature:
854852
return true;
855853
}
856854
llvm_unreachable("Unknown ValidationState");
857855
}
858856

859-
/// Update the validation state for the declaration to allow access to the
860-
/// generic signature.
861-
void setSignatureIsValidated() {
862-
assert(getValidationState() == ValidationState::Checking);
863-
setValidationState(ValidationState::CheckingWithValidSignature);
864-
}
865-
866857
bool hasValidationStarted() const {
867858
return getValidationState() > ValidationState::Unchecked;
868859
}
@@ -1769,11 +1760,6 @@ class ExtensionDecl final : public GenericContext, public Decl,
17691760

17701761
void setInherited(MutableArrayRef<TypeLoc> i) { Inherited = i; }
17711762

1772-
/// Whether we have fully checked the extension signature.
1773-
bool hasValidSignature() const {
1774-
return getValidationState() > ValidationState::CheckingWithValidSignature;
1775-
}
1776-
17771763
bool hasDefaultAccessLevel() const {
17781764
return Bits.ExtensionDecl.DefaultAndMaxAccessLevel != 0;
17791765
}
@@ -2608,8 +2594,6 @@ class ValueDecl : public Decl {
26082594

26092595
/// Set the interface type for the given value.
26102596
void setInterfaceType(Type type);
2611-
2612-
bool hasValidSignature() const;
26132597

26142598
/// isInstanceMember - Determine whether this value is an instance member
26152599
/// of an enum or protocol.

lib/AST/ASTVerifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2968,7 +2968,7 @@ class Verifier : public ASTWalker {
29682968
void verifyChecked(AbstractFunctionDecl *AFD) {
29692969
PrettyStackTraceDecl debugStack("verifying AbstractFunctionDecl", AFD);
29702970

2971-
if (!AFD->hasValidSignature()) {
2971+
if (!AFD->hasInterfaceType()) {
29722972
if (isa<AccessorDecl>(AFD) && AFD->isImplicit())
29732973
return;
29742974

lib/AST/Decl.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2720,14 +2720,6 @@ void ValueDecl::setInterfaceType(Type type) {
27202720
TypeAndAccess.setPointer(type);
27212721
}
27222722

2723-
bool ValueDecl::hasValidSignature() const {
2724-
if (!hasInterfaceType())
2725-
return false;
2726-
// FIXME -- The build blows up if the correct code is used:
2727-
// return getValidationState() > ValidationState::CheckingWithValidSignature;
2728-
return getValidationState() != ValidationState::Checking;
2729-
}
2730-
27312723
Optional<ObjCSelector> ValueDecl::getObjCRuntimeName(
27322724
bool skipIsObjCResolution) const {
27332725
if (auto func = dyn_cast<AbstractFunctionDecl>(this))

lib/IDE/CodeCompletion.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2046,7 +2046,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
20462046
auto *GenericSig = VD->getInnermostDeclContext()
20472047
->getGenericSignatureOfContext();
20482048

2049-
assert(VD->hasValidSignature());
2049+
assert(VD->hasInterfaceType());
20502050
Type T = VD->getInterfaceType();
20512051

20522052
if (ExprType) {
@@ -2135,7 +2135,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
21352135
addValueBaseName(Builder, Name);
21362136
setClangDeclKeywords(VD, Pairs, Builder);
21372137

2138-
if (!VD->hasValidSignature())
2138+
if (!VD->hasInterfaceType())
21392139
return;
21402140

21412141
// Add a type annotation.

lib/Sema/CSDiag.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,7 +1329,7 @@ DeclContext *FailureDiagnosis::findDeclContext(Expr *subExpr) const {
13291329
// variables would be accessible to name lookup of the subexpression and
13301330
// may thus leak in. Reset them to UnresolvedTypes for safe measures.
13311331
assert(llvm::all_of(*closure->getParameters(), [](const ParamDecl *PD) {
1332-
if (PD->hasValidSignature()) {
1332+
if (PD->hasInterfaceType()) {
13331333
auto paramTy = PD->getType();
13341334
return !(paramTy->hasTypeVariable() || paramTy->hasError());
13351335
}
@@ -5345,7 +5345,7 @@ diagnoseAmbiguousMultiStatementClosure(ClosureExpr *closure) {
53455345
if (auto DRE = dyn_cast<DeclRefExpr>(childExpr)) {
53465346
if (auto param = dyn_cast<ParamDecl>(DRE->getDecl())) {
53475347
auto paramType =
5348-
param->hasValidSignature() ? param->getType() : Type();
5348+
param->hasInterfaceType() ? param->getType() : Type();
53495349
if (!paramType || paramType->hasTypeVariable()) {
53505350
hasUnresolvedParams = true;
53515351
return nullptr;

lib/Sema/CSDiagnostics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1473,7 +1473,7 @@ bool TrailingClosureAmbiguityFailure::diagnoseAsNote() {
14731473
const ParamDecl *param = paramList->getArray().back();
14741474

14751475
// Sanity-check that the trailing closure corresponds to this parameter.
1476-
if (!param->hasValidSignature() ||
1476+
if (!param->hasInterfaceType() ||
14771477
!param->getInterfaceType()->is<AnyFunctionType>())
14781478
return false;
14791479

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2144,7 +2144,7 @@ static ConstraintFix *fixPropertyWrapperFailure(
21442144
};
21452145

21462146
auto applyFix = [&](Fix fix, VarDecl *decl, Type type) -> ConstraintFix * {
2147-
if (!decl->hasValidSignature() || !type)
2147+
if (!decl->hasInterfaceType() || !type)
21482148
return nullptr;
21492149

21502150
if (baseTy->isEqual(type))

lib/Sema/CalleeCandidateInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ OverloadCandidate::OverloadCandidate(ValueDecl *decl, bool skipCurriedSelf)
6161
: declOrExpr(decl), skipCurriedSelf(skipCurriedSelf), substituted(false) {
6262

6363
if (auto *PD = dyn_cast<ParamDecl>(decl)) {
64-
if (PD->hasValidSignature())
64+
if (PD->hasInterfaceType())
6565
entityType = PD->getType();
6666
else
6767
entityType = PD->getASTContext().TheUnresolvedType;

lib/Sema/CodeSynthesis.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ synthesizeDesignatedInitOverride(AbstractFunctionDecl *fn, void *context) {
540540

541541
auto *superclassCtor = (ConstructorDecl *) context;
542542

543-
if (!superclassCtor->hasValidSignature())
543+
if (!superclassCtor->hasInterfaceType())
544544
ctx.getLazyResolver()->resolveDeclSignature(superclassCtor);
545545

546546
// Reference to super.init.
@@ -856,9 +856,9 @@ static void addImplicitConstructorsToStruct(StructDecl *decl, ASTContext &ctx) {
856856
if (!var->isMemberwiseInitialized(/*preferDeclaredProperties=*/true))
857857
continue;
858858

859-
if (!var->hasValidSignature())
859+
if (!var->hasInterfaceType())
860860
ctx.getLazyResolver()->resolveDeclSignature(var);
861-
if (!var->hasValidSignature())
861+
if (!var->hasInterfaceType())
862862
return;
863863
}
864864
}
@@ -923,9 +923,9 @@ static void addImplicitConstructorsToClass(ClassDecl *decl, ASTContext &ctx) {
923923
if (!decl->hasClangNode()) {
924924
for (auto member : decl->getMembers()) {
925925
if (auto ctor = dyn_cast<ConstructorDecl>(member)) {
926-
if (!ctor->hasValidSignature())
926+
if (!ctor->hasInterfaceType())
927927
ctx.getLazyResolver()->resolveDeclSignature(ctor);
928-
if (!ctor->hasValidSignature())
928+
if (!ctor->hasInterfaceType())
929929
return;
930930
}
931931
}
@@ -1081,7 +1081,7 @@ static void addImplicitConstructorsToClass(ClassDecl *decl, ASTContext &ctx) {
10811081

10821082
// We have a designated initializer. Create an override of it.
10831083
// FIXME: Validation makes sure we get a generic signature here.
1084-
if (!decl->hasValidSignature())
1084+
if (!decl->hasInterfaceType())
10851085
ctx.getLazyResolver()->resolveDeclSignature(decl);
10861086

10871087
if (auto ctor = createDesignatedInitOverride(

lib/Sema/ConstraintSystem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ Type ConstraintSystem::getUnopenedTypeOfReference(VarDecl *value, Type baseType,
819819
if (auto *param = dyn_cast<ParamDecl>(var))
820820
return getType(param);
821821

822-
if (!var->hasValidSignature()) {
822+
if (!var->hasInterfaceType()) {
823823
if (!var->isInvalid()) {
824824
TC.diagnose(var->getLoc(), diag::recursive_decl_reference,
825825
var->getDescriptiveKind(), var->getName());

lib/Sema/TypeCheckAttr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,7 @@ static bool hasSingleNonVariadicParam(SubscriptDecl *decl,
11511151
return false;
11521152

11531153
auto *index = indices->get(0);
1154-
if (index->isVariadic() || !index->hasValidSignature())
1154+
if (index->isVariadic() || !index->hasInterfaceType())
11551155
return false;
11561156

11571157
if (ignoreLabel) {

lib/Sema/TypeCheckDecl.cpp

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2881,7 +2881,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
28812881
checkUnsupportedNestedType(PD);
28822882

28832883
TC.validateDecl(PD);
2884-
if (!PD->hasValidSignature())
2884+
if (!PD->hasInterfaceType())
28852885
return;
28862886

28872887
auto *SF = PD->getParentSourceFile();
@@ -3731,12 +3731,12 @@ void TypeChecker::validateDecl(ValueDecl *D) {
37313731
return;
37323732

37333733
// Handling validation failure due to re-entrancy is left
3734-
// up to the caller, who must call hasValidSignature() to
3734+
// up to the caller, who must call hasInterfaceType() to
37353735
// check that validateDecl() returned a fully-formed decl.
37363736
if (D->hasValidationStarted()) {
37373737
// If this isn't reentrant (i.e. D has already been validated), the
37383738
// signature better be valid.
3739-
assert(D->isBeingValidated() || D->hasValidSignature());
3739+
assert(D->isBeingValidated() || D->hasInterfaceType());
37403740
return;
37413741
}
37423742

@@ -3759,7 +3759,7 @@ void TypeChecker::validateDecl(ValueDecl *D) {
37593759
auto dc = D->getDeclContext();
37603760
if (auto nominal = dyn_cast<NominalTypeDecl>(dc)) {
37613761
validateDecl(nominal);
3762-
if (!nominal->hasValidSignature())
3762+
if (!nominal->hasInterfaceType())
37633763
return;
37643764
} else if (auto ext = dyn_cast<ExtensionDecl>(dc)) {
37653765
// If we're currently validating, or have already validated this extension,
@@ -3776,14 +3776,14 @@ void TypeChecker::validateDecl(ValueDecl *D) {
37763776
(void)ext->getGenericSignature();
37773777
}
37783778
}
3779-
if (!ext->hasValidSignature())
3779+
if (ext->getValidationState() == Decl::ValidationState::Checking)
37803780
return;
37813781
}
37823782

37833783
// Validating the parent may have triggered validation of this declaration,
37843784
// so just return if that was the case.
37853785
if (D->hasValidationStarted()) {
3786-
assert(D->hasValidSignature());
3786+
assert(D->hasInterfaceType());
37873787
return;
37883788
}
37893789

@@ -3940,7 +3940,7 @@ void TypeChecker::validateDecl(ValueDecl *D) {
39403940
if (auto accessor = dyn_cast<AccessorDecl>(FD)) {
39413941
auto *storage = accessor->getStorage();
39423942
validateDecl(storage);
3943-
if (!storage->hasValidSignature())
3943+
if (!storage->hasInterfaceType())
39443944
return;
39453945
}
39463946

@@ -4046,7 +4046,6 @@ void TypeChecker::validateDecl(ValueDecl *D) {
40464046
FD->getBodyResultTypeLoc(), resolution);
40474047
// FIXME: Roll all of this interface type computation into a request.
40484048
FD->computeType();
4049-
FD->setSignatureIsValidated();
40504049

40514050
// Member functions need some special validation logic.
40524051
if (FD->getDeclContext()->isTypeContext()) {
@@ -4091,11 +4090,6 @@ void TypeChecker::validateDecl(ValueDecl *D) {
40914090
typeCheckParameterList(CD->getParameters(), res,
40924091
TypeResolverContext::AbstractFunctionDecl);
40934092
CD->computeType();
4094-
4095-
// We want the constructor to be available for name lookup as soon
4096-
// as it has a valid interface type.
4097-
CD->setSignatureIsValidated();
4098-
40994093
break;
41004094
}
41014095

@@ -4108,8 +4102,6 @@ void TypeChecker::validateDecl(ValueDecl *D) {
41084102
typeCheckParameterList(DD->getParameters(), res,
41094103
TypeResolverContext::AbstractFunctionDecl);
41104104
DD->computeType();
4111-
4112-
DD->setSignatureIsValidated();
41134105
break;
41144106
}
41154107

@@ -4125,8 +4117,6 @@ void TypeChecker::validateDecl(ValueDecl *D) {
41254117
SD->getElementTypeLoc(), res);
41264118
SD->computeType();
41274119

4128-
SD->setSignatureIsValidated();
4129-
41304120
if (SD->getOpaqueResultTypeDecl()) {
41314121
if (auto SF = SD->getInnermostDeclContext()->getParentSourceFile()) {
41324122
SF->markDeclWithOpaqueResultTypeAsValidated(SD);
@@ -4170,8 +4160,6 @@ void TypeChecker::validateDecl(ValueDecl *D) {
41704160
// type.
41714161
EED->computeType();
41724162

4173-
EED->setSignatureIsValidated();
4174-
41754163
if (auto argTy = EED->getArgumentInterfaceType()) {
41764164
assert(argTy->isMaterializable());
41774165
(void) argTy;
@@ -4181,7 +4169,7 @@ void TypeChecker::validateDecl(ValueDecl *D) {
41814169
}
41824170
}
41834171

4184-
assert(D->hasValidSignature());
4172+
assert(D->hasInterfaceType());
41854173
}
41864174

41874175
llvm::Expected<DeclRange>

lib/Sema/TypeCheckNameLookup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ LookupTypeResult TypeChecker::lookupMemberType(DeclContext *dc,
497497
auto *protocol = cast<ProtocolDecl>(assocType->getDeclContext());
498498

499499
// If we're validating the protocol recursively, bail out.
500-
if (!protocol->hasValidSignature())
500+
if (!protocol->hasInterfaceType())
501501
continue;
502502

503503
auto conformance = conformsToProtocol(type, protocol, dc,

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ swift::matchWitness(
330330
return RequirementMatch(witness, MatchKind::KindConflict);
331331

332332
// If the witness has not been validated yet, do so now.
333-
if (!witness->hasValidSignature()) {
333+
if (!witness->hasInterfaceType()) {
334334
auto &ctx = dc->getASTContext();
335335
ctx.getLazyResolver()->resolveDeclSignature(witness);
336336
}
@@ -340,7 +340,7 @@ swift::matchWitness(
340340
return RequirementMatch(witness, MatchKind::WitnessInvalid);
341341

342342
// If we're currently validating the witness, bail out.
343-
if (!witness->hasValidSignature())
343+
if (!witness->hasInterfaceType())
344344
return RequirementMatch(witness, MatchKind::Circularity);
345345

346346
// Get the requirement and witness attributes.
@@ -3854,11 +3854,11 @@ void ConformanceChecker::resolveValueWitnesses() {
38543854
continue;
38553855
}
38563856

3857-
// Make sure we've validated the requirement.
3857+
// Make sure we've got an interface type.
38583858
if (!requirement->hasInterfaceType())
38593859
TC.validateDecl(requirement);
38603860

3861-
if (requirement->isInvalid() || !requirement->hasValidSignature()) {
3861+
if (requirement->isInvalid() || !requirement->hasInterfaceType()) {
38623862
Conformance->setInvalid();
38633863
continue;
38643864
}

lib/Sema/TypeCheckProtocolInference.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ AssociatedTypeInference::inferTypeWitnessesViaValueWitnesses(
453453

454454
// Validate the requirement.
455455
tc.validateDecl(req);
456-
if (req->isInvalid() || !req->hasValidSignature())
456+
if (req->isInvalid() || !req->hasInterfaceType())
457457
continue;
458458

459459
// Check whether any of the associated types we care about are
@@ -501,7 +501,7 @@ static Type getWitnessTypeForMatching(TypeChecker &tc,
501501
if (!witness->hasInterfaceType())
502502
tc.validateDecl(witness);
503503

504-
if (witness->isInvalid() || !witness->hasValidSignature())
504+
if (witness->isInvalid() || !witness->hasInterfaceType())
505505
return Type();
506506

507507
if (!witness->getDeclContext()->isTypeContext()) {
@@ -2039,7 +2039,7 @@ void ConformanceChecker::resolveSingleWitness(ValueDecl *requirement) {
20392039
if (!requirement->hasInterfaceType())
20402040
TC.validateDecl(requirement);
20412041

2042-
if (requirement->isInvalid() || !requirement->hasValidSignature()) {
2042+
if (requirement->isInvalid() || !requirement->hasInterfaceType()) {
20432043
Conformance->setInvalid();
20442044
return;
20452045
}

lib/Sema/TypeChecker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1423,7 +1423,7 @@ class TypeChecker final : public LazyResolver {
14231423
[&](VarDecl *var) -> Type {
14241424
validateDecl(var);
14251425

1426-
if (!var->hasValidSignature() || var->isInvalid())
1426+
if (!var->hasInterfaceType() || var->isInvalid())
14271427
return ErrorType::get(Context);
14281428

14291429
return wantInterfaceType ? value->getInterfaceType()

lib/Serialization/Serialization.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3262,7 +3262,7 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
32623262
//
32633263
// FIXME: Once accessor synthesis and getInterfaceType() itself are
32643264
// request-ified this goes away.
3265-
if (!fn->hasValidSignature()) {
3265+
if (!fn->hasInterfaceType()) {
32663266
assert(fn->isImplicit());
32673267
S.M->getASTContext().getLazyResolver()->resolveDeclSignature(
32683268
const_cast<AccessorDecl *>(fn));

0 commit comments

Comments
 (0)