-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: x/tools/go/packages: Provide an AST loader for single binary applications #52974
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
If you mean that A simpler alternative, if you only need ASTs, is https://pkg.go.dev/go/parser#ParseDir. That does require you to have the Go package already on the filesystem somewhere, but it then means you don't need |
@mvdan , thks for the feedback. I retract the proposal.
That would be doable indeed but complex to implement from my perspective. My idea of the go standard library is to provide functions with most complexity hidden from the programmer. BTW : indicating in the
Thank-you for pointing this but the example above needs a bit more than the results of the of Field: models.Country{}.Hello, In order to construe the link between the PS : a workaround is possible with |
Thanks for writing up your interesting use case so clearly. The root of the problem is that the
I would have thought that a stakeholder who cares about the code at the level of UML diagrams would be working in an environment where 'go build' works. But if not, perhaps you could package your program as Linux container image that contains a Go toolchain. |
@adonovan , thks for the explanation. I admit that when I used
For your information, there is a recent trend in system engineering where stakeholders routinely deal with complex custom data model to explore their problem domain (see ref. below). Data model, also named ontology, can be complex (for instance in the model I currently work with, there are 40 classes and 61 associations). For stakeholders, it is natural to navigate the ontology/data thanks to a UML diagram (this is the use case # 1). Most stakeholders do not know that this is a UML diagram, they see (and understand) a diagram of interrelated concepts.
|
This proposal has been declined as retracted. |
This request describes a need for a new function that provides the same results as the
Load()
function of thegolang.org/x/tools/go/packages
package but that allows embedding in a single binary.This request is based on end-user use cases with UML diagrams, on an implementation of UML diagrams in go that uses the
packages.Load()
function and on the description of the current limitations of thisLoad()
function.Uses cases for using UML diagrams at run time
UML diagrams are useful artifacts for documenting code but they can be also useful at runtime as it is shown here with both structural and state UML diagrams.
For UML structural diagram, 2 use cases can be met at run time:
The following movie illustrates the use case with a toy plane simulation. At time stamp 10'', the end-user opens the UML diagrams describing the simulation model (use case #1) and then he checks the values of the Liner agent with clicking on the
Liner
class shape (use case #2).https://vimeo.com/709811836
For UML state diagrams, there is one other case that can be useful when developing simulations of protocols between devices that are statefull agents. In this case, it is interesting to to check the state of each agent during the simulation. The following movie shows such a use case. It is a toy laundromat simulation. The UX provides insight into the state of the washer and the state of the machine.
https://vimeo.com/709811805
Persistence of UML diagrams in go code
In the above use cases, UML diagrams are integral parts of applications developed with the gong framework, a go+angular full stack framework for developing applications for system engineers.
With gong, UML diagrams such a the simple one below are marshaled as go code.
Load of the UML diagram with the
packages.Load()
go functionIn a gong diagram, every shape references a go element such a struct or a field via a a zero value of the struct of the field of the actual go code.
This solution brings two benefits:
At run time, an Unmarshall function loads the go code by using the
packages.Load()
function and then parses the Abstract Syntax Tree to find which UML shapes references which go struct or fieldLimitations of the current
packages.Load
functionIn system engineering, it is interesting to ship simulation binaries to interested stakeholders. This is where go is interesting because one great advantage of go is the single binary feature. However, the above simulations cannot be considered single binary for two limitations.
packages.Load
makes a system call to the go compilerIn order to be executed, uses cases described above cannot be executed on a machine where go is not installed. Indeed, the
packages.Load
function makes a system call to the go compiler.package.Load
cannot supportembed
directoriesIn order to be executed, uses cases described above needs the go files describing the UML diagram as well as the go model both accessible in local directories. This is because, unless mistaken, one cannot use the
embed.FS
type in theDir
field of thepackages.Config
struct that is passed as a parameter to thepackages.Load
function.Expected feature
A
packages.<name to be defined>()
function that does not makes a system call to the go compiler and that allows embedded go files and that returns the AST.The text was updated successfully, but these errors were encountered: