Skip to content

Conversation

visualfc
Copy link
Member

@visualfc visualfc commented Oct 11, 2025

deps by goplus/gogen#541

  • ast.OverloadFuncDecl preload overload func
  • remove pkgCtx.overpos

@gemini-code-assist
Copy link
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 introduces fundamental changes to the compiler's preloading mechanism to properly support ast.OverloadFuncDecl. It modifies how functions and methods are registered and represented internally, enabling the compiler to recognize and manage overloaded entities. By creating specialized internal objects and a synthetic dispatcher for overloads, this change lays the groundwork for robust overload resolution within the compilation process.

Highlights

  • Enhanced Function Preloading: The preloadFuncDecl internal function now accepts an overload boolean parameter, allowing the compiler to differentiate between standard and overloaded function declarations during the initial preloading phase.
  • Specialized Overload Handling: New conditional logic has been introduced to create distinct internal representations for overloaded functions and methods. Instead of directly calling loadFunc, overloaded entities now trigger the creation of gogen.NewOverloadFunc or gogen.NewOverloadMethod objects.
  • Synthetic Overload Dispatcher: When an ast.OverloadFuncDecl is encountered, the system now generates a synthetic ast.FuncDecl that acts as an overload dispatcher. This dispatcher function is marked as overloaded and accepts a single any type parameter, facilitating runtime overload resolution.
  • New Constant for Overload Arguments: A new constant, __xgo_overload_args__, has been added to serve as the parameter name for the synthetic overload dispatcher function, ensuring consistent naming.
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.

@visualfc visualfc marked this pull request as draft October 11, 2025 11:56
loadFunc(ctx, recv, fname, d, genFnBody)
if overload {
pkg := ctx.pkg.Types
typ := pkg.Scope().Lookup(tname).Type().(*types.Named)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Security & Quality Issue: Unsafe type lookup/assertion chain. This will panic if Lookup(tname) returns nil or type is not *types.Named.

Suggested change
typ := pkg.Scope().Lookup(tname).Type().(*types.Named)
obj := pkg.Scope().Lookup(tname)
if obj == nil {
ctx.handleErrorf(d.Name.Pos(), d.Name.End(), "type %s not found", tname)
return
}
typ, ok := obj.Type().(*types.Named)
if !ok {
ctx.handleErrorf(d.Name.Pos(), d.Name.End(), "type %s is not a named type", tname)
return
}
gogen.NewOverloadMethod(typ, d.Name.Pos(), pkg, fname)

}

const (
overloadArgs = "__xgo_overload_args__"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation: Add doc comment explaining this constant's purpose as placeholder parameter name for preloading overload signatures.

Suggested change
overloadArgs = "__xgo_overload_args__"
const (
// overloadArgs is the placeholder parameter name used when preloading overload function
// signatures. This allows overload functions to be registered in the package scope
// during the preload phase before actual implementations are processed.
overloadArgs = "__xgo_overload_args__"
)

cl/compile.go Outdated
Comment on lines 1312 to 1319
List: []*ast.Field{
&ast.Field{
Names: []*ast.Ident{
ast.NewIdent(overloadArgs),
},
Type: ast.NewIdent("any"),
},
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style: Unnecessary & in Field literal (slice already takes address). Also consider adding a comment explaining this placeholder signature.

Suggested change
List: []*ast.Field{
&ast.Field{
Names: []*ast.Ident{
ast.NewIdent(overloadArgs),
},
Type: ast.NewIdent("any"),
},
},
// Create placeholder function signature for overload preloading
// with single parameter (__xgo_overload_args__: any)
Params: &ast.FieldList{
List: []*ast.Field{
{
Names: []*ast.Ident{ast.NewIdent(overloadArgs)},
Type: ast.NewIdent("any"),
},
},
},

@niupilot
Copy link
Contributor

niupilot bot commented Oct 11, 2025

Code Review Summary

Clean implementation of overload function preloading. Three areas need attention:

Critical:

  • Line 1071: Unsafe type lookup/assertion - add nil checks to prevent panic

Documentation:

  • Line 1361: Add doc comment for overloadArgs constant
  • Line 1312-1319: Explain placeholder signature purpose

Style:

  • Line 1312-1319: Remove unnecessary & in Field literal

No performance or security vulnerabilities found beyond the nil check issue.

Copy link
Contributor

@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 functionality to preload overloaded functions by modifying preloadFuncDecl to handle an overload flag. When this flag is true, it registers a special placeholder for the overloaded function/method. The changes appear to correctly implement the intended feature. I have one suggestion to improve code clarity by removing an unnecessary part of a newly created AST node.

cl/compile.go Outdated
Comment on lines 1310 to 1321
Type: &ast.FuncType{
Params: &ast.FieldList{
List: []*ast.Field{
&ast.Field{
Names: []*ast.Ident{
ast.NewIdent(overloadArgs),
},
Type: ast.NewIdent("any"),
},
},
},
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The Type field of this ast.FuncDecl is constructed with a specific signature, but it appears to be unused. When preloadFuncDecl is called with overload=true, as it is here, the code path that uses the Type field is not executed. This makes the Type definition unnecessary and potentially confusing.

To improve clarity and remove this dead code, you can replace this block with Type: nil.

Type: nil,

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.

1 participant