From e0e024ee93b5fb434575cf48627e6b3600c464bc Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Sat, 12 Sep 2026 19:37:55 +0800 Subject: [PATCH] =?UTF-8?q?fix(tpv):=20=E6=B3=A8=E8=A7=A3=E8=A3=B8?= =?UTF-8?q?=E5=90=8D=E6=8C=89=20from-import=20=E5=BD=92=E5=B1=9E=E6=9F=A5?= =?UTF-8?q?=E6=89=BE=EF=BC=88D26=20=E9=97=AD=E7=8E=AF=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit stub 注入注解时 trans.ModuleSha1 是正在翻译的文件,而注解里的类归属 stub 源模块;仅靠当前模块 sha1 加全局可见性在 App 严格模式下查不到(AsyncGenMixin 未 import ast.Expression),导致 ast/__init__.vpi 的 parse_expression -> rowptr[Expression] 返回类型解析失败 fail-fast。TypeGenResolve 的 Name 分支在 own 之后、可见性之前插入 from_imports 归属查找(LookupModNameByAlias 到 LookupSha1ByModName 到 find_struct_by_module)。TPV 自举 Phase1 从 28/53 推进到 40/53 --- App/lib/core/Gen/Type/TypeGenResolve.vp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/App/lib/core/Gen/Type/TypeGenResolve.vp b/App/lib/core/Gen/Type/TypeGenResolve.vp index a7611dd..743b14d 100644 --- a/App/lib/core/Gen/Type/TypeGenResolve.vp +++ b/App/lib/core/Gen/Type/TypeGenResolve.vp @@ -1994,6 +1994,28 @@ class TypeGenResolve(TypeGenBase.TypeGenBase): if own_entry.HasNew != 0: return llvmlite.Ptr(pool, own_entry.Ty) return own_entry.Ty + # from-import 归属查找:注解里的裸名(或 import 别名)经 from_imports + # 定位到定义模块,再按 (name, sha1) 精确取类。这是 stub 注入场景的 + # 正解——此刻 trans.ModuleSha1 是"正在翻译的文件",而注解里的类归属 + # **stub 源模块**(from_imports 即该 stub 的名字→模块映射)。 + # 反例(D26 根因):ast/__init__.vpi 的 + # `parse_expression -> rowptr[Expression]`,Expression 定义在 + # ast.stmts;仅靠"当前模块 sha1 + 全局可见性"在 App 严格模式下查不到 + # (AsyncGenMixin 并未 import ast.Expression)⇒ 返回类型解析失败 + # fail-fast。from_imports 里的 `Expression:ast.stmts` 是精确归属依据。 + if trans is not None and from_imports is not None: + fi_mod: str = StubMergerStore.LookupModNameByAlias(from_imports, nm.id) + if fi_mod is not None: + fi_sha1: str = StubMergerStore.LookupSha1ByModName(fi_mod) + if fi_sha1 is None: + fi_sha1 = StubMergerStore.LookupSha1ByModNameSuffix(fi_mod) + stdlib.free(fi_mod) + if fi_sha1 is not None: + fi_entry: GenTypes.StructEntry | t.CPtr = self.Gen.StructGen.find_struct_by_module(nm.id, fi_sha1) + if fi_entry is not None and fi_entry.Ty is not None: + if fi_entry.HasNew != 0: + return llvmlite.Ptr(pool, fi_entry.Ty) + return fi_entry.Ty if self.Gen.StructGen.is_struct_visible(nm.id) != 0: struct_ty: llvmlite.LLVMType | t.CPtr = self.Gen.StructGen.get_struct_type(nm.id) if struct_ty is not None: