修正:直接操作操作跨模块变量(VLogger),避免间接 global 函数
This commit is contained in:
1 parent
ab0f37e1a8
commit
a603736f64
23 files changed
+677
-1036
No files matched your search
@@ -253,10 +253,8 @@ def _PyiTypeStr(buf: bytes, buf_size: t.CSizeT, pos: t.CSizeT,
|
||||
# BinOp.left 等回指祖先)时无限递归直至栈耗尽(Phase1 vpi 生成最先
|
||||
# 执行,早于翻译阶段)。fail-fast 终止,不静默回退。
|
||||
if depth > 64:
|
||||
fb_pt: str = VLogger.fmt_buf()
|
||||
if fb_pt is not None:
|
||||
viperlib.snprintf(fb_pt, 256, "vpi 类型注解递归过深(AST 环或嵌套超过 64 层)")
|
||||
VLogger.error(fb_pt, "StubGen")
|
||||
viperlib.snprintf(VLogger.fmtbuffer, 256, "vpi 类型注解递归过深(AST 环或嵌套超过 64 层)")
|
||||
VLogger.error(VLogger.fmtbuffer, "StubGen")
|
||||
sys.exit(1)
|
||||
if annot is None:
|
||||
return _PyiEmit(buf, buf_size, pos, "t.CInt")
|
||||
@@ -372,10 +370,8 @@ def _PyiDefaultStr(buf: bytes, buf_size: t.CSizeT, pos: t.CSizeT,
|
||||
"""生成默认值表达式文本到 buf,返回新的 pos"""
|
||||
# 递归深度守卫:AST 损坏成自引用环时 fail-fast 终止(同 _PyiTypeStr)
|
||||
if depth > 64:
|
||||
fb_pd: str = VLogger.fmt_buf()
|
||||
if fb_pd is not None:
|
||||
viperlib.snprintf(fb_pd, 256, "vpi 默认值表达式递归过深(AST 环或嵌套超过 64 层)")
|
||||
VLogger.error(fb_pd, "StubGen")
|
||||
viperlib.snprintf(VLogger.fmtbuffer, 256, "vpi 默认值表达式递归过深(AST 环或嵌套超过 64 层)")
|
||||
VLogger.error(VLogger.fmtbuffer, "StubGen")
|
||||
sys.exit(1)
|
||||
if node is None:
|
||||
return pos
|
||||
|
||||
@@ -108,13 +108,12 @@ def _SeenInsert(tbl: bytes, cap: t.CSizeT, count: int, key: str, key_hash: t.CUI
|
||||
if tbl is None or key is None:
|
||||
return count
|
||||
kl: t.CSizeT = string.strlen(key)
|
||||
fb: str = VLogger.fmtbuffer
|
||||
if kl >= _SEEN_NAME_MAX:
|
||||
return count
|
||||
if count >= cap:
|
||||
fb_full: str = VLogger.fmt_buf()
|
||||
if fb_full is not None:
|
||||
viperlib.snprintf(fb_full, 1024, "已见符号表满(容量 %d),新增符号登记被丢弃——去重失效,必须增大容量", cap)
|
||||
VLogger.error(fb_full, "StubMerger")
|
||||
viperlib.snprintf(fb, 1024, "已见符号表满(容量 %d),新增符号登记被丢弃——去重失效,必须增大容量", cap)
|
||||
VLogger.error(fb, "StubMerger")
|
||||
return count
|
||||
mask: t.CSizeT = cap - 1
|
||||
idx: t.CSizeT = t.CSizeT(key_hash) & mask
|
||||
@@ -289,15 +288,14 @@ def _LoadAndAppendStub(temp_dir: str, td_len: t.CSizeT, dep_sha1: str,
|
||||
if dep_path is None:
|
||||
return out_pos
|
||||
df_ls: fileio.File | t.CPtr = fileio.File(dep_path, fileio.MODE.R)
|
||||
fb: str = VLogger.fmtbuffer
|
||||
if df_ls.closed:
|
||||
stdlib.free(dep_path)
|
||||
# 依赖 stub 缺失:includes 映射内的模块缺失属编译错误(fail-fast),
|
||||
# 非映射模块(如 t/c 内部库、用户文件)按设计跳过
|
||||
if StubMergerStore.LookupSha1RelPath(dep_sha1) is not None:
|
||||
fb_ls: str = VLogger.fmt_buf()
|
||||
if fb_ls is not None:
|
||||
viperlib.snprintf(fb_ls, 1024, "依赖 stub 缺失: %s", dep_sha1)
|
||||
VLogger.error(fb_ls, "StubMerger")
|
||||
viperlib.snprintf(fb, 1024, "依赖 stub 缺失: %s", dep_sha1)
|
||||
VLogger.error(fb, "StubMerger")
|
||||
return out_pos
|
||||
dep_br_ls: t.CInt64T = df_ls.read_all(dep_buf, StubMerger.STUB_READ_BUF_SIZE)
|
||||
df_ls.close()
|
||||
@@ -488,16 +486,15 @@ def _LoadAndAppendTextDeclares(temp_dir: str, td_len: t.CSizeT, dep_sha1: str,
|
||||
text_path: str = StubMergerCollect._sliced_path(temp_dir, td_len, dep_sha1, "text.ll")
|
||||
if text_path is None:
|
||||
return out_pos
|
||||
fb: str = VLogger.fmtbuffer
|
||||
tf_lt: fileio.File | t.CPtr = fileio.File(text_path, fileio.MODE.R)
|
||||
if tf_lt.closed:
|
||||
stdlib.free(text_path)
|
||||
# 依赖 text 缺失:includes 映射内的模块缺失属编译错误(fail-fast),
|
||||
# 非映射模块(如 t/c 内部库、用户文件)按设计跳过
|
||||
if StubMergerStore.LookupSha1RelPath(dep_sha1) is not None:
|
||||
fb_lt: str = VLogger.fmt_buf()
|
||||
if fb_lt is not None:
|
||||
viperlib.snprintf(fb_lt, 1024, "依赖 text 缺失: %s", dep_sha1)
|
||||
VLogger.error(fb_lt, "StubMerger")
|
||||
viperlib.snprintf(fb, 1024, "依赖 text 缺失: %s", dep_sha1)
|
||||
VLogger.error(fb, "StubMerger")
|
||||
return out_pos
|
||||
text_br: t.CInt64T = tf_lt.read_all(dep_buf, StubMerger.STUB_READ_BUF_SIZE)
|
||||
tf_lt.close()
|
||||
@@ -760,10 +757,9 @@ def _BuildReachableSha1Set(mb: memhub.MemBuddy | t.CPtr, source_dir: str,
|
||||
stdlib.free(sha1_arr)
|
||||
stdlib.free(mod_arr)
|
||||
return -1
|
||||
fb: str = VLogger.fmt_buf()
|
||||
if fb is not None:
|
||||
viperlib.snprintf(fb, 1024, "SHA1 映射: %d 个", map_count)
|
||||
VLogger.debug(fb, "Reachable")
|
||||
fb: str = VLogger.fmtbuffer
|
||||
viperlib.snprintf(fb, 1024, "SHA1 映射: %d 个", map_count)
|
||||
VLogger.debug(fb, "Reachable")
|
||||
|
||||
# 工作列表(空格分隔的模块名)
|
||||
worklist: bytes = stdlib.malloc(StubMerger.REACH_WORKLIST_BUF)
|
||||
@@ -872,10 +868,9 @@ def _BuildReachableSha1Set(mb: memhub.MemBuddy | t.CPtr, source_dir: str,
|
||||
worklist[wl_len - 1] = '\0'
|
||||
wl_len -= 1
|
||||
|
||||
fb: str = VLogger.fmt_buf()
|
||||
if fb is not None:
|
||||
viperlib.snprintf(fb, 1024, "源文件直接依赖: '%s'", worklist)
|
||||
VLogger.debug(fb, "Reachable")
|
||||
fb: str = VLogger.fmtbuffer
|
||||
viperlib.snprintf(fb, 1024, "源文件直接依赖: '%s'", worklist)
|
||||
VLogger.debug(fb, "Reachable")
|
||||
|
||||
# 2.5. 预加入基础模块(builtins)
|
||||
#
|
||||
@@ -895,10 +890,9 @@ def _BuildReachableSha1Set(mb: memhub.MemBuddy | t.CPtr, source_dir: str,
|
||||
worklist[wl_len] = ' '
|
||||
wl_len += 1
|
||||
worklist[wl_len] = '\0'
|
||||
fb: str = VLogger.fmt_buf()
|
||||
if fb is not None:
|
||||
viperlib.snprintf(fb, 1024, "预加入容器模块后: '%s'", worklist)
|
||||
VLogger.debug(fb, "Reachable")
|
||||
|
||||
viperlib.snprintf(fb, 1024, "预加入容器模块后: '%s'", worklist)
|
||||
VLogger.debug(fb, "Reachable")
|
||||
|
||||
# 3. 工作列表算法:递归收集可达 SHA1
|
||||
processed: bytes = stdlib.malloc(StubMerger.REACH_WORKLIST_BUF)
|
||||
@@ -1030,10 +1024,8 @@ def _BuildReachableSha1Set(mb: memhub.MemBuddy | t.CPtr, source_dir: str,
|
||||
stdlib.free(app_mod_path)
|
||||
if is_app_src == 0:
|
||||
# fast-fail: includes 文件依赖未在内存中找到,Phase 1a-pre 未正确填充
|
||||
fb_ff: str = VLogger.fmt_buf()
|
||||
if fb_ff is not None:
|
||||
viperlib.snprintf(fb_ff, 1024, "依赖未找到 fast-fail: 模块 %s(sha1=%s) 的依赖未在内存中注册", mod_buf, found_sha1)
|
||||
VLogger.error(fb_ff, "Reachable")
|
||||
viperlib.snprintf(fb, 1024, "依赖未找到 fast-fail: 模块 %s(sha1=%s) 的依赖未在内存中注册", mod_buf, found_sha1)
|
||||
VLogger.error(fb, "Reachable")
|
||||
stdlib.free(sha1_arr)
|
||||
stdlib.free(mod_arr)
|
||||
stdlib.free(worklist)
|
||||
@@ -1046,10 +1038,8 @@ def _BuildReachableSha1Set(mb: memhub.MemBuddy | t.CPtr, source_dir: str,
|
||||
stdlib.free(worklist)
|
||||
stdlib.free(processed)
|
||||
|
||||
fb: str = VLogger.fmt_buf()
|
||||
if fb is not None:
|
||||
viperlib.snprintf(fb, 1024, "可达 SHA1: %d 个", reachable_count)
|
||||
VLogger.debug(fb, "Reachable")
|
||||
viperlib.snprintf(fb, 1024, "可达 SHA1: %d 个", reachable_count)
|
||||
VLogger.debug(fb, "Reachable")
|
||||
return reachable_count
|
||||
# ============================================================
|
||||
# BuildCombinedIR - 组合本地 stub + 依赖 stubs + 本地 text → 完整 IR
|
||||
@@ -1286,6 +1276,7 @@ def BuildCombinedIR(temp_dir: str, local_sha1: str,
|
||||
# 2d. 验证 deps.txt 中所有依赖模块的 stub 文件都存在(fail-fast)
|
||||
# 避免到 llc 才报 undefined value 错误。
|
||||
# 仅验证在 includes 映射中找到的模块(t/c 等内部库无 SHA1 映射,自动跳过)。
|
||||
fb: str = VLogger.fmtbuffer
|
||||
if deps_loaded != 0 and inc_count > 0:
|
||||
dep_total: t.CSizeT = string.strlen(deps_buf)
|
||||
dp: t.CSizeT = 0
|
||||
@@ -1326,10 +1317,8 @@ def BuildCombinedIR(temp_dir: str, local_sha1: str,
|
||||
if chk_path is not None:
|
||||
chk_f: fileio.File | t.CPtr = fileio.File(chk_path, fileio.MODE.R)
|
||||
if chk_f.closed:
|
||||
fb: str = VLogger.fmt_buf()
|
||||
if fb is not None:
|
||||
viperlib.snprintf(fb, 1024, "依赖模块 '%s' (sha1=%s) 的 stub 文件不存在: %s,立即终止编译", mod_nm, found_s, chk_path)
|
||||
VLogger.error(fb, "BuildCombinedIR")
|
||||
viperlib.snprintf(fb, 1024, "依赖模块 '%s' (sha1=%s) 的 stub 文件不存在: %s,立即终止编译", mod_nm, found_s, chk_path)
|
||||
VLogger.error(fb, "BuildCombinedIR")
|
||||
chk_f.close()
|
||||
stdlib.free(chk_path)
|
||||
stdlib.free(mod_nm)
|
||||
@@ -1341,10 +1330,8 @@ def BuildCombinedIR(temp_dir: str, local_sha1: str,
|
||||
tf: fileio.File | t.CPtr = fileio.File(text_path, fileio.MODE.R)
|
||||
if tf.closed:
|
||||
# 本地 text.ll 缺失:合并 IR 无法生成定义块,fail-fast 终止
|
||||
fb_tlp: str = VLogger.fmt_buf()
|
||||
if fb_tlp is not None:
|
||||
viperlib.snprintf(fb_tlp, 1024, "本地 text.ll 缺失: %s", text_path)
|
||||
VLogger.error(fb_tlp, "StubMerger")
|
||||
viperlib.snprintf(fb, 1024, "本地 text.ll 缺失: %s", text_path)
|
||||
VLogger.error(fb, "StubMerger")
|
||||
stdlib.free(text_path)
|
||||
else:
|
||||
text_content: bytes = stdlib.malloc(StubMerger.STUB_READ_BUF_SIZE)
|
||||
|
||||
@@ -119,10 +119,8 @@ def PopulateSha1MapStore(scan_result: IncludesScanner.ScanResult | t.CPtr) -> in
|
||||
StubMerger._sha1_store_incdir[idx_inc + StubMerger.MAX_INC_DIR_LEN - 1] = '\0'
|
||||
StubMerger._sha1_store_count += 1
|
||||
if p_bad > 0:
|
||||
fb_pbad: str = VLogger.fmt_buf()
|
||||
if fb_pbad is not None:
|
||||
viperlib.snprintf(fb_pbad, 1024, "includes SHA1 存储有 %d 个条目失败", p_bad)
|
||||
VLogger.error(fb_pbad, "StubMerger")
|
||||
viperlib.snprintf(VLogger.fmtbuffer, 1024, "includes SHA1 存储有 %d 个条目失败", p_bad)
|
||||
VLogger.error(VLogger.fmtbuffer, "StubMerger")
|
||||
return StubMerger._sha1_store_count
|
||||
# ============================================================
|
||||
# AppendToSha1MapStore - 追加条目到全局 SHA1 映射存储器
|
||||
|
||||
@@ -91,10 +91,8 @@ def BuildTopoSortedIndices(store_count: int, store_sha1_arr: bytes,
|
||||
rel_idx[rel_count] = i_t
|
||||
rel_count += 1
|
||||
# 诊断:可达 store 索引数(rel_count=0 → topo_count=0 → PhaseB+ 循环不执行)
|
||||
fb_rel: str = VLogger.fmt_buf()
|
||||
if fb_rel is not None:
|
||||
viperlib.snprintf(fb_rel, 1024, "诊断 topo rel_count=%d", rel_count)
|
||||
VLogger.debug(fb_rel, "StubMergerTopo")
|
||||
viperlib.snprintf(VLogger.fmtbuffer, 1024, "诊断 topo rel_count=%d", rel_count)
|
||||
VLogger.debug(VLogger.fmtbuffer, "StubMergerTopo")
|
||||
# 计算入度:m 在可达集合内的直接依赖数
|
||||
i_r: int
|
||||
for i_r in range(rel_count):
|
||||
|
||||
Reference in new issue
Block a user