Skip to content

Commit 3e48f71

Browse files
authored
Merge pull request #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

lib/IRGen/GenEnum.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5777,10 +5777,7 @@ EnumImplStrategy::get(TypeConverter &TC, SILType type, EnumDecl *theEnum) {
57775777
elementsWithPayload.push_back({elt, nativeTI, nativeTI});
57785778
continue;
57795779
}
5780-
5781-
if (!elt->hasInterfaceType())
5782-
TC.IGM.Context.getLazyResolver()->resolveDeclSignature(elt);
5783-
5780+
57845781
// Compute whether this gives us an apparent payload or dynamic layout.
57855782
// Note that we do *not* apply substitutions from a bound generic instance
57865783
// yet. We want all instances of a generic enum to share an implementation

lib/IRGen/GenType.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,9 +1920,6 @@ namespace {
19201920
return true;
19211921

19221922
for (auto field : decl->getStoredProperties()) {
1923-
if (!field->hasInterfaceType())
1924-
IGM.Context.getLazyResolver()->resolveDeclSignature(field);
1925-
19261923
if (visit(field->getInterfaceType()->getCanonicalType()))
19271924
return true;
19281925
}
@@ -1947,9 +1944,6 @@ namespace {
19471944
if (!elt->hasAssociatedValues() || elt->isIndirect())
19481945
continue;
19491946

1950-
if (!elt->hasInterfaceType())
1951-
IGM.Context.getLazyResolver()->resolveDeclSignature(elt);
1952-
19531947
if (visit(elt->getArgumentInterfaceType()->getCanonicalType()))
19541948
return true;
19551949
}

lib/SIL/SILType.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,13 @@ bool SILType::canRefCast(SILType operTy, SILType resultTy, SILModule &M) {
139139

140140
SILType SILType::getFieldType(VarDecl *field,
141141
TypeConverter &TC) const {
142-
auto baseTy = getASTType();
143-
144-
if (!field->hasInterfaceType())
145-
TC.Context.getLazyResolver()->resolveDeclSignature(field);
146-
147142
AbstractionPattern origFieldTy = TC.getAbstractionPattern(field);
148143
CanType substFieldTy;
149144
if (field->hasClangNode()) {
150145
substFieldTy = origFieldTy.getType();
151146
} else {
152147
substFieldTy =
153-
baseTy->getTypeOfMember(&TC.M, field, nullptr)->getCanonicalType();
148+
getASTType()->getTypeOfMember(&TC.M, field, nullptr)->getCanonicalType();
154149
}
155150

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

178-
if (!elt->hasInterfaceType())
179-
TC.Context.getLazyResolver()->resolveDeclSignature(elt);
180-
181173
// If the case is indirect, then the payload is boxed.
182174
if (elt->isIndirect() || elt->getParentEnum()->isIndirect()) {
183175
auto box = TC.getBoxTypeForEnumElement(*this, elt);

lib/SIL/TypeLowering.cpp

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,10 +1267,6 @@ namespace {
12671267

12681268
// Classify the type according to its stored properties.
12691269
for (auto field : D->getStoredProperties()) {
1270-
// FIXME: Remove this once getInterfaceType() is a request.
1271-
if (!field->hasInterfaceType())
1272-
TC.Context.getLazyResolver()->resolveDeclSignature(field);
1273-
12741270
auto substFieldType =
12751271
field->getInterfaceType().subst(subMap)->getCanonicalType();
12761272

@@ -1313,11 +1309,7 @@ namespace {
13131309
properties.setNonTrivial();
13141310
continue;
13151311
}
1316-
1317-
// FIXME: Remove this once getInterfaceType() is a request.
1318-
if (!elt->hasInterfaceType())
1319-
TC.Context.getLazyResolver()->resolveDeclSignature(elt);
1320-
1312+
13211313
auto substEltType =
13221314
elt->getArgumentInterfaceType().subst(subMap)->getCanonicalType();
13231315

@@ -1895,11 +1887,6 @@ getFunctionInterfaceTypeWithCaptures(TypeConverter &TC,
18951887

18961888
CanAnyFunctionType TypeConverter::makeConstantInterfaceType(SILDeclRef c) {
18971889
auto *vd = c.loc.dyn_cast<ValueDecl *>();
1898-
1899-
if (vd && !vd->hasInterfaceType()) {
1900-
Context.getLazyResolver()->resolveDeclSignature(vd);
1901-
}
1902-
19031890
switch (c.kind) {
19041891
case SILDeclRef::Kind::Func: {
19051892
CanAnyFunctionType funcTy;
@@ -2612,11 +2599,6 @@ CanSILBoxType TypeConverter::getBoxTypeForEnumElement(SILType enumType,
26122599
assert(elt->isIndirect() || elt->getParentEnum()->isIndirect());
26132600

26142601
auto &C = M.getASTContext();
2615-
2616-
// FIXME: Remove this once getInterfaceType() is a request.
2617-
if (!elt->hasInterfaceType())
2618-
Context.getLazyResolver()->resolveDeclSignature(elt);
2619-
26202602
auto boxSignature = getCanonicalSignatureOrNull(
26212603
enumDecl->getGenericSignature());
26222604

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

2691-
if (!elt->hasInterfaceType())
2692-
TC.Context.getLazyResolver()->resolveDeclSignature(elt);
2693-
26942673
// Although one might assume enums have a fields count of 1
26952674
// Which holds true for current uses of this code
26962675
// (we shouldn't expand enums)

lib/SILOptimizer/Analysis/DestructorAnalysis.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,6 @@ bool DestructorAnalysis::isSafeType(CanType Ty) {
7474

7575
// Check the stored properties.
7676
for (auto SP : Struct->getStoredProperties()) {
77-
// FIXME: Remove this once getInterfaceType() is a request.
78-
if (!SP->hasInterfaceType()) {
79-
ASTContext &Ctx = Mod->getSwiftModule()->getASTContext();
80-
Ctx.getLazyResolver()->resolveDeclSignature(SP);
81-
}
8277
if (!isSafeType(SP->getInterfaceType()->getCanonicalType()))
8378
return cacheResult(Ty, false);
8479
}

0 commit comments

Comments
 (0)