@@ -1957,7 +1957,8 @@ static TinyPtrVector<NominalTypeDecl *>
1957
1957
resolveTypeDeclsToNominal (Evaluator &evaluator,
1958
1958
ASTContext &ctx,
1959
1959
ArrayRef<TypeDecl *> typeDecls,
1960
- SmallVectorImpl<ModuleDecl *> &modulesFound) {
1960
+ SmallVectorImpl<ModuleDecl *> &modulesFound,
1961
+ bool &anyObject) {
1961
1962
TinyPtrVector<NominalTypeDecl *> nominalDecls;
1962
1963
1963
1964
for (auto typeDecl : typeDecls) {
@@ -1973,10 +1974,32 @@ resolveTypeDeclsToNominal(Evaluator &evaluator,
1973
1974
= evaluator (UnderlyingTypeDeclsReferencedRequest{typealias});
1974
1975
auto underlyingNominalReferences
1975
1976
= resolveTypeDeclsToNominal (evaluator, ctx, underlyingTypeReferences,
1976
- modulesFound);
1977
+ modulesFound, anyObject );
1977
1978
nominalDecls.insert (nominalDecls.end (),
1978
1979
underlyingNominalReferences.begin (),
1979
1980
underlyingNominalReferences.end ());
1981
+
1982
+ // Recognize Swift.AnyObject directly.
1983
+ if (typealias->getName ().is (" AnyObject" )) {
1984
+ // TypeRepr version: Builtin.AnyObject
1985
+ if (auto typeRepr = typealias->getUnderlyingTypeLoc ().getTypeRepr ()) {
1986
+ if (auto compound = dyn_cast<CompoundIdentTypeRepr>(typeRepr)) {
1987
+ auto components = compound->getComponents ();
1988
+ if (components.size () == 2 &&
1989
+ components[0 ]->getIdentifier ().is (" Builtin" ) &&
1990
+ components[1 ]->getIdentifier ().is (" AnyObject" )) {
1991
+ anyObject = true ;
1992
+ }
1993
+ }
1994
+ }
1995
+
1996
+ // Type version: an empty class-bound existential.
1997
+ if (auto type = typealias->getUnderlyingTypeLoc ().getType ()) {
1998
+ if (type->isAnyObject ())
1999
+ anyObject = true ;
2000
+ }
2001
+ }
2002
+
1980
2003
continue ;
1981
2004
}
1982
2005
@@ -2018,8 +2041,10 @@ directReferencesForQualifiedTypeLookup(Evaluator &evaluator,
2018
2041
// Look through the base types to find something on which we can perform
2019
2042
// qualified name lookup.
2020
2043
SmallVector<ModuleDecl *, 2 > moduleBaseTypes;
2044
+ bool anyObject = false ;
2021
2045
auto nominalBaseTypes =
2022
- resolveTypeDeclsToNominal (evaluator, ctx, baseTypes, moduleBaseTypes);
2046
+ resolveTypeDeclsToNominal (evaluator, ctx, baseTypes, moduleBaseTypes,
2047
+ anyObject);
2023
2048
2024
2049
DirectlyReferencedTypeDecls result;
2025
2050
auto addResults = [&result](ArrayRef<ValueDecl *> found){
@@ -2241,9 +2266,10 @@ ClassDecl *SuperclassDeclRequest::evaluate(Evaluator &evaluator,
2241
2266
2242
2267
// Resolve those type declarations to nominal type declarations.
2243
2268
SmallVector<ModuleDecl *, 2 > modulesFound;
2269
+ bool anyObject = false ;
2244
2270
auto inheritedNominalTypes
2245
2271
= resolveTypeDeclsToNominal (evaluator, subject->getASTContext (),
2246
- inheritedTypes, modulesFound);
2272
+ inheritedTypes, modulesFound, anyObject );
2247
2273
2248
2274
// Look for a class declaration.
2249
2275
for (auto inheritedNominal : inheritedNominalTypes) {
@@ -2273,15 +2299,18 @@ NominalTypeDecl *ExtendedNominalRequest::evaluate(Evaluator &evaluator,
2273
2299
2274
2300
// Resolve those type declarations to nominal type declarations.
2275
2301
SmallVector<ModuleDecl *, 2 > modulesFound;
2302
+ bool anyObject = false ;
2276
2303
auto nominalTypes
2277
- = resolveTypeDeclsToNominal (evaluator, ctx, referenced, modulesFound);
2304
+ = resolveTypeDeclsToNominal (evaluator, ctx, referenced, modulesFound,
2305
+ anyObject);
2278
2306
return nominalTypes.empty () ? nullptr : nominalTypes.front ();
2279
2307
}
2280
2308
2281
2309
void swift::getDirectlyInheritedNominalTypeDecls (
2282
2310
llvm::PointerUnion<TypeDecl *, ExtensionDecl *> decl,
2283
2311
unsigned i,
2284
- llvm::SmallVectorImpl<std::pair<SourceLoc, NominalTypeDecl *>> &result) {
2312
+ llvm::SmallVectorImpl<std::pair<SourceLoc, NominalTypeDecl *>> &result,
2313
+ bool &anyObject) {
2285
2314
auto typeDecl = decl.dyn_cast <TypeDecl *>();
2286
2315
auto extDecl = decl.dyn_cast <ExtensionDecl *>();
2287
2316
@@ -2294,7 +2323,8 @@ void swift::getDirectlyInheritedNominalTypeDecls(
2294
2323
// Resolve those type declarations to nominal type declarations.
2295
2324
SmallVector<ModuleDecl *, 2 > modulesFound;
2296
2325
auto nominalTypes
2297
- = resolveTypeDeclsToNominal (ctx.evaluator , ctx, referenced, modulesFound);
2326
+ = resolveTypeDeclsToNominal (ctx.evaluator , ctx, referenced, modulesFound,
2327
+ anyObject);
2298
2328
2299
2329
// Dig out the source location
2300
2330
// FIXME: This is a hack. We need cooperation from
@@ -2313,7 +2343,8 @@ void swift::getDirectlyInheritedNominalTypeDecls(
2313
2343
2314
2344
SmallVector<std::pair<SourceLoc, NominalTypeDecl *>, 4 >
2315
2345
swift::getDirectlyInheritedNominalTypeDecls (
2316
- llvm::PointerUnion<TypeDecl *, ExtensionDecl *> decl) {
2346
+ llvm::PointerUnion<TypeDecl *, ExtensionDecl *> decl,
2347
+ bool &anyObject) {
2317
2348
auto typeDecl = decl.dyn_cast <TypeDecl *>();
2318
2349
auto extDecl = decl.dyn_cast <ExtensionDecl *>();
2319
2350
@@ -2322,7 +2353,7 @@ swift::getDirectlyInheritedNominalTypeDecls(
2322
2353
: extDecl->getInherited ().size ();
2323
2354
SmallVector<std::pair<SourceLoc, NominalTypeDecl *>, 4 > result;
2324
2355
for (unsigned i : range (numInherited)) {
2325
- getDirectlyInheritedNominalTypeDecls (decl, i, result);
2356
+ getDirectlyInheritedNominalTypeDecls (decl, i, result, anyObject );
2326
2357
}
2327
2358
2328
2359
return result;
0 commit comments