revert(viperc): 回退闭包变量取址的放行,仅保留“实参级报错定位”
- 回退 a060e1d 中 ExprGenOps 的闭包取址改动与 TypeGenErr 的临时打印移除:&_on_submit 仍按级数不符报 CastError(source level 2 -> target level 1),语义不变、不放行
- 保留 CallGenCall._call_method_on_ptr 的实参级 AST 节点透传:方法/构造实参转换失败时报错定位到具体实参表达式,并显示完整两帧(函数定义帧 + 错误点)
This commit is contained in:
1 parent
a060e1d76e
commit
ee3337f3c4
2 files changed
+9
-8
No files matched your search
@@ -755,14 +755,6 @@ novirtual class ExprGenOps(ExprGenBase.ExprGenBase):
|
|||||||
gv_ao: mlirlite.GlobalVariable* = self.Gen.ExprGenAttr.find_global_in_module(mod, nm_ao.id)
|
gv_ao: mlirlite.GlobalVariable* = self.Gen.ExprGenAttr.find_global_in_module(mod, nm_ao.id)
|
||||||
if gv_ao is not None and gv_ao.Name is not None and gv_ao.Ty is not None: v_ao = self.Gen.ExprGenAttr.make_global_ref(pool, gv_ao.Name, gv_ao.Ty)
|
if gv_ao is not None and gv_ao.Name is not None and gv_ao.Ty is not None: v_ao = self.Gen.ExprGenAttr.make_global_ref(pool, gv_ao.Name, gv_ao.Ty)
|
||||||
if v_ao is not None and v_ao.Ty is not None:
|
if v_ao is not None and v_ao.Ty is not None:
|
||||||
# 闭包变量(嵌套 `def f()` 被提升后在父函数里是一个 **i8\*\*** 槽,见
|
|
||||||
# FuncGenMixin.translate_nested_function_def 第 13e 步):变量自身就是那个
|
|
||||||
# 函数的闭包指针,`&f` 应给出它的**值**(一级 i8*),而不是槽地址 i8**(二级)
|
|
||||||
# ——否则传给 `callback: t.CPtr` 会因级数不符报 CastError(source level 2 ->
|
|
||||||
# target level 1)。与“函数名即地址(同 C)”一致。闭包槽与普通函数指针变量
|
|
||||||
# 同为 i8**、类型上无法区分,故用闭包名表判定(第 13e 步已登记该名字)。
|
|
||||||
if self.Gen.CallGenLeafKit.is_closure_name(nm_ao.id) != 0 and v_ao.Ty.Pointee is not None:
|
|
||||||
return mlirlite.build_load(builder, v_ao.Ty.Pointee, v_ao)
|
|
||||||
# Object-pointer variable (alloca is Ptr(Ptr(Struct))): the variable is the object, return the object pointer (load once), aligned with translate_c_addr.
|
# Object-pointer variable (alloca is Ptr(Ptr(Struct))): the variable is the object, return the object pointer (load once), aligned with translate_c_addr.
|
||||||
match v_ao.Ty:
|
match v_ao.Ty:
|
||||||
case mlirlite.LLVMType.Ptr(ao1):
|
case mlirlite.LLVMType.Ptr(ao1):
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ novirtual class TypeGenErr(TypeGenBase.TypeGenBase):
|
|||||||
# 当前帧(错误点)位置:优先 node,其次调用栈最内层有行号的帧,最后 current_file。
|
# 当前帧(错误点)位置:优先 node,其次调用栈最内层有行号的帧,最后 current_file。
|
||||||
lineno: int = 0
|
lineno: int = 0
|
||||||
if node is not None: lineno = node.lineno
|
if node is not None: lineno = node.lineno
|
||||||
|
raw_line: int = lineno # [TEMP-DIAG] 兜底前的原始节点行号(定位完删除)
|
||||||
file_name: str = self.Gen.TypeGenResolve.get_current_file()
|
file_name: str = self.Gen.TypeGenResolve.get_current_file()
|
||||||
if file_name is None: file_name = "<unknown>"
|
if file_name is None: file_name = "<unknown>"
|
||||||
# 报错位置兜底(“节点位置不可信”时优先用正在翻译的实参位置,精确定位到
|
# 报错位置兜底(“节点位置不可信”时优先用正在翻译的实参位置,精确定位到
|
||||||
@@ -84,6 +85,14 @@ novirtual class TypeGenErr(TypeGenBase.TypeGenBase):
|
|||||||
Diag.finish()
|
Diag.finish()
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
# [TEMP-DIAG] 定位“报错位置”问题用(定位完删除):把决策输入打出来
|
||||||
|
# node=节点原始行号(0=合成) curarg=当前实参行号 trace=栈深 top=栈最内层行号
|
||||||
|
ti_top: int = -1
|
||||||
|
if self.Gen.TypeGenBase.TraceCount > 0:
|
||||||
|
tf_d: GenTypes.TraceFrame* = self.Gen.TypeGenBase._get_trace_frame(self.Gen.TypeGenBase.TraceCount - 1)
|
||||||
|
if tf_d is not None: ti_top = tf_d.lineno
|
||||||
|
stdio.printf("[TEMP-DIAG] node=%d curarg=%d trace=%d top=%d -> shown=%d\n",
|
||||||
|
raw_line, self.Gen.TypeGenBase.CurArgLine, self.Gen.TypeGenBase.TraceCount, ti_top, lineno)
|
||||||
Diag.begin(ent, err_type, msg)
|
Diag.begin(ent, err_type, msg)
|
||||||
# 调用链帧(按"自外向内"顺序)**由本类遍历**(只有它拿得到 TraceFrame),填入 entry。
|
# 调用链帧(按"自外向内"顺序)**由本类遍历**(只有它拿得到 TraceFrame),填入 entry。
|
||||||
for i in range(int(self.Gen.TypeGenBase.TraceCount)):
|
for i in range(int(self.Gen.TypeGenBase.TraceCount)):
|
||||||
|
|||||||
Reference in new issue
Block a user