重置上传,新增了多个标准库,开始 TransPyV 自举实验

This commit is contained in:
2026-07-19 11:38:15 +08:00
parent 796222a300
commit 4e66207ba1
1041 changed files with 6597 additions and 27814 deletions

View File

@@ -1601,6 +1601,15 @@ class FunctionHandle(BaseHandle):
}
if IsExternFunc or IsStateFunc:
return
# 治本修复:如果函数已经有 bodyblocks 不为空),跳过重复编译。
# 否则会导致同一函数被追加第二个 entry blockllvmlite 自动重命名为 entry.1
# 产生非法 IR两个 entry block + 第二个 block 无前驱成为死代码。
# 触发场景:泛型特化路径 _EmitGenericSpecialization 先调用 _EmitFunctionForwardDeclLlvm
# 再调用 _EmitFunctionLlvm若特化在多个调用点被重复触发如 list[str] 在 split/upper 等多处使用),
# 同一 MangledName 会进入此函数两次,第二次会重复追加 entry block。
existing_blocks: list = getattr(func, 'blocks', [])
if existing_blocks:
return func
EntryBlock = func.append_basic_block(name="entry")
Gen.builder = ir.IRBuilder(EntryBlock)
Gen.func = func
@@ -1612,6 +1621,15 @@ class FunctionHandle(BaseHandle):
# 保存当前的 var_type_info以便函数结束时恢复
saved_var_type_info = Gen.var_type_info.copy()
saved_var_type_assignments = Gen.var_type_assignments.copy()
# 治本修复:保存并清空 _local_heap_ptrs / _var_to_heap_ptr。
# 当 with 上下文中的代码(如 s1.split(','))触发内联编译 list[str].__new__ 时,
# 若不清空__new__ 方法会继承外层 with 的 _local_heap_ptrs含 %call_enter 条目),
# 方法结束时 _emit_local_heap_frees 会尝试 bitcast/free %call_enter
# 但该值在 __new__ 作用域中不存在 → llc 报错 'use of undefined value'。
saved_local_heap_ptrs = list(Gen._local_heap_ptrs)
saved_var_to_heap_ptr = dict(Gen._var_to_heap_ptr)
Gen._local_heap_ptrs = []
Gen._var_to_heap_ptr = {}
# 函数内部定义的变量会在赋值时添加到 var_type_info 中
# 这样函数内部定义的元类型变量(如 a = t.CInt32T就能被正确处理
for stmt in Node.body:
@@ -1810,8 +1828,9 @@ class FunctionHandle(BaseHandle):
Gen.var_type_info = saved_var_type_info
Gen.var_type_assignments = saved_var_type_assignments
Gen._stop_iter_flag_param = None
Gen._local_heap_ptrs = []
Gen._var_to_heap_ptr = {}
# 恢复外层作用域的 _local_heap_ptrs / _var_to_heap_ptr
Gen._local_heap_ptrs = saved_local_heap_ptrs
Gen._var_to_heap_ptr = saved_var_to_heap_ptr
Gen._variadic_info = None
self.Trans._CurrentCpythonObjectClass = saved_cpython_class
self.Trans.CurrentCReturnTypes = None