From b71ed43f103f8c79eec129a4a0db4a1ceec3b797 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Fri, 9 Oct 2026 08:46:24 +0800 Subject: [PATCH] =?UTF-8?q?feat(gen):=20P5=20slife=20=E7=99=BB=E8=AE=B0?= =?UTF-8?q?=E8=A1=A8=E5=AE=B9=E9=87=8F=E6=8F=90=E5=88=B0=20256=EF=BC=8C?= =?UTF-8?q?=E8=B6=85=E9=99=90=20fail-fast?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 分配与上限判定共用 _SLIFE_MAX = 256(原 128 且满时静默停止登记)。_SlifeEnsureOwned 超限改为 fatal_error(LifetimeError):静默返回 None 会让该对象永不登记、永不释放(纯泄漏),与编译器自动管理的承诺矛盾。 --- App/lib/core/Gen/VarGenMixin.vp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/App/lib/core/Gen/VarGenMixin.vp b/App/lib/core/Gen/VarGenMixin.vp index 0594d96..0b2596e 100644 --- a/App/lib/core/Gen/VarGenMixin.vp +++ b/App/lib/core/Gen/VarGenMixin.vp @@ -42,7 +42,8 @@ define SCOPE_BLOCK = 2 # · 登记区间是**栈式**的:[_g_slife_count, _g_slife_top) 属于当前函数。进入嵌套函数时 # 起点抬到当前栈顶(_SlifeReset),退出时弹回(_SlifeRestore)——否则内层函数会在 # 0 号槽覆写外层登记项,且内层出口会把外层的对象一起 free 掉。 -# 容量 128 项,满则停止登记(退化为不释放=泄漏,不报错也不悬垂)。 +# 登记表容量(P5:128 → 256)。超限时 **fail-fast**(不再静默退化为"不登记 = 不释放"的泄漏)。 +define _SLIFE_MAX = 256 _g_slife_owned: sizet* = None _g_slife_count: int = 0 _g_slife_top: int = 0 @@ -448,7 +449,7 @@ novirtual class VarGenMixin: global _g_slife_owned, _g_slife_count, _g_slife_top if _g_slife_owned is None: if pool is None: return -1 - _g_slife_owned = sizet*(pool.alloc(128 * 16)) + _g_slife_owned = sizet*(pool.alloc(_SLIFE_MAX * 16)) if _g_slife_owned is None: return -1 old_base: int = _g_slife_count _g_slife_count = _g_slife_top @@ -484,7 +485,12 @@ novirtual class VarGenMixin: if alloca is None or _g_slife_owned is None: return None exist: mlirlite.Value* = self._SlifeShadow(alloca) if exist is not None: return exist - if _g_slife_top >= 128: return None + if _g_slife_top >= _SLIFE_MAX: + # P5:超限 **fail-fast**(容量见文件头的 _SLIFE_MAX,此处文案里的数字与之同步)。 + # 静默返回 None 会让该对象永不登记 → 永不释放(纯泄漏),与"编译器自动管理"的承诺矛盾; + # 下面的 return None 只是流程完整(fatal_error 已终止进程)。 + self.Gen.TypeGenErr.fatal_error(None, "the slife ownership table is full (capacity 256): this function registers too many compiler-owned slife bindings; split the function or reduce the number of live slife objects", "LifetimeError") + return None if pool is None or builder is None: return None sh: mlirlite.Value* = self._alloca_at_entry(builder, mlirlite.Int8(pool)) if sh is None: return None