fix(cl): fill cross-package unexported method Ifn/Tfn so itab is complete#1560
fix(cl): fill cross-package unexported method Ifn/Tfn so itab is complete#1560xushiwei merged 2 commits intogoplus:mainfrom
Conversation
Summary of ChangesHello @luoliwoshang, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces two significant compiler fixes: one addressing a nil pointer dereference when calling interface methods on types with promoted, cross-package unexported embedded methods, and another correcting Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request contains two main changes: a fix for itab generation for promoted embedded methods, and a fix for a float-to-uint conversion issue (issue #1538). The itab generation fix is well-implemented, and the associated refactoring of the ABI type system in ssa/abitype.go is a significant improvement. The regression test is also comprehensive. However, bundling the unrelated fix for issue #1538 makes this pull request difficult to review and understand. It's a strong convention to have one pull request address one concern. This helps with reviewability, testing, and maintaining a clean commit history. I highly recommend splitting this PR into two separate ones. My review comments are focused on the current state of the code.
ab67963 to
3944c0a
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1560 +/- ##
==========================================
- Coverage 91.01% 91.01% -0.01%
==========================================
Files 45 45
Lines 11971 11960 -11
==========================================
- Hits 10896 10885 -11
Misses 899 899
Partials 176 176 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
50c5e3d to
3bcc87d
Compare
Code Review SummaryThis PR correctly fixes the itab generation bug for promoted embedded methods. The fix is well-targeted: removing the flawed Strengths:
Minor suggestions:
Overall, this is a correct and focused bug fix. |
359eea3 to
9a2cc20
Compare
5309b43 to
2849944
Compare
2849944 to
d2adf5d
Compare
|
对于 Go 官方编译器,结构体的嵌入类型如果位于不同包,未导出的的 method ifn/tfn 始终为 -1 。这块可以分析一下是否还有其他实现原因。 |
明白了,在Go中的可达性标记+链接阶段的DCE后,最终的类型在二进制的元数据中对于未导出的的 method ifn/tfn 始终为 -1 , Got it. In Go, IFn/Tfns are emitted in full during compilation, then the linker’s reachability + DCE pass rewrites unreachable method entries to -1. In the #1450 optimization, we want our generated IR metadata to resemble Go’s final post-link type metadata. In Go’s runtime, |
|
提交新的PR https://github.com/goplus/llgo/pull/1576,在https://github.com/goplus/llgo/pull/1450优化之后,类型元数据的abi.Method列表与Go保持一致,并且对于未导出并跨包的嵌入方法不填充TFn和IFn(在Go中实现为-1),所以在创建Itab的时候,IFn返回nil,现在并不是代表签名匹配失败,所以修改findMethod为返回 bool(是否签名匹配), abi.Text(函数指针)而函数指针在分析为不可达的情况下是允许为空的,这里保持和Go的行为一致,继续下一个itab的方法指针填充 |
Fixed #1559
Summary
fun[0]=0and causing interface calls to jump to a null pointer. NowIfn/Tfn are always emitted, so the itab is complete.
_demo/go/ifaceprom-1599(self-contained foo package) that embeds a foreignGameand asserts it implements the foreign interface, covering the crash path.cl/_testgo/abimethod/out.llto align with the corrected method metadata (no skipped Ifn/Tfn).Root Cause
abiUncommonMethods), for unexported methods from another package,skipfnset Ifn/Tfn to nil. The method name/type still matched the interface, but the pointer was nil.NewItabmatched the method but received a nil Ifn, setfun[0]=0, and marked the itab as “not implemented”; interface calls then dereferenced a null pointer and crashed.Fix
Tests
_demo/go:llgo run ./ifaceprom-1599