Skip to content

ssa: type assert closure use MatchesClosure func#1535

Merged
xushiwei merged 1 commit intogoplus:mainfrom
visualfc:eqclosure
Jan 11, 2026
Merged

ssa: type assert closure use MatchesClosure func#1535
xushiwei merged 1 commit intogoplus:mainfrom
visualfc:eqclosure

Conversation

@visualfc
Copy link
Member

@visualfc visualfc commented Jan 7, 2026

support reflect.Value.Method.Interface.(func()) for no need abi type list.

@gemini-code-assist
Copy link

Summary of Changes

Hello @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 enhances the type assertion mechanism within the Static Single Assignment (SSA) form generation, specifically targeting closure types. The primary goal is to correctly support reflect.Value.Method.Interface().(func()) operations by introducing a dedicated runtime function, MatchesClosure, for accurate comparison of closure types. This change moves away from potentially unreliable direct pointer comparisons, ensuring more precise and robust type assertions for closures in the generated code.

Highlights

  • New Closure Comparison Function: A new runtime function, MatchesClosure, has been introduced in runtime/internal/runtime/z_face.go. This function provides a robust way to compare two abi.Type instances to determine if they represent identical closure types, specifically by comparing the type of their first field.
  • Updated SSA Type Assertion Logic: The TypeAssert method within the SSA builder (ssa/interface.go) has been modified. It now explicitly checks if the asserted type is a closure (vkClosure) and, if so, uses the newly introduced MatchesClosure function for the type equality check, rather than a generic binary equality operation.
  • LLVM IR Generation Refinement: The generated LLVM IR in several test output files (cl/_testgo/reflect/out.ll, cl/_testgo/reflectmkfn/out.ll, cl/_testrt/closureiface/out.ll, cl/_testrt/funcdecl/out.ll, cl/_testrt/methodthunk/out.ll) has been updated. Direct pointer equality comparisons (icmp eq ptr) for closure types have been replaced with calls to the new MatchesClosure runtime function, along with its declaration.

🧠 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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a 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 MatchesClosure runtime function to correctly handle type assertions on closures. This is a good improvement, as it addresses cases where reflect.Value.Method creates new closure types that are not identical but should be compatible if their function signatures match. The change correctly replaces a direct pointer comparison with a call to this new function, which checks for function signature compatibility. The implementation of MatchesClosure and its usage in ssa.Builder.TypeAssert are sound. I have one minor suggestion to improve a comment for better clarity and maintainability.

@xgopilot
Copy link
Contributor

xgopilot bot commented Jan 7, 2026

Code Review Summary

This PR correctly implements closure type assertion support. However, there's a critical nil pointer dereference vulnerability in MatchesClosure that should be fixed before merging.

Key Issues:

  1. Critical: Missing nil/bounds checks in MatchesClosure (see inline comment)
  2. ⚠️ Important: Incomplete function documentation
  3. ℹ️ Minor: Missing code comments explaining closure handling logic

The implementation is otherwise sound with good test coverage. Please address the critical safety issue first.

@codecov
Copy link

codecov bot commented Jan 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.04%. Comparing base (a3db8d0) to head (65f2dd9).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1535   +/-   ##
=======================================
  Coverage   91.04%   91.04%           
=======================================
  Files          45       45           
  Lines       11999    12002    +3     
=======================================
+ Hits        10924    10927    +3     
  Misses        899      899           
  Partials      176      176           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@xushiwei xushiwei merged commit 01ee853 into goplus:main Jan 11, 2026
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants