fix(gen): list 内置分支置位 hit_box 并确认对象类型,修复 nums.set 找不到模块 SHA1

- list 内置分支 set/clear 等 void 方法成功处理返回 None 时未被标记命中,translate_call 误判未命中继续走跨模块路径,把对象名当模块名查 SHA1 → '跨模块调用 nums.set 找不到模块 SHA1'(ListTest 根因)
- 进入 list 内置分支即置位 hit_box(对齐 _translate_method_call 调用点模式),void 方法返回 None 视为已处理
- 增加对象类型确认(额外搜索路径):从对象结构体名匹配 list,明确非 list(dict/普通类未注册场景)跳过本分支,避免按 list 布局 GEP 误处理
This commit is contained in:
TermiNexus committed 2026-08-17 18:31:10 +08:00
1 parent 51ae18a160
commit 33c8609882
1 file changed
+22
+22
View File
@@ -1288,6 +1288,28 @@ class CallGenDispatch(CallGenBase.CallGenBase):
# fail-fast,绝不 VLogger.critical 后 return None 静默吞掉
HandlesType.fatal_error(
lm_at.value, f"list 方法 '{lm_name}' 目标对象非指针", "TypeError")
# list 对象类型确认(额外搜索路径):list 内置分支仅按方法名
# 判断(get/set/__getitem__ 等非 list 专有),须确认对象确实
# 是 list——从对象结构体名匹配 "list"。明确非 list(如 dict /
# 普通类未注册场景)跳过本分支,避免按 list 布局 GEP 生成
# 错误 IR(dict 的 get 被当 list.get 按 __data__/__elem_size__
# 偏移读写垃圾)。
lm_conf_ty: llvmlite.LLVMType | t.CPtr = \
HandlesStruct.get_struct_type_from_value(lm_obj)
lm_conf_nm: str = None
if lm_conf_ty is not None:
lm_conf_nm = llvmlite.get_struct_name(lm_conf_ty)
if lm_conf_nm is not None and \
string.strstr(lm_conf_nm, "list") is None:
return None
# list 内置分支命中标记:void 方法(set/clear)成功处理后返回
# None,必须置位 hit_box 区分"已识别为 list 方法路径",否则
# translate_call 误判未命中继续走跨模块函数路径,把对象名当
# 模块名查 SHA1 → "跨模块调用 'nums.set' 找不到模块 SHA1"
# (ListTest main.vp nums.set(1,99) 根因;对齐 _translate_method_call
# 调用点的 hit_box 置位模式)。
if hit_box is not None:
hit_box[0] = 1
i64_ty: llvmlite.LLVMType | t.CPtr = llvmlite.Int64(pool)
i8_ty: llvmlite.LLVMType | t.CPtr = llvmlite.Int8(pool)
i8_ptr_ty: llvmlite.LLVMType | t.CPtr = llvmlite.Ptr(pool, i8_ty)