Skip to content

Commit 64224ca

Browse files
authored
Merge pull request #27553 from slavapestov/circular-validation-cleanups-4
Circular validation cleanups, part 4
2 parents d20418e + 6e70b39 commit 64224ca

26 files changed

+126
-194
lines changed

lib/AST/ASTMangler.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2372,13 +2372,9 @@ CanType ASTMangler::getDeclTypeForMangling(
23722372
}
23732373

23742374

2375-
Type type = decl->getInterfaceType()
2376-
->getReferenceStorageReferent();
2377-
if (type->hasArchetype()) {
2378-
assert(isa<ParamDecl>(decl) && "Only ParamDecl's still have archetypes");
2379-
type = type->mapTypeOutOfContext();
2380-
}
2381-
CanType canTy = type->getCanonicalType();
2375+
auto canTy = decl->getInterfaceType()
2376+
->getReferenceStorageReferent()
2377+
->getCanonicalType();
23822378

23832379
if (auto gft = dyn_cast<GenericFunctionType>(canTy)) {
23842380
genericSig = gft.getGenericSignature();

lib/AST/Decl.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2731,8 +2731,11 @@ Type ValueDecl::getInterfaceType() const {
27312731
// Our clients that don't register the lazy resolver are relying on the
27322732
// fact that they can't pull an interface type out to avoid doing work.
27332733
// This is a necessary evil until we can wean them off.
2734-
if (auto resolver = getASTContext().getLazyResolver())
2734+
if (auto resolver = getASTContext().getLazyResolver()) {
27352735
resolver->resolveDeclSignature(const_cast<ValueDecl *>(this));
2736+
if (!hasInterfaceType())
2737+
return ErrorType::get(getASTContext());
2738+
}
27362739
}
27372740
return TypeAndAccess.getPointer();
27382741
}
@@ -2741,13 +2744,7 @@ void ValueDecl::setInterfaceType(Type type) {
27412744
if (type) {
27422745
assert(!type->hasTypeVariable() && "Type variable in interface type");
27432746
assert(!type->is<InOutType>() && "Interface type must be materializable");
2744-
2745-
// ParamDecls in closure contexts can have type variables
2746-
// archetype in them during constraint generation.
2747-
if (!(isa<ParamDecl>(this) && isa<AbstractClosureExpr>(getDeclContext()))) {
2748-
assert(!type->hasArchetype() &&
2749-
"Archetype in interface type");
2750-
}
2747+
assert(!type->hasArchetype() && "Archetype in interface type");
27512748

27522749
if (type->hasError())
27532750
setInvalid();

lib/IDE/CodeCompletion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ calculateTypeRelationForDecl(const Decl *D, Type ExpectedType,
868868
bool UseFuncResultType = true) {
869869
auto VD = dyn_cast<ValueDecl>(D);
870870
auto DC = D->getDeclContext();
871-
if (!VD || !VD->getInterfaceType())
871+
if (!VD)
872872
return CodeCompletionResult::ExpectedTypeRelation::Unrelated;
873873

874874
if (auto FD = dyn_cast<AbstractFunctionDecl>(VD)) {

lib/IDE/ExprContextAnalysis.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -888,9 +888,6 @@ bool swift::ide::isReferenceableByImplicitMemberExpr(
888888
if (VD->isOperator())
889889
return false;
890890

891-
if (!VD->getInterfaceType())
892-
return false;
893-
894891
if (T->getOptionalObjectType() &&
895892
VD->getModuleContext()->isStdlibModule()) {
896893
// In optional context, ignore '.init(<some>)', 'init(nilLiteral:)',

lib/IDE/TypeContextInfo.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,6 @@ void ContextInfoCallbacks::getImplicitMembers(
139139
if (VD->isOperator())
140140
return false;
141141

142-
if (!VD->getInterfaceType()) {
143-
return false;
144-
}
145-
146142
// Enum element decls can always be referenced by implicit member
147143
// expression.
148144
if (isa<EnumElementDecl>(VD))

lib/SIL/SILFunctionType.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,6 @@ static CanType getKnownType(Optional<CanType> &cacheSlot, ASTContext &C,
136136
if (!typeDecl)
137137
return CanType();
138138

139-
assert(typeDecl->hasInterfaceType() &&
140-
"bridged type must be type-checked");
141139
return typeDecl->getDeclaredInterfaceType()->getCanonicalType();
142140
})();
143141
}

lib/SILGen/SILGen.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ getBridgingFn(Optional<SILDeclRef> &cacheSlot,
107107
llvm::report_fatal_error("unable to set up the ObjC bridge!");
108108
}
109109

110-
assert(fd->hasInterfaceType() && "bridging functions must be type-checked");
111-
112110
// Check that the function takes the expected arguments and returns the
113111
// expected result type.
114112
SILDeclRef c(fd);

lib/Sema/CSGen.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2028,8 +2028,9 @@ namespace {
20282028

20292029
// If a type was explicitly specified, use its opened type.
20302030
if (auto type = param->getTypeLoc().getType()) {
2031+
paramType = closureExpr->mapTypeIntoContext(type);
20312032
// FIXME: Need a better locator for a pattern as a base.
2032-
paramType = CS.openUnboundGenericType(type, locator);
2033+
paramType = CS.openUnboundGenericType(paramType, locator);
20332034
internalType = paramType;
20342035
} else {
20352036
// Otherwise, create fresh type variables.

lib/Sema/CodeSynthesis.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -841,18 +841,6 @@ static void addImplicitConstructorsToStruct(StructDecl *decl, ASTContext &ctx) {
841841
assert(!decl->hasUnreferenceableStorage() &&
842842
"User-defined structs cannot have unreferenceable storage");
843843

844-
// Bail out if we're validating one of our stored properties already;
845-
// we'll revisit the issue later.
846-
for (auto member : decl->getMembers()) {
847-
if (auto var = dyn_cast<VarDecl>(member)) {
848-
if (!var->isMemberwiseInitialized(/*preferDeclaredProperties=*/true))
849-
continue;
850-
851-
if (!var->getInterfaceType())
852-
return;
853-
}
854-
}
855-
856844
decl->setAddedImplicitInitializers();
857845

858846
// Check whether there is a user-declared constructor or an instance
@@ -913,7 +901,7 @@ static void addImplicitConstructorsToClass(ClassDecl *decl, ASTContext &ctx) {
913901
if (!decl->hasClangNode()) {
914902
for (auto member : decl->getMembers()) {
915903
if (auto ctor = dyn_cast<ConstructorDecl>(member)) {
916-
if (!ctor->getInterfaceType())
904+
if (ctor->isRecursiveValidation())
917905
return;
918906
}
919907
}

lib/Sema/DerivedConformanceCodable.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,6 @@ static CodableConformanceType varConformsToCodable(TypeChecker &tc,
117117
// var x: Int // <- we get to valuate x's var decl here, but its type
118118
// // hasn't yet been evaluated
119119
// }
120-
//
121-
// If the var decl didn't validate, it may still not have a type; confirm it
122-
// has a type before ensuring the type conforms to Codable.
123-
if (!varDecl->getInterfaceType())
124-
return TypeNotValidated;
125-
126120
bool isIUO = varDecl->isImplicitlyUnwrappedOptional();
127121
return typeConformsToCodable(context, varDecl->getValueInterfaceType(),
128122
isIUO, proto);

lib/Sema/DerivedConformanceEquatableHashable.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ associatedValuesNotConformingToProtocol(DeclContext *DC, EnumDecl *theEnum,
4747
ProtocolDecl *protocol) {
4848
SmallVector<ParamDecl *, 3> nonconformingAssociatedValues;
4949
for (auto elt : theEnum->getAllElements()) {
50-
if (!elt->getInterfaceType())
51-
continue;
50+
// FIXME: Remove this once getInterfaceType() on a ParamDecl works.
51+
(void) elt->getInterfaceType();
5252

5353
auto PL = elt->getParameterList();
5454
if (!PL)

lib/Sema/LookupVisibleDecls.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,11 @@ static void doDynamicLookup(VisibleDeclConsumer &Consumer,
279279
if (!D->isObjC())
280280
return;
281281

282-
// Ensure that the declaration has a type.
283-
if (!D->getInterfaceType()) return;
282+
if (D->isRecursiveValidation())
283+
return;
284+
285+
// FIXME: This is used to compute isInvalid() below.
286+
(void) D->getInterfaceType();
284287

285288
switch (D->getKind()) {
286289
#define DECL(ID, SUPER) \
@@ -757,9 +760,11 @@ class OverrideFilteringConsumer : public VisibleDeclConsumer {
757760
continue;
758761
}
759762

760-
if (!VD->getInterfaceType()) {
763+
if (VD->isRecursiveValidation())
761764
continue;
762-
}
765+
766+
// FIXME: This is used to compute isInvalid() below.
767+
(void) VD->getInterfaceType();
763768

764769
auto &PossiblyConflicting = DeclsByName[VD->getBaseName()];
765770

@@ -801,11 +806,14 @@ class OverrideFilteringConsumer : public VisibleDeclConsumer {
801806
for (auto I = PossiblyConflicting.begin(), E = PossiblyConflicting.end();
802807
I != E; ++I) {
803808
auto *OtherVD = *I;
804-
if (OtherVD->isInvalid() || !OtherVD->getInterfaceType()) {
805-
// For some invalid decls it might be impossible to compute the
806-
// signature, for example, if the types could not be resolved.
809+
if (OtherVD->isRecursiveValidation())
810+
continue;
811+
812+
// FIXME: This is used to compute isInvalid() below.
813+
(void) OtherVD->getInterfaceType();
814+
815+
if (OtherVD->isInvalid())
807816
continue;
808-
}
809817

810818
auto OtherSignature = OtherVD->getOverloadSignature();
811819
auto OtherSignatureType = OtherVD->getOverloadSignatureType();

lib/Sema/TypeCheckCircularity.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,7 @@ bool CircularityChecker::expandStruct(CanType type, StructDecl *S,
249249
S->getModuleContext(), S);
250250

251251
for (auto field: S->getStoredProperties()) {
252-
if (!field->getInterfaceType())
253-
continue;
254-
255-
auto fieldType =field->getInterfaceType().subst(subMap);
252+
auto fieldType =field->getValueInterfaceType().subst(subMap);
256253
if (addMember(type, field, fieldType, depth))
257254
return true;
258255
}
@@ -283,9 +280,6 @@ bool CircularityChecker::expandEnum(CanType type, EnumDecl *E,
283280
if (!elt->hasAssociatedValues())
284281
continue;
285282

286-
if (!elt->getInterfaceType())
287-
continue;
288-
289283
auto eltType = elt->getArgumentInterfaceType().subst(subMap);
290284
if (addMember(type, elt, eltType, depth))
291285
return true;
@@ -614,9 +608,6 @@ void CircularityChecker::diagnoseNonWellFoundedEnum(EnumDecl *E) {
614608
return false;
615609

616610
for (auto elt: elts) {
617-
if (!elt->getInterfaceType())
618-
return false;
619-
620611
if (!elt->isIndirect() && !E->isIndirect())
621612
return false;
622613

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -440,12 +440,6 @@ static bool findNonMembers(TypeChecker &TC,
440440
if (!isValid(D))
441441
return false;
442442

443-
// FIXME: Circularity hack.
444-
if (!D->getInterfaceType()) {
445-
AllDeclRefs = false;
446-
continue;
447-
}
448-
449443
if (matchesDeclRefKind(D, refKind))
450444
ResultValues.push_back(D);
451445
}
@@ -1356,8 +1350,7 @@ bool PreCheckExpression::walkToClosureExprPre(ClosureExpr *closure) {
13561350
options |= TypeResolutionFlags::AllowUnboundGenerics;
13571351
bool hadParameterError = false;
13581352

1359-
auto resolution = TypeResolution::forContextual(closure);
1360-
if (TC.typeCheckParameterList(PL, resolution, options)) {
1353+
if (TC.typeCheckParameterList(PL, closure, options)) {
13611354
// If we encounter an error validating the parameter list, don't bail.
13621355
// Instead, go on to validate any potential result type, and bail
13631356
// afterwards. This allows for better diagnostics, and keeps the
@@ -1367,8 +1360,9 @@ bool PreCheckExpression::walkToClosureExprPre(ClosureExpr *closure) {
13671360

13681361
// Validate the result type, if present.
13691362
if (closure->hasExplicitResultType() &&
1370-
TypeChecker::validateType(TC.Context, closure->getExplicitResultTypeLoc(),
1371-
resolution,
1363+
TypeChecker::validateType(TC.Context,
1364+
closure->getExplicitResultTypeLoc(),
1365+
TypeResolution::forContextual(closure),
13721366
TypeResolverContext::InExpression)) {
13731367
return false;
13741368
}

0 commit comments

Comments
 (0)