mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
Use type hash for doc writer
This commit is contained in:
+7
-47
@@ -26,11 +26,10 @@ struct OdinDocWriter {
|
|||||||
|
|
||||||
StringMap<OdinDocString> string_cache;
|
StringMap<OdinDocString> string_cache;
|
||||||
|
|
||||||
OrderedInsertPtrMap<AstFile *, OdinDocFileIndex> file_cache;
|
OrderedInsertPtrMap<AstFile *, OdinDocFileIndex> file_cache;
|
||||||
OrderedInsertPtrMap<AstPackage *, OdinDocPkgIndex> pkg_cache;
|
OrderedInsertPtrMap<AstPackage *, OdinDocPkgIndex> pkg_cache;
|
||||||
OrderedInsertPtrMap<Entity *, OdinDocEntityIndex> entity_cache;
|
OrderedInsertPtrMap<Entity *, OdinDocEntityIndex> entity_cache;
|
||||||
OrderedInsertPtrMap<Type *, OdinDocTypeIndex> type_cache;
|
OrderedInsertPtrMap<u64/*type hash*/, OdinDocTypeIndex> type_cache;
|
||||||
OrderedInsertPtrMap<Type *, Type *> stable_type_cache;
|
|
||||||
|
|
||||||
OdinDocWriterItemTracker<OdinDocFile> files;
|
OdinDocWriterItemTracker<OdinDocFile> files;
|
||||||
OdinDocWriterItemTracker<OdinDocPkg> pkgs;
|
OdinDocWriterItemTracker<OdinDocPkg> pkgs;
|
||||||
@@ -61,7 +60,6 @@ gb_internal void odin_doc_writer_prepare(OdinDocWriter *w) {
|
|||||||
map_init(&w->pkg_cache, 1<<10);
|
map_init(&w->pkg_cache, 1<<10);
|
||||||
map_init(&w->entity_cache, 1<<18);
|
map_init(&w->entity_cache, 1<<18);
|
||||||
map_init(&w->type_cache, 1<<18);
|
map_init(&w->type_cache, 1<<18);
|
||||||
map_init(&w->stable_type_cache, 1<<18);
|
|
||||||
|
|
||||||
odin_doc_writer_item_tracker_init(&w->files, 1);
|
odin_doc_writer_item_tracker_init(&w->files, 1);
|
||||||
odin_doc_writer_item_tracker_init(&w->pkgs, 1);
|
odin_doc_writer_item_tracker_init(&w->pkgs, 1);
|
||||||
@@ -81,7 +79,6 @@ gb_internal void odin_doc_writer_destroy(OdinDocWriter *w) {
|
|||||||
map_destroy(&w->pkg_cache);
|
map_destroy(&w->pkg_cache);
|
||||||
map_destroy(&w->entity_cache);
|
map_destroy(&w->entity_cache);
|
||||||
map_destroy(&w->type_cache);
|
map_destroy(&w->type_cache);
|
||||||
map_destroy(&w->stable_type_cache);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -492,55 +489,18 @@ gb_internal OdinDocTypeIndex odin_doc_type(OdinDocWriter *w, Type *type) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Type **mapped_type = map_get(&w->stable_type_cache, type); // may map to itself
|
u64 type_hash = type_hash_canonical_type(type);
|
||||||
// if (mapped_type && *mapped_type) {
|
OdinDocTypeIndex *found = map_get(&w->type_cache, type_hash);
|
||||||
// type = *mapped_type;
|
|
||||||
// }
|
|
||||||
|
|
||||||
OdinDocTypeIndex *found = map_get(&w->type_cache, type);
|
|
||||||
if (found) {
|
if (found) {
|
||||||
return *found;
|
return *found;
|
||||||
}
|
}
|
||||||
for (auto const &entry : w->type_cache) {
|
|
||||||
// NOTE(bill): THIS IS SLOW
|
|
||||||
Type *x = type;
|
|
||||||
Type *y = entry.key;
|
|
||||||
|
|
||||||
if (x == y) {
|
|
||||||
goto do_set;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!x | !y) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (y->kind == Type_Named) {
|
|
||||||
Entity *e = y->Named.type_name;
|
|
||||||
if (e->TypeName.is_type_alias) {
|
|
||||||
y = y->Named.base;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (x->kind != y->kind) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!are_types_identical_internal(x, y, true)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
do_set:
|
|
||||||
OdinDocTypeIndex index = entry.value;
|
|
||||||
map_set(&w->type_cache, type, index);
|
|
||||||
map_set(&w->stable_type_cache, type, entry.key);
|
|
||||||
return index;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
OdinDocType *dst = nullptr;
|
OdinDocType *dst = nullptr;
|
||||||
OdinDocType doc_type = {};
|
OdinDocType doc_type = {};
|
||||||
OdinDocTypeIndex type_index = 0;
|
OdinDocTypeIndex type_index = 0;
|
||||||
type_index = odin_doc_write_item(w, &w->types, &doc_type, &dst);
|
type_index = odin_doc_write_item(w, &w->types, &doc_type, &dst);
|
||||||
map_set(&w->type_cache, type, type_index);
|
map_set(&w->type_cache, type_hash, type_index);
|
||||||
map_set(&w->stable_type_cache, type, type);
|
|
||||||
|
|
||||||
switch (type->kind) {
|
switch (type->kind) {
|
||||||
case Type_Basic:
|
case Type_Basic:
|
||||||
|
|||||||
@@ -160,9 +160,9 @@ struct lbModule {
|
|||||||
AstFile *file; // possibly associated
|
AstFile *file; // possibly associated
|
||||||
char const *module_name;
|
char const *module_name;
|
||||||
|
|
||||||
PtrMap<u64, LLVMTypeRef> types; // mutex: types_mutex
|
PtrMap<u64/*type hash*/, LLVMTypeRef> types; // mutex: types_mutex
|
||||||
PtrMap<void *, lbStructFieldRemapping> struct_field_remapping; // Key: LLVMTypeRef or Type *, mutex: types_mutex
|
PtrMap<void *, lbStructFieldRemapping> struct_field_remapping; // Key: LLVMTypeRef or Type *, mutex: types_mutex
|
||||||
PtrMap<u64, LLVMTypeRef> func_raw_types; // mutex: func_raw_types_mutex
|
PtrMap<u64/*type hash*/, LLVMTypeRef> func_raw_types; // mutex: func_raw_types_mutex
|
||||||
RecursiveMutex types_mutex;
|
RecursiveMutex types_mutex;
|
||||||
RecursiveMutex func_raw_types_mutex;
|
RecursiveMutex func_raw_types_mutex;
|
||||||
i32 internal_type_level;
|
i32 internal_type_level;
|
||||||
@@ -178,7 +178,7 @@ struct lbModule {
|
|||||||
|
|
||||||
StringMap<LLVMValueRef> const_strings;
|
StringMap<LLVMValueRef> const_strings;
|
||||||
|
|
||||||
PtrMap<u64, struct lbFunctionType *> function_type_map;
|
PtrMap<u64/*type hash*/, struct lbFunctionType *> function_type_map;
|
||||||
|
|
||||||
StringMap<lbProcedure *> gen_procs; // key is the canonicalized name
|
StringMap<lbProcedure *> gen_procs; // key is the canonicalized name
|
||||||
|
|
||||||
@@ -201,8 +201,8 @@ struct lbModule {
|
|||||||
StringMap<lbObjcRef> objc_classes;
|
StringMap<lbObjcRef> objc_classes;
|
||||||
StringMap<lbObjcRef> objc_selectors;
|
StringMap<lbObjcRef> objc_selectors;
|
||||||
|
|
||||||
PtrMap<u64, lbAddr> map_cell_info_map; // address of runtime.Map_Info
|
PtrMap<u64/*type hash*/, lbAddr> map_cell_info_map; // address of runtime.Map_Info
|
||||||
PtrMap<u64, lbAddr> map_info_map; // address of runtime.Map_Cell_Info
|
PtrMap<u64/*type hash*/, lbAddr> map_info_map; // address of runtime.Map_Cell_Info
|
||||||
|
|
||||||
PtrMap<Ast *, lbAddr> exact_value_compound_literal_addr_map; // Key: Ast_CompoundLit
|
PtrMap<Ast *, lbAddr> exact_value_compound_literal_addr_map; // Key: Ast_CompoundLit
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user