Skip to content

Commit f8db055

Browse files
committed
[NFC][lldb] Replace swift::ASTContext with SwiftASTContext
In SwiftEnumDescriptor, replace the usages of swift::ASTContext with SwiftASTContext. swift::ASTContext is wrapped on a lock now, and SwiftEnumDescriptor would only use it to access SwiftASTContext, so pass the latter directly.
1 parent c7323d2 commit f8db055

File tree

1 file changed

+36
-40
lines changed

1 file changed

+36
-40
lines changed

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -278,18 +278,18 @@ typedef std::shared_ptr<SwiftEnumDescriptor> SwiftEnumDescriptorSP;
278278
typedef llvm::DenseMap<opaque_compiler_type_t, SwiftEnumDescriptorSP>
279279
EnumInfoCache;
280280
typedef std::shared_ptr<EnumInfoCache> EnumInfoCacheSP;
281-
typedef llvm::DenseMap<const swift::ASTContext *, EnumInfoCacheSP>
281+
typedef llvm::DenseMap<const SwiftASTContext *, EnumInfoCacheSP>
282282
ASTEnumInfoCacheMap;
283283

284-
static EnumInfoCache *GetEnumInfoCache(const swift::ASTContext *a) {
284+
static EnumInfoCache *GetEnumInfoCache(const SwiftASTContext *swift_ast_ctx) {
285285
static ASTEnumInfoCacheMap g_cache;
286286
static std::mutex g_mutex;
287287
std::lock_guard<std::mutex> locker(g_mutex);
288-
ASTEnumInfoCacheMap::iterator pos = g_cache.find(a);
288+
ASTEnumInfoCacheMap::iterator pos = g_cache.find(swift_ast_ctx);
289289
if (pos == g_cache.end()) {
290-
g_cache.insert(
291-
std::make_pair(a, std::shared_ptr<EnumInfoCache>(new EnumInfoCache())));
292-
return g_cache.find(a)->second.get();
290+
g_cache.insert(std::make_pair(
291+
swift_ast_ctx, std::shared_ptr<EnumInfoCache>(new EnumInfoCache())));
292+
return g_cache.find(swift_ast_ctx)->second.get();
293293
}
294294
return pos->second.get();
295295
}
@@ -357,12 +357,12 @@ class SwiftEnumDescriptor {
357357

358358
virtual ~SwiftEnumDescriptor() = default;
359359

360-
static SwiftEnumDescriptor *CreateDescriptor(swift::ASTContext *ast,
360+
static SwiftEnumDescriptor *CreateDescriptor(SwiftASTContext *swift_ast_ctx,
361361
swift::CanType swift_can_type,
362362
swift::EnumDecl *enum_decl);
363363

364364
protected:
365-
SwiftEnumDescriptor(swift::ASTContext *ast, swift::CanType swift_can_type,
365+
SwiftEnumDescriptor(swift::CanType swift_can_type,
366366
swift::EnumDecl *enum_decl, SwiftEnumDescriptor::Kind k)
367367
: m_kind(k), m_type_name() {
368368
if (swift_can_type.getPointer()) {
@@ -381,10 +381,9 @@ class SwiftEnumDescriptor {
381381

382382
class SwiftEmptyEnumDescriptor : public SwiftEnumDescriptor {
383383
public:
384-
SwiftEmptyEnumDescriptor(swift::ASTContext *ast,
385-
swift::CanType swift_can_type,
384+
SwiftEmptyEnumDescriptor(swift::CanType swift_can_type,
386385
swift::EnumDecl *enum_decl)
387-
: SwiftEnumDescriptor(ast, swift_can_type, enum_decl,
386+
: SwiftEnumDescriptor(swift_can_type, enum_decl,
388387
SwiftEnumDescriptor::Kind::Empty) {}
389388

390389
ElementInfo *GetElementFromData(const lldb_private::DataExtractor &data,
@@ -445,18 +444,15 @@ class SwiftCStyleEnumDescriptor : public SwiftEnumDescriptor {
445444
llvm::SmallString<32> m_description = {"SwiftCStyleEnumDescriptor"};
446445

447446
public:
448-
SwiftCStyleEnumDescriptor(swift::ASTContext *ast,
447+
SwiftCStyleEnumDescriptor(SwiftASTContext *swift_ast_ctx,
449448
swift::CanType swift_can_type,
450449
swift::EnumDecl *enum_decl)
451-
: SwiftEnumDescriptor(ast, swift_can_type, enum_decl,
450+
: SwiftEnumDescriptor(swift_can_type, enum_decl,
452451
SwiftEnumDescriptor::Kind::CStyle),
453452
m_nopayload_elems_bitmask(), m_elements(), m_element_indexes() {
454453
LOG_PRINTF(GetLog(LLDBLog::Types), "doing C-style enum layout for %s",
455454
GetTypeName().AsCString());
456455

457-
SwiftASTContext *swift_ast_ctx = SwiftASTContext::GetSwiftASTContext(ast);
458-
if (!swift_ast_ctx)
459-
return;
460456
swift::irgen::IRGenModule &irgen_module = swift_ast_ctx->GetIRGenModule();
461457
const swift::irgen::EnumImplStrategy &enum_impl_strategy =
462458
swift::irgen::getEnumImplStrategy(irgen_module, swift_can_type);
@@ -587,15 +583,14 @@ class SwiftAllPayloadEnumDescriptor : public SwiftEnumDescriptor {
587583
llvm::SmallString<32> m_description = {"SwiftAllPayloadEnumDescriptor"};
588584

589585
public:
590-
SwiftAllPayloadEnumDescriptor(swift::ASTContext *ast,
586+
SwiftAllPayloadEnumDescriptor(SwiftASTContext *swift_ast_ctx,
591587
swift::CanType swift_can_type,
592588
swift::EnumDecl *enum_decl)
593-
: SwiftEnumDescriptor(ast, swift_can_type, enum_decl,
589+
: SwiftEnumDescriptor(swift_can_type, enum_decl,
594590
SwiftEnumDescriptor::Kind::AllPayload) {
595591
LOG_PRINTF(GetLog(LLDBLog::Types), "doing ADT-style enum layout for %s",
596592
GetTypeName().AsCString());
597593

598-
SwiftASTContext *swift_ast_ctx = SwiftASTContext::GetSwiftASTContext(ast);
599594
swift::irgen::IRGenModule &irgen_module = swift_ast_ctx->GetIRGenModule();
600595
const swift::irgen::EnumImplStrategy &enum_impl_strategy =
601596
swift::irgen::getEnumImplStrategy(irgen_module, swift_can_type);
@@ -730,13 +725,13 @@ class SwiftAllPayloadEnumDescriptor : public SwiftEnumDescriptor {
730725

731726
class SwiftMixedEnumDescriptor : public SwiftEnumDescriptor {
732727
public:
733-
SwiftMixedEnumDescriptor(swift::ASTContext *ast,
728+
SwiftMixedEnumDescriptor(SwiftASTContext *swift_ast_ctx,
734729
swift::CanType swift_can_type,
735730
swift::EnumDecl *enum_decl)
736-
: SwiftEnumDescriptor(ast, swift_can_type, enum_decl,
731+
: SwiftEnumDescriptor(swift_can_type, enum_decl,
737732
SwiftEnumDescriptor::Kind::Mixed),
738-
m_non_payload_cases(ast, swift_can_type, enum_decl),
739-
m_payload_cases(ast, swift_can_type, enum_decl) {}
733+
m_non_payload_cases(swift_ast_ctx, swift_can_type, enum_decl),
734+
m_payload_cases(swift_ast_ctx, swift_can_type, enum_decl) {}
740735

741736
ElementInfo *GetElementFromData(const lldb_private::DataExtractor &data,
742737
bool no_payload) override {
@@ -775,10 +770,9 @@ class SwiftResilientEnumDescriptor : public SwiftEnumDescriptor {
775770
llvm::SmallString<32> m_description = {"SwiftResilientEnumDescriptor"};
776771

777772
public:
778-
SwiftResilientEnumDescriptor(swift::ASTContext *ast,
779-
swift::CanType swift_can_type,
773+
SwiftResilientEnumDescriptor(swift::CanType swift_can_type,
780774
swift::EnumDecl *enum_decl)
781-
: SwiftEnumDescriptor(ast, swift_can_type, enum_decl,
775+
: SwiftEnumDescriptor(swift_can_type, enum_decl,
782776
SwiftEnumDescriptor::Kind::Resilient) {
783777
LOG_PRINTF(GetLog(LLDBLog::Types), "doing resilient enum layout for %s",
784778
GetTypeName().AsCString());
@@ -803,13 +797,12 @@ class SwiftResilientEnumDescriptor : public SwiftEnumDescriptor {
803797
};
804798

805799
SwiftEnumDescriptor *
806-
SwiftEnumDescriptor::CreateDescriptor(swift::ASTContext *ast,
800+
SwiftEnumDescriptor::CreateDescriptor(SwiftASTContext *swift_ast_ctx,
807801
swift::CanType swift_can_type,
808802
swift::EnumDecl *enum_decl) {
809-
assert(ast);
803+
assert(swift_ast_ctx);
810804
assert(enum_decl);
811805
assert(swift_can_type.getPointer());
812-
SwiftASTContext *swift_ast_ctx = SwiftASTContext::GetSwiftASTContext(ast);
813806
assert(swift_ast_ctx);
814807
swift::irgen::IRGenModule &irgen_module = swift_ast_ctx->GetIRGenModule();
815808
const swift::irgen::EnumImplStrategy &enum_impl_strategy =
@@ -820,32 +813,35 @@ SwiftEnumDescriptor::CreateDescriptor(swift::ASTContext *ast,
820813
elements_with_no_payload = enum_impl_strategy.getElementsWithNoPayload();
821814
swift::SILType swift_sil_type = irgen_module.getLoweredType(swift_can_type);
822815
if (!irgen_module.getTypeInfo(swift_sil_type).isFixedSize())
823-
return new SwiftResilientEnumDescriptor(ast, swift_can_type, enum_decl);
816+
return new SwiftResilientEnumDescriptor(swift_can_type, enum_decl);
824817
if (elements_with_no_payload.size() == 0) {
825818
// Nothing with no payload.. empty or all payloads?
826819
if (elements_with_payload.size() == 0)
827-
return new SwiftEmptyEnumDescriptor(ast, swift_can_type, enum_decl);
828-
return new SwiftAllPayloadEnumDescriptor(ast, swift_can_type, enum_decl);
820+
return new SwiftEmptyEnumDescriptor(swift_can_type, enum_decl);
821+
return new SwiftAllPayloadEnumDescriptor(swift_ast_ctx, swift_can_type,
822+
enum_decl);
829823
}
830824

831825
// Something with no payload.. mixed or C-style?
832826
if (elements_with_payload.size() == 0)
833-
return new SwiftCStyleEnumDescriptor(ast, swift_can_type, enum_decl);
834-
return new SwiftMixedEnumDescriptor(ast, swift_can_type, enum_decl);
827+
return new SwiftCStyleEnumDescriptor(swift_ast_ctx, swift_can_type,
828+
enum_decl);
829+
return new SwiftMixedEnumDescriptor(swift_ast_ctx, swift_can_type, enum_decl);
835830
}
836831

837832
static SwiftEnumDescriptor *
838-
GetEnumInfoFromEnumDecl(swift::ASTContext *ast, swift::CanType swift_can_type,
833+
GetEnumInfoFromEnumDecl(SwiftASTContext *swift_ast_ctx,
834+
swift::CanType swift_can_type,
839835
swift::EnumDecl *enum_decl) {
840-
return SwiftEnumDescriptor::CreateDescriptor(ast, swift_can_type, enum_decl);
836+
return SwiftEnumDescriptor::CreateDescriptor(swift_ast_ctx, swift_can_type,
837+
enum_decl);
841838
}
842839

843840
SwiftEnumDescriptor *
844841
SwiftASTContext::GetCachedEnumInfo(opaque_compiler_type_t type) {
845842
VALID_OR_RETURN_CHECK_TYPE(type, nullptr);
846843

847-
ThreadSafeASTContext ast_ctx = GetASTContext();
848-
EnumInfoCache *enum_info_cache = GetEnumInfoCache(*ast_ctx);
844+
EnumInfoCache *enum_info_cache = GetEnumInfoCache(this);
849845
EnumInfoCache::const_iterator pos = enum_info_cache->find(type);
850846
if (pos != enum_info_cache->end())
851847
return pos->second.get();
@@ -856,11 +852,11 @@ SwiftASTContext::GetCachedEnumInfo(opaque_compiler_type_t type) {
856852
SwiftEnumDescriptorSP enum_info_sp;
857853
swift::CanType swift_can_type(GetCanonicalSwiftType(type));
858854
if (auto *enum_type = swift_can_type->getAs<swift::EnumType>()) {
859-
enum_info_sp.reset(GetEnumInfoFromEnumDecl(*ast_ctx, swift_can_type,
855+
enum_info_sp.reset(GetEnumInfoFromEnumDecl(this, swift_can_type,
860856
enum_type->getDecl()));
861857
} else if (auto *bound_enum_type =
862858
swift_can_type->getAs<swift::BoundGenericEnumType>()) {
863-
enum_info_sp.reset(GetEnumInfoFromEnumDecl(*ast_ctx, swift_can_type,
859+
enum_info_sp.reset(GetEnumInfoFromEnumDecl(this, swift_can_type,
864860
bound_enum_type->getDecl()));
865861
}
866862

0 commit comments

Comments
 (0)