Skip to content

Commit 28bf67b

Browse files
tromeyggreif
authored andcommitted
Remove by-name cache from RustASTContext
Remove the by-name cache from RustASTContext. This was not needed and could interact badly with the DWARF parser. Closes llvm#22 Signed-off-by: Gabor Greif <[email protected]>
1 parent f6f8aee commit 28bf67b

File tree

3 files changed

+20
-59
lines changed

3 files changed

+20
-59
lines changed

lldb/include/lldb/Symbol/RustASTContext.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,14 +449,12 @@ class RustASTContext : public TypeSystem {
449449

450450
private:
451451
int m_pointer_byte_size;
452-
std::map<ConstString, std::unique_ptr<RustType>> m_types;
453-
std::set<std::unique_ptr<RustType>> m_anon_types;
452+
std::set<std::unique_ptr<RustType>> m_types;
454453
std::unique_ptr<DWARFASTParser> m_dwarf_ast_parser_ap;
455454

456455
std::unique_ptr<RustDeclContext> m_tu_decl;
457456

458-
RustType *FindCachedType(const lldb_private::ConstString &name);
459-
CompilerType CacheType(const lldb_private::ConstString &name, RustType *new_type);
457+
CompilerType CacheType(RustType *new_type);
460458

461459
RustASTContext(const RustASTContext &) = delete;
462460
const RustASTContext &operator=(const RustASTContext &) = delete;

lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserRust.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ TypeSP DWARFASTParserRust::ParseSimpleType(const DWARFDIE &die) {
237237
compiler_type = m_ast.CreateBoolType(type_name_const_str);
238238
else if (encoding == DW_ATE_float)
239239
compiler_type = m_ast.CreateFloatType(type_name_const_str, byte_size);
240+
else if (byte_size == 0 && type_name_const_str &&
241+
strcmp(type_name_const_str.AsCString(), "()") == 0)
242+
compiler_type = m_ast.CreateTupleType(type_name_const_str, byte_size, false);
240243
else if (encoding == DW_ATE_signed || encoding == DW_ATE_unsigned ||
241244
// DW_ATE_UCS seems to be less used (perhaps
242245
// Fortran-specific?) and since I'm not planning to have

lldb/source/Symbol/RustASTContext.cpp

Lines changed: 15 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,40 +1834,22 @@ void RustASTContext::DumpTypeDescription(lldb::opaque_compiler_type_t type, Stre
18341834
s->PutCString(name.AsCString());
18351835
}
18361836

1837-
RustType *RustASTContext::FindCachedType(const lldb_private::ConstString &name) {
1838-
if (name.IsEmpty())
1839-
return nullptr;
1840-
auto result = m_types.find(name);
1841-
if (result == m_types.end ())
1842-
return nullptr;
1843-
return result->second.get();
1844-
}
1845-
1846-
CompilerType RustASTContext::CacheType(const ConstString &name, RustType *new_type) {
1847-
if (name.IsEmpty()) {
1848-
// Be sure to keep nameless types alive.
1849-
m_anon_types.insert(std::unique_ptr<RustType>(new_type));
1850-
} else {
1851-
m_types[name].reset(new_type);
1852-
}
1837+
CompilerType RustASTContext::CacheType(RustType *new_type) {
1838+
m_types.insert(std::unique_ptr<RustType>(new_type));
18531839
return CompilerType(this, new_type);
18541840
}
18551841

18561842
CompilerType RustASTContext::CreateBoolType(const lldb_private::ConstString &name) {
1857-
if (RustType *cached = FindCachedType(name))
1858-
return CompilerType(this, cached);
18591843
RustType *type = new RustBool(name);
1860-
return CacheType(name, type);
1844+
return CacheType(type);
18611845
}
18621846

18631847
CompilerType RustASTContext::CreateIntegralType(const lldb_private::ConstString &name,
18641848
bool is_signed,
18651849
uint64_t byte_size,
18661850
bool is_char_type) {
1867-
if (RustType *cached = FindCachedType(name))
1868-
return CompilerType(this, cached);
18691851
RustType *type = new RustIntegral(name, is_signed, byte_size, is_char_type);
1870-
return CacheType(name, type);
1852+
return CacheType(type);
18711853
}
18721854

18731855
CompilerType RustASTContext::CreateIntrinsicIntegralType(bool is_signed, uint64_t byte_size) {
@@ -1885,10 +1867,8 @@ CompilerType RustASTContext::CreateCharType() {
18851867

18861868
CompilerType RustASTContext::CreateFloatType(const lldb_private::ConstString &name,
18871869
uint64_t byte_size) {
1888-
if (RustType *cached = FindCachedType(name))
1889-
return CompilerType(this, cached);
18901870
RustType *type = new RustFloat(name, byte_size);
1891-
return CacheType(name, type);
1871+
return CacheType(type);
18921872
}
18931873

18941874
CompilerType RustASTContext::CreateArrayType(const CompilerType &element_type,
@@ -1900,53 +1880,41 @@ CompilerType RustASTContext::CreateArrayType(const CompilerType &element_type,
19001880
name += "]";
19011881
ConstString newname(name);
19021882

1903-
if (RustType *cached = FindCachedType(newname))
1904-
return CompilerType(this, cached);
19051883
RustType *type = new RustArray(newname, length, element_type);
1906-
return CacheType(newname, type);
1884+
return CacheType(type);
19071885
}
19081886

19091887
CompilerType RustASTContext::CreateTypedefType(const ConstString &name, CompilerType impl) {
1910-
if (RustType *cached = FindCachedType(name))
1911-
return CompilerType(this, cached);
19121888
RustType *type = new RustTypedef(name, impl);
1913-
return CacheType(name, type);
1889+
return CacheType(type);
19141890
}
19151891

19161892
CompilerType
19171893
RustASTContext::CreateStructType(const lldb_private::ConstString &name, uint32_t byte_size,
19181894
bool has_discriminant) {
1919-
if (RustType *cached = FindCachedType(name))
1920-
return CompilerType(this, cached);
19211895
RustType *type = new RustStruct(name, byte_size, has_discriminant);
1922-
return CacheType(name, type);
1896+
return CacheType(type);
19231897
}
19241898

19251899
CompilerType
19261900
RustASTContext::CreateTupleType(const lldb_private::ConstString &name, uint32_t byte_size,
19271901
bool has_discriminant) {
1928-
if (RustType *cached = FindCachedType(name))
1929-
return CompilerType(this, cached);
19301902
RustType *type = new RustTuple(name, byte_size, has_discriminant);
1931-
return CacheType(name, type);
1903+
return CacheType(type);
19321904
}
19331905

19341906
CompilerType
19351907
RustASTContext::CreateUnionType(const lldb_private::ConstString &name, uint32_t byte_size) {
1936-
if (RustType *cached = FindCachedType(name))
1937-
return CompilerType(this, cached);
19381908
RustType *type = new RustUnion(name, byte_size);
1939-
return CacheType(name, type);
1909+
return CacheType(type);
19401910
}
19411911

19421912
CompilerType
19431913
RustASTContext::CreatePointerType(const lldb_private::ConstString &name,
19441914
const CompilerType &pointee_type,
19451915
uint32_t byte_size) {
1946-
if (RustType *cached = FindCachedType(name))
1947-
return CompilerType(this, cached);
19481916
RustType *type = new RustPointer(name, pointee_type, byte_size);
1949-
return CacheType(name, type);
1917+
return CacheType(type);
19501918
}
19511919

19521920
void RustASTContext::AddFieldToStruct(const CompilerType &struct_type,
@@ -1973,39 +1941,31 @@ CompilerType
19731941
RustASTContext::CreateFunctionType(const lldb_private::ConstString &name,
19741942
const CompilerType &return_type,
19751943
const std::vector<CompilerType> &&params) {
1976-
if (RustType *cached = FindCachedType(name))
1977-
return CompilerType(this, cached);
19781944
RustType *type = new RustFunction(name, m_pointer_byte_size, return_type, std::move(params));
1979-
return CacheType(name, type);
1945+
return CacheType(type);
19801946
}
19811947

19821948
CompilerType
19831949
RustASTContext::CreateVoidType() {
19841950
ConstString name("()");
1985-
if (RustType *cached = FindCachedType(name))
1986-
return CompilerType(this, cached);
19871951
RustType *type = new RustTuple(name, 0, false);
1988-
return CacheType(name, type);
1952+
return CacheType(type);
19891953
}
19901954

19911955
CompilerType
19921956
RustASTContext::CreateEnumType(const lldb_private::ConstString &name,
19931957
uint64_t byte_size, uint32_t discr_offset,
19941958
uint32_t discr_byte_size) {
1995-
if (RustType *cached = FindCachedType(name))
1996-
return CompilerType(this, cached);
19971959
RustType *type = new RustEnum(name, byte_size, discr_offset, discr_byte_size);
1998-
return CacheType(name, type);
1960+
return CacheType(type);
19991961
}
20001962

20011963
CompilerType
20021964
RustASTContext::CreateCLikeEnumType(const lldb_private::ConstString &name,
20031965
const CompilerType &underlying_type,
20041966
std::map<uint64_t, std::string> &&values) {
2005-
if (RustType *cached = FindCachedType(name))
2006-
return CompilerType(this, cached);
20071967
RustType *type = new RustCLikeEnum(name, underlying_type, std::move(values));
2008-
return CacheType(name, type);
1968+
return CacheType(type);
20091969
}
20101970

20111971
bool

0 commit comments

Comments
 (0)