From f56a0a80d3b606b1cbefb973b03b9ddae88bbf48 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 24 Feb 2025 15:37:54 +0000 Subject: Use type hash for doc writer --- src/docs_writer.cpp | 54 +++++++---------------------------------------------- 1 file changed, 7 insertions(+), 47 deletions(-) (limited to 'src/docs_writer.cpp') diff --git a/src/docs_writer.cpp b/src/docs_writer.cpp index 341b3fa6b..5401e5f76 100644 --- a/src/docs_writer.cpp +++ b/src/docs_writer.cpp @@ -26,11 +26,10 @@ struct OdinDocWriter { StringMap string_cache; - OrderedInsertPtrMap file_cache; - OrderedInsertPtrMap pkg_cache; - OrderedInsertPtrMap entity_cache; - OrderedInsertPtrMap type_cache; - OrderedInsertPtrMap stable_type_cache; + OrderedInsertPtrMap file_cache; + OrderedInsertPtrMap pkg_cache; + OrderedInsertPtrMap entity_cache; + OrderedInsertPtrMap type_cache; OdinDocWriterItemTracker files; OdinDocWriterItemTracker pkgs; @@ -61,7 +60,6 @@ gb_internal void odin_doc_writer_prepare(OdinDocWriter *w) { map_init(&w->pkg_cache, 1<<10); map_init(&w->entity_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->pkgs, 1); @@ -81,7 +79,6 @@ gb_internal void odin_doc_writer_destroy(OdinDocWriter *w) { map_destroy(&w->pkg_cache); map_destroy(&w->entity_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 - // if (mapped_type && *mapped_type) { - // type = *mapped_type; - // } - - OdinDocTypeIndex *found = map_get(&w->type_cache, type); + u64 type_hash = type_hash_canonical_type(type); + OdinDocTypeIndex *found = map_get(&w->type_cache, type_hash); if (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 doc_type = {}; OdinDocTypeIndex type_index = 0; type_index = odin_doc_write_item(w, &w->types, &doc_type, &dst); - map_set(&w->type_cache, type, type_index); - map_set(&w->stable_type_cache, type, type); + map_set(&w->type_cache, type_hash, type_index); switch (type->kind) { case Type_Basic: -- cgit v1.2.3 From 344eb6cb42a635f36d669fee8fc25dc37c852ba1 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 24 Feb 2025 15:44:38 +0000 Subject: Fix name canonicalization for doc writer --- src/docs_writer.cpp | 11 +++++++++++ src/name_canonicalization.cpp | 10 +++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) (limited to 'src/docs_writer.cpp') diff --git a/src/docs_writer.cpp b/src/docs_writer.cpp index 5401e5f76..a92ffc7ad 100644 --- a/src/docs_writer.cpp +++ b/src/docs_writer.cpp @@ -16,6 +16,8 @@ gb_global char const* OdinDocWriterState_strings[] { "writing ", }; +gb_global std::atomic g_in_doc_writer; + struct OdinDocWriter { CheckerInfo *info; OdinDocWriterState state; @@ -1137,6 +1139,8 @@ gb_internal void odin_doc_write_to_file(OdinDocWriter *w, char const *filename) } gb_internal void odin_doc_write(CheckerInfo *info, char const *filename) { + g_in_doc_writer.store(true); + OdinDocWriter w_ = {}; OdinDocWriter *w = &w_; defer (odin_doc_writer_destroy(w)); @@ -1152,4 +1156,11 @@ gb_internal void odin_doc_write(CheckerInfo *info, char const *filename) { odin_doc_writer_end_writing(w); odin_doc_write_to_file(w, filename); + + g_in_doc_writer.store(false); } + + +gb_internal bool is_in_doc_writer(void) { + return g_in_doc_writer.load(); +} \ No newline at end of file diff --git a/src/name_canonicalization.cpp b/src/name_canonicalization.cpp index 5d311068f..a80dc1996 100644 --- a/src/name_canonicalization.cpp +++ b/src/name_canonicalization.cpp @@ -520,6 +520,8 @@ write_base_name: return; } +gb_internal bool is_in_doc_writer(void); + // NOTE(bill): This exists so that we deterministically hash a type by serializing it to a canonical string gb_internal void write_type_to_canonical_string(TypeWriter *w, Type *type) { if (type == nullptr) { @@ -719,7 +721,13 @@ gb_internal void write_type_to_canonical_string(TypeWriter *w, Type *type) { return; case Type_Generic: - GB_PANIC("Type_Generic should never be hit"); + if (is_in_doc_writer()) { + type_writer_appendc(w, "$"); + type_writer_append(w, type->Generic.name.text, type->Generic.name.len); + type_writer_append_fmt(w, "%lld", cast(long long)type->Generic.id); + } else { + GB_PANIC("Type_Generic should never be hit"); + } return; case Type_Named: -- cgit v1.2.3