-
Notifications
You must be signed in to change notification settings - Fork 18k
go/parser: deprecate parser.ParseDir (which returns deprecated type ast.Package) #71122
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
Comments
Related Issues
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.) |
ParseDir cannot be compatibly changed to return the recommended replacement type.
I think |
It sounds like ast.Package is deprecated, parser.ParseDir returns ast.Package, and we agree that people should not use parser.ParseDir anymore. So it seems like we should as a matter of logic also deprecate parser.ParseDir. |
Have all remaining concerns about this proposal been addressed? The proposal is to mark parser.ParseDir deprecated. It will still exist and be usable, but it returns ast.Package which is already deprecated. |
This proposal has been added to the active column of the proposals project |
It seems a shame to lose “parse directory” functionality in the stdlib. Package wasn’t that useful, but I’d rather un-deprecate it if it meant keeping ParseDir. Perhaps an alternative is to make a ParseFiles function that returns a slice of Files that ParseDir calls under the hood. |
We won't be losing any functionality; the function will still be there. But users will be informed that it's really not a satisfactory solution to most problems. |
I know, I meant non-deprecated functionality. Aside from the container type the Files are returned in, it’s a perfectly satisfactory solution to parsing a directory. If there’s an argument that it’s harmful because people should use the packages package instead, that would be interesting, but I haven’t heard it. |
|
Should the “packages” package’s functionality be added to the “parser” package to provide a working package parser in the stdlib? |
The parser works. But it doesn't know which files to parse. ParseDir is based on outdated build logic that may work for most packages (most being simple) but it doesn't handle lots of edge cases. There's go/build which handles more cases but basically at this point you need to get the list of what files to parse from the go command as that is what ultimately handles all the build logic. This is what go/packages does. (It would be nice if there were a golang.org/x lib for the go command that handled all the encoding decoding and executing of all the subcommands as that's tedious to do and makes it hard to keep up with changes... cough cough) |
No, because they have different responsibilities: the parser parses the content of a file; the go/packages package loads and optionally parses and type-checks a set of packages, and perhaps their dependencies. The implementation of go/packages is fairly substantial.
I agree. x/tools has an internal one but it's not nearly in a state to share. |
It's fine to wish it was better, but it's not. This is marking it with the truth that it's not that great. |
Based on the discussion above, this proposal seems like a likely accept. The proposal is to mark parser.ParseDir deprecated. It will still exist and be usable, but it returns ast.Package which is already deprecated. |
Change https://go.dev/cl/649275 mentions this issue: |
No change in consensus, so accepted. 🎉 The proposal is to mark parser.ParseDir deprecated. It will still exist and be usable, but it returns ast.Package which is already deprecated. |
func FilterPackage(pkg *Package, f Filter) bool
func PackageExports(pkg *Package) bool
func MergePackageFiles(pkg *Package, mode MergeMode) *File |
Also in func New(pkg *ast.Package, importPath string, mode Mode) *Package Seems like |
I agree that doc.New should be deprecated, but I don't think we can retroactively sneak it into this proposal. |
Go version
1.23.4
Output of
go env
in your module/workspace:What did you do?
Write some simple code using the go/ast and go/parser:
What did you see happen?
The IDE marks
ast.Package
as deprecated conforming to the comment on the type. Butparser.ParseDir()
nevertheless referencesast.Package
in its return type.What did you expect to see?
Either:
ParseDir()
use the recommended replacement type.Or:
ParseDir()
marked as deprecated too.The text was updated successfully, but these errors were encountered: