fix(compiler): stub 注入泛型类跳过方法 declare,修复 ndarray[T] 错误特化
Phase2 翻译 App 文件注入 numpy stub 时,_inject_method_declare 解析
class ndarray[T] 的模板签名(ndarray[T] | t.CPtr),T 无上下文可替换
→ _specialize_generic_class("ndarray", ["T"]) 递归崩溃。泛型类
(type_params 非空)跳过方法 declare 注入,具体特化方法 define 已由
Phase1 生成,返回类型仍走 vpi 返回注解缓存泛型归一化。
(含 4 处 TC-DBG 定位插桩,验证后移除)
This commit is contained in:
1 parent
94b84c7dc1
commit
16d0302b08
3 files changed
+26
No files matched your search
@@ -869,6 +869,16 @@ def _ParseVpiIntoModuleImpl(pool: memhub.MemBuddy | t.CPtr,
|
||||
if class_cd is None or class_cd.name is None:
|
||||
continue
|
||||
cls_name_v: str = class_cd.name
|
||||
# 泛型类(class X[T])跳过方法 declare 注入:stub 模板签名含类级
|
||||
# 类型参数 T(如 ndarray[T].__add__ 的返回 ndarray[T] | t.CPtr),
|
||||
# 注入时 T 无法确定具体类型,直接解析会触发
|
||||
# _specialize_generic_class("ndarray", ["T"]) 错误特化
|
||||
# (Phase2 翻译 App 文件注入 numpy stub 时崩溃)。
|
||||
# 具体特化的方法 define 已在 Phase1 生成,跨模块调用按特化类名
|
||||
# (ndarray[t.CDouble].__add__)查找命中,无需 stub 模板 declare。
|
||||
tp_stub: list[str] | t.CPtr = class_cd.type_params
|
||||
if tp_stub is not None and tp_stub.__len__() > 0:
|
||||
continue
|
||||
cls_children: list[ast.AST | t.CPtr] | t.CPtr = class_cd.children
|
||||
if cls_children is not None:
|
||||
cn2: t.CSizeT = cls_children.__len__()
|
||||
|
||||
@@ -2279,6 +2279,10 @@ def _specialize_generic_class(trans: HT.Translator | t.CPtr,
|
||||
type_args.set(ta_i_g, ta_rsv_g)
|
||||
|
||||
pool: memhub.MemBuddy | t.CPtr = trans.Pool
|
||||
fb_spc: t.CChar | t.CPtr = VLogger.fmt_buf()
|
||||
if fb_spc is not None:
|
||||
viperlib.snprintf(fb_spc, 1024, "_specialize_generic_class: %s declare_only=%d", class_name, trans._declare_only)
|
||||
VLogger.info(fb_spc, "TC-DBG")
|
||||
|
||||
# ============================================================
|
||||
# 诊断输出:追踪 GSListNode 特化调用路径
|
||||
@@ -2466,6 +2470,10 @@ def translate_class_def(trans: HT.Translator | t.CPtr,
|
||||
|
||||
pool: memhub.MemBuddy | t.CPtr = trans.Pool
|
||||
class_name: str = cd.name
|
||||
fb_tcd: t.CChar | t.CPtr = VLogger.fmt_buf()
|
||||
if fb_tcd is not None:
|
||||
viperlib.snprintf(fb_tcd, 1024, "translate_class_def: %s line=%d", class_name, cd.lineno)
|
||||
VLogger.info(fb_tcd, "TC-DBG")
|
||||
|
||||
# 命名空间隔离:标记为当前文件可见(必须在 existing 检查之前,
|
||||
# 因为 Phase B 时结构体已注册会提前 return,否则永远无法标记本地类)
|
||||
@@ -3492,6 +3500,10 @@ def _translate_method(trans: HT.Translator | t.CPtr,
|
||||
"""翻译单个方法,返回 0"""
|
||||
if trans is None or fd is None or struct_ty is None or class_name is None:
|
||||
return 0
|
||||
fb_tm: t.CChar | t.CPtr = VLogger.fmt_buf()
|
||||
if fb_tm is not None:
|
||||
viperlib.snprintf(fb_tm, 1024, "_translate_method: %s.%s", class_name, fd.name)
|
||||
VLogger.info(fb_tm, "TC-DBG")
|
||||
|
||||
# 懒导入
|
||||
import lib.core.Handles.HandlesFunctions as HandlesFunctions
|
||||
|
||||
@@ -87,6 +87,10 @@ def translate_children(trans: HT.Translator | t.CPtr,
|
||||
child: ast.AST | t.CPtr = ch.get(ci)
|
||||
if child is None: continue
|
||||
kd: int = child.kind()
|
||||
fb_tc: t.CChar | t.CPtr = VLogger.fmt_buf()
|
||||
if fb_tc is not None:
|
||||
viperlib.snprintf(fb_tc, 1024, "translate_children[%d]: kind=%d line=%d", ci, kd, child.lineno)
|
||||
VLogger.info(fb_tc, "TC-DBG")
|
||||
|
||||
# _declare_only == 0 时,_translate_module_level 已预处理导入语句,
|
||||
# 此处跳过避免重复处理(from_imports 条目重复)
|
||||
|
||||
Reference in new issue
Block a user