-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: add syntax only mode? #29429
Comments
Also cc @ianthehat because when @mvdan (I think?) proposed this some time ago, there was some rationale against it which I can't recall. |
I'm not sure about the "more information" hierarchy. The increments were designed in a somewhat weird way to the user, where type information can be obtained before syntax trees. If we can make an exception with the hierarchy, I'd suggest:
In a way, I'm not suggesting a This is a suggestion on the hierarchy though, not so much the name. Other names that come to mind are |
Another way to think about my proposed addition is that it would be |
If breaking backwards compatibility was an option, then my vote would go for:
This way, it's much clearer which modes contain types and/or syntax, and by consequence which ones don't. |
Throwing another idea into the pile - perhaps we could add typechecking knobs into I'm not sure how much API from The advantage here is that we wouldn't mess with the load mode hierarchy, and we'd also support recursive loading of syntax trees without type information. The disadvantage would be that |
@jayconrod who suggested the idea, and @ianthehat for his opinions (and the hat) We've thought about this a bit and on reflection I think the hierarchy was a mistake. But: we promised compatibility so we're going to keep it. But jayconrod suggested and idea I like: The proposal would be to add a bit field (or something that behaves like it) that would allow users to specify the options they want (do I want type information? ASTs? etc.) I think some options would have to override others... we'd have to come up with clear precedence rules. We could then make the "iota" mode one lower than LoadFiles, and have that select the bit mask. What do y'all think? |
Not sure I follow. Could you give a small code snippet to demonstrate? Overall the idea seems feasible to me, as it would let us add the features and not break backwards compatibility. It would also allow us to add more knobs to the load mode in the future without having this problem again. Having said that, it seems to me like long-term it would result in a bit of a hacky and complex API. Which might be fine, if we say that most Perhaps the answer could be for |
Thinking about @matloob's suggestion, how about something like this:
This potentially allows for more LoadMode values and the idiom might also extend to suppressing other overheads in the future, such the type checking of function bodies. |
To elaborate on the idea @matloob described, I think tools need to describe exactly what they need from So the idea was that To preserve compatibility in the current API, each current |
Change https://golang.org/cl/162140 mentions this issue: |
If you have opinions on what the bits should indicate, see the above change... |
The options are all unexported, and this CL is (almost) a no-op: the one difference is that since needImports and needSyntax are now independently specified, LoadSyntax and LoadAllSyntax are equivalent, because LoadSyntax needs both the needImports and needSyntax bits. I want to pin down the options that we want to split into, and future CLs can allow the options to be used individually... Updates golang/go#29429 Updates golang/go#29427 Change-Id: I5b2913e2c53e7ade56905e46912b076ccc339827 Reviewed-on: https://go-review.googlesource.com/c/tools/+/162140 Run-TryBot: Michael Matloob <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Cottrell <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
Hi, I've submitted my change. Writing out the LoadMode in terms of bits and setting LoadSyntax (but not LoadTypes) should only load syntax. |
I'll close this issue. |
Maybe we should add a go/packages LoadMode to just parse files but not perform type checking.
The name LoadSyntax is already taken, so I don't want to change its meaning, but if we can find a good name for the new mode, it seems like we could add it in. One unfortunate detail would be that we'd break the "feature" of the LoadMode heirarchy that each successive mode provides more information.
The text was updated successfully, but these errors were encountered: