Merge pull request #5258 from laytan/fix-docs-writer

fix package docs in a "hacky" way
This commit is contained in:
Laytan
2025-06-02 17:09:59 +02:00
committed by GitHub
+14 -6
View File
@@ -43,7 +43,7 @@ struct OdinDocWriter {
}; };
gb_internal OdinDocEntityIndex odin_doc_add_entity(OdinDocWriter *w, Entity *e); gb_internal OdinDocEntityIndex odin_doc_add_entity(OdinDocWriter *w, Entity *e);
gb_internal OdinDocTypeIndex odin_doc_type(OdinDocWriter *w, Type *type); gb_internal OdinDocTypeIndex odin_doc_type(OdinDocWriter *w, Type *type, bool cache);
template <typename T> template <typename T>
gb_internal void odin_doc_writer_item_tracker_init(OdinDocWriterItemTracker<T> *t, isize size) { gb_internal void odin_doc_writer_item_tracker_init(OdinDocWriterItemTracker<T> *t, isize size) {
@@ -467,8 +467,8 @@ gb_internal OdinDocArray<OdinDocString> odin_doc_where_clauses(OdinDocWriter *w,
return odin_write_slice(w, clauses.data, clauses.count); return odin_write_slice(w, clauses.data, clauses.count);
} }
gb_internal OdinDocArray<OdinDocTypeIndex> odin_doc_type_as_slice(OdinDocWriter *w, Type *type) { gb_internal OdinDocArray<OdinDocTypeIndex> odin_doc_type_as_slice(OdinDocWriter *w, Type *type, bool cache=true) {
OdinDocTypeIndex index = odin_doc_type(w, type); OdinDocTypeIndex index = odin_doc_type(w, type, cache);
return odin_write_item_as_slice(w, index); return odin_write_item_as_slice(w, index);
} }
@@ -479,7 +479,7 @@ gb_internal OdinDocArray<OdinDocEntityIndex> odin_doc_add_entity_as_slice(OdinDo
gb_internal OdinDocTypeIndex odin_doc_type(OdinDocWriter *w, Type *type) { gb_internal OdinDocTypeIndex odin_doc_type(OdinDocWriter *w, Type *type, bool cache=true) {
if (type == nullptr) { if (type == nullptr) {
return 0; return 0;
} }
@@ -491,18 +491,23 @@ gb_internal OdinDocTypeIndex odin_doc_type(OdinDocWriter *w, Type *type) {
} }
} }
u64 type_hash = type_hash_canonical_type(type); u64 type_hash = {0};
if (cache) {
type_hash = type_hash_canonical_type(type);
OdinDocTypeIndex *found = map_get(&w->type_cache, type_hash); OdinDocTypeIndex *found = map_get(&w->type_cache, type_hash);
if (found) { if (found) {
return *found; return *found;
} }
}
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);
if (cache) {
map_set(&w->type_cache, type_hash, type_index); map_set(&w->type_cache, type_hash, type_index);
}
switch (type->kind) { switch (type->kind) {
case Type_Basic: case Type_Basic:
@@ -527,7 +532,10 @@ gb_internal OdinDocTypeIndex odin_doc_type(OdinDocWriter *w, Type *type) {
doc_type.kind = OdinDocType_Generic; doc_type.kind = OdinDocType_Generic;
doc_type.name = odin_doc_write_string(w, name); doc_type.name = odin_doc_write_string(w, name);
if (type->Generic.specialized) { if (type->Generic.specialized) {
doc_type.types = odin_doc_type_as_slice(w, type->Generic.specialized); // NOTE(laytan): do not look at the cache for the specialization, it would resolve
// to the same entry as the type itself because `default_type` resolves to the
// specialization of a generic type.
doc_type.types = odin_doc_type_as_slice(w, type->Generic.specialized, cache=false);
} }
} }
break; break;