refactor(tpv): 去掉函数内懒导入,改用顶层 import

Viper 的 import 是编译期的,懒导入在编译型语义下毫无作用,模块环不需要也不应该用它规避。

TypeSpec 顶层 import GenApi(GenApi→GenTypes→TypeSpec 成环但编译期无碍);CallGenLib 的既有懒导入(VpiReader)一并改顶层(VpiReader 不反向依赖 Call 层,无环)。
This commit is contained in:
TermiNexus committed 2026-09-12 10:23:08 +08:00
1 parent 7fbf69ae63
commit cc17a8f8db
2 files changed
+2 -5

No files matched your search

+1 -2
View File
@@ -6,6 +6,7 @@ import memhub
import string
import stdlib
import lib.core.Gen.Translator as HT
import lib.Stub.StubGen.VpiReader as VpiReader
from . import CallGenBase
@@ -216,8 +217,6 @@ class CallGenLib(CallGenBase.CallGenBase):
"""把跨模块调用实参 coerce 到 vpi 定义侧形参类型,返回重建的实参链"""
if pool is None or builder is None or call_name is None or head is None:
return head
# 函数内懒 import:与 _lookup_method_ret_ty_via_vpi 同源,规避顶层循环依赖
import lib.Stub.StubGen.VpiReader as VpiReader
if self._is_sha1_mangled_call(call_name) == 0:
return head
# 拆 {sha1}.{rest}:rest 含 '.' 则为 {cls}.{method},否则为 {func}
+1 -3
View File
@@ -5,6 +5,7 @@ import memhub
import string
import viperlib
import lib.core.CompilerFactory as CompilerFactory
import lib.core.Gen.GenApi as GenApi
# ============================================================
@@ -845,10 +846,7 @@ def InternSpec(arena: TypeSpecArena | t.CPtr,
# 不能返回 None —— 调用链会把 None 一路传到 entry.Spec,条目**静默失去类型信息**
# (如 _entry_spec_unsigned 恒返回 0 ⇒ zext/sext 方向取错),属静默数据损坏,
# 与「不兜底 / fail-fast」原则直接冲突(原注释声称 fail-fast,实现却只返回 None)。
# 破环:TypeSpec 与 GenApi 互为依赖(GenApi→GenTypes→TypeSpec),故**函数内懒 import**
# (同 CallGenLib.vp:220「函数内懒 import 规避顶层循环依赖」的既有模式)。
if arena.Count >= arena.Cap:
import lib.core.Gen.GenApi as GenApi
GenApi.fatal_error(
None,
f"TypeSpec 驻留表已满(上限 {arena.Cap} 条),无法登记新类型",