fix(tpv): 注解裸名按 from-import 归属查找(D26 闭环)
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
This commit is contained in:
1 parent
ea2abba574
commit
e0e024ee93
1 file changed
+22
@@ -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:
|
||||
|
||||
Reference in new issue
Block a user