From fb01dfe04845a489760956cea4f0019e1464b2e3 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 17 Jan 2022 22:17:07 +0000 Subject: Improve docs_writer.cpp --- src/types.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'src/types.cpp') diff --git a/src/types.cpp b/src/types.cpp index f621d4346..6162a5aa8 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -3933,7 +3933,7 @@ gbString write_type_to_string(gbString str, Type *type) { str = gb_string_appendc(str, " = "); str = write_exact_value_to_string(str, var->Constant.value); } else { - str = gb_string_appendc(str, "="); + str = gb_string_appendc(str, " := "); str = write_exact_value_to_string(str, var->Constant.value); } continue; @@ -3961,14 +3961,10 @@ gbString write_type_to_string(gbString str, Type *type) { str = gb_string_appendc(str, "typeid/"); str = write_type_to_string(str, var->type); } else { - if (var->kind == Entity_TypeName) { - str = gb_string_appendc(str, "$"); - str = gb_string_append_length(str, name.text, name.len); - str = gb_string_appendc(str, "="); - str = write_type_to_string(str, var->type); - } else { - str = gb_string_appendc(str, "typeid"); - } + str = gb_string_appendc(str, "$"); + str = gb_string_append_length(str, name.text, name.len); + str = gb_string_appendc(str, "="); + str = write_type_to_string(str, var->type); } } } -- cgit v1.2.3 From 5ff82fc1132a05d76592e8e21db98913cd498f64 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 19 Jan 2022 15:11:42 +0000 Subject: Correct tuple name checking for doc writing --- src/docs_writer.cpp | 2 +- src/exact_value.cpp | 2 +- src/types.cpp | 9 +++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) (limited to 'src/types.cpp') diff --git a/src/docs_writer.cpp b/src/docs_writer.cpp index c4a0cd27f..f1f110a57 100644 --- a/src/docs_writer.cpp +++ b/src/docs_writer.cpp @@ -483,7 +483,7 @@ OdinDocTypeIndex odin_doc_type(OdinDocWriter *w, Type *type) { for_array(i, w->type_cache.entries) { // NOTE(bill): THIS IS SLOW Type *other = w->type_cache.entries[i].key; - if (are_types_identical(type, other)) { + if (are_types_identical(type, other, true)) { OdinDocTypeIndex index = w->type_cache.entries[i].value; map_set(&w->type_cache, type, index); return index; diff --git a/src/exact_value.cpp b/src/exact_value.cpp index fd90278e5..e979e3d45 100644 --- a/src/exact_value.cpp +++ b/src/exact_value.cpp @@ -9,7 +9,7 @@ struct Ast; struct HashKey; struct Type; struct Entity; -bool are_types_identical(Type *x, Type *y); +bool are_types_identical(Type *x, Type *y, bool check_tuple_names=false); struct Complex128 { f64 real, imag; diff --git a/src/types.cpp b/src/types.cpp index 6162a5aa8..98dc30703 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -694,7 +694,7 @@ gbString type_to_string (Type *type); i64 type_size_of_internal(Type *t, TypePath *path); void init_map_internal_types(Type *type); Type * bit_set_to_int(Type *t); -bool are_types_identical(Type *x, Type *y); +bool are_types_identical(Type *x, Type *y, bool check_tuple_names/*=false*/); bool is_type_pointer(Type *t); bool is_type_proc(Type *t); @@ -2338,7 +2338,7 @@ Type *strip_type_aliasing(Type *x) { return x; } -bool are_types_identical(Type *x, Type *y) { +bool are_types_identical(Type *x, Type *y, bool check_tuple_names) { if (x == y) { return true; } @@ -2487,6 +2487,11 @@ bool are_types_identical(Type *x, Type *y) { if (xe->kind != ye->kind || !are_types_identical(xe->type, ye->type)) { return false; } + if (check_tuple_names) { + if (xe->token.string != ye->token.string) { + return false; + } + } if (xe->kind == Entity_Constant && !compare_exact_values(Token_CmpEq, xe->Constant.value, ye->Constant.value)) { // NOTE(bill): This is needed for polymorphic procedures return false; -- cgit v1.2.3 From ecdaac9921fbf351bfddaf920553855ae6a5d58f Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 19 Jan 2022 15:14:15 +0000 Subject: Unify `are_types_identical_unique_tuples` --- src/checker.cpp | 4 ++-- src/docs_writer.cpp | 2 +- src/exact_value.cpp | 2 +- src/types.cpp | 14 ++++++++++++-- 4 files changed, 16 insertions(+), 6 deletions(-) (limited to 'src/types.cpp') diff --git a/src/checker.cpp b/src/checker.cpp index 44dc90c67..63a697072 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -1253,7 +1253,7 @@ isize type_info_index(CheckerInfo *info, Type *type, bool error_on_failure) { // TODO(bill): This is O(n) and can be very slow for_array(i, info->type_info_map.entries){ auto *e = &info->type_info_map.entries[i]; - if (are_types_identical(e->key, type)) { + if (are_types_identical_unique_tuples(e->key, type)) { entry_index = e->value; // NOTE(bill): Add it to the search map map_set(&info->type_info_map, type, entry_index); @@ -1601,7 +1601,7 @@ void add_type_info_type_internal(CheckerContext *c, Type *t) { isize ti_index = -1; for_array(i, c->info->type_info_map.entries) { auto *e = &c->info->type_info_map.entries[i]; - if (are_types_identical(t, e->key)) { + if (are_types_identical_unique_tuples(t, e->key)) { // Duplicate entry ti_index = e->value; prev = true; diff --git a/src/docs_writer.cpp b/src/docs_writer.cpp index f1f110a57..c2d07dc12 100644 --- a/src/docs_writer.cpp +++ b/src/docs_writer.cpp @@ -483,7 +483,7 @@ OdinDocTypeIndex odin_doc_type(OdinDocWriter *w, Type *type) { for_array(i, w->type_cache.entries) { // NOTE(bill): THIS IS SLOW Type *other = w->type_cache.entries[i].key; - if (are_types_identical(type, other, true)) { + if (are_types_identical_unique_tuples(type, other)) { OdinDocTypeIndex index = w->type_cache.entries[i].value; map_set(&w->type_cache, type, index); return index; diff --git a/src/exact_value.cpp b/src/exact_value.cpp index e979e3d45..fd90278e5 100644 --- a/src/exact_value.cpp +++ b/src/exact_value.cpp @@ -9,7 +9,7 @@ struct Ast; struct HashKey; struct Type; struct Entity; -bool are_types_identical(Type *x, Type *y, bool check_tuple_names=false); +bool are_types_identical(Type *x, Type *y); struct Complex128 { f64 real, imag; diff --git a/src/types.cpp b/src/types.cpp index 98dc30703..07951196a 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -694,7 +694,7 @@ gbString type_to_string (Type *type); i64 type_size_of_internal(Type *t, TypePath *path); void init_map_internal_types(Type *type); Type * bit_set_to_int(Type *t); -bool are_types_identical(Type *x, Type *y, bool check_tuple_names/*=false*/); +bool are_types_identical(Type *x, Type *y); bool is_type_pointer(Type *t); bool is_type_proc(Type *t); @@ -2338,7 +2338,17 @@ Type *strip_type_aliasing(Type *x) { return x; } -bool are_types_identical(Type *x, Type *y, bool check_tuple_names) { +bool are_types_identical_internal(Type *x, Type *y, bool check_tuple_names); + +bool are_types_identical(Type *x, Type *y) { + return are_types_identical_internal(x, y, false); +} +bool are_types_identical_unique_tuples(Type *x, Type *y) { + return are_types_identical_internal(x, y, true); +} + + +bool are_types_identical_internal(Type *x, Type *y, bool check_tuple_names) { if (x == y) { return true; } -- cgit v1.2.3