From 604a244473e659d4283c7ec064afae696d3dab95 Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Thu, 13 Aug 2026 11:05:36 -0700 Subject: [PATCH] rdi_from_dwarf: turn off aggressive type hash caching for now - need to solve cyclical graph hashing problem later when it is more pressing... also fix local-UDTs not being gathered/converted --- src/rdi_from_dwarf/rdi_from_dwarf.c | 158 +++------------------------- 1 file changed, 16 insertions(+), 142 deletions(-) diff --git a/src/rdi_from_dwarf/rdi_from_dwarf.c b/src/rdi_from_dwarf/rdi_from_dwarf.c index cd7be489..a17a535a 100644 --- a/src/rdi_from_dwarf/rdi_from_dwarf.c +++ b/src/rdi_from_dwarf/rdi_from_dwarf.c @@ -1469,7 +1469,8 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params) if(tag.kind == DW_TagKind_Namespace || tag.kind == DW_TagKind_ClassType || tag.kind == DW_TagKind_StructureType || - tag.kind == DW_TagKind_UnionType) + tag.kind == DW_TagKind_UnionType || + tag.kind == DW_TagKind_SubProgram) { children_should_be_deduped = 1; } @@ -1569,139 +1570,6 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params) //- rjf: unpack tag node U64 start_off = tag_n->info_off; - //- rjf: gather the set of tree hashes in the type graph pointed into by `tag_n` -#if 0 - D2R_TreeHashNode *first_tree_hash = 0; - D2R_TreeHashNode *last_tree_hash = 0; - U64 tree_hash_count = 0; - { - typedef struct Task Task; - struct Task - { - Task *next; - U64 unit_idx; - U64 start_off; - }; - Task start_task = {0, origin_unit_idx, start_off}; - Task *first_task = &start_task; - Task *last_task = 0; - Task *free_task = 0; - for(;first_task != 0;) - { - // rjf: unpack this task's unit info - U64 unit_idx = first_task->unit_idx; - Rng1U64 unit_info_tag_range = unit_info_tag_ranges[unit_idx]; - DW2_ParseCtx *unit_parse_ctx = &unit_parse_ctxs[unit_idx]; - - // rjf: combine all tag hashes in this tag tree - S64 depth = 0; - U64 tree_hash = 0; - for(U64 off = first_task->start_off; contains_1u64(unit_info_tag_range, off) && (depth > 0 || off == first_task->start_off);) - { - U64 start_off = off; - Temp tag_scratch = scratch_begin(&dedup_root_scratch.arena, 1); - - // rjf: look up this tag hash - U64 tag_hash = 0; - { - U64 off_hash = u64_hash_from_str8(str8_struct(&start_off)); - U64 slot_idx = off_hash%tag_hash_slots_count; - for(D2R_TagHashNode *n = tag_hash_slots[slot_idx]; n != 0; n = n->next) - { - if(n->info_off == start_off) - { - tag_hash = n->hash; - break; - } - } - } - - // rjf: combine this tag hash into the tree hash - tree_hash = u64_hash_from_seed_str8(tree_hash, str8_struct(&tag_hash)); - - // rjf: read the next tag - DW2_Tag tag = {0}; - off += dw2_read_tag(tag_scratch.arena, raw, unit_parse_ctx, raw->sec[DW_SectionKind_Info].data, off, &tag); - - // rjf: find type reference in this tag, use to generate additional tasks - DW2_Attrib *type_attrib = dw2_attrib_from_kind(&tag, DW_AttribKind_Type); - if(type_attrib != &dw2_attrib_nil) - { - U64 type_ref_info_off = dw2_reference_info_off_from_form_val(unit_parse_ctx, &type_attrib->val); - U64 type_ref_unit_idx = unit_idx; - if(!contains_1u64(unit_info_tag_range, type_ref_info_off)) - { - U64 new_unit_num = rng1u64_array_num_from_value__binary_search(&unit_info_tag_ranges_array, type_ref_info_off); - if(0 < new_unit_num && new_unit_num <= unit_count) - { - type_ref_unit_idx = new_unit_num-1; - } - } - Task *t = free_task; - if(t) - { - SLLStackPop(free_task); - } - else - { - t = push_array(dedup_root_scratch.arena, Task, 1); - } - SLLQueuePush(first_task, last_task, t); - t->unit_idx = type_ref_unit_idx; - t->start_off = type_ref_info_off; - } - - scratch_end(tag_scratch); - if(off == start_off) - { - break; - } - } - - // rjf: push this tree hash - D2R_TreeHashNode *n = push_array(dedup_root_scratch.arena, D2R_TreeHashNode, 1); - SLLQueuePush(first_tree_hash, last_tree_hash, n); - n->v.info_off = start_off; - n->v.hash = tree_hash; - tree_hash_count += 1; - - // rjf: pop this task off the queue - Task *popped = first_task; - first_task = first_task->next; - SLLStackPush(free_task, popped); - } - } - - //- rjf: flatten & sort the hash pieces deterministically - D2R_TreeHash *tree_hashes_sorted = 0; - { - D2R_TreeHash *unsorted = push_array(scratch.arena, D2R_TreeHash, tree_hash_count); - U64 idx = 0; - for EachNode(n, D2R_TreeHashNode, first_tree_hash) - { - unsorted[idx] = n->v; - idx += 1; - } - radsort(unsorted, tree_hash_count, d2r_tree_hash_is_less_than); - tree_hashes_sorted = unsorted; - } - - //- rjf: form combined hash of all pieces in deterministic order - U64 combined_hash = 0; - for EachIndex(tree_hash_idx, tree_hash_count) - { - combined_hash = u64_hash_from_seed_str8(combined_hash, str8_struct(&tree_hashes_sorted[tree_hash_idx].hash)); - } - - //- rjf: walk the sorted hash pieces - for each piece, it's full hash is - // the combined hash, + an identifier of which node it came from. - for EachIndex(tree_hash_idx, tree_hash_count) - { - U64 tree_and_ref_hash = u64_hash_from_seed_str8(combined_hash, str8_struct(&tree_hash_idx)); - // TODO(rjf): cache mapping of `tree_hashes_sorted[tree_hash_idx].info_off -> tree_and_ref_hash` - } -#endif - //- rjf: compute tree hash U64 hash = 0; D2R_UniqueTagKind unique_tag_kind = D2R_UniqueTagKind_Type; @@ -1720,6 +1588,7 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params) U64 off; S64 depth; U64 hash; + B32 is_member; }; TagTask start_task = {0, DW_TagKind_Null, 0, 0, origin_unit_idx, start_off, start_off, 0}; TagTask *top_task = &start_task; @@ -1730,6 +1599,7 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params) U64 already_computed_hash = 0; U64 already_computed_dependency_count = 0; B32 found_already_computed_hash = 0; +#if 0 { U64 off_hash = u64_hash_from_str8(str8_struct(&top_task->start_off)); U64 off_slot_idx = off_hash%unit_deduped_tag_maps[top_task->unit_idx].slots_count; @@ -1745,6 +1615,7 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params) } } } +#endif //- rjf: if we found an already-computed hash, just write it into this task as its result if(found_already_computed_hash) @@ -1861,7 +1732,10 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params) // rjf: if this tag has a non-recursive type reference -> push a new task to hash the type. if(!type_ref_is_recursive && type_info_off != 0) { - top_task->dependency_count += 1; + if(tag.kind != DW_TagKind_Member) + { + top_task->dependency_count += 1; + } U64 unit_idx = top_task->unit_idx; if(!contains_1u64(unit_info_tag_range, type_info_off)) { @@ -1881,16 +1755,17 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params) task = push_array_no_zero(dedup_root_scratch.arena, TagTask, 1); } MemoryZeroStruct(task); - SLLStackPush(top_task, task); task->unit_idx = unit_idx; task->start_off = task->off = type_info_off; + task->is_member = (tag.kind == DW_TagKind_Member); + SLLStackPush(top_task, task); } scratch_end(tag_scratch); } //- rjf: if we're done, and if we computed the hash on this lane -> record in the per-unit (offset -> hash) table - if(done && !found_already_computed_hash) + if(done && !found_already_computed_hash && top_task == &start_task) { U64 info_off_hash = u64_hash_from_str8(str8_struct(&top_task->start_off)); U64 info_off_slot_idx = info_off_hash%unit_deduped_tag_maps[top_task->unit_idx].slots_count; @@ -1918,7 +1793,10 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params) if(top_task != 0) { top_task->hash = u64_hash_from_seed_str8(top_task->hash, str8_struct(&popped->hash)); - top_task->dependency_count += popped->dependency_count; + if(!popped->is_member) + { + top_task->dependency_count += popped->dependency_count; + } } } } @@ -2528,10 +2406,6 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params) dst_type->kind = rdi_type_kind; dst_type->direct_type = direct_type; dst_type->byte_size = arch_addr_size; - if(direct_type == 0) - { - int x = 0; - } }break; case DW_TagKind_RestrictType: {