Skip to content

Commit b5b39ab

Browse files
tromeynikic
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 rust-lang#22
1 parent ef4f252 commit b5b39ab

File tree

3 files changed

+20
-59
lines changed

3 files changed

+20
-59
lines changed

lldb/include/lldb/Symbol/RustASTContext.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -435,14 +435,12 @@ class RustASTContext : public TypeSystem {
435435

436436
private:
437437
int m_pointer_byte_size;
438-
std::map<ConstString, std::unique_ptr<RustType>> m_types;
439-
std::set<std::unique_ptr<RustType>> m_anon_types;
438+
std::set<std::unique_ptr<RustType>> m_types;
440439
std::unique_ptr<DWARFASTParser> m_dwarf_ast_parser_ap;
441440

442441
std::unique_ptr<RustDeclContext> m_tu_decl;
443442

444-
RustType *FindCachedType(const lldb_private::ConstString &name);
445-
CompilerType CacheType(const lldb_private::ConstString &name, RustType *new_type);
443+
CompilerType CacheType(RustType *new_type);
446444

447445
RustASTContext(const RustASTContext &) = delete;
448446
const RustASTContext &operator=(const RustASTContext &) = delete;

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

+3
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ TypeSP DWARFASTParserRust::ParseSimpleType(lldb_private::Log *log, const DWARFDI
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

+15-55
Original file line numberDiff line numberDiff line change
@@ -1802,40 +1802,22 @@ void RustASTContext::DumpTypeDescription(lldb::opaque_compiler_type_t type, Stre
18021802
s->PutCString(name.AsCString());
18031803
}
18041804

1805-
RustType *RustASTContext::FindCachedType(const lldb_private::ConstString &name) {
1806-
if (name.IsEmpty())
1807-
return nullptr;
1808-
auto result = m_types.find(name);
1809-
if (result == m_types.end ())
1810-
return nullptr;
1811-
return result->second.get();
1812-
}
1813-
1814-
CompilerType RustASTContext::CacheType(const ConstString &name, RustType *new_type) {
1815-
if (name.IsEmpty()) {
1816-
// Be sure to keep nameless types alive.
1817-
m_anon_types.insert(std::unique_ptr<RustType>(new_type));
1818-
} else {
1819-
m_types[name].reset(new_type);
1820-
}
1805+
CompilerType RustASTContext::CacheType(RustType *new_type) {
1806+
m_types.insert(std::unique_ptr<RustType>(new_type));
18211807
return CompilerType(this, new_type);
18221808
}
18231809

18241810
CompilerType RustASTContext::CreateBoolType(const lldb_private::ConstString &name) {
1825-
if (RustType *cached = FindCachedType(name))
1826-
return CompilerType(this, cached);
18271811
RustType *type = new RustBool(name);
1828-
return CacheType(name, type);
1812+
return CacheType(type);
18291813
}
18301814

18311815
CompilerType RustASTContext::CreateIntegralType(const lldb_private::ConstString &name,
18321816
bool is_signed,
18331817
uint64_t byte_size,
18341818
bool is_char_type) {
1835-
if (RustType *cached = FindCachedType(name))
1836-
return CompilerType(this, cached);
18371819
RustType *type = new RustIntegral(name, is_signed, byte_size, is_char_type);
1838-
return CacheType(name, type);
1820+
return CacheType(type);
18391821
}
18401822

18411823
CompilerType RustASTContext::CreateIntrinsicIntegralType(bool is_signed, uint64_t byte_size) {
@@ -1853,10 +1835,8 @@ CompilerType RustASTContext::CreateCharType() {
18531835

18541836
CompilerType RustASTContext::CreateFloatType(const lldb_private::ConstString &name,
18551837
uint64_t byte_size) {
1856-
if (RustType *cached = FindCachedType(name))
1857-
return CompilerType(this, cached);
18581838
RustType *type = new RustFloat(name, byte_size);
1859-
return CacheType(name, type);
1839+
return CacheType(type);
18601840
}
18611841

18621842
CompilerType RustASTContext::CreateArrayType(const CompilerType &element_type,
@@ -1868,53 +1848,41 @@ CompilerType RustASTContext::CreateArrayType(const CompilerType &element_type,
18681848
name += "]";
18691849
ConstString newname(name);
18701850

1871-
if (RustType *cached = FindCachedType(newname))
1872-
return CompilerType(this, cached);
18731851
RustType *type = new RustArray(newname, length, element_type);
1874-
return CacheType(newname, type);
1852+
return CacheType(type);
18751853
}
18761854

18771855
CompilerType RustASTContext::CreateTypedefType(const ConstString &name, CompilerType impl) {
1878-
if (RustType *cached = FindCachedType(name))
1879-
return CompilerType(this, cached);
18801856
RustType *type = new RustTypedef(name, impl);
1881-
return CacheType(name, type);
1857+
return CacheType(type);
18821858
}
18831859

18841860
CompilerType
18851861
RustASTContext::CreateStructType(const lldb_private::ConstString &name, uint32_t byte_size,
18861862
bool has_discriminant) {
1887-
if (RustType *cached = FindCachedType(name))
1888-
return CompilerType(this, cached);
18891863
RustType *type = new RustStruct(name, byte_size, has_discriminant);
1890-
return CacheType(name, type);
1864+
return CacheType(type);
18911865
}
18921866

18931867
CompilerType
18941868
RustASTContext::CreateTupleType(const lldb_private::ConstString &name, uint32_t byte_size,
18951869
bool has_discriminant) {
1896-
if (RustType *cached = FindCachedType(name))
1897-
return CompilerType(this, cached);
18981870
RustType *type = new RustTuple(name, byte_size, has_discriminant);
1899-
return CacheType(name, type);
1871+
return CacheType(type);
19001872
}
19011873

19021874
CompilerType
19031875
RustASTContext::CreateUnionType(const lldb_private::ConstString &name, uint32_t byte_size) {
1904-
if (RustType *cached = FindCachedType(name))
1905-
return CompilerType(this, cached);
19061876
RustType *type = new RustUnion(name, byte_size);
1907-
return CacheType(name, type);
1877+
return CacheType(type);
19081878
}
19091879

19101880
CompilerType
19111881
RustASTContext::CreatePointerType(const lldb_private::ConstString &name,
19121882
const CompilerType &pointee_type,
19131883
uint32_t byte_size) {
1914-
if (RustType *cached = FindCachedType(name))
1915-
return CompilerType(this, cached);
19161884
RustType *type = new RustPointer(name, pointee_type, byte_size);
1917-
return CacheType(name, type);
1885+
return CacheType(type);
19181886
}
19191887

19201888
void RustASTContext::AddFieldToStruct(const CompilerType &struct_type,
@@ -1941,39 +1909,31 @@ CompilerType
19411909
RustASTContext::CreateFunctionType(const lldb_private::ConstString &name,
19421910
const CompilerType &return_type,
19431911
const std::vector<CompilerType> &&params) {
1944-
if (RustType *cached = FindCachedType(name))
1945-
return CompilerType(this, cached);
19461912
RustType *type = new RustFunction(name, m_pointer_byte_size, return_type, std::move(params));
1947-
return CacheType(name, type);
1913+
return CacheType(type);
19481914
}
19491915

19501916
CompilerType
19511917
RustASTContext::CreateVoidType() {
19521918
ConstString name("()");
1953-
if (RustType *cached = FindCachedType(name))
1954-
return CompilerType(this, cached);
19551919
RustType *type = new RustTuple(name, 0, false);
1956-
return CacheType(name, type);
1920+
return CacheType(type);
19571921
}
19581922

19591923
CompilerType
19601924
RustASTContext::CreateEnumType(const lldb_private::ConstString &name,
19611925
uint64_t byte_size, uint32_t discr_offset,
19621926
uint32_t discr_byte_size) {
1963-
if (RustType *cached = FindCachedType(name))
1964-
return CompilerType(this, cached);
19651927
RustType *type = new RustEnum(name, byte_size, discr_offset, discr_byte_size);
1966-
return CacheType(name, type);
1928+
return CacheType(type);
19671929
}
19681930

19691931
CompilerType
19701932
RustASTContext::CreateCLikeEnumType(const lldb_private::ConstString &name,
19711933
const CompilerType &underlying_type,
19721934
std::map<uint64_t, std::string> &&values) {
1973-
if (RustType *cached = FindCachedType(name))
1974-
return CompilerType(this, cached);
19751935
RustType *type = new RustCLikeEnum(name, underlying_type, std::move(values));
1976-
return CacheType(name, type);
1936+
return CacheType(type);
19771937
}
19781938

19791939
bool

0 commit comments

Comments
 (0)