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

feat: add a Gno2Go precompiler #119

Merged
merged 11 commits into from
Apr 20, 2022
Merged

Conversation

moul
Copy link
Member

@moul moul commented Apr 13, 2022

This PR is a proposal for https://github.com/gnolang/bounties#10-use-go-typechecker

Official target:

  • Rename .go to .gno where appropriate
  • Make gno precompiler (which comes before preprocessor) compile .gno to .go in same folder.
  • "gno.land/r/realm" in .gno becomes "github.com/gnolang/gno/examples/gno.land/r/realm" in .go.
  • "std" becomes "github.com/gnolang/gno/stdlibs/stdshim" (?)
  • keeps a whitelist of stdlib packages (to prevent attacks, to prevent compiling malware).
  • Precompiler tries to compile the translated .go code using go, before proceeding.

My plan/implementation:

  • implement a transformation system in the gno.Gno2Go func.
  • replace std with github.com/gnolang/gno/stdlibs/stdshim.
  • replace gno.land/r/realm with github.com/gnolang/gno/examples/gno.land/r/realm.
  • always add a top-level comment to indicate that the .go files was generated (in case someone commits the generated files).
  • removed tests/go.mod, no you can safely run go test -v ./... from the top-level directory.
  • because ./stdlibs/* is both used by the .gno files and also by some .go files, I decided to rename them to .gno and create symlinks for each files so that go test ./... can work.
  • initial version of a gnodev tool with gnodev precompile ./path/to/package
  • bootstrap a simple stdshim package.
  • way to ensure the go version we're checking against, for distributed determinism. (feat: add a Gno2Go precompiler #119 (comment))

Also, I’ve a suggestion: what do about creating a new cmd/gnodev command, dedicated to contract developers, with tools like precompile, test and other developer tools?
That’s personally what I would love to work with.

Note: the PR is pretty big, because it renames a lot of .go files to .gno; the interesting files here are gno2go{,_test}.go.


Fixes #107
Related with #121
Closes #113 (replace)

@moul moul marked this pull request as draft April 13, 2022 06:37
@moul moul changed the title WIP feat: add a Gno2Go precompiler feat: add a Gno2Go precompiler Apr 13, 2022
@moul moul mentioned this pull request Apr 14, 2022
@moul moul marked this pull request as ready for review April 17, 2022 14:45
@moul-bot moul-bot force-pushed the dev/moul/bounty-10 branch 2 times, most recently from a084fa1 to 714f80f Compare April 17, 2022 15:45
@moul moul marked this pull request as draft April 17, 2022 15:50
@moul moul marked this pull request as ready for review April 17, 2022 16:01
@jaekwon
Copy link
Contributor

jaekwon commented Apr 17, 2022

thank you @moul, this looks awesome, though i've yet to read the code yet. I will review by tomorrow when I'm back.
cmd/gnodev command sounds great.
I noticed that in the last commit, git didn't seem to register that many of the files were renamed. Can that be fixed, to preserve file history of the original .go files?

@moul
Copy link
Member Author

moul commented Apr 17, 2022

I noticed that in the last commit, git didn't seem to register that many of the files were renamed. Can that be fixed, to preserve file history of the original .go files?

Sure thing, I'll create a commit for the git mv and another one for the porting changes.

Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com>
Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com>
Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com>
@moul
Copy link
Member Author

moul commented Apr 17, 2022

I'm not sure why, but even with a dedicated commit for moving, and another one for fixing, GitHub seems to make shortcuts and only look the general diff with master.


here it works (probably because the change is small)

Screenshot 2022-04-17 at 20 35 05@2x

here it doesn't work

Screenshot 2022-04-17 at 20 35 23@2x


Any suggestions?

Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com>
Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com>
@moul
Copy link
Member Author

moul commented Apr 17, 2022

New: an initial version of gnodev.

Screenshot 2022-04-18 at 01 12 00@2x

…e executed by standard tools implicitely

Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com>
gno2go.go Outdated Show resolved Hide resolved
Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com>
Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com>
@jaekwon
Copy link
Contributor

jaekwon commented Apr 19, 2022

looks good so far... we probably also want a way to ensure the go version we're checking against, for distributed determinism.

Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com>
@moul
Copy link
Member Author

moul commented Apr 19, 2022

looks good so far... we probably also want a way to ensure the go version we're checking against, for distributed determinism.

I added it in the list of checkboxes at the top of the PR, so we can remind to do them in a new one.

@jaekwon
Copy link
Contributor

jaekwon commented Apr 20, 2022

Merging in to prevent conflicts; another PR will complete the precompile logic. Thank you @moul.

@jaekwon jaekwon merged commit 38f1ee4 into gnolang:master Apr 20, 2022
@moul moul deleted the dev/moul/bounty-10 branch July 5, 2022 09:16
@moul moul added this to the 🏗1️⃣ test1.gno.land milestone Oct 20, 2022
@moul moul self-assigned this Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Archived in project
Development

Successfully merging this pull request may close these issues.

Doesn't check for return
2 participants