fix(coro): M3 三处修复——nonlocal 闭包、wake 空块终止、coro_run 唤醒槽按索引定位
- _PreScanExtraSlots 内嵌 _walk 闭包变量需 nonlocal(UnboundLocalError) - coro_run wake_due_bb 补 br loop(空块导致 opt ASan 插桩解析失败) - coro_run 内联在 main 翻译时 _coro_wake_ptr 已被恢复为 None,改为按 _coro_slot_vars 索引定位 __coro_wake_us 槽 - 验证:CoroTest ASan 模式编译+运行通过,coro result = 15
This commit is contained in:
1 parent
3acf24c7d0
commit
c979f0f94d
1 file changed
+12
-2
@@ -261,6 +261,7 @@ class AsyncFunctionHandle(BaseHandle):
|
||||
uses_sleep: list[bool] = [False]
|
||||
|
||||
def _walk(stmts: list[ast.stmt]) -> None:
|
||||
nonlocal await_counter, for_counter
|
||||
for stmt in stmts:
|
||||
if isinstance(stmt, (ast.If, ast.While)):
|
||||
_walk(stmt.body)
|
||||
@@ -951,8 +952,16 @@ class AsyncFunctionHandle(BaseHandle):
|
||||
Gen.builder.cbranch(done_cond, after_bb, check_bb)
|
||||
# SUSPEND:若 coro_sleep 唤醒槽存在且未到点,Sleep(1) 后继续轮询
|
||||
Gen.builder.position_at_start(check_bb)
|
||||
wake_ptr: ir.Value | None = getattr(Gen, '_coro_wake_ptr', None)
|
||||
if wake_ptr is not None:
|
||||
wake_idx: int | None = None
|
||||
slot_vars: list[str] = getattr(Gen, '_coro_slot_vars', {}).get(async_name, [])
|
||||
if '__coro_wake_us' in slot_vars:
|
||||
wake_idx = 3 + slot_vars.index('__coro_wake_us')
|
||||
if wake_idx is not None:
|
||||
wake_ptr: ir.Value = Gen.builder.gep(
|
||||
frame_ptr,
|
||||
[ir.Constant(ir.IntType(32), 0), ir.Constant(ir.IntType(32), wake_idx)],
|
||||
name='coro_wake_ptr',
|
||||
)
|
||||
wake_val: ir.Value = Gen._load(wake_ptr, name='coro_wake')
|
||||
now_fn: ir.Function = self._GetWinFunc('GetTickCount64', Gen, ir.IntType(64))
|
||||
now_val: ir.Value = Gen.builder.call(now_fn, [], name='tick_now')
|
||||
@@ -965,6 +974,7 @@ class AsyncFunctionHandle(BaseHandle):
|
||||
Gen.builder.call(sleep_fn, [ir.Constant(ir.IntType(32), 1)])
|
||||
Gen.builder.branch(loop_bb)
|
||||
Gen.builder.position_at_start(wake_due_bb)
|
||||
Gen.builder.branch(loop_bb)
|
||||
else:
|
||||
Gen.builder.branch(loop_bb)
|
||||
Gen.builder.position_at_start(after_bb)
|
||||
|
||||
Reference in new issue
Block a user