feat(tpv): vpi 预生成失败输出失败文件路径与原因(含 AST 解析错误行列)
This commit is contained in:
1 parent
6daec5fa58
commit
19171ee165
2 files changed
+26
-8
No files matched your search
@@ -577,6 +577,7 @@ def RunPhase1(mb: memhub.MemBuddy | t.CPtr, includes_dir: str, temp_dir: str,
|
||||
vpi_path_pv: str = StubMergerCollect._sliced_path(temp_dir, dir_len_pv, sha1_pv, "vpi")
|
||||
if vpi_path_pv is None:
|
||||
p1bpre_failed += 1
|
||||
VLogger.error(f"[Phase 1b-pre] {entry_pv.Path} | vpi 路径生成失败", "Phase1")
|
||||
continue
|
||||
vf_pv: fileio.File | t.CPtr = fileio.File(vpi_path_pv, fileio.MODE.R)
|
||||
if not vf_pv.closed:
|
||||
@@ -589,17 +590,20 @@ def RunPhase1(mb: memhub.MemBuddy | t.CPtr, includes_dir: str, temp_dir: str,
|
||||
f_pv: fileio.File | t.CPtr = fileio.File(file_path_pv, fileio.MODE.R)
|
||||
if f_pv.closed:
|
||||
p1bpre_failed += 1
|
||||
VLogger.error(f"[Phase 1b-pre] {file_path_pv} | 无法打开源文件", "Phase1")
|
||||
continue
|
||||
src_buf_pv: bytes = stdlib.malloc(Phase1.SRC_BUF_SIZE)
|
||||
if src_buf_pv is None:
|
||||
f_pv.close()
|
||||
p1bpre_failed += 1
|
||||
VLogger.error(f"[Phase 1b-pre] {file_path_pv} | 源文件缓冲分配失败(OOM)", "Phase1")
|
||||
continue
|
||||
bytes_read_pv: LONG = f_pv.read_all(src_buf_pv, Phase1.SRC_BUF_SIZE)
|
||||
f_pv.close()
|
||||
if bytes_read_pv <= 0:
|
||||
stdlib.free(src_buf_pv)
|
||||
p1bpre_failed += 1
|
||||
VLogger.error(f"[Phase 1b-pre] {file_path_pv} | 文件读取失败或为空", "Phase1")
|
||||
continue
|
||||
if bytes_read_pv < Phase1.SRC_BUF_SIZE:
|
||||
src_buf_pv[bytes_read_pv] = 0
|
||||
@@ -609,6 +613,7 @@ def RunPhase1(mb: memhub.MemBuddy | t.CPtr, includes_dir: str, temp_dir: str,
|
||||
if lx_pv is None:
|
||||
stdlib.free(src_buf_pv)
|
||||
p1bpre_failed += 1
|
||||
VLogger.error(f"[Phase 1b-pre] {file_path_pv} | 词法器分配失败(OOM)", "Phase1")
|
||||
continue
|
||||
ast._lexer_init(lx_pv, src_buf_pv, mb)
|
||||
tokens_pv: ast.Token | t.CPtr = ast.tokenize(lx_pv)
|
||||
@@ -616,6 +621,10 @@ def RunPhase1(mb: memhub.MemBuddy | t.CPtr, includes_dir: str, temp_dir: str,
|
||||
if tree_pv is None:
|
||||
stdlib.free(src_buf_pv)
|
||||
p1bpre_failed += 1
|
||||
VLogger.error(
|
||||
f"[Phase 1b-pre] {file_path_pv} | AST 解析失败"
|
||||
f"(第 {ast.get_parse_err_line()} 行第 {ast.get_parse_err_col()} 列: "
|
||||
f"{ast.get_parse_err_msg()})", "Phase1")
|
||||
continue
|
||||
pyi_buf_pv: bytes = stdlib.malloc(Phase1.PYI_BUF_SIZE)
|
||||
if pyi_buf_pv is not None:
|
||||
@@ -631,6 +640,7 @@ def RunPhase1(mb: memhub.MemBuddy | t.CPtr, includes_dir: str, temp_dir: str,
|
||||
stdlib.free(pyi_buf_pv)
|
||||
else:
|
||||
p1bpre_failed += 1
|
||||
VLogger.error(f"[Phase 1b-pre] {file_path_pv} | pyi 缓冲分配失败(OOM)", "Phase1")
|
||||
stdlib.free(src_buf_pv)
|
||||
# 回收本文件 AST(vpi 已写盘,AST 不再需要;mark1 后无其他持久数据)
|
||||
mb.reset_to(mark1)
|
||||
@@ -640,7 +650,7 @@ def RunPhase1(mb: memhub.MemBuddy | t.CPtr, includes_dir: str, temp_dir: str,
|
||||
VLogger.info(f"1b-pre 总耗时: {t_pv1-t_pv0} ms (vpi 预生成)", "Phase1")
|
||||
|
||||
if p1bpre_failed > 0:
|
||||
VLogger.error(f"Phase 1b-pre 有 {p1bpre_failed} 个文件 vpi 预生成失败", "Phase1")
|
||||
VLogger.error(f"Phase 1b-pre 有 {p1bpre_failed} 个文件 vpi 预生成失败(失败文件与原因见上方逐条 [Phase 1b-pre] 日志)", "Phase1")
|
||||
return 1
|
||||
|
||||
# 遍历每个文件(拓扑序优先:父类所在文件先翻译,确保跨模块 vtable
|
||||
|
||||
@@ -153,8 +153,7 @@ def _ScanDirForPyFiles(mb: memhub.MemBuddy | t.CPtr,
|
||||
ent.Sha1 = sha1_val
|
||||
file_count += 1
|
||||
|
||||
viperlib.snprintf(VLogger.fmtbuffer, 1024, "%s (sha1=%s)", fname, sha1_val)
|
||||
VLogger.info(VLogger.fmtbuffer, "project")
|
||||
VLogger.info(f"{fname} (sha1={sha1_val})", "project")
|
||||
stdlib.free(sbuf)
|
||||
# full_path 不释放:ent.Path 引用它
|
||||
|
||||
@@ -255,8 +254,7 @@ def _ScanDirForAsmFiles(mb: memhub.MemBuddy | t.CPtr,
|
||||
ent.Sha1 = sha1_val
|
||||
file_count += 1
|
||||
|
||||
viperlib.snprintf(VLogger.fmtbuffer, 1024, "%s (asm sha1=%s)", fname, sha1_val)
|
||||
VLogger.info(VLogger.fmtbuffer, "project")
|
||||
VLogger.info(f"{fname} (asm sha1={sha1_val})", "project")
|
||||
# full_path 不释放:ent.Path 引用它
|
||||
|
||||
if w32.win32file.FindNextFileA(handle, find_data) == 0:
|
||||
@@ -340,8 +338,7 @@ def _PreRegisterAppGenericTemplates(mb: memhub.MemBuddy | t.CPtr,
|
||||
handled += 1
|
||||
stdlib.free(src_buf_pa)
|
||||
if handled > 0:
|
||||
viperlib.snprintf(VLogger.fmtbuffer, 1024, "mark2 前预注册 %d 个 App 泛型类模板", handled)
|
||||
VLogger.info(VLogger.fmtbuffer, "PhaseA")
|
||||
VLogger.info(f"mark2 前预注册 {handled} 个 App 泛型类模板", "PhaseA")
|
||||
return handled
|
||||
|
||||
|
||||
@@ -491,11 +488,13 @@ def RunMultiFileProject(mb: memhub.MemBuddy | t.CPtr,
|
||||
ent_vp2: SrcFileEntry | t.CPtr = (SrcFileEntry | t.CPtr)(t.CVoid(ea_vp2, t.CPtr))
|
||||
if ent_vp2 is None or ent_vp2.Path is None or ent_vp2.Sha1 is None:
|
||||
vpi_failed_p2 += 1
|
||||
VLogger.error("[Phase A-pre-vpi] 源文件条目无效(Path/Sha1 缺失),跳过", "PhaseA")
|
||||
continue
|
||||
# vpi 已存在则跳过(sha1 基于内容,同名 vpi 必然有效;跨次编译缓存)
|
||||
vpi_path_vp2: str = StubMergerCollect._sliced_path(temp_dir, td_len_vpa, ent_vp2.Sha1, "vpi")
|
||||
if vpi_path_vp2 is None:
|
||||
vpi_failed_p2 += 1
|
||||
VLogger.error(f"[Phase A-pre-vpi] {ent_vp2.Path} | vpi 路径生成失败", "PhaseA")
|
||||
continue
|
||||
vf_vp2: fileio.File | t.CPtr = fileio.File(vpi_path_vp2, fileio.MODE.R)
|
||||
if not vf_vp2.closed:
|
||||
@@ -508,17 +507,20 @@ def RunMultiFileProject(mb: memhub.MemBuddy | t.CPtr,
|
||||
f_vp2: fileio.File | t.CPtr = fileio.File(ent_vp2.Path, fileio.MODE.R)
|
||||
if f_vp2.closed:
|
||||
vpi_failed_p2 += 1
|
||||
VLogger.error(f"[Phase A-pre-vpi] {ent_vp2.Path} | 无法打开源文件", "PhaseA")
|
||||
continue
|
||||
src_buf_vp2: bytes = stdlib.malloc(SRC_BUF_SIZE)
|
||||
if src_buf_vp2 is None:
|
||||
f_vp2.close()
|
||||
vpi_failed_p2 += 1
|
||||
VLogger.error(f"[Phase A-pre-vpi] {ent_vp2.Path} | 源文件缓冲分配失败(OOM)", "PhaseA")
|
||||
continue
|
||||
bytes_read_vp2: LONG = f_vp2.read_all(src_buf_vp2, SRC_BUF_SIZE)
|
||||
f_vp2.close()
|
||||
if bytes_read_vp2 <= 0:
|
||||
stdlib.free(src_buf_vp2)
|
||||
vpi_failed_p2 += 1
|
||||
VLogger.error(f"[Phase A-pre-vpi] {ent_vp2.Path} | 文件读取失败或为空", "PhaseA")
|
||||
continue
|
||||
if bytes_read_vp2 < SRC_BUF_SIZE:
|
||||
src_buf_vp2[bytes_read_vp2] = 0
|
||||
@@ -528,6 +530,7 @@ def RunMultiFileProject(mb: memhub.MemBuddy | t.CPtr,
|
||||
if lx_vp2 is None:
|
||||
stdlib.free(src_buf_vp2)
|
||||
vpi_failed_p2 += 1
|
||||
VLogger.error(f"[Phase A-pre-vpi] {ent_vp2.Path} | 词法器分配失败(OOM)", "PhaseA")
|
||||
continue
|
||||
ast._lexer_init(lx_vp2, src_buf_vp2, mb)
|
||||
tokens_vp2: ast.Token | t.CPtr = ast.tokenize(lx_vp2)
|
||||
@@ -535,6 +538,10 @@ def RunMultiFileProject(mb: memhub.MemBuddy | t.CPtr,
|
||||
if tree_vp2 is None:
|
||||
stdlib.free(src_buf_vp2)
|
||||
vpi_failed_p2 += 1
|
||||
VLogger.error(
|
||||
f"[Phase A-pre-vpi] {ent_vp2.Path} | AST 解析失败"
|
||||
f"(第 {ast.get_parse_err_line()} 行第 {ast.get_parse_err_col()} 列: "
|
||||
f"{ast.get_parse_err_msg()})", "PhaseA")
|
||||
continue
|
||||
pyi_buf_vp2: bytes = stdlib.malloc(PYI_BUF_SIZE_P2)
|
||||
if pyi_buf_vp2 is not None:
|
||||
@@ -551,11 +558,12 @@ def RunMultiFileProject(mb: memhub.MemBuddy | t.CPtr,
|
||||
stdlib.free(pyi_buf_vp2)
|
||||
else:
|
||||
vpi_failed_p2 += 1
|
||||
VLogger.error(f"[Phase A-pre-vpi] {ent_vp2.Path} | pyi 缓冲分配失败(OOM)", "PhaseA")
|
||||
stdlib.free(src_buf_vp2)
|
||||
# OOM 清理:回收本文件 AST(vpi 已写盘;mark2 后持久数据已 stdlib 化)
|
||||
mb.reset_to(mark2)
|
||||
if vpi_failed_p2 > 0:
|
||||
VLogger.error(f"Phase A-pre-vpi 有 {vpi_failed_p2} 个文件 vpi 预生成失败", "PhaseA")
|
||||
VLogger.error(f"Phase A-pre-vpi 有 {vpi_failed_p2} 个文件 vpi 预生成失败(失败文件与原因见上方逐条 [Phase A-pre-vpi] 日志)", "PhaseA")
|
||||
return 1
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user