@@ -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
@@ -1856,7 +1867,8 @@ uint32_t TypeSystemSwiftTypeRef::CollectTypeInfo(
1856
1867
1857
1868
// Clang-imported types.
1858
1869
llvm::SmallVector<CompilerContext, 2 > decl_context;
1859
- if (!IsClangImportedType (node, decl_context))
1870
+ bool ignore_modules = false ;
1871
+ if (!IsClangImportedType (node, decl_context, ignore_modules))
1860
1872
break ;
1861
1873
1862
1874
auto mangling = GetMangledName (dem, node, flavor);
@@ -1868,7 +1880,8 @@ uint32_t TypeSystemSwiftTypeRef::CollectTypeInfo(
1868
1880
return {};
1869
1881
}
1870
1882
// Resolve the typedef within the Clang debug info.
1871
- auto clang_type = LookupClangForwardType (mangling.result (), decl_context);
1883
+ auto clang_type =
1884
+ LookupClangForwardType (mangling.result (), decl_context, ignore_modules);
1872
1885
collect_clang_type (clang_type.GetCanonicalType ());
1873
1886
return swift_flags;
1874
1887
}
@@ -4409,10 +4422,12 @@ bool TypeSystemSwiftTypeRef::IsImportedType(opaque_compiler_type_t type,
4409
4422
4410
4423
// This is an imported Objective-C type; look it up in the debug info.
4411
4424
llvm::SmallVector<CompilerContext, 2 > decl_context;
4412
- if (!IsClangImportedType (node, decl_context))
4425
+ bool ignore_modules = false ;
4426
+ if (!IsClangImportedType (node, decl_context, ignore_modules))
4413
4427
return false ;
4414
4428
if (original_type)
4415
- if (TypeSP clang_type = LookupClangType (AsMangledName (type), decl_context))
4429
+ if (TypeSP clang_type = LookupClangType (AsMangledName (type), decl_context,
4430
+ ignore_modules))
4416
4431
*original_type = clang_type->GetForwardCompilerType ();
4417
4432
return true ;
4418
4433
};
0 commit comments