From 77e879ef18432236cf8f2774e2b7dee9ec21b74b Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Mon, 2 Nov 2026 13:48:28 +0800 Subject: [PATCH] fix(gen): correct two latent lookup bugs exposed by the new call order - ExprGenOps called `_lookup_module_sha1` on ExprGenAttr, but the method lives on CallGenBase. With ExprGenOps now translated before the callee's stub/text.ll is available, the receiver lookup failed with "method return type cannot be obtained precisely": `cls=ExprGenAttr ... _lookup_module_sha1`. Use `self.Gen.CallGenBase._lookup_module_sha1`. - VpiReader._lookup_vpi_ret_annot's generic-specialization fallback used `sha1_len` without declaring it. The new `list[int].set` return-type lookup reaches that fallback and failed with `NameError: undefined name 'sha1_len'`. Compute `sha1_len = strlen(src_sha1)` before the cache scan. Self-host 110/110 (two generations); ListTest, GenericTest3, PtrOpProbe and HashLibTest pass. --- App/lib/Stub/StubGen/VpiReader.vp | 1 + App/lib/core/Gen/Expr/ExprGenOps.vp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/App/lib/Stub/StubGen/VpiReader.vp b/App/lib/Stub/StubGen/VpiReader.vp index 92e7d75..546101c 100644 --- a/App/lib/Stub/StubGen/VpiReader.vp +++ b/App/lib/Stub/StubGen/VpiReader.vp @@ -1741,6 +1741,7 @@ def _lookup_vpi_ret_annot(src_sha1: str, cls_name: str, method_name: str) -> str """Look up a method's cached return-annotation string; None if not found.""" if _g_vpi_ret_keys is None or _g_vpi_ret_count == 0: return None if src_sha1 is None or method_name is None: return None + sha1_len: sizet = string.strlen(src_sha1) key_buf: bytes = _vpi_method_key(src_sha1, cls_name, method_name) if key_buf is None: return None i: int diff --git a/App/lib/core/Gen/Expr/ExprGenOps.vp b/App/lib/core/Gen/Expr/ExprGenOps.vp index 011e2ad..0ea2d69 100644 --- a/App/lib/core/Gen/Expr/ExprGenOps.vp +++ b/App/lib/core/Gen/Expr/ExprGenOps.vp @@ -400,7 +400,7 @@ novirtual class ExprGenOps(ExprGenBase.ExprGenBase): mod_path = om_buf_mg # package submodules (`intr.idt`) count as known when the package is imported if self.Gen.ImportsGen.is_module_imported_or_known(trans._imported_modules, mod_path) == 0: return None - gv: mlirlite.GlobalVariable* = self.Gen.ExprGenAttr.find_global_in_module(trans.Module, self.Gen.FuncGenBase._mangle_name_with_sha1(self.Gen.ExprGenAttr._lookup_module_sha1(mod_path), at.attr)) + gv: mlirlite.GlobalVariable* = self.Gen.ExprGenAttr.find_global_in_module(trans.Module, self.Gen.FuncGenBase._mangle_name_with_sha1(self.Gen.CallGenBase._lookup_module_sha1(mod_path), at.attr)) if gv is None: gv = self.Gen.ExprGenAttr.find_global_in_module(trans.Module, at.attr) if gv is None or gv.Ty is None: return None # a global is usually `Element*` / `Element**` or an array `[N]Element`: descend to the leaf type