aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-10-07 21:23:37 +0100
committergingerBill <bill@gingerbill.org>2021-10-07 21:23:37 +0100
commitd3865633441f0e22626142a0f9fbfde0e9c2ef19 (patch)
treecf86edfa3cc00486475b00cb0b904041fe86cacf /src
parent9ecc2ab15b161cea506b93e7f5607cf13dbb21f5 (diff)
Correct issue with the generated `map` type internals; Simplify map rehash logic to utilize `resize`
Diffstat (limited to 'src')
-rw-r--r--src/check_type.cpp3
-rw-r--r--src/llvm_backend.cpp10
-rw-r--r--src/llvm_backend_proc.cpp5
-rw-r--r--src/types.cpp14
4 files changed, 21 insertions, 11 deletions
diff --git a/src/check_type.cpp b/src/check_type.cpp
index 75fa503e5..0d5c0f977 100644
--- a/src/check_type.cpp
+++ b/src/check_type.cpp
@@ -2058,7 +2058,6 @@ void init_map_entry_type(Type *type) {
// NOTE(bill): The preload types may have not been set yet
GB_ASSERT(t_map_hash != nullptr);
- Type *entry_type = alloc_type_struct();
/*
struct {
@@ -2076,7 +2075,7 @@ void init_map_entry_type(Type *type) {
fields[2] = alloc_entity_field(s, make_token_ident(str_lit("key")), type->Map.key, false, 2, EntityState_Resolved);
fields[3] = alloc_entity_field(s, make_token_ident(str_lit("value")), type->Map.value, false, 3, EntityState_Resolved);
-
+ Type *entry_type = alloc_type_struct();
entry_type->Struct.fields = fields;
entry_type->Struct.tags = gb_alloc_array(permanent_allocator(), String, fields.count);
diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp
index ff1137861..3111006e9 100644
--- a/src/llvm_backend.cpp
+++ b/src/llvm_backend.cpp
@@ -495,9 +495,13 @@ lbValue lb_gen_map_header(lbProcedure *p, lbValue map_val_ptr, Type *map_type) {
Type *val_type = map_type->Map.value;
gb_unused(val_type);
+ GB_ASSERT(map_type->Map.entry_type->kind == Type_Struct);
+ map_type->Map.entry_type->cached_size = -1;
+ map_type->Map.entry_type->Struct.are_offsets_set = false;
+
i64 entry_size = type_size_of (map_type->Map.entry_type);
i64 entry_align = type_align_of (map_type->Map.entry_type);
-
+
i64 key_offset = type_offset_of(map_type->Map.entry_type, 2);
i64 key_size = type_size_of (map_type->Map.key);
@@ -507,9 +511,9 @@ lbValue lb_gen_map_header(lbProcedure *p, lbValue map_val_ptr, Type *map_type) {
Type *map_header_base = base_type(t_map_header);
GB_ASSERT(map_header_base->Struct.fields.count == 8);
- Type *m_type = map_header_base->Struct.fields[0]->type;
+ Type *raw_map_ptr_type = map_header_base->Struct.fields[0]->type;
LLVMValueRef const_values[8] = {};
- const_values[0] = LLVMConstNull(lb_type(p->module, m_type));
+ const_values[0] = LLVMConstNull(lb_type(p->module, raw_map_ptr_type));
const_values[1] = lb_get_equal_proc_for_type(p->module, key_type) .value;
const_values[2] = lb_const_int(p->module, t_int, entry_size) .value;
const_values[3] = lb_const_int(p->module, t_int, entry_align) .value;
diff --git a/src/llvm_backend_proc.cpp b/src/llvm_backend_proc.cpp
index 792cf31a7..222161164 100644
--- a/src/llvm_backend_proc.cpp
+++ b/src/llvm_backend_proc.cpp
@@ -239,8 +239,11 @@ lbProcedure *lb_create_procedure(lbModule *m, Entity *entity, bool ignore_body)
}
if (p->body != nullptr) {
+ // String debug_name = entity->token.string.text;
+ String debug_name = p->name;
+
p->debug_info = LLVMDIBuilderCreateFunction(m->debug_builder, scope,
- cast(char const *)entity->token.string.text, entity->token.string.len,
+ cast(char const *)debug_name.text, debug_name.len,
cast(char const *)p->name.text, p->name.len,
file, line, type,
is_local_to_unit, is_definition,
diff --git a/src/types.cpp b/src/types.cpp
index f3ac014d9..a808b54fb 100644
--- a/src/types.cpp
+++ b/src/types.cpp
@@ -3018,8 +3018,7 @@ i64 type_align_of_internal(Type *t, TypePath *path) {
} break;
case Type_Map:
- init_map_internal_types(t);
- return type_align_of_internal(t->Map.internal_type, path);
+ return build_context.word_size;
case Type_Enum:
return type_align_of_internal(t->Enum.base_type, path);
@@ -3248,11 +3247,16 @@ i64 type_size_of_internal(Type *t, TypePath *path) {
case Type_DynamicArray:
// data + len + cap + allocator(procedure+data)
- return 3*build_context.word_size + 2*build_context.word_size;
+ return (3 + 2)*build_context.word_size;
case Type_Map:
- init_map_internal_types(t);
- return type_size_of_internal(t->Map.internal_type, path);
+ /*
+ struct {
+ hashes: []int, // 2 words
+ entries: [dynamic]Entry_Type, // 5 words
+ }
+ */
+ return (2 + (3 + 2))*build_context.word_size;
case Type_Tuple: {
i64 count, align, size;