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

Tool for comparing source code of standard libaries between Go and Gno #1310

Open
thehowl opened this issue Oct 27, 2023 · 10 comments · May be fixed by #1425 or #2869
Open

Tool for comparing source code of standard libaries between Go and Gno #1310

thehowl opened this issue Oct 27, 2023 · 10 comments · May be fixed by #1425 or #2869
Labels
📖 documentation Improvements or additions to documentation 📦 🤖 gnovm Issues or PRs gnovm related 🌱 feature New update to Gno

Comments

@thehowl
Copy link
Member

thehowl commented Oct 27, 2023

It would be useful to have a tool to do what is described in the title. Right now, when reviewing PRs, I'm comparing the source with Go's using diffchecker. I think we can create a simple tool that compares the directories and source code in GOROOT/src and those in GNOROOT/gnovm/stdlibs.

My idea:

  • misc/stdlibs_diff
  • Go executable for generating HTML files showing the diff.
  • One HTML file per stdlib package.
  • Show entire stdlibs/files we're missing, and entire stdlibs/files that have been added.
  • Publish on https://gnolang.github.io/gno/stdlibs/
@FloRichardAloeCorp
Copy link

Hello, the purpose is to indicate the missing / added files or the differences between source code implementation?

@thehowl
Copy link
Member Author

thehowl commented Dec 5, 2023

Yes, I envision it as such: for each standard library, have a statically-generated HTML page showing side-to-side diff comparisons of matching go/gno files in the stdlibs. (ie. strings.go matches the equivalent strings.gno). If they differ by a file (because either of the two misses it entirely), show the entire "missing" source file.

Then, in the future, other possible improvements:

  • Also do the diff between the go doc -short -all and gno doc -short -all of the same standard library, and use it as the first element shown on the page
  • Allow for multiple diff options (ie. joined diff, like on GitHub, or expanding collapsed source, ...)
  • Preview the changes when somebody makes a PR modifying stdlibs

@FloRichardAloeCorp
Copy link

I understand. Does code comments count as a diff, and do unit test files count as well?
My first thought is that it doesn't need to be a CLI; a simple executable will do the job, at least for the first version.

@thehowl
Copy link
Member Author

thehowl commented Dec 5, 2023

I understand. Does code comments count as a diff, and do unit test files count as well?

Yes and yes.

Ideally: find a system for Gno source code to specify the reference Go source code; and add a dropdown to switch between Go source code versions.

My first thought is that it doesn't need to be a CLI; a simple executable will do the job, at least for the first version.

Totally. I'd think of an executable that can generate this, maybe with a couple of flags or env variables to specify where to find the Go stdlibs and the Gno stdlibs.

Then, additionally, we should incorporate in our CI pipeline the upload of the statically-generated HTML files containing the diffs.

@FloRichardAloeCorp
Copy link

Ok, I will work on it.

@thehowl
Copy link
Member Author

thehowl commented Dec 6, 2023

@FloRichardAloeCorp 🎉

Ping me on Discord on the #gnolang-dev channel if you need any help. (username: morganbaz)

@FloRichardAloeCorp
Copy link

Hello, I've been thinking about which algorithm to use to detect differences between file contents. I'm considering the Myers Algorithm, essentially the output of git diff, with the original file on the left and the differences on the right. Something that might look like this:
stdlibs_diff

Are you okay with that ?

@thehowl
Copy link
Member Author

thehowl commented Dec 6, 2023

@FloRichardAloeCorp This works, although for "split view" I was thinking of something closer to what GitHub does (try opening a Pull request's diff, clicking the cog and putting "split view"), so you see the original and deletions on the left, and the changed file with additions on the right.

Any diff will pretty much work for a first version, though. If you think that would require too much work to get the alignment right for instance, let's roll with what you made and iterate later :)

@FloRichardAloeCorp
Copy link

@thehowl Coming back to you again. I've tried the above suggestions that you've made. Here are the results:

stdlib_diff_2

I need your validation to continue further :)

Another question about usage: will you use it on the entire standard library, or do you want the tool to be able to specify a particular package to process? (both usage are also possible)

@thehowl
Copy link
Member Author

thehowl commented Dec 7, 2023

@FloRichardAloeCorp love this!

I'd like the tool to work on entire standard library source trees. Ie. stdlib-diff --src /usr/lib/go/src --dst /path/to/gno-repo/gnovm/stdlibs

also, check your discord DM's

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📖 documentation Improvements or additions to documentation 📦 🤖 gnovm Issues or PRs gnovm related 🌱 feature New update to Gno
Projects
Status: 🔵 Not Needed for Launch
2 participants