From c54e87bd6d4ea00587159fa61de9cebfe5c9a4bb Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Thu, 27 Aug 2026 14:27:24 +0800 Subject: [PATCH] =?UTF-8?q?fix(imports):=20from=20.=20import=20Y=20?= =?UTF-8?q?=E7=9A=84=20Y=20=E6=98=AF=E5=8C=85=E5=86=85=E7=AC=A6=E5=8F=B7?= =?UTF-8?q?=EF=BC=88=E9=9D=9E=E5=AD=90=E6=A8=A1=E5=9D=97=EF=BC=89=E6=97=B6?= =?UTF-8?q?=E8=B7=B3=E8=BF=87=20SHA1=20=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - translate_import_from_module 对 from . import Y 曾无条件把每个 name 拼成 resolved.Y 当子模块校验 SHA1 → json/__parser.vp 的 from . import JsonValue 等符号(json/__init__.vp 定义)被误报"模块 json.JsonValue 未注册 SHA1" - 仅在完整名已注册 SHA1(真子模块)或本地文件时才校验+登记;符号映射 由 translate_import_from_names 的 from-import / re-export 处理 - 顺带:Reexport 懒初始化改用 CompilerFactory.factory.PermPool(配合 TPC 跨模块全局写端修复) --- App/lib/core/Gen/ImportsGenMixin.vp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/App/lib/core/Gen/ImportsGenMixin.vp b/App/lib/core/Gen/ImportsGenMixin.vp index 8e4b7b6..0fc4d01 100644 --- a/App/lib/core/Gen/ImportsGenMixin.vp +++ b/App/lib/core/Gen/ImportsGenMixin.vp @@ -344,9 +344,9 @@ class ImportsGenMixin: return -1 # 懒初始化 if self.ReexportSha1s is None: - self.ReexportSha1s = CompilerFactory.get_perm_pool().alloc(MAX_REEXPORT * 17) - self.ReexportFuncs = CompilerFactory.get_perm_pool().alloc(MAX_REEXPORT * 64) - self.ReexportSrcs = CompilerFactory.get_perm_pool().alloc(MAX_REEXPORT * 64) + self.ReexportSha1s = CompilerFactory.factory.PermPool.alloc(MAX_REEXPORT * 17) + self.ReexportFuncs = CompilerFactory.factory.PermPool.alloc(MAX_REEXPORT * 64) + self.ReexportSrcs = CompilerFactory.factory.PermPool.alloc(MAX_REEXPORT * 64) if self.ReexportSha1s is None or self.ReexportFuncs is None or self.ReexportSrcs is None: return -1 string.memset(self.ReexportSha1s, 0, MAX_REEXPORT * 17) @@ -754,10 +754,20 @@ class ImportsGenMixin: string.strcpy(jb_m, resolved) jb_m[rl_m] = '.' string.strcpy(jb_m + rl_m + 1, alias_m.name) - if trans._declare_only == 0: - self._check_import_sha1(node, jb_m) - trans._imported_modules = self.add_imported_module( - trans.Pool, trans._imported_modules, jb_m) + # from . import Y 的 Y 不一定是包子模块文件: + # 可能是包 __init__.vp 中定义的符号(类/常量,如 + # json/__init__.vp 的 JsonValue),无独立文件、不注册 + # SHA1。此前无条件按子模块校验 → 误报"模块 'json.JsonValue' + # 未注册 SHA1"。仅当完整名已注册 SHA1(真子模块,如 + # vpsdk.syscall)或是本地文件时才校验+登记;否则跳过, + # 符号映射由 translate_import_from_names 的 from-import + # / re-export 处理。 + if (StubMergerStore.LookupSha1ByModName(jb_m) is not None + or self._is_local_module_file(alias_m.name) != 0): + if trans._declare_only == 0: + self._check_import_sha1(node, jb_m) + trans._imported_modules = self.add_imported_module( + trans.Pool, trans._imported_modules, jb_m) return 0 # ============================================================