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
proposal: x/tools/go/analysis: add Pass.Module field #66315
Comments
Thanks for the heads-up. Bazel's rules_go has adopted We would thus be able to fill these fields (maybe except for |
My suggestion for a minimal set of fields |
Should we make Pass.Module an optional feature only to be filled in if it is requested by a boolean field on the Analyzer? Such as |
That wouldn't be a compatible change. If we add the field, then a driver that hasn't implemented support for it yet will run analyzers unconditionally, despite their RequiresModule declaration, so they will crash. Drivers and analyzers must both be able to handle missing module information. |
Good point. What do we want to do when
The first option seems like the easiest to relax in the future. |
Option 3. If the pass is running, it means we got a package (possibly with errors if RunDespiteErrors). The analyzer can deal with them. |
Maybe related, a recent very minimal CL (not yet submitted) to forward module path information from vet (which already contains module version). https://go.dev/cl/571016. Perhaps that CL should be revised, @michaelmatloob suggested a design document or issue to link to, neither of which yet exists, which is why I have not yet submitted. There's no guarantee (as I understand it) that packages from which a vet analysis imports facts, have themselves been analyzed to ensure that those facts are exported. I verified that the export-import worked if I pre-ran the analyses by hand, but if I did not do that, then there are no facts to import. |
This proposal discussion will determine whether we go for a "maximalist" approach (plumb through everything from go/packages.Module) or a minimalist one (just module path and version). Either way, your linked CL will need to specify at least one additional field.
There is such a guarantee, except for the standard library. (That unfortunate exception is because the std lib is precompiled in Blaze and Bazel, not built on demand.) In other words, if a driver makes a pass of analyzer A on package P, where A uses facts and P imports Q, then the driver must already have executed pass (A, Q) successfully, unless Q is in std. |
@dr2chase Definitely related. For that CL to help an Analyzer, this proposal or something similar will need to be approved to give that data a place to be plumbed to. You may want to wait on this being approved. It would also help to know what the minimal data you need is. Also your 2 cents on maximal interface or minimal interface would be appreciated. |
Thanks for looping us in on this! Please's Go plugin has most of the module information available to it; these days it's typically synced from the go.mod file using Puku. Hence I expect we shouldn't have much trouble producing this information. The only fields I expect we would be unlikely to fill in are Overall the proposal LGTM. |
If the fields are not optional, Analyzers can assume they are always provided. If not present, the Analyzer could crash (nil-pointer dereference) or otherwise misbehave.
@peterebden Is it fair to say that this is a request that |
@timothy-king Sorry for the late reply, been out-of-hemisphere and hacking on other problems also. The information that (I think) I need is just Path and Version, but I am a little worried about the fields that I don't know for sure that I understand (that might affect the effective version, for example). So if in fact I need those fields to correctly answer "are these two packages from the same module or not?" or "what Go version applies to compilation of this package?" then they should be included, otherwise, if nobody has a use for them yet, then maybe wait. Maybe. I approve of it being a pointer-to-a-thing, so that "nope, no module info here" can be signaled with a nil pointer. One thing to remember is that we'll want to fill this in, in the .cfg that vet passes to analysis passes. I have a pair of CLs for doing this with I went to look at the full set of module information available to go-build-vet-etc, and saw
and was curious about whether any of this should be included, if it happens to be available in an analysis framework. |
Let's stick with the subset of fields Tim proposed: {Path, Version, GoVersion}; the rest are more obscure. We can always add more later when a clear need arises. I've appended the updated API proposal to the bottom of the first comment. Any objections? |
This proposal has been added to the active column of the proposals project |
Have all remaining concerns about this proposal been addressed? The proposal is to add
|
Based on the discussion above, this proposal seems like a likely accept. The proposal is to add
|
I have a candidate implementation here https://go.dev/cl/577996. One thing I observed was that IMO what we should do is document that "" means unknown and that this includes local packages so Analyzer writers are aware of this. Alternatively this could be a reason to have Pass.Module == nil to signal 'unknown'. |
Proposal Details
Some analyzers need information about the module to which a package belongs, such as its version of Go. We have already exposed this information in x/tools/go/packages (and I observe that most features of packages.Package that are plausibly build system-agnostic eventually end up needing to be exposed through analysis.Pass too).
I propose that we define a
Pass.Module
field, something like this: [see bottom of note for most current proposal]This set of fields exactly matches what is in
packages.Module
. Clearly this is the maximal set of fields, since a go/packages-based driver will not be able to set any additional (non-derived) fields. But perhaps a more minimal set might be a safer starting point; suggestions welcome.Build systems other than
go list
, such as Bazel, Blaze, Pants, Buck, Please and so on, will need to simulate the module information if they do not use go.mod files. I am interested to hear from maintainers of Go integrations in those systems whether this set of fields looks manageable. See:Update (Apr 4):
The text was updated successfully, but these errors were encountered: