Skip to content

x/tools/go/packages: include directness information to ParseFile callback #28740

Open
@zombiezen

Description

@zombiezen

Wire recently switched to go/packages after using golang.org/x/tools/go/loader. As noted in google/go-cloud#663, we observed a ~4x slowdown. Since not all of the time is spent inside the Wire process, profiling has been difficult. However, for a baseline Wire run that took 2.26s (originally 0.3s), half the time is spent in go list, the other half is spent in go/types.dependencyGraph and map assignments.

This indicates to me that at least part of the problem still is having too much input being sent to the typechecker. One of the tricks Wire employed in the loader-based code was to skip function bodies for dependency packages (Wire needs function body type-checking for the root packages). However, the ParseFile callback does not give enough information to make this determination. I would like for the arguments to ParseFile to include whether the file is being parsed for the root packages or imported packages. Something like:

package packages

type Config struct {
  // ...
  ParseFile func(fset *token.FileSet, filename string, src []byte, isRoot bool) (*ast.File, error)
}

It does seem quite possible that more information could be added over time, so a more future-friendly change could be along the lines of:

package packages

type ParseFileRequest struct {
  Fset *token.FileSet
  Filename string
  Src []byte
  IsRoot bool
}

type Config struct {
  // ...
  ParseFile func(*ParseFileRequest) (*ast.File, error)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    ToolsThis label describes issues relating to any tools in the x/tools repository.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions