Skip to content

Commit

Permalink
Fix name canonicalization for doc writer
Browse files Browse the repository at this point in the history
  • Loading branch information
gingerBill committed Feb 24, 2025
1 parent f56a0a8 commit 344eb6c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/docs_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand All @@ -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();
}
10 changes: 9 additions & 1 deletion src/name_canonicalization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,8 @@ gb_internal void write_canonical_entity_name(TypeWriter *w, Entity *e) {
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) {
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 344eb6c

Please sign in to comment.