From bbd86449d86e850778d3c155dc16f5561c5bc5d8 Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Thu, 19 Sep 2024 16:07:14 -0700 Subject: [PATCH] fix ghost auto-view-rule text visualization to calculate auto view rule from raw type expression rather than post-view-rule-applied one --- src/eval/eval_types.c | 45 +++++++++++++++++++ src/eval/eval_types.h | 1 + .../eval_visualization_core.c | 16 ++++--- .../eval_visualization_core.h | 2 + src/raddbg/raddbg_core.c | 2 +- src/raddbg/raddbg_views.c | 3 +- 6 files changed, 62 insertions(+), 7 deletions(-) diff --git a/src/eval/eval_types.c b/src/eval/eval_types.c index 784656a4..ecdb645b 100644 --- a/src/eval/eval_types.c +++ b/src/eval/eval_types.c @@ -243,6 +243,7 @@ e_select_type_ctx(E_TypeCtx *ctx) } arena_pop_to(e_type_state->arena, e_type_state->arena_eval_start_pos); e_type_state->ctx = ctx; + e_type_state->cons_id_gen = 0; e_type_state->cons_content_slots_count = 256; e_type_state->cons_key_slots_count = 256; e_type_state->cons_content_slots = push_array(e_type_state->arena, E_ConsTypeSlot, e_type_state->cons_content_slots_count); @@ -489,6 +490,50 @@ e_type_key_match(E_TypeKey l, E_TypeKey r) //- rjf: key -> info extraction +internal U64 +e_hash_from_type_key(E_TypeKey key) +{ + U64 hash = 0; + if(!e_type_key_match(e_type_key_zero(), key)) + { + Temp scratch = scratch_begin(0, 0); + E_Type *type = e_type_from_key(scratch.arena, key); + String8List strings = {0}; + str8_serial_begin(scratch.arena, &strings); + str8_serial_push_struct(scratch.arena, &strings, &type->kind); + str8_serial_push_struct(scratch.arena, &strings, &type->flags); + str8_serial_push_string(scratch.arena, &strings, type->name); + str8_serial_push_struct(scratch.arena, &strings, &type->byte_size); + str8_serial_push_struct(scratch.arena, &strings, &type->count); + str8_serial_push_struct(scratch.arena, &strings, &type->off); + U64 direct_hash = e_hash_from_type_key(type->direct_type_key); + U64 owner_hash = e_hash_from_type_key(type->direct_type_key); + str8_serial_push_struct(scratch.arena, &strings, &direct_hash); + str8_serial_push_struct(scratch.arena, &strings, &owner_hash); + if(type->param_type_keys != 0) + { + for EachIndex(idx, type->count) + { + U64 param_type_hash = e_hash_from_type_key(type->param_type_keys[idx]); + str8_serial_push_struct(scratch.arena, &strings, ¶m_type_hash); + } + } + else if(type->members != 0) + { + for EachIndex(idx, type->count) + { + U64 member_type_hash = e_hash_from_type_key(type->members[idx].type_key); + str8_serial_push_struct(scratch.arena, &strings, &type->members[idx].off); + str8_serial_push_struct(scratch.arena, &strings, &member_type_hash); + } + } + String8 string = str8_serial_end(scratch.arena, &strings); + hash = e_hash_from_string(5381, string); + scratch_end(scratch); + } + return hash; +} + internal E_TypeKind e_type_kind_from_key(E_TypeKey key) { diff --git a/src/eval/eval_types.h b/src/eval/eval_types.h index f1bbe19b..4624b3df 100644 --- a/src/eval/eval_types.h +++ b/src/eval/eval_types.h @@ -249,6 +249,7 @@ internal E_TypeKey e_type_key_cons_base(Type *type, String8 name); internal B32 e_type_key_match(E_TypeKey l, E_TypeKey r); //- rjf: key -> info extraction +internal U64 e_hash_from_type_key(E_TypeKey key); internal E_TypeKind e_type_kind_from_key(E_TypeKey key); internal U64 e_type_byte_size_from_key(E_TypeKey key); internal E_Type *e_type_from_key(Arena *arena, E_TypeKey key); diff --git a/src/eval_visualization/eval_visualization_core.c b/src/eval_visualization/eval_visualization_core.c index 2b254f61..61b75031 100644 --- a/src/eval_visualization/eval_visualization_core.c +++ b/src/eval_visualization/eval_visualization_core.c @@ -363,7 +363,7 @@ ev_auto_view_rule_table_push_new(Arena *arena, EV_AutoViewRuleTable *table, E_Ty table->slots_count = 4096; table->slots = push_array(arena, EV_AutoViewRuleSlot, table->slots_count); } - U64 hash = e_hash_from_string(5381, str8_struct(&type_key)); + U64 hash = e_hash_from_type_key(type_key); U64 slot_idx = hash%table->slots_count; EV_AutoViewRuleSlot *slot = &table->slots[slot_idx]; EV_AutoViewRuleNode *node = 0; @@ -396,7 +396,7 @@ ev_auto_view_rule_from_type_key(E_TypeKey type_key) String8 string = {0}; if(ev_auto_view_rule_table != 0 && ev_auto_view_rule_table->slots_count != 0) { - U64 hash = e_hash_from_string(5381, str8_struct(&type_key)); + U64 hash = e_hash_from_type_key(type_key); U64 slot_idx = hash%ev_auto_view_rule_table->slots_count; EV_AutoViewRuleSlot *slot = &ev_auto_view_rule_table->slots[slot_idx]; EV_AutoViewRuleNode *node = 0; @@ -501,6 +501,7 @@ ev_block_begin(Arena *arena, EV_BlockKind kind, EV_Key parent_key, EV_Key key, S n->v.key = key; n->v.depth = depth; n->v.expr = &e_expr_nil; + n->v.expr_raw = &e_expr_nil; n->v.view_rules = &ev_nil_view_rule_list; return &n->v; } @@ -514,6 +515,7 @@ ev_block_split_and_continue(Arena *arena, EV_BlockList *list, EV_Block *split_bl EV_Block *continue_block = ev_block_begin(arena, split_block->kind, split_block->parent_key, split_block->key, split_block->depth); continue_block->string = split_block->string; continue_block->expr = split_block->expr; + continue_block->expr_raw = split_block->expr_raw; continue_block->visual_idx_range = continue_block->semantic_idx_range = r1u64(split_idx+1, total_count); continue_block->view_rules = split_block->view_rules; continue_block->members = split_block->members; @@ -540,6 +542,7 @@ ev_append_expr_blocks__rec(Arena *arena, EV_View *view, EV_Key parent_key, EV_Ke Temp scratch = scratch_begin(&arena, 1); //- rjf: apply expr resolution view rules + E_Expr *expr_raw = expr; expr = ev_expr_from_expr_view_rules(arena, expr, view_rules); //- rjf: determine if this key is expanded @@ -551,6 +554,7 @@ ev_append_expr_blocks__rec(Arena *arena, EV_View *view, EV_Key parent_key, EV_Ke EV_Block *block = ev_block_begin(arena, EV_BlockKind_Root, parent_key, key, depth); block->string = string; block->expr = expr; + block->expr_raw = expr_raw; block->view_rules = view_rules; block->visual_idx_range = r1u64(key.child_num-1, key.child_num+0); block->semantic_idx_range = r1u64(key.child_num-1, key.child_num+0); @@ -912,6 +916,7 @@ ev_row_list_push_new(Arena *arena, EV_View *view, EV_WindowedRowList *rows, EV_B // rjf: pick view rule list; resolve expression if needed EV_ViewRuleList *view_rules = 0; + E_Expr *expr_resolved = expr; switch(block->kind) { default: @@ -929,7 +934,7 @@ ev_row_list_push_new(Arena *arena, EV_View *view, EV_WindowedRowList *rows, EV_B { ev_view_rule_list_push_string(arena, view_rules, row_view_rules); } - expr = ev_expr_from_expr_view_rules(arena, expr, view_rules); + expr_resolved = ev_expr_from_expr_view_rules(arena, expr, view_rules); }break; case EV_BlockKind_Root: case EV_BlockKind_Canvas: @@ -945,7 +950,8 @@ ev_row_list_push_new(Arena *arena, EV_View *view, EV_WindowedRowList *rows, EV_B row->key = key; row->size_in_rows = 1; row->string = block->string; - row->expr = expr; + row->expr = expr_resolved; + row->expr_raw = expr; if(row->expr->kind == E_ExprKind_MemberAccess) { Temp scratch = scratch_begin(&arena, 1); @@ -1038,7 +1044,7 @@ ev_windowed_row_list_from_block_list(Arena *arena, EV_View *view, Rng1S64 visibl case EV_BlockKind_Null: case EV_BlockKind_Root: { - ev_row_list_push_new(arena, view, &list, block, block->key, block->expr); + ev_row_list_push_new(arena, view, &list, block, block->key, block->expr_raw); }break; ////////////////////////////// diff --git a/src/eval_visualization/eval_visualization_core.h b/src/eval_visualization/eval_visualization_core.h index cff14315..f3e1d504 100644 --- a/src/eval_visualization/eval_visualization_core.h +++ b/src/eval_visualization/eval_visualization_core.h @@ -126,6 +126,7 @@ struct EV_Block // rjf: evaluation info String8 string; E_Expr *expr; + E_Expr *expr_raw; // rjf: info about ranges that this block spans Rng1U64 visual_idx_range; @@ -284,6 +285,7 @@ struct EV_Row String8 string; E_Member *member; E_Expr *expr; + E_Expr *expr_raw; // rjf: view rule attachments EV_ViewRuleList *view_rules; diff --git a/src/raddbg/raddbg_core.c b/src/raddbg/raddbg_core.c index f769579f..eb51bdf2 100644 --- a/src/raddbg/raddbg_core.c +++ b/src/raddbg/raddbg_core.c @@ -10399,7 +10399,7 @@ rd_frame(void) // EV_AutoViewRuleTable *auto_view_rule_table = push_array(scratch.arena, EV_AutoViewRuleTable, 1); { - // TODO(rjf) + ev_auto_view_rule_table_push_new(scratch.arena, auto_view_rule_table, e_type_key_cons_base(type(CTRL_MetaEvalFrameArray), str8_zero()), str8_lit("slice")); } ev_select_auto_view_rule_table(auto_view_rule_table); diff --git a/src/raddbg/raddbg_views.c b/src/raddbg/raddbg_views.c index e4345d43..99d8cbc1 100644 --- a/src/raddbg/raddbg_views.c +++ b/src/raddbg/raddbg_views.c @@ -2511,7 +2511,8 @@ rd_watch_view_build(RD_WatchViewState *ewv, B32 modifiable, U32 default_radix, R cell_autocomp_flags = RD_AutoCompListerFlag_ViewRules; if(cell_pre_edit_string.size == 0) { - cell_ghost_text = ev_auto_view_rule_from_type_key(row_eval.type_key); + E_IRTreeAndType raw_irtree = e_irtree_and_type_from_expr(scratch.arena, row->expr_raw); + cell_ghost_text = ev_auto_view_rule_from_type_key(raw_irtree.type_key); } }break; case RD_WatchViewColumnKind_FrameSelection: