perf(reachable): 移除 _list/_dict/json 无条件预加入,按需编译
_BuildReachableSha1Set 原本无条件把 _list/_dict/json 塞进可达集,
导致未使用的 App 也整链编译(json/__init__ → __parser/__writer)。
_list/_dict 已由 Phase A _inject_auto_container_visibility 按需注入,
现补充 []/{} 字面量检测防漏;json 由 _dict 真实 import 链带入。
builtins 保留始终纳入(设计意图)。
This commit is contained in:
1 parent
b4c01808bf
commit
ad2b97a140
2 files changed
+11
-45
No files matched your search
@@ -513,6 +513,12 @@ class Translator:
|
||||
sub_s: ast.Subscript | t.CPtr = (ast.Subscript | t.CPtr)(node)
|
||||
if sub_s.value is not None:
|
||||
self._check_container_type_node(sub_s.value, need_list_box, need_dict_box)
|
||||
elif k == ast.ASTKind.List:
|
||||
# [] 字面量:容器模板仍需注册
|
||||
need_list_box[0] = 1
|
||||
elif k == ast.ASTKind.Dict:
|
||||
# {} 字面量:容器模板仍需注册
|
||||
need_dict_box[0] = 1
|
||||
# 递归语句块子节点
|
||||
if node.children is not None:
|
||||
ch_s: list[ast.AST | t.CPtr] | t.CPtr = node.children
|
||||
|
||||
@@ -1664,52 +1664,12 @@ def _BuildReachableSha1Set(mb: memhub.MemBuddy | t.CPtr, source_dir: str,
|
||||
viperlib.snprintf(fb, 1024, "源文件直接依赖: '%s'", worklist)
|
||||
VLogger.debug(fb, "Reachable")
|
||||
|
||||
# 2.5. 全局预加入基础容器模块(_list/_dict/json)
|
||||
# 2.5. 预加入基础模块(builtins)
|
||||
#
|
||||
# 这些模块定义了 list/dict 等内建容器的泛型模板。
|
||||
# 使用 list[...]/dict[...] 语法时需要这些模块被翻译并注册模板。
|
||||
# 即使源文件和 includes 文件没有显式 import _list,也预加入以确保可达。
|
||||
# 这对应 TPC 的 _inject_auto_imports 机制(TPC 在翻译前自动注入 import _list)。
|
||||
# _list
|
||||
if HandlesImports.is_module_imported(worklist, "_list") == 0:
|
||||
bsha1_l: str = _FindSha1ByModName(sha1_arr, mod_arr, map_count, "_list")
|
||||
if bsha1_l is not None:
|
||||
if wl_len + 7 < 8192:
|
||||
if wl_len > 0:
|
||||
worklist[wl_len] = ' '
|
||||
wl_len += 1
|
||||
string.strcpy(worklist + wl_len, "_list")
|
||||
wl_len += 5
|
||||
worklist[wl_len] = ' '
|
||||
wl_len += 1
|
||||
worklist[wl_len] = '\0'
|
||||
# _dict
|
||||
if HandlesImports.is_module_imported(worklist, "_dict") == 0:
|
||||
bsha1_d: str = _FindSha1ByModName(sha1_arr, mod_arr, map_count, "_dict")
|
||||
if bsha1_d is not None:
|
||||
if wl_len + 7 < 8192:
|
||||
if wl_len > 0:
|
||||
worklist[wl_len] = ' '
|
||||
wl_len += 1
|
||||
string.strcpy(worklist + wl_len, "_dict")
|
||||
wl_len += 5
|
||||
worklist[wl_len] = ' '
|
||||
wl_len += 1
|
||||
worklist[wl_len] = '\0'
|
||||
# json
|
||||
if HandlesImports.is_module_imported(worklist, "json") == 0:
|
||||
bsha1_j: str = _FindSha1ByModName(sha1_arr, mod_arr, map_count, "json")
|
||||
if bsha1_j is not None:
|
||||
if wl_len + 6 < 8192:
|
||||
if wl_len > 0:
|
||||
worklist[wl_len] = ' '
|
||||
wl_len += 1
|
||||
string.strcpy(worklist + wl_len, "json")
|
||||
wl_len += 4
|
||||
worklist[wl_len] = ' '
|
||||
wl_len += 1
|
||||
worklist[wl_len] = '\0'
|
||||
# builtins(内置函数模块:ord/chr 等,始终纳入编译链,调用时自动关联)
|
||||
# builtins(内置函数模块:ord/chr 等)始终纳入编译链,调用时自动关联。
|
||||
# _list/_dict 不再无条件预加入:Phase A 翻译 App 源文件时
|
||||
# _inject_auto_container_visibility 已按需检测 list/dict 使用并注入
|
||||
# _imported_modules(含 []/{} 字面量),json 由 _dict 的真实 import 链带入。
|
||||
if HandlesImports.is_module_imported(worklist, "builtins") == 0:
|
||||
bsha1_b: str = _FindSha1ByModName(sha1_arr, mod_arr, map_count, "builtins")
|
||||
if bsha1_b is not None:
|
||||
|
||||
Reference in new issue
Block a user