Skip to content

Circular validation cleanups, part 4 #27553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions lib/AST/ASTMangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2372,13 +2372,9 @@ CanType ASTMangler::getDeclTypeForMangling(
}


Type type = decl->getInterfaceType()
->getReferenceStorageReferent();
if (type->hasArchetype()) {
assert(isa<ParamDecl>(decl) && "Only ParamDecl's still have archetypes");
type = type->mapTypeOutOfContext();
}
CanType canTy = type->getCanonicalType();
auto canTy = decl->getInterfaceType()
->getReferenceStorageReferent()
->getCanonicalType();

if (auto gft = dyn_cast<GenericFunctionType>(canTy)) {
genericSig = gft.getGenericSignature();
Expand Down
13 changes: 5 additions & 8 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2731,8 +2731,11 @@ Type ValueDecl::getInterfaceType() const {
// Our clients that don't register the lazy resolver are relying on the
// fact that they can't pull an interface type out to avoid doing work.
// This is a necessary evil until we can wean them off.
if (auto resolver = getASTContext().getLazyResolver())
if (auto resolver = getASTContext().getLazyResolver()) {
resolver->resolveDeclSignature(const_cast<ValueDecl *>(this));
if (!hasInterfaceType())
return ErrorType::get(getASTContext());
}
}
return TypeAndAccess.getPointer();
}
Expand All @@ -2741,13 +2744,7 @@ void ValueDecl::setInterfaceType(Type type) {
if (type) {
assert(!type->hasTypeVariable() && "Type variable in interface type");
assert(!type->is<InOutType>() && "Interface type must be materializable");

// ParamDecls in closure contexts can have type variables
// archetype in them during constraint generation.
if (!(isa<ParamDecl>(this) && isa<AbstractClosureExpr>(getDeclContext()))) {
assert(!type->hasArchetype() &&
"Archetype in interface type");
}
assert(!type->hasArchetype() && "Archetype in interface type");

if (type->hasError())
setInvalid();
Expand Down
2 changes: 1 addition & 1 deletion lib/IDE/CodeCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ calculateTypeRelationForDecl(const Decl *D, Type ExpectedType,
bool UseFuncResultType = true) {
auto VD = dyn_cast<ValueDecl>(D);
auto DC = D->getDeclContext();
if (!VD || !VD->getInterfaceType())
if (!VD)
return CodeCompletionResult::ExpectedTypeRelation::Unrelated;

if (auto FD = dyn_cast<AbstractFunctionDecl>(VD)) {
Expand Down
3 changes: 0 additions & 3 deletions lib/IDE/ExprContextAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -888,9 +888,6 @@ bool swift::ide::isReferenceableByImplicitMemberExpr(
if (VD->isOperator())
return false;

if (!VD->getInterfaceType())
return false;

if (T->getOptionalObjectType() &&
VD->getModuleContext()->isStdlibModule()) {
// In optional context, ignore '.init(<some>)', 'init(nilLiteral:)',
Expand Down
4 changes: 0 additions & 4 deletions lib/IDE/TypeContextInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,6 @@ void ContextInfoCallbacks::getImplicitMembers(
if (VD->isOperator())
return false;

if (!VD->getInterfaceType()) {
return false;
}

// Enum element decls can always be referenced by implicit member
// expression.
if (isa<EnumElementDecl>(VD))
Expand Down
2 changes: 0 additions & 2 deletions lib/SIL/SILFunctionType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ static CanType getKnownType(Optional<CanType> &cacheSlot, ASTContext &C,
if (!typeDecl)
return CanType();

assert(typeDecl->hasInterfaceType() &&
"bridged type must be type-checked");
return typeDecl->getDeclaredInterfaceType()->getCanonicalType();
})();
}
Expand Down
2 changes: 0 additions & 2 deletions lib/SILGen/SILGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ getBridgingFn(Optional<SILDeclRef> &cacheSlot,
llvm::report_fatal_error("unable to set up the ObjC bridge!");
}

assert(fd->hasInterfaceType() && "bridging functions must be type-checked");

// Check that the function takes the expected arguments and returns the
// expected result type.
SILDeclRef c(fd);
Expand Down
3 changes: 2 additions & 1 deletion lib/Sema/CSGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2028,8 +2028,9 @@ namespace {

// If a type was explicitly specified, use its opened type.
if (auto type = param->getTypeLoc().getType()) {
paramType = closureExpr->mapTypeIntoContext(type);
// FIXME: Need a better locator for a pattern as a base.
paramType = CS.openUnboundGenericType(type, locator);
paramType = CS.openUnboundGenericType(paramType, locator);
internalType = paramType;
} else {
// Otherwise, create fresh type variables.
Expand Down
14 changes: 1 addition & 13 deletions lib/Sema/CodeSynthesis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -843,18 +843,6 @@ static void addImplicitConstructorsToStruct(StructDecl *decl, ASTContext &ctx) {
assert(!decl->hasUnreferenceableStorage() &&
"User-defined structs cannot have unreferenceable storage");

// Bail out if we're validating one of our stored properties already;
// we'll revisit the issue later.
for (auto member : decl->getMembers()) {
if (auto var = dyn_cast<VarDecl>(member)) {
if (!var->isMemberwiseInitialized(/*preferDeclaredProperties=*/true))
continue;

if (!var->getInterfaceType())
return;
}
}

decl->setAddedImplicitInitializers();

// Check whether there is a user-declared constructor or an instance
Expand Down Expand Up @@ -915,7 +903,7 @@ static void addImplicitConstructorsToClass(ClassDecl *decl, ASTContext &ctx) {
if (!decl->hasClangNode()) {
for (auto member : decl->getMembers()) {
if (auto ctor = dyn_cast<ConstructorDecl>(member)) {
if (!ctor->getInterfaceType())
if (ctor->isRecursiveValidation())
return;
}
}
Expand Down
6 changes: 0 additions & 6 deletions lib/Sema/DerivedConformanceCodable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,6 @@ static CodableConformanceType varConformsToCodable(TypeChecker &tc,
// var x: Int // <- we get to valuate x's var decl here, but its type
// // hasn't yet been evaluated
// }
//
// If the var decl didn't validate, it may still not have a type; confirm it
// has a type before ensuring the type conforms to Codable.
if (!varDecl->getInterfaceType())
return TypeNotValidated;

bool isIUO = varDecl->isImplicitlyUnwrappedOptional();
return typeConformsToCodable(context, varDecl->getValueInterfaceType(),
isIUO, proto);
Expand Down
4 changes: 2 additions & 2 deletions lib/Sema/DerivedConformanceEquatableHashable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ associatedValuesNotConformingToProtocol(DeclContext *DC, EnumDecl *theEnum,
ProtocolDecl *protocol) {
SmallVector<ParamDecl *, 3> nonconformingAssociatedValues;
for (auto elt : theEnum->getAllElements()) {
if (!elt->getInterfaceType())
continue;
// FIXME: Remove this once getInterfaceType() on a ParamDecl works.
(void) elt->getInterfaceType();

auto PL = elt->getParameterList();
if (!PL)
Expand Down
24 changes: 16 additions & 8 deletions lib/Sema/LookupVisibleDecls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,11 @@ static void doDynamicLookup(VisibleDeclConsumer &Consumer,
if (!D->isObjC())
return;

// Ensure that the declaration has a type.
if (!D->getInterfaceType()) return;
if (D->isRecursiveValidation())
return;

// FIXME: This is used to compute isInvalid() below.
(void) D->getInterfaceType();

switch (D->getKind()) {
#define DECL(ID, SUPER) \
Expand Down Expand Up @@ -757,9 +760,11 @@ class OverrideFilteringConsumer : public VisibleDeclConsumer {
continue;
}

if (!VD->getInterfaceType()) {
if (VD->isRecursiveValidation())
continue;
}

// FIXME: This is used to compute isInvalid() below.
(void) VD->getInterfaceType();

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

Expand Down Expand Up @@ -801,11 +806,14 @@ class OverrideFilteringConsumer : public VisibleDeclConsumer {
for (auto I = PossiblyConflicting.begin(), E = PossiblyConflicting.end();
I != E; ++I) {
auto *OtherVD = *I;
if (OtherVD->isInvalid() || !OtherVD->getInterfaceType()) {
// For some invalid decls it might be impossible to compute the
// signature, for example, if the types could not be resolved.
if (OtherVD->isRecursiveValidation())
continue;

// FIXME: This is used to compute isInvalid() below.
(void) OtherVD->getInterfaceType();

if (OtherVD->isInvalid())
continue;
}

auto OtherSignature = OtherVD->getOverloadSignature();
auto OtherSignatureType = OtherVD->getOverloadSignatureType();
Expand Down
11 changes: 1 addition & 10 deletions lib/Sema/TypeCheckCircularity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,7 @@ bool CircularityChecker::expandStruct(CanType type, StructDecl *S,
S->getModuleContext(), S);

for (auto field: S->getStoredProperties()) {
if (!field->getInterfaceType())
continue;

auto fieldType =field->getInterfaceType().subst(subMap);
auto fieldType =field->getValueInterfaceType().subst(subMap);
if (addMember(type, field, fieldType, depth))
return true;
}
Expand Down Expand Up @@ -283,9 +280,6 @@ bool CircularityChecker::expandEnum(CanType type, EnumDecl *E,
if (!elt->hasAssociatedValues())
continue;

if (!elt->getInterfaceType())
continue;

auto eltType = elt->getArgumentInterfaceType().subst(subMap);
if (addMember(type, elt, eltType, depth))
return true;
Expand Down Expand Up @@ -614,9 +608,6 @@ void CircularityChecker::diagnoseNonWellFoundedEnum(EnumDecl *E) {
return false;

for (auto elt: elts) {
if (!elt->getInterfaceType())
return false;

if (!elt->isIndirect() && !E->isIndirect())
return false;

Expand Down
14 changes: 4 additions & 10 deletions lib/Sema/TypeCheckConstraints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,12 +440,6 @@ static bool findNonMembers(TypeChecker &TC,
if (!isValid(D))
return false;

// FIXME: Circularity hack.
if (!D->getInterfaceType()) {
AllDeclRefs = false;
continue;
}

if (matchesDeclRefKind(D, refKind))
ResultValues.push_back(D);
}
Expand Down Expand Up @@ -1356,8 +1350,7 @@ bool PreCheckExpression::walkToClosureExprPre(ClosureExpr *closure) {
options |= TypeResolutionFlags::AllowUnboundGenerics;
bool hadParameterError = false;

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

// Validate the result type, if present.
if (closure->hasExplicitResultType() &&
TypeChecker::validateType(TC.Context, closure->getExplicitResultTypeLoc(),
resolution,
TypeChecker::validateType(TC.Context,
closure->getExplicitResultTypeLoc(),
TypeResolution::forContextual(closure),
TypeResolverContext::InExpression)) {
return false;
}
Expand Down
Loading