-
Notifications
You must be signed in to change notification settings - Fork 561
[WIP] cl: ast.OverloadFuncDecl preload overload func #2469
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 introduces fundamental changes to the compiler's preloading mechanism to properly support Highlights
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
|
loadFunc(ctx, recv, fname, d, genFnBody) | ||
if overload { | ||
pkg := ctx.pkg.Types | ||
typ := pkg.Scope().Lookup(tname).Type().(*types.Named) |
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.
Security & Quality Issue: Unsafe type lookup/assertion chain. This will panic if Lookup(tname)
returns nil or type is not *types.Named
.
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__" |
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.
Documentation: Add doc comment explaining this constant's purpose as placeholder parameter name for preloading overload signatures.
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
List: []*ast.Field{ | ||
&ast.Field{ | ||
Names: []*ast.Ident{ | ||
ast.NewIdent(overloadArgs), | ||
}, | ||
Type: ast.NewIdent("any"), | ||
}, | ||
}, |
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.
Style: Unnecessary &
in Field literal (slice already takes address). Also consider adding a comment explaining this placeholder signature.
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"), | |
}, | |
}, | |
}, |
Code Review SummaryClean implementation of overload function preloading. Three areas need attention: Critical:
Documentation:
Style:
No performance or security vulnerabilities found beyond the nil check issue. |
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 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
Type: &ast.FuncType{ | ||
Params: &ast.FieldList{ | ||
List: []*ast.Field{ | ||
&ast.Field{ | ||
Names: []*ast.Ident{ | ||
ast.NewIdent(overloadArgs), | ||
}, | ||
Type: ast.NewIdent("any"), | ||
}, | ||
}, | ||
}, | ||
}, |
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.
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,
deps by goplus/gogen#541