Skip to content

Requestify getInterfaceType() in Name Only #27314

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 5 commits into from
Sep 24, 2019
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
9 changes: 2 additions & 7 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -922,8 +922,8 @@ static FuncDecl *findLibraryIntrinsic(const ASTContext &ctx,
ctx.lookupInSwiftModule(name, results);
if (results.size() == 1) {
if (auto FD = dyn_cast<FuncDecl>(results.front())) {
if (auto *resolver = ctx.getLazyResolver())
resolver->resolveDeclSignature(FD);
// FIXME(InterfaceTypeRequest): Remove this.
(void)FD->getInterfaceType();
return FD;
}
}
Expand Down Expand Up @@ -987,9 +987,6 @@ lookupOperatorFunc(const ASTContext &ctx, StringRef oper, Type contextType,
if (!contextTy->isEqual(contextType)) continue;
}

if (auto resolver = ctx.getLazyResolver())
resolver->resolveDeclSignature(fnDecl);

auto *funcTy = getIntrinsicCandidateType(fnDecl, /*allowTypeMembers=*/true);
if (!funcTy)
continue;
Expand Down Expand Up @@ -3969,8 +3966,6 @@ static NominalTypeDecl *findUnderlyingTypeInModule(ASTContext &ctx,

// Look through typealiases.
if (auto typealias = dyn_cast<TypeAliasDecl>(result)) {
if (auto resolver = ctx.getLazyResolver())
resolver->resolveDeclSignature(typealias);
return typealias->getDeclaredInterfaceType()->getAnyNominal();
}
}
Expand Down
8 changes: 1 addition & 7 deletions lib/AST/ASTMangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2343,13 +2343,7 @@ CanType ASTMangler::getDeclTypeForMangling(
parentGenericSig = nullptr;

auto &C = decl->getASTContext();
if (!decl->hasInterfaceType() && !decl->getDeclContext()->isLocalContext()) {
if (auto *resolver = C.getLazyResolver()) {
resolver->resolveDeclSignature(const_cast<ValueDecl *>(decl));
}
}

if (!decl->hasInterfaceType() || decl->getInterfaceType()->is<ErrorType>()) {
if (!decl->getInterfaceType() || decl->getInterfaceType()->is<ErrorType>()) {
if (isa<AbstractFunctionDecl>(decl))
return CanFunctionType::get({AnyFunctionType::Param(C.TheErrorType)},
C.TheErrorType);
Expand Down
21 changes: 8 additions & 13 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2697,7 +2697,13 @@ bool ValueDecl::hasInterfaceType() const {
}

Type ValueDecl::getInterfaceType() const {
assert(hasInterfaceType() && "No interface type was set");
if (!hasInterfaceType()) {
// 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())
resolver->resolveDeclSignature(const_cast<ValueDecl *>(this));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need the assert after this call I think.

}
return TypeAndAccess.getPointer();
}

Expand Down Expand Up @@ -3241,7 +3247,7 @@ Type TypeDecl::getDeclaredInterfaceType() const {
selfTy, const_cast<AssociatedTypeDecl *>(ATD));
}

Type interfaceType = hasInterfaceType() ? getInterfaceType() : nullptr;
Type interfaceType = getInterfaceType();
if (interfaceType.isNull() || interfaceType->is<ErrorType>())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It won't be null now?

return interfaceType;

Expand Down Expand Up @@ -6549,17 +6555,6 @@ static bool requiresNewVTableEntry(const AbstractFunctionDecl *decl) {
if (decl->isEffectiveLinkageMoreVisibleThan(base))
return true;

// FIXME: Remove this once getInterfaceType() has been request-ified.
if (!decl->hasInterfaceType()) {
ctx.getLazyResolver()->resolveDeclSignature(
const_cast<AbstractFunctionDecl *>(decl));
}

if (!base->hasInterfaceType()) {
ctx.getLazyResolver()->resolveDeclSignature(
const_cast<AbstractFunctionDecl *>(base));
}

// If the method overrides something, we only need a new entry if the
// override has a more general AST type. However an abstraction
// change is OK; we don't want to add a whole new vtable entry just
Expand Down
5 changes: 3 additions & 2 deletions lib/AST/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1817,14 +1817,15 @@ SourceFile::lookupOpaqueResultType(StringRef MangledName,
auto found = ValidatedOpaqueReturnTypes.find(MangledName);
if (found != ValidatedOpaqueReturnTypes.end())
return found->second;

// If there are unvalidated decls with opaque types, go through and validate
// them now.
if (resolver && !UnvalidatedDeclsWithOpaqueReturnTypes.empty()) {
while (!UnvalidatedDeclsWithOpaqueReturnTypes.empty()) {
ValueDecl *decl = *UnvalidatedDeclsWithOpaqueReturnTypes.begin();
UnvalidatedDeclsWithOpaqueReturnTypes.erase(decl);
resolver->resolveDeclSignature(decl);
// FIXME(InterfaceTypeRequest): Remove this.
(void)decl->getInterfaceType();
}

found = ValidatedOpaqueReturnTypes.find(MangledName);
Expand Down
11 changes: 3 additions & 8 deletions lib/AST/NameLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,6 @@ static void recordShadowedDecls(ArrayRef<ValueDecl *> decls,
if (decls.size() < 2)
return;

auto typeResolver = decls[0]->getASTContext().getLazyResolver();

// Categorize all of the declarations based on their overload signatures.
llvm::SmallDenseMap<CanType, llvm::TinyPtrVector<ValueDecl *>> collisions;
llvm::SmallVector<CanType, 2> collisionTypes;
Expand Down Expand Up @@ -463,19 +461,16 @@ static void recordShadowedDecls(ArrayRef<ValueDecl *> decls,
CanType signature;

if (!isa<TypeDecl>(decl)) {
// We need an interface type here.
if (typeResolver)
typeResolver->resolveDeclSignature(decl);

// If the decl is currently being validated, this is likely a recursive
// reference and we'll want to skip ahead so as to avoid having its type
// attempt to desugar itself.
if (!decl->hasInterfaceType())
auto ifaceType = decl->getInterfaceType();
if (!ifaceType)
continue;

// FIXME: the canonical type makes a poor signature, because we don't
// canonicalize away default arguments.
signature = decl->getInterfaceType()->getCanonicalType();
signature = ifaceType->getCanonicalType();

// FIXME: The type of a variable or subscript doesn't include
// enough context to distinguish entities from different
Expand Down
5 changes: 3 additions & 2 deletions lib/AST/USRGeneration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,12 @@ swift::USRGenerationRequest::evaluate(Evaluator &evaluator,
}
}

if (!D->hasInterfaceType())
auto declIFaceTy = D->getInterfaceType();
if (!declIFaceTy)
return std::string();

// Invalid code.
if (D->getInterfaceType().findIf([](Type t) -> bool {
if (declIFaceTy.findIf([](Type t) -> bool {
return t->is<ModuleType>();
}))
return std::string();
Expand Down
3 changes: 0 additions & 3 deletions lib/ClangImporter/ImportType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2297,9 +2297,6 @@ Type ClangImporter::Implementation::getNamedSwiftType(ModuleDecl *module,

assert(!decl->hasClangNode() && "picked up the original type?");

if (auto *lazyResolver = SwiftContext.getLazyResolver())
lazyResolver->resolveDeclSignature(decl);

if (auto *nominalDecl = dyn_cast<NominalTypeDecl>(decl))
return nominalDecl->getDeclaredType();
return decl->getDeclaredInterfaceType();
Expand Down
23 changes: 11 additions & 12 deletions lib/IDE/CodeCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2046,8 +2046,8 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
auto *GenericSig = VD->getInnermostDeclContext()
->getGenericSignatureOfContext();

assert(VD->hasInterfaceType());
Type T = VD->getInterfaceType();
assert(!T.isNull());

if (ExprType) {
Type ContextTy = VD->getDeclContext()->getDeclaredInterfaceType();
Expand Down Expand Up @@ -2984,10 +2984,9 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {

if (IsSwiftKeyPathExpr && !SwiftKeyPathFilter(D, Reason))
return;

if (!D->hasInterfaceType())
D->getASTContext().getLazyResolver()->resolveDeclSignature(D);


// FIXME(InterfaceTypeRequest): Remove this.
(void)D->getInterfaceType();
switch (Kind) {
case LookupKind::ValueExpr:
if (auto *CD = dyn_cast<ConstructorDecl>(D)) {
Expand Down Expand Up @@ -3144,9 +3143,9 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {

bool handleEnumElement(ValueDecl *D, DeclVisibilityKind Reason,
DynamicLookupInfo dynamicLookupInfo) {
if (!D->hasInterfaceType())
D->getASTContext().getLazyResolver()->resolveDeclSignature(D);

// FIXME(InterfaceTypeRequest): Remove this.
(void)D->getInterfaceType();
if (auto *EED = dyn_cast<EnumElementDecl>(D)) {
addEnumElementRef(EED, Reason, dynamicLookupInfo,
/*HasTypeContext=*/true);
Expand All @@ -3155,8 +3154,8 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
llvm::DenseSet<EnumElementDecl *> Elements;
ED->getAllElements(Elements);
for (auto *Ele : Elements) {
if (!Ele->hasInterfaceType())
D->getASTContext().getLazyResolver()->resolveDeclSignature(Ele);
// FIXME(InterfaceTypeRequest): Remove this.
(void)Ele->getInterfaceType();
addEnumElementRef(Ele, Reason, dynamicLookupInfo,
/*HasTypeContext=*/true);
}
Expand Down Expand Up @@ -4330,8 +4329,8 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
(D->isStatic() && D->getAttrs().hasAttribute<HasInitialValueAttr>()))
return;

if (!D->hasInterfaceType())
D->getASTContext().getLazyResolver()->resolveDeclSignature(D);
// FIXME(InterfaceTypeRequest): Remove this.
(void)D->getInterfaceType();

bool hasIntroducer = hasFuncIntroducer ||
hasVarIntroducer ||
Expand Down
10 changes: 4 additions & 6 deletions lib/IDE/ExprContextAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,10 @@ static void collectPossibleCalleesByQualifiedLookup(
continue;
if (!isMemberDeclApplied(&DC, baseTy->getMetatypeInstanceType(), VD))
continue;
if (!VD->hasInterfaceType()) {
VD->getASTContext().getLazyResolver()->resolveDeclSignature(VD);
if (!VD->hasInterfaceType())
continue;
}
Type declaredMemberType = VD->getInterfaceType();
if (!declaredMemberType) {
continue;
}
if (!declaredMemberType->is<AnyFunctionType>())
continue;
if (VD->getDeclContext()->isTypeContext()) {
Expand Down Expand Up @@ -899,7 +897,7 @@ bool swift::ide::isReferenceableByImplicitMemberExpr(
if (VD->isOperator())
return false;

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

if (T->getOptionalObjectType() &&
Expand Down
6 changes: 2 additions & 4 deletions lib/IDE/TypeContextInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,8 @@ void ContextInfoCallbacks::getImplicitMembers(
if (VD->isOperator())
return false;

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

// Enum element decls can always be referenced by implicit member
Expand Down
5 changes: 1 addition & 4 deletions lib/IRGen/GenEnum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5777,10 +5777,7 @@ EnumImplStrategy::get(TypeConverter &TC, SILType type, EnumDecl *theEnum) {
elementsWithPayload.push_back({elt, nativeTI, nativeTI});
continue;
}

if (!elt->hasInterfaceType())
TC.IGM.Context.getLazyResolver()->resolveDeclSignature(elt);


// Compute whether this gives us an apparent payload or dynamic layout.
// Note that we do *not* apply substitutions from a bound generic instance
// yet. We want all instances of a generic enum to share an implementation
Expand Down
6 changes: 0 additions & 6 deletions lib/IRGen/GenType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1920,9 +1920,6 @@ namespace {
return true;

for (auto field : decl->getStoredProperties()) {
if (!field->hasInterfaceType())
IGM.Context.getLazyResolver()->resolveDeclSignature(field);

if (visit(field->getInterfaceType()->getCanonicalType()))
return true;
}
Expand All @@ -1947,9 +1944,6 @@ namespace {
if (!elt->hasAssociatedValues() || elt->isIndirect())
continue;

if (!elt->hasInterfaceType())
IGM.Context.getLazyResolver()->resolveDeclSignature(elt);

if (visit(elt->getArgumentInterfaceType()->getCanonicalType()))
return true;
}
Expand Down
10 changes: 1 addition & 9 deletions lib/SIL/SILType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,13 @@ bool SILType::canRefCast(SILType operTy, SILType resultTy, SILModule &M) {

SILType SILType::getFieldType(VarDecl *field,
TypeConverter &TC) const {
auto baseTy = getASTType();

if (!field->hasInterfaceType())
TC.Context.getLazyResolver()->resolveDeclSignature(field);

AbstractionPattern origFieldTy = TC.getAbstractionPattern(field);
CanType substFieldTy;
if (field->hasClangNode()) {
substFieldTy = origFieldTy.getType();
} else {
substFieldTy =
baseTy->getTypeOfMember(&TC.M, field, nullptr)->getCanonicalType();
getASTType()->getTypeOfMember(&TC.M, field, nullptr)->getCanonicalType();
}

auto loweredTy = TC.getLoweredRValueType(origFieldTy, substFieldTy);
Expand All @@ -175,9 +170,6 @@ SILType SILType::getEnumElementType(EnumElementDecl *elt,
return SILType(objectType, getCategory());
}

if (!elt->hasInterfaceType())
TC.Context.getLazyResolver()->resolveDeclSignature(elt);

// If the case is indirect, then the payload is boxed.
if (elt->isIndirect() || elt->getParentEnum()->isIndirect()) {
auto box = TC.getBoxTypeForEnumElement(*this, elt);
Expand Down
23 changes: 1 addition & 22 deletions lib/SIL/TypeLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1267,10 +1267,6 @@ namespace {

// Classify the type according to its stored properties.
for (auto field : D->getStoredProperties()) {
// FIXME: Remove this once getInterfaceType() is a request.
if (!field->hasInterfaceType())
TC.Context.getLazyResolver()->resolveDeclSignature(field);

auto substFieldType =
field->getInterfaceType().subst(subMap)->getCanonicalType();

Expand Down Expand Up @@ -1313,11 +1309,7 @@ namespace {
properties.setNonTrivial();
continue;
}

// FIXME: Remove this once getInterfaceType() is a request.
if (!elt->hasInterfaceType())
TC.Context.getLazyResolver()->resolveDeclSignature(elt);


auto substEltType =
elt->getArgumentInterfaceType().subst(subMap)->getCanonicalType();

Expand Down Expand Up @@ -1895,11 +1887,6 @@ getFunctionInterfaceTypeWithCaptures(TypeConverter &TC,

CanAnyFunctionType TypeConverter::makeConstantInterfaceType(SILDeclRef c) {
auto *vd = c.loc.dyn_cast<ValueDecl *>();

if (vd && !vd->hasInterfaceType()) {
Context.getLazyResolver()->resolveDeclSignature(vd);
}

switch (c.kind) {
case SILDeclRef::Kind::Func: {
CanAnyFunctionType funcTy;
Expand Down Expand Up @@ -2612,11 +2599,6 @@ CanSILBoxType TypeConverter::getBoxTypeForEnumElement(SILType enumType,
assert(elt->isIndirect() || elt->getParentEnum()->isIndirect());

auto &C = M.getASTContext();

// FIXME: Remove this once getInterfaceType() is a request.
if (!elt->hasInterfaceType())
Context.getLazyResolver()->resolveDeclSignature(elt);

auto boxSignature = getCanonicalSignatureOrNull(
enumDecl->getGenericSignature());

Expand Down Expand Up @@ -2688,9 +2670,6 @@ static void countNumberOfInnerFields(unsigned &fieldsCount, TypeConverter &TC,
if (elt->isIndirect())
continue;

if (!elt->hasInterfaceType())
TC.Context.getLazyResolver()->resolveDeclSignature(elt);

// Although one might assume enums have a fields count of 1
// Which holds true for current uses of this code
// (we shouldn't expand enums)
Expand Down
5 changes: 0 additions & 5 deletions lib/SILOptimizer/Analysis/DestructorAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,6 @@ bool DestructorAnalysis::isSafeType(CanType Ty) {

// Check the stored properties.
for (auto SP : Struct->getStoredProperties()) {
// FIXME: Remove this once getInterfaceType() is a request.
if (!SP->hasInterfaceType()) {
ASTContext &Ctx = Mod->getSwiftModule()->getASTContext();
Ctx.getLazyResolver()->resolveDeclSignature(SP);
}
if (!isSafeType(SP->getInterfaceType()->getCanonicalType()))
return cacheResult(Ty, false);
}
Expand Down
Loading