Skip to content

Commit 3e48f71

Browse files
authored
Merge pull request swiftlang#27314 from CodaFi/an-interface-to-the-interface
Requestify getInterfaceType() in Name Only
2 parents b7f9130 + 1233cdf commit 3e48f71

Some content is hidden

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

54 files changed

+205
-422
lines changed

lib/AST/ASTContext.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -922,8 +922,8 @@ static FuncDecl *findLibraryIntrinsic(const ASTContext &ctx,
922922
ctx.lookupInSwiftModule(name, results);
923923
if (results.size() == 1) {
924924
if (auto FD = dyn_cast<FuncDecl>(results.front())) {
925-
if (auto *resolver = ctx.getLazyResolver())
926-
resolver->resolveDeclSignature(FD);
925+
// FIXME(InterfaceTypeRequest): Remove this.
926+
(void)FD->getInterfaceType();
927927
return FD;
928928
}
929929
}
@@ -987,9 +987,6 @@ lookupOperatorFunc(const ASTContext &ctx, StringRef oper, Type contextType,
987987
if (!contextTy->isEqual(contextType)) continue;
988988
}
989989

990-
if (auto resolver = ctx.getLazyResolver())
991-
resolver->resolveDeclSignature(fnDecl);
992-
993990
auto *funcTy = getIntrinsicCandidateType(fnDecl, /*allowTypeMembers=*/true);
994991
if (!funcTy)
995992
continue;
@@ -3969,8 +3966,6 @@ static NominalTypeDecl *findUnderlyingTypeInModule(ASTContext &ctx,
39693966

39703967
// Look through typealiases.
39713968
if (auto typealias = dyn_cast<TypeAliasDecl>(result)) {
3972-
if (auto resolver = ctx.getLazyResolver())
3973-
resolver->resolveDeclSignature(typealias);
39743969
return typealias->getDeclaredInterfaceType()->getAnyNominal();
39753970
}
39763971
}

lib/AST/ASTMangler.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2343,13 +2343,7 @@ CanType ASTMangler::getDeclTypeForMangling(
23432343
parentGenericSig = nullptr;
23442344

23452345
auto &C = decl->getASTContext();
2346-
if (!decl->hasInterfaceType() && !decl->getDeclContext()->isLocalContext()) {
2347-
if (auto *resolver = C.getLazyResolver()) {
2348-
resolver->resolveDeclSignature(const_cast<ValueDecl *>(decl));
2349-
}
2350-
}
2351-
2352-
if (!decl->hasInterfaceType() || decl->getInterfaceType()->is<ErrorType>()) {
2346+
if (!decl->getInterfaceType() || decl->getInterfaceType()->is<ErrorType>()) {
23532347
if (isa<AbstractFunctionDecl>(decl))
23542348
return CanFunctionType::get({AnyFunctionType::Param(C.TheErrorType)},
23552349
C.TheErrorType);

lib/AST/Decl.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2697,7 +2697,13 @@ bool ValueDecl::hasInterfaceType() const {
26972697
}
26982698

26992699
Type ValueDecl::getInterfaceType() const {
2700-
assert(hasInterfaceType() && "No interface type was set");
2700+
if (!hasInterfaceType()) {
2701+
// Our clients that don't register the lazy resolver are relying on the
2702+
// fact that they can't pull an interface type out to avoid doing work.
2703+
// This is a necessary evil until we can wean them off.
2704+
if (auto resolver = getASTContext().getLazyResolver())
2705+
resolver->resolveDeclSignature(const_cast<ValueDecl *>(this));
2706+
}
27012707
return TypeAndAccess.getPointer();
27022708
}
27032709

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

3244-
Type interfaceType = hasInterfaceType() ? getInterfaceType() : nullptr;
3250+
Type interfaceType = getInterfaceType();
32453251
if (interfaceType.isNull() || interfaceType->is<ErrorType>())
32463252
return interfaceType;
32473253

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

6552-
// FIXME: Remove this once getInterfaceType() has been request-ified.
6553-
if (!decl->hasInterfaceType()) {
6554-
ctx.getLazyResolver()->resolveDeclSignature(
6555-
const_cast<AbstractFunctionDecl *>(decl));
6556-
}
6557-
6558-
if (!base->hasInterfaceType()) {
6559-
ctx.getLazyResolver()->resolveDeclSignature(
6560-
const_cast<AbstractFunctionDecl *>(base));
6561-
}
6562-
65636558
// If the method overrides something, we only need a new entry if the
65646559
// override has a more general AST type. However an abstraction
65656560
// change is OK; we don't want to add a whole new vtable entry just

lib/AST/Module.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,14 +1817,15 @@ SourceFile::lookupOpaqueResultType(StringRef MangledName,
18171817
auto found = ValidatedOpaqueReturnTypes.find(MangledName);
18181818
if (found != ValidatedOpaqueReturnTypes.end())
18191819
return found->second;
1820-
1820+
18211821
// If there are unvalidated decls with opaque types, go through and validate
18221822
// them now.
18231823
if (resolver && !UnvalidatedDeclsWithOpaqueReturnTypes.empty()) {
18241824
while (!UnvalidatedDeclsWithOpaqueReturnTypes.empty()) {
18251825
ValueDecl *decl = *UnvalidatedDeclsWithOpaqueReturnTypes.begin();
18261826
UnvalidatedDeclsWithOpaqueReturnTypes.erase(decl);
1827-
resolver->resolveDeclSignature(decl);
1827+
// FIXME(InterfaceTypeRequest): Remove this.
1828+
(void)decl->getInterfaceType();
18281829
}
18291830

18301831
found = ValidatedOpaqueReturnTypes.find(MangledName);

lib/AST/NameLookup.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,6 @@ static void recordShadowedDecls(ArrayRef<ValueDecl *> decls,
434434
if (decls.size() < 2)
435435
return;
436436

437-
auto typeResolver = decls[0]->getASTContext().getLazyResolver();
438-
439437
// Categorize all of the declarations based on their overload signatures.
440438
llvm::SmallDenseMap<CanType, llvm::TinyPtrVector<ValueDecl *>> collisions;
441439
llvm::SmallVector<CanType, 2> collisionTypes;
@@ -463,19 +461,16 @@ static void recordShadowedDecls(ArrayRef<ValueDecl *> decls,
463461
CanType signature;
464462

465463
if (!isa<TypeDecl>(decl)) {
466-
// We need an interface type here.
467-
if (typeResolver)
468-
typeResolver->resolveDeclSignature(decl);
469-
470464
// If the decl is currently being validated, this is likely a recursive
471465
// reference and we'll want to skip ahead so as to avoid having its type
472466
// attempt to desugar itself.
473-
if (!decl->hasInterfaceType())
467+
auto ifaceType = decl->getInterfaceType();
468+
if (!ifaceType)
474469
continue;
475470

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

480475
// FIXME: The type of a variable or subscript doesn't include
481476
// enough context to distinguish entities from different

lib/AST/USRGeneration.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,12 @@ swift::USRGenerationRequest::evaluate(Evaluator &evaluator,
241241
}
242242
}
243243

244-
if (!D->hasInterfaceType())
244+
auto declIFaceTy = D->getInterfaceType();
245+
if (!declIFaceTy)
245246
return std::string();
246247

247248
// Invalid code.
248-
if (D->getInterfaceType().findIf([](Type t) -> bool {
249+
if (declIFaceTy.findIf([](Type t) -> bool {
249250
return t->is<ModuleType>();
250251
}))
251252
return std::string();

lib/ClangImporter/ImportType.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,9 +2293,6 @@ Type ClangImporter::Implementation::getNamedSwiftType(ModuleDecl *module,
22932293

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

2296-
if (auto *lazyResolver = SwiftContext.getLazyResolver())
2297-
lazyResolver->resolveDeclSignature(decl);
2298-
22992296
if (auto *nominalDecl = dyn_cast<NominalTypeDecl>(decl))
23002297
return nominalDecl->getDeclaredType();
23012298
return decl->getDeclaredInterfaceType();

lib/IDE/CodeCompletion.cpp

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

2049-
assert(VD->hasInterfaceType());
20502049
Type T = VD->getInterfaceType();
2050+
assert(!T.isNull());
20512051

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

29852985
if (IsSwiftKeyPathExpr && !SwiftKeyPathFilter(D, Reason))
29862986
return;
2987-
2988-
if (!D->hasInterfaceType())
2989-
D->getASTContext().getLazyResolver()->resolveDeclSignature(D);
2990-
2987+
2988+
// FIXME(InterfaceTypeRequest): Remove this.
2989+
(void)D->getInterfaceType();
29912990
switch (Kind) {
29922991
case LookupKind::ValueExpr:
29932992
if (auto *CD = dyn_cast<ConstructorDecl>(D)) {
@@ -3144,9 +3143,9 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
31443143

31453144
bool handleEnumElement(ValueDecl *D, DeclVisibilityKind Reason,
31463145
DynamicLookupInfo dynamicLookupInfo) {
3147-
if (!D->hasInterfaceType())
3148-
D->getASTContext().getLazyResolver()->resolveDeclSignature(D);
3149-
3146+
// FIXME(InterfaceTypeRequest): Remove this.
3147+
(void)D->getInterfaceType();
3148+
31503149
if (auto *EED = dyn_cast<EnumElementDecl>(D)) {
31513150
addEnumElementRef(EED, Reason, dynamicLookupInfo,
31523151
/*HasTypeContext=*/true);
@@ -3155,8 +3154,8 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
31553154
llvm::DenseSet<EnumElementDecl *> Elements;
31563155
ED->getAllElements(Elements);
31573156
for (auto *Ele : Elements) {
3158-
if (!Ele->hasInterfaceType())
3159-
D->getASTContext().getLazyResolver()->resolveDeclSignature(Ele);
3157+
// FIXME(InterfaceTypeRequest): Remove this.
3158+
(void)Ele->getInterfaceType();
31603159
addEnumElementRef(Ele, Reason, dynamicLookupInfo,
31613160
/*HasTypeContext=*/true);
31623161
}
@@ -4330,8 +4329,8 @@ class CompletionOverrideLookup : public swift::VisibleDeclConsumer {
43304329
(D->isStatic() && D->getAttrs().hasAttribute<HasInitialValueAttr>()))
43314330
return;
43324331

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

43364335
bool hasIntroducer = hasFuncIntroducer ||
43374336
hasVarIntroducer ||

lib/IDE/ExprContextAnalysis.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,10 @@ static void collectPossibleCalleesByQualifiedLookup(
284284
continue;
285285
if (!isMemberDeclApplied(&DC, baseTy->getMetatypeInstanceType(), VD))
286286
continue;
287-
if (!VD->hasInterfaceType()) {
288-
VD->getASTContext().getLazyResolver()->resolveDeclSignature(VD);
289-
if (!VD->hasInterfaceType())
290-
continue;
291-
}
292287
Type declaredMemberType = VD->getInterfaceType();
288+
if (!declaredMemberType) {
289+
continue;
290+
}
293291
if (!declaredMemberType->is<AnyFunctionType>())
294292
continue;
295293
if (VD->getDeclContext()->isTypeContext()) {
@@ -899,7 +897,7 @@ bool swift::ide::isReferenceableByImplicitMemberExpr(
899897
if (VD->isOperator())
900898
return false;
901899

902-
if (!VD->hasInterfaceType())
900+
if (!VD->getInterfaceType())
903901
return false;
904902

905903
if (T->getOptionalObjectType() &&

lib/IDE/TypeContextInfo.cpp

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

142-
if (!VD->hasInterfaceType()) {
143-
TypeResolver->resolveDeclSignature(VD);
144-
if (!VD->hasInterfaceType())
145-
return false;
142+
if (!VD->getInterfaceType()) {
143+
return false;
146144
}
147145

148146
// Enum element decls can always be referenced by implicit member

0 commit comments

Comments
 (0)