@@ -389,16 +389,19 @@ CompilerType TypeSystemSwiftTypeRef::GetTypeFromTypeMetadataNode(
389
389
TypeSP TypeSystemSwiftTypeRef::LookupClangType (StringRef name_ref) {
390
390
llvm::SmallVector<CompilerContext, 2 > decl_context;
391
391
// Make up a decl context for non-nested types.
392
- decl_context.push_back ({CompilerContextKind::AnyModule, ConstString ()});
393
392
decl_context.push_back ({CompilerContextKind::AnyType, ConstString (name_ref)});
394
- return LookupClangType (name_ref, decl_context);
393
+ return LookupClangType (name_ref, decl_context, /* ignore_modules= */ true );
395
394
}
396
395
397
396
// / Look up one Clang type in a module.
398
397
static TypeSP LookupClangType (Module &m,
399
- llvm::ArrayRef<CompilerContext> decl_context) {
400
- TypeQuery query (decl_context, TypeQueryOptions::e_find_one |
401
- TypeQueryOptions::e_module_search);
398
+ llvm::ArrayRef<CompilerContext> decl_context,
399
+ bool ignore_modules) {
400
+ auto opts = TypeQueryOptions::e_find_one | TypeQueryOptions::e_module_search;
401
+ if (ignore_modules) {
402
+ opts |= TypeQueryOptions::e_ignore_modules;
403
+ }
404
+ TypeQuery query (decl_context, opts);
402
405
query.SetLanguages (TypeSystemClang::GetSupportedLanguagesForTypes ());
403
406
TypeResults results;
404
407
m.FindTypes (query, results);
@@ -407,16 +410,17 @@ static TypeSP LookupClangType(Module &m,
407
410
408
411
TypeSP TypeSystemSwiftTypeRef::LookupClangType (
409
412
StringRef name_ref, llvm::ArrayRef<CompilerContext> decl_context,
410
- ExecutionContext *exe_ctx) {
413
+ bool ignore_modules, ExecutionContext *exe_ctx) {
411
414
Module *m = GetModule ();
412
415
if (!m)
413
416
return {};
414
- return ::LookupClangType (const_cast <Module &>(*m), decl_context);
417
+ return ::LookupClangType (const_cast <Module &>(*m), decl_context,
418
+ ignore_modules);
415
419
}
416
420
417
421
TypeSP TypeSystemSwiftTypeRefForExpressions::LookupClangType (
418
422
StringRef name_ref, llvm::ArrayRef<CompilerContext> decl_context,
419
- ExecutionContext *exe_ctx) {
423
+ bool ignore_modules, ExecutionContext *exe_ctx) {
420
424
// Check the cache first. Negative results are also cached.
421
425
TypeSP result;
422
426
ConstString name (name_ref);
@@ -440,7 +444,8 @@ TypeSP TypeSystemSwiftTypeRefForExpressions::LookupClangType(
440
444
441
445
// Don't recursively call into LookupClangTypes() to avoid filling
442
446
// hundreds of image caches with negative results.
443
- result = ::LookupClangType (const_cast <Module &>(*m), decl_context);
447
+ result = ::LookupClangType (const_cast <Module &>(*m), decl_context,
448
+ ignore_modules);
444
449
// Cache it in the expression context.
445
450
if (result)
446
451
m_clang_type_cache.Insert (name.AsCString (), result);
@@ -458,8 +463,9 @@ TypeSP TypeSystemSwiftTypeRefForExpressions::LookupClangType(
458
463
459
464
// / Find a Clang type by name in module \p M.
460
465
CompilerType TypeSystemSwiftTypeRef::LookupClangForwardType (
461
- StringRef name, llvm::ArrayRef<CompilerContext> decl_context) {
462
- if (TypeSP type = LookupClangType (name, decl_context))
466
+ StringRef name, llvm::ArrayRef<CompilerContext> decl_context,
467
+ bool ignore_modules) {
468
+ if (TypeSP type = LookupClangType (name, decl_context, ignore_modules))
463
469
return type->GetForwardCompilerType ();
464
470
return {};
465
471
}
@@ -939,10 +945,11 @@ GetBuiltinAnyObjectNode(swift::Demangle::Demangler &dem) {
939
945
// / Builds the decl context to look up clang types with.
940
946
static bool
941
947
IsClangImportedType (NodePointer node,
942
- llvm::SmallVectorImpl<CompilerContext> &decl_context) {
948
+ llvm::SmallVectorImpl<CompilerContext> &decl_context,
949
+ bool &ignore_modules) {
943
950
if (node->getKind () == Node::Kind::Module && node->hasText () &&
944
951
node->getText () == swift::MANGLING_MODULE_OBJC) {
945
- decl_context. push_back ({CompilerContextKind::AnyModule, ConstString ()}) ;
952
+ ignore_modules = true ;
946
953
return true ;
947
954
}
948
955
@@ -954,7 +961,8 @@ IsClangImportedType(NodePointer node,
954
961
case Node::Kind::Class:
955
962
case Node::Kind::Enum:
956
963
case Node::Kind::TypeAlias:
957
- if (!IsClangImportedType (node->getFirstChild (), decl_context))
964
+ if (!IsClangImportedType (node->getFirstChild (), decl_context,
965
+ ignore_modules))
958
966
return false ;
959
967
960
968
// When C++ interop is enabled, Swift enums represent Swift namespaces.
@@ -996,12 +1004,13 @@ TypeSystemSwiftTypeRef::ResolveTypeAlias(swift::Demangle::Demangler &dem,
996
1004
auto resolve_clang_type = [&]() -> CompilerType {
997
1005
// This is an imported Objective-C type; look it up in the debug info.
998
1006
llvm::SmallVector<CompilerContext, 2 > decl_context;
999
- if (!IsClangImportedType (node, decl_context))
1007
+ bool ignore_modules = false ;
1008
+ if (!IsClangImportedType (node, decl_context, ignore_modules))
1000
1009
return {};
1001
1010
1002
1011
// Resolve the typedef within the Clang debug info.
1003
- auto clang_type =
1004
- LookupClangForwardType (mangled. GetStringRef (), decl_context);
1012
+ auto clang_type = LookupClangForwardType (mangled. GetStringRef (),
1013
+ decl_context, ignore_modules );
1005
1014
if (!clang_type)
1006
1015
return {};
1007
1016
@@ -1474,12 +1483,14 @@ swift::Demangle::NodePointer TypeSystemSwiftTypeRef::GetSwiftified(
1474
1483
}
1475
1484
1476
1485
llvm::SmallVector<CompilerContext, 2 > decl_context;
1477
- if (!IsClangImportedType (node, decl_context))
1486
+ bool ignore_modules = false ;
1487
+ if (!IsClangImportedType (node, decl_context, ignore_modules))
1478
1488
return node;
1479
1489
1480
1490
// This is an imported Objective-C type; look it up in the
1481
1491
// debug info.
1482
- TypeSP clang_type = LookupClangType (mangling.result (), decl_context);
1492
+ TypeSP clang_type =
1493
+ LookupClangType (mangling.result (), decl_context, ignore_modules);
1483
1494
if (!clang_type)
1484
1495
return node;
1485
1496
@@ -1838,7 +1849,8 @@ uint32_t TypeSystemSwiftTypeRef::CollectTypeInfo(
1838
1849
1839
1850
// Clang-imported types.
1840
1851
llvm::SmallVector<CompilerContext, 2 > decl_context;
1841
- if (!IsClangImportedType (node, decl_context))
1852
+ bool ignore_modules = false ;
1853
+ if (!IsClangImportedType (node, decl_context, ignore_modules))
1842
1854
break ;
1843
1855
1844
1856
auto mangling = GetMangledName (dem, node, flavor);
@@ -1850,7 +1862,8 @@ uint32_t TypeSystemSwiftTypeRef::CollectTypeInfo(
1850
1862
return {};
1851
1863
}
1852
1864
// Resolve the typedef within the Clang debug info.
1853
- auto clang_type = LookupClangForwardType (mangling.result (), decl_context);
1865
+ auto clang_type =
1866
+ LookupClangForwardType (mangling.result (), decl_context, ignore_modules);
1854
1867
collect_clang_type (clang_type.GetCanonicalType ());
1855
1868
return swift_flags;
1856
1869
}
@@ -4391,10 +4404,12 @@ bool TypeSystemSwiftTypeRef::IsImportedType(opaque_compiler_type_t type,
4391
4404
4392
4405
// This is an imported Objective-C type; look it up in the debug info.
4393
4406
llvm::SmallVector<CompilerContext, 2 > decl_context;
4394
- if (!IsClangImportedType (node, decl_context))
4407
+ bool ignore_modules = false ;
4408
+ if (!IsClangImportedType (node, decl_context, ignore_modules))
4395
4409
return false ;
4396
4410
if (original_type)
4397
- if (TypeSP clang_type = LookupClangType (AsMangledName (type), decl_context))
4411
+ if (TypeSP clang_type = LookupClangType (AsMangledName (type), decl_context,
4412
+ ignore_modules))
4398
4413
*original_type = clang_type->GetForwardCompilerType ();
4399
4414
return true ;
4400
4415
};
0 commit comments