-
Notifications
You must be signed in to change notification settings - Fork 46
runtime: fix reflect.Value.Method #1528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @visualfc, 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 addresses and resolves issues within the 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request updates the runtime reflection logic to correctly handle a new representation of function types as closures.
The main change in reflect.FuncOf correctly obtains a function type prototype by treating the type of func() as a closure struct and extracting the function type from its first field. This aligns with the updated runtime representation.
Additionally, reflect.Value.Pointer and reflect.Value.UnsafePointer are improved to differentiate between closure and non-closure function values. By adding an IsClosure() check, the code now correctly avoids dereferencing a direct function pointer, which is a good correctness fix.
The changes are consistent and seem correct. I have not found any issues in this pull request.
Code Review SummaryI've completed a comprehensive review of this PR using specialized agents for code quality, performance, security, and documentation. Overall, this is a well-designed fix that properly addresses the distinction between closure types and function types in the LLGo reflection system. Key Findings✅ Security: No vulnerabilities identified. The changes demonstrate proper defensive programming with type and null guards. ✅ Performance: Negligible impact. The additional ✅ Code Quality: Clean and focused changes that follow established patterns. RecommendationsBefore merging:
See inline comments for specific details. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1528 +/- ##
=======================================
Coverage 91.01% 91.01%
=======================================
Files 45 45
Lines 11958 11959 +1
=======================================
+ Hits 10883 10884 +1
Misses 899 899
Partials 176 176 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
d294170 to
b27eb92
Compare
Validation SummaryI've reviewed and validated the PR changes. Here's my assessment: Changes OverviewThis PR introduces several important fixes to the reflect package's method handling:
Code Quality✅ Formatting: All code is properly formatted (verified with Testing Status
RecommendationThe changes appear sound and address real issues with:
The comprehensive demo program in Suggested next steps: Run the full test suite in a properly configured development environment with all dependencies installed to ensure the fixes work correctly across all scenarios. |
69cf0c0 to
ff169a9
Compare
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a series of significant fixes to the reflect package, primarily focusing on the correctness of method handling and calls. The changes correctly handle method value creation for various receiver types, fix FuncOf to align with closure representation, and ensure proper alignment for multiple return values in Value.call. The introduction of resolveIndirectValue and the export of runtime.DirectIfaceData improve the handling of values stored directly in interfaces. The addition of a comprehensive test suite is a valuable contribution that validates these complex changes. The PR is of high quality and substantially improves the robustness of the reflection implementation. I have one suggestion regarding potential data corruption for small array/struct types in the new resolveIndirectValue function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces several important fixes to the reflect package, primarily targeting reflect.Value.Method and reflect.Value.Call. The changes correctly handle method receivers for both value and pointer types, ensure proper alignment and value representation for function return values, and adjust the function prototype creation to match the closure-based function representation in the runtime. Additionally, runtime.DirectIfaceData is now correctly used to handle values stored directly in interfaces. A comprehensive test suite has been added to validate these reflection features. My review found one minor opportunity for code simplification.
ff169a9 to
0f11115
Compare
e1545d7 to
b5b5d33
Compare
b5b5d33 to
b751007
Compare
Code Review CompleteI've reviewed the changes in PR #1528. This PR fixes several critical issues in Summary of ChangesThe PR addresses:
Technical Issues Identified1. Potential Issue in
|
7fc6f4d to
9741b71
Compare
9741b71 to
ec35b1d
Compare
Code Review CompleteI've reviewed the changes in PR #1528. This PR fixes several critical issues in reflect.Value.Method and related reflection functionality. The changes are generally well-structured, but I've identified some specific technical concerns that should be addressed. Critical Issues1. Flag Check Inconsistency in toFFIArg (value.go:2174)Location: The change from case abi.Bool, abi.Int, abi.Int8, abi.Int16, abi.Int32, abi.Int64,
abi.Uint, abi.Uint8, abi.Uint16, abi.Uint32, abi.Uint64, abi.Uintptr,
abi.Float32, abi.Float64:
- if v.flag&flagAddr != 0 {
+ if v.flag&flagIndir != 0 {
return v.ptr
} else {
return unsafe.Pointer(&v.ptr)
}Issue:
Question: Is this change intentional? A value can be addressable without being indirect, and this change could affect how arguments are passed to FFI calls. This needs careful verification that it doesn't break cases where values are addressable but stored directly. 2. Potential Alignment Issue in resolveIndirectValue Default Case (value.go:2427-2431)Location: default:
// convert abi.Bool~abi.Uintptr and abi.Struct/abi.Array themselves.
// struct/array elem conversion by caller func.
if typ.Size_ < unsafe.Sizeof(0) {
v.ptr = truncate(*(*unsafe.Pointer)(v.ptr), typ.Size_*8)
} else {
v.ptr = *(*unsafe.Pointer)(v.ptr)
}Issues: a) Struct layout correctness: For small structs/arrays (< word size), loading
This may be incorrect for:
b) Comment inaccuracy: The comment says "convert abi.Bool~abi.Uintptr and abi.Struct/abi.Array" but the Recommendation:
3. Unconditional Pointer Conversion of Receiver Type (value.go:2778-2781)Location: if rcvrtype.Kind() != abi.Pointer {
// convert rcvrtype to abi.Pointer to match ifn call
rcvrtype = toRType(rcvrtype).ptrTo()
}Issue: This unconditionally converts all non-pointer receiver types to pointers. While this may be correct for the FFI calling convention, it raises questions: a) Value receiver semantics: For methods with explicit value receivers, does converting the type to pointer affect:
b) Missing documentation: The comment "to match ifn call" is vague. It should explain:
Recommendation: Add comprehensive documentation explaining the calling convention requirement and verify this doesn't break type identity checks elsewhere. Medium Priority Issues4. storeRcvr Condition Ordering (value.go:2448-2458)Location: if t.Kind() == abi.Interface {
*(*unsafe.Pointer)(p) = ifacePtrData(iface)
} else if v.flag&flagIndir != 0 && !ifaceIndir(t) {
*(*unsafe.Pointer)(p) = *(*unsafe.Pointer)(v.ptr)
} else if v.flag&flagIndir == 0 && runtime.DirectIfaceData(t) {
*(*unsafe.Pointer)(p) = unsafe.Pointer(&v.ptr)
} else {
*(*unsafe.Pointer)(p) = v.ptr
}Issue: The condition ordering could be clearer. The third condition ( Questions:
Recommendation: Add comments documenting what each branch handles and why the ordering matters, or reorder for clarity. 5. IsClosure Check Addition (value.go:1128, 1735)Location: // Old code
if p != nil {
p = *(*unsafe.Pointer)(p)
}
// New code
if p != nil && v.typ_.IsClosure() {
p = *(*unsafe.Pointer)(p)
}Good: This correctly distinguishes between closure types and direct function pointers. Question: Are there any edge cases where:
Recommendation: Verify that Minor Issues6. FuncOf Closure Type Extraction (type.go:1242-1244)Location: // Closures are always struct{fn *funcType, data unsafe.Pointer}
// This is guaranteed by closureOf() construction
closureType := *(**abi.StructType)(unsafe.Pointer(&ifunc))
prototype := closureType.Fields[0].Typ.FuncType()Good: The added comment explains the closure structure invariant. Minor concern: This assumes if len(closureType.Fields) < 1 {
panic("reflect: invalid closure type structure")
}7. makeMethodValue Simplification (makefunc.go:218-224)Location: _, _, fn := methodReceiver(op, rcvr, int(v.flag)>>flagMethodShift)
var ptr unsafe.Pointer
storeRcvr(v, unsafe.Pointer(&ptr))
fv := &struct {
fn unsafe.Pointer
env unsafe.Pointer
}{fn, ptr}Good: This correctly uses Observation: The ordering matters - SSA Changes8. needAbiInit Detection Movement (ssa/decl.go, ssa/expr.go)Location: Moved from Good: Moving detection to the call site is more accurate, as it detects actual usage rather than just function declaration. Question: The new location adds Recommendation: Document why these specific reflect functions require ABI initialization. Testing Concerns9. Demo Test Coverage (_demo/go/reflectmethod/main.go)Good: The 1145-line demo provides comprehensive test coverage for:
Missing: Consider adding tests for:
SummaryCritical concerns requiring attention:
Positive aspects:
Recommendations before merge:
👉 Want me to re-run this review? Just type |
5789e2c to
5d7226a
Compare
runtime reflect