refactor(sidecar): 删除 BuildCombinedIR 文本合并死代码(④-d)
在线模型方案(④-a~④-c)已由 LoadFullIR 取代文本合并,BuildCombinedIR 及其专属辅助(_Seen* 去重表、_RegisterStubLines、_LoadAndAppendStub、_LoadAndAppendTextDeclares、_IsTypeDefLine/_IsIrHeaderLine/HoistTypeDefsBeforeDeclares、_collect_stub_sha1s、_stub_scan_cache_*)已无调用方,一并删除(约 1348 行);同步改写 #35/TranslatorGenMixin 中引用旧函数的注释。
This commit is contained in:
1 parent
df9a5a9beb
commit
9bd3ac3dfb
4 files changed
+6
-1347
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -57,7 +57,7 @@ def _sliced_path(temp_dir: str, td_len: sizet, sha1: str, ext: str) -> str:
|
||||
|
||||
# 确保子目录存在: {temp_dir}/{subdir}
|
||||
# 不创建目录会导致 fileio.File(MODE.W) 静默失败(file.closed==True),
|
||||
# 进而 BuildCombinedIR 读不到文件返回 0("BuildCombinedIR 失败")。
|
||||
# 进而读取端读不到文件返回 0("加载 IR 失败")。
|
||||
dir_path_len: sizet = td_len + sub_len + 2
|
||||
dir_path: bytes = stdlib.malloc(dir_path_len)
|
||||
if dir_path is not None:
|
||||
@@ -80,86 +80,7 @@ def _sliced_path(temp_dir: str, td_len: sizet, sha1: str, ext: str) -> str:
|
||||
viperlib.snprintf(path, path_len, "%s/%s.%s", temp_dir, sha1, ext)
|
||||
|
||||
return path
|
||||
# ============================================================
|
||||
# _collect_stub_sha1s - 递归扫描子目录,收集 .stub.ll 文件的 SHA1(从文件名提取)
|
||||
#
|
||||
# level=0 → 扫描 {base_dir}/*.stub.ll;level>0 → 扫描 {base_dir}/* 的子目录并对每个子目录递归调用。
|
||||
#
|
||||
# Args: base_dir 当前扫描目录;bd_len base_dir 长度;level 剩余递归层数;out_arr 输出数组(每个 SHA1 17 字节 = 16字符 + null);out_count 当前已收集数量;max_count 最大数量
|
||||
# Returns: 收集后的总数量
|
||||
# ============================================================
|
||||
def _collect_stub_sha1s(base_dir: str, bd_len: sizet, level: int,
|
||||
out_arr: str, out_count: int, max_count: int) -> int:
|
||||
"""递归扫描子目录,收集 .stub.ll 文件的 SHA1"""
|
||||
if base_dir is None or out_arr is None:
|
||||
return out_count
|
||||
if out_count >= max_count:
|
||||
return out_count
|
||||
|
||||
find_data: rawptr[win32file.WIN32_FIND_DATAA] = stdlib.malloc(win32file.WIN32_FIND_DATAA.__sizeof__())
|
||||
if find_data is None:
|
||||
return out_count
|
||||
string.memset(find_data, 0, win32file.WIN32_FIND_DATAA.__sizeof__())
|
||||
|
||||
if level <= 0:
|
||||
# 扫描 {base_dir}/*.stub.ll
|
||||
pattern: bytes = stdlib.malloc(bd_len + 16)
|
||||
if pattern is None:
|
||||
stdlib.free(find_data)
|
||||
return out_count
|
||||
viperlib.snprintf(pattern, bd_len + 16, "%s/*.stub.ll", base_dir)
|
||||
handle: win32base.HANDLE = win32file.FindFirstFileA(pattern, find_data)
|
||||
stdlib.free(pattern)
|
||||
if handle != win32base.INVALID_HANDLE_VALUE:
|
||||
while True:
|
||||
if out_count >= max_count:
|
||||
break
|
||||
fname: str = find_data.cFileName
|
||||
if fname is not None:
|
||||
if fname[0] != '\0':
|
||||
# 从文件名提取 SHA1(前 16 字符)
|
||||
string.strncpy(out_arr + out_count * 17, fname, 16)
|
||||
out_arr[out_count * 17 + 16] = '\0'
|
||||
out_count += 1
|
||||
if win32file.FindNextFileA(handle, find_data) == 0:
|
||||
break
|
||||
win32file.FindClose(handle)
|
||||
else:
|
||||
# 扫描 {base_dir}/* 的子目录
|
||||
pattern = stdlib.malloc(bd_len + 4)
|
||||
if pattern is None:
|
||||
stdlib.free(find_data)
|
||||
return out_count
|
||||
viperlib.snprintf(pattern, bd_len + 4, "%s/*", base_dir)
|
||||
handle = win32file.FindFirstFileA(pattern, find_data)
|
||||
stdlib.free(pattern)
|
||||
if handle != win32base.INVALID_HANDLE_VALUE:
|
||||
while True:
|
||||
# 检查是否是目录(FILE_ATTRIBUTE_DIRECTORY = 0x10 = 16)
|
||||
attrs: uint32 = find_data.dwFileAttributes
|
||||
if (attrs & 16) != 0:
|
||||
fname = find_data.cFileName
|
||||
if fname is not None:
|
||||
# 跳过 "." 和 ".."
|
||||
is_dot: int = 0
|
||||
if fname[0] == '.':
|
||||
if fname[1] == '\0':
|
||||
is_dot = 1
|
||||
elif fname[1] == '.' and fname[2] == '\0':
|
||||
is_dot = 1
|
||||
if is_dot == 0:
|
||||
# 构建子目录路径并递归扫描
|
||||
sub_dir: str = Utils.JoinPath(base_dir, fname)
|
||||
if sub_dir is not None:
|
||||
sub_dir_len: sizet = string.strlen(sub_dir)
|
||||
out_count = _collect_stub_sha1s(sub_dir, sub_dir_len, level - 1, out_arr, out_count, max_count)
|
||||
stdlib.free(sub_dir)
|
||||
if win32file.FindNextFileA(handle, find_data) == 0:
|
||||
break
|
||||
win32file.FindClose(handle)
|
||||
|
||||
stdlib.free(find_data)
|
||||
return out_count
|
||||
# ============================================================
|
||||
# _load_includes_sha1_set - 从全局内存存储器收集 includes 的 SHA1
|
||||
#
|
||||
|
||||
@@ -31,9 +31,9 @@ _mbuddy: memhub.MemBuddy*
|
||||
|
||||
# 最大 includes SHA1 数(用于过滤)
|
||||
MAX_INCLUDES_SHA1: t.CDefine = 1024
|
||||
# stub 读取缓冲区大小
|
||||
# 1MB 不够:ast/parser.vp 的 text.ll >1MB,BuildCombinedIR 读取本地 text.ll
|
||||
# 单次截断 → 合并 IR 尾部丢字(opt: "end of file in global variable name")。
|
||||
# stub/text 读取缓冲区大小
|
||||
# 1MB 不够:ast/parser.vp 的 text.ll >1MB,读取本地 text.ll 单次截断
|
||||
# → 尾部丢字(opt: "end of file in global variable name")。
|
||||
STUB_READ_BUF_SIZE: t.CDefine = 8388608
|
||||
# 最大 includes 条目数
|
||||
MAX_INCLUDES: t.CDefine = 1024
|
||||
@@ -56,12 +56,6 @@ _includes_deps_sha1: bytes # SHA1 数组(每个 17 字节,MAX_INCLUDES 个
|
||||
_includes_deps_str: bytes # 依赖字符串数组(每个 512 字节,MAX_INCLUDES 个)
|
||||
_includes_deps_count: int # 条目数
|
||||
|
||||
# BuildCombinedIR 全目录扫描缓存:Phase B 每个源文件调用一次 BuildCombinedIR,而 _collect_stub_sha1s 会递归枚举
|
||||
# temp_dir 全部切片子目录(O(N×S) 目录枚举很慢);按 temp_dir 缓存扫描结果,首次扫描后复用,temp_dir 变化时自动重建。
|
||||
_stub_scan_cache_dir: str # 缓存对应的 temp_dir(None=未初始化)
|
||||
_stub_scan_cache_arr: str # 扫描结果数组(每 17 字节一个 SHA1,MAX_INCLUDES_SHA1 个)
|
||||
_stub_scan_cache_count: int # 收集数量
|
||||
|
||||
# 单条依赖字符串最大长度
|
||||
MAX_DEPS_STR_LEN: t.CDefine = 512
|
||||
|
||||
|
||||
@@ -1050,7 +1050,7 @@ novirtual class TranslatorGenMixin:
|
||||
vt_mangled: str = self.Gen.FuncGenBase._mangle_name_with_sha1(vt_sha1, vt_name_buf)
|
||||
if vt_mangled is not None:
|
||||
# 跨模块 vtable 只被本初始化器文本引用 ⇒ 模块内无对应 GlobalVariable ⇒
|
||||
# 单模块 FULL IR 缺该符号声明(旧架构靠 BuildCombinedIR 合并依赖 stub
|
||||
# 单模块 FULL IR 缺该符号声明(旧架构靠文本合并依赖 stub
|
||||
# 补入 external 声明)。此处补声明,使单模块 IR 自足(对齐
|
||||
# CallGenLeafKit._make_vtable_ref_i8 的跨模块分支)。
|
||||
# 仅跨模块补:本模块类由 _generate_vtable 产出定义,补声明会重复定义。
|
||||
|
||||
Reference in new issue
Block a user