docs(gen): _translate_new_expr 注明缺省规则(stack 默认 slife)
缺省规则(§3.2 / D3):来源缺省 = heap;生命期缺省由来源决定——stack → slife(故 new stack T(...) 不写 slife 也等效),heap/memgr → hlife。生命期在 life_of_expr 按同一张表落地(LIFE_FRAME / LIFE_HEAP)。
This commit is contained in:
1 parent
9e55e909a8
commit
09b5bf5ac3
1 file changed
+4
@@ -322,6 +322,10 @@ novirtual class CallGenCtor(CallGenBase.CallGenBase):
|
||||
if pool is None or builder is None or new_node is None or trans is None: return None
|
||||
src: int = new_node.Source
|
||||
life: int = new_node.Life
|
||||
# 缺省规则(§3.2 / D3):来源缺省 = heap;生命期缺省由来源决定
|
||||
# stack → slife(帧生命期;故 `new stack T(...)` 不写 slife 也等效)
|
||||
# heap / memgr → hlife(自由生命期)
|
||||
# 生命期在 life_of_expr 里按同一张表落地(LIFE_FRAME / LIFE_HEAP),此处只管存储。
|
||||
# §2.4-3:stack 不可能超帧
|
||||
if src == ast.NEW_SRC_STACK and life == ast.NEW_LIFE_HLIFE:
|
||||
self.Gen.TypeGenErr.fatal_error(new_node, "`new stack hlife` is contradictory: a stack allocation can never outlive its frame; use `new stack slife` (the default for stack), or `heap`/`memgr(x)` for a longer lifetime", "LifetimeError")
|
||||
|
||||
Reference in new issue
Block a user