Repository navigation
compiler: fix nested &self method lookup and global array indexing - #209
Merged
Merged
Conversation
- Method lookup dereferences TYP_REF receivers. `&self` parameters have type TYP_REF(struct), so `self.inner()` inside a method body missed the method table and emitted a call through an empty function pointer. - e2_load_var global loads used r11 as the RIP scratch, clobbering an already-untagged index held in r11. Global array `a[i]` then indexed with the array pointer and read zero. Use the destination register as the lea scratch (`lea reg; mov reg,[reg]`), which keeps r11 intact. - Tests: nested &self method case in test_impl; global array dynamic read/write case (B8) in test_global_seams. Canary 5/5 unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
修复
1. 嵌套
&self方法调用段错误&self/&mut self的参数类型是TYP_REF(struct),但方法的接收者查找只解TYP_GENERIC_APPLY,没有解TYP_REF:修法:方法表查找前先对接收者类型解一层
TYP_REF,再按原有流程解泛型应用/命名 struct。2. 全局数组动态下标读取 0 / 写错槽
e2_load_var的全局路径用 r11 作为leascratch:BigInt 模式下
IR_LOAD_INDEX_VAR/IR_STORE_INDEX_VAR先把 index 解 tag 到 r11,随后加载全局数组指针时lea r11覆盖 index ⇒mov dest, [r10 + r11*8]用数组指针当索引。修法:全局加载改用目标寄存器自身做 RIP scratch(
lea reg; mov reg,[reg]),编码长度不变,不再触碰 r11。该路径同时修复 BYTE_ADD/RAW_ADD 等“先转 index 到 r11、再加载全局操作数”的同族冲突。判据
test_impl.py新增nested_self_method(8/8)test_global_seams.py新增 B8:全局[int;4], mut的动态下标读/写(13/13,ELF + 解释器双绿)selfhost-tests/bootstrap-tests/check绿canary5/5 不变