Skip to content
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

x/tools/go/packages: NeedSyntax without NeedFiles/NeedCompiledGoFiles produces empty slice #56677

Open
mdempsky opened this issue Nov 9, 2022 · 1 comment
Labels
NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@mdempsky
Copy link
Contributor

mdempsky commented Nov 9, 2022

The program below prints:

runtime (LoadMode(NeedName|NeedSyntax)):
	len(Syntax) = 0
	Errors: []

runtime (LoadMode(NeedName|NeedFiles|NeedSyntax)):
	len(Syntax) = 136
	Errors: []

runtime (LoadMode(NeedName|NeedCompiledGoFiles|NeedSyntax)):
	len(Syntax) = 145
	Errors: [/home/mdempsky/wd/go/src/runtime/asm.s:5:1: illegal character U+0023 '#' /home/mdempsky/wd/go/src/runtime/asm_amd64.s:5:1: illegal character U+0023 '#' /home/mdempsky/wd/go/src/runtime/duff_amd64.s:5:1: illegal character U+0023 '#' /home/mdempsky/wd/go/src/runtime/memclr_amd64.s:7:1: illegal character U+0023 '#' /home/mdempsky/wd/go/src/runtime/memmove_amd64.s:28:1: illegal character U+0023 '#' /home/mdempsky/wd/go/src/runtime/preempt_amd64.s:3:1: illegal character U+0023 '#' /home/mdempsky/wd/go/src/runtime/rt0_linux_amd64.s:5:1: illegal character U+0023 '#' /home/mdempsky/wd/go/src/runtime/sys_linux_amd64.s:9:1: illegal character U+0023 '#' /home/mdempsky/wd/go/src/runtime/time_linux_amd64.s:7:1: illegal character U+0023 '#']

I think only the middle case is working as documented.

The last case appears to be due to #56632.

package main

import (
	"fmt"
	"log"

	"golang.org/x/tools/go/packages"
)

func main() {
	var modes = []packages.LoadMode{
		packages.NeedName | packages.NeedSyntax,
		packages.NeedName | packages.NeedFiles | packages.NeedSyntax,
		packages.NeedName | packages.NeedCompiledGoFiles | packages.NeedSyntax,
	}

	for _, mode := range modes {
		cfg := packages.Config{Mode: mode}
		pkgs, err := packages.Load(&cfg, "runtime")
		if err != nil {
			log.Fatal(err)
		}
		pkg := pkgs[0]
		fmt.Printf("%v (%v):\n\tlen(Syntax) = %v\n\tErrors: %v\n\n", pkg.PkgPath, mode, len(pkg.Syntax), pkg.Errors)
	}
}
@mdempsky mdempsky added the NeedsFix The path to resolution is known, but the work has not been done. label Nov 9, 2022
@mdempsky mdempsky added this to the Unreleased milestone Nov 9, 2022
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Nov 9, 2022
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/588141 mentions this issue: go/packages: document fields that are part of JSON schema

gopherbot pushed a commit to golang/tools that referenced this issue May 29, 2024
Package is both the "cooked" result data type of a Load
call, and the "raw" JSON schema used by DriverResponse.

This change documents the fields that are part of the
protocol, and ensures that the others are omitted from
the JSON encoding. (They are populated by the post-
processing done by 'refine', if the appropriate Need
bits are set.)

Also
- document that there are a number of open bugs
  in places where it may be likely to help,
  particularly Mode-related issues.
- document that Load returns new Packages,
  using distinct symbol realms (types.Importers).
- document Overlays in slightly more detail.

Fixes golang/go#67614
Fixes golang/go#61418
Fixes golang/go#67601
Fixes golang/go#43850
Updates golang/go#65816
Updates golang/go#58726
Updates golang/go#56677
Updates golang/go#48226
Updates golang/go#63517
Updates golang/go#56633

Change-Id: I2f5f2567baf61512042fc344fca56494f0f5e638
Reviewed-on: https://go-review.googlesource.com/c/tools/+/588141
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

2 participants