Fix name canonicalization for doc writer

This commit is contained in:
gingerBill
2025-02-24 15:44:38 +00:00
parent f56a0a80d3
commit 344eb6cb42
2 changed files with 20 additions and 1 deletions

View File

@@ -16,6 +16,8 @@ gb_global char const* OdinDocWriterState_strings[] {
"writing ",
};
gb_global std::atomic<bool> 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();
}

View File

@@ -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: