-
Notifications
You must be signed in to change notification settings - Fork 18k
x/tools/go/loader: importers should just work #10276
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
FWIW: The godex command tries various importers. But I don't think it's a "good" solution. |
What is wrong with the godex approach? (Genuine question.) |
The "trial-and-error" approach seems not very disciplined. A standardized export format would be nice but may be more than compiler writers are willing to sign up for. The importer/exporter written for go/types could be plugged in. We have a prototype hooked up to gccgo (work currently paused due to manpower constraints). |
for the x/tools packages, we just need to support gc, gccgo and source. I think many of the frustration for tools like stringer comes from the fact We should do something here. |
Hi Josh. I agree that go/loader is far from satisfactory. There are a number of separate issues here.
The stringer tool has its own logic for loading a type-checked package from an import path. For consistency with other tools it should probably use go/loader. I don't know why it doesn't; most likely its author didn't know about go/loader. A second question is whether stringer should load the program from source or from export data. I think source is the right answer, since it's the ground truth; the extra cost is small and infrequently paid. Loading export data assumes that the user did a 'go install' recently (unlikely) and that the tool author guessed correct the right compiler.
I agree that each tool should not make the choice of which kind of import data to use; it should be deduced from the workspace state, or offered to the user as a standard flag. Using source where possible finesses the problem.
I'm not sure what you meant by this. Could you clarify?
This would mean duplicating yet more of the go/build logic (computeStale et al) in go/loader, but perhaps it would be worthwhile if it would simplify the configuration API. Ideally you would simply tell the loader which packages must be loaded from source and it would take care of the rest. To date, most of go/loader's clients want source position information for dependencies, which is not recorded in the export data, so there's been little demand for the export data use case.
We already have such a hook, but users shouldn't have to think that hard to get sensible behavior. There are too many moving parts involved in correctly loading a program. |
Thanks, I'll look into it.
I agree. The API has a lot of moving parts and not enough documentation, and the implementation is more complex than it looks. I'm tempted to just remove support for loading binary export data entirely, since supporting it well will require the addition of a lot more complexity: the addition of staleness-checking logic as described above, and the fixing of a subtle bug about loading a mixture of source and binary. [I seem to have misunderstood the Github UI here and edited Josh's comment while trying to respond to it. The quoted text is Josh, the responses are me. --adonovan] |
Josh: I can't reproduce the problems you mentioned w.r.t. 'eg' and the relative cmd directories. Please let me know if you see this again. go/loader no longer supports loading from binary, which simplifies the API slightly and the internals rather more. I've moved the API documentation into doc.go, and added a number of Example tests showing basic usage of the API. Please let me know if you find further problems with this package, or have ideas for improving it. |
Apologies in advance that this is vague.
Symptoms of the problem:
cmd/internal/gc
but./cmd/?g
.gcimporter
but the user uses gccgo?I'm not familiar enough with go/loader to make a concrete detailed suggestion, but perhaps go/loader could do something like: automatically start with gcimporter (if the object files aren't stale), then fall back to a source importer, and then fall back to other importers (gccgo, llgo, etc.)? And provide hooks so that advanced users can insert their own importers (as I presume Google does internally).
/cc @randall77 @alandonovan
The text was updated successfully, but these errors were encountered: