Conversation
Summary of ChangesHello @cpunion, 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 significantly refines how 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. Changelog
Activity
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 correctly identifies a bug in defer handling within loops and proposes a robust solution using SCC for loop detection and a dispatch mechanism for executing the correct defers. The changes are well-tested. However, I've found a significant issue in the implementation where the defer-draining logic is generated multiple times, which needs to be addressed. I've also included a suggestion for a potential performance improvement in the dispatch logic.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1642 +/- ##
==========================================
+ Coverage 91.13% 91.18% +0.04%
==========================================
Files 45 45
Lines 12117 12201 +84
==========================================
+ Hits 11043 11125 +82
- Misses 897 898 +1
- Partials 177 178 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Code Review SummaryThis PR correctly fixes the defer classification for loop semantics by introducing Tarjan's SCC algorithm to identify all blocks participating in cycles, replacing the previous Strengths:
Minor suggestions: A few documentation updates would improve maintainability — see inline comments for the stale pseudo-code comment and the |
|
Addressed review notes:
Re dispatch perf: ssa.Builder doesn't currently expose a switch helper (it's commented out), so keeping the linear chain for now. |
|
Follow-up fix: loop-defer drainer must survive rethrow.
Fix: in the DeferInLoop drainer, store This makes |
Fix llgo's defer lowering for defers executed inside loops.
time: Stop called on uninitialized Timer.Tests:
test/defer_test.go.ssa/eh_loop_test.go.cl/_testdefer/gobuild/out.txtto match new classification.Rationale / Notes
blocks-only is not sufficient: ongoplus/main, the loop-defer lowering inssa/eh.gofails to record some loop defers (notably non-closure + no-args forms), so the drain loop has nothing to pop/run. In an isolated cherry-pick of only the SCC classification + tests,go test ./ssa -run TestDeferInLoopIRfails and the IR contains noFreeDeferNodefor loop defers.runtime/internal/runtime.Defer(its layout stays the same). The only "structure" change is the compiler-emitted internal linked-list node layout stored inDefer.Args(adding a small header fieldid uintptr). Runtime never decodes these nodes; it only frees them viaFreeDeferNode.idtag (or an equivalent discriminator) is required to preserve correct semantics when multiple defer statements inside the same loop share a single LIFO chain and their nodes are interleaved. Without a tag, the drainer cannot safely determine which static defer statement should decode/call a given node, and it risks decoding the wrong layout or draining unrelated defers.Possible follow-up
DeferInLoopstatements duringendDefer(instead of accumulating state onaDefer), but the semantic requirements above (recording nodes, per-node dispatch, and rethrow-to-drain) remain.