Skip to content

internal/build: fix instance patch, remove fakeRuntime - #1423

Merged
xushiwei merged 3 commits into
xgo-dev:mainfrom
visualfc:instance
Nov 28, 2025
Merged

internal/build: fix instance patch, remove fakeRuntime#1423
xushiwei merged 3 commits into
xgo-dev:mainfrom
visualfc:instance

Conversation

@visualfc

@visualfc visualfc commented Nov 27, 2025

Copy link
Copy Markdown
Collaborator
  • internal/build: fix instance patch
  • runtime: remove fakeRuntime

@gemini-code-assist

Copy link
Copy Markdown
Contributor

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 implements a fix for "instance patching" within the build system. By passing the build context to the createSSAPkg function, the system can now correctly identify and apply alternative type definitions to existing instances during the Static Single Assignment (SSA) package creation phase. This ensures that the build process accurately reflects patched type information, resolving potential inconsistencies when dealing with modified or alternative package structures.

Highlights

  • createSSAPkg Context Parameter: The createSSAPkg function now accepts a *context parameter, providing it with access to the broader build context, which is crucial for applying instance patches.
  • Instance Patching Logic: New logic has been added to createSSAPkg to iterate through type instances (p.TypesInfo.Instances) and apply patches. This involves looking up patched objects in the ctx.patches map and re-instantiating types to update inst.Type and p.TypesInfo.Uses.
  • unsafe Package for Type Conversion: A new helper function toTypeList is introduced, which uses unsafe.Pointer to convert *types.TypeList to []types.Type. This conversion is necessary for the types.Instantiate call within the patching logic.
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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 fix for patching generic type instances by manually re-instantiating types in the patched context before SSA generation. The core change involves iterating through p.TypesInfo.Instances and replacing types and objects with their patched equivalents. While this appears to be a necessary fix for a complex problem, it introduces a fragile dependency on the internal structure of go/types.TypeList via unsafe.Pointer. My review includes suggestions to mitigate this risk by adding explanatory comments and to improve debuggability by logging potential errors.

Comment thread internal/build/build.go
Comment thread internal/build/build.go Outdated
Comment thread internal/build/build.go Outdated
Comment thread internal/build/build.go Outdated
@fennoai

fennoai Bot commented Nov 27, 2025

Copy link
Copy Markdown
Contributor

Code Review Summary

This PR fixes an important issue with generic type instantiation for patched packages. The implementation is well-structured, but there's one critical issue that must be addressed:

Critical Issue: The toTypeList function uses unsafe.Pointer to access internal fields of types.TypeList. This is fragile and could break with Go version updates. Please use the safe public API (At() and Len() methods) instead, following the pattern already established in ssa/type_cvt.go.

Documentation: The instance patching logic would benefit from a brief comment explaining its purpose.

Overall code quality is good with appropriate defensive checks and integration with existing patterns.

@codecov

codecov Bot commented Nov 27, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.59%. Comparing base (66f99bb) to head (10536e0).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1423   +/-   ##
=======================================
  Coverage   90.59%   90.59%           
=======================================
  Files          43       43           
  Lines       11400    11400           
=======================================
  Hits        10328    10328           
  Misses        911      911           
  Partials      161      161           

☔ 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.

@visualfc visualfc changed the title internal/build: fix instance patch [WIP] internal/build: fix instance patch Nov 27, 2025
@visualfc visualfc changed the title [WIP] internal/build: fix instance patch internal/build: fix instance patch, remove fakeRuntime Nov 27, 2025
@xushiwei
xushiwei merged commit ccb2eed into xgo-dev:main Nov 28, 2025
42 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