Skip to content

feat: transpile to Gno 0.9 (latest interrealm spec) with @cross #4264

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

Merged
merged 87 commits into from
May 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
619bddb
add xform
jaekwon May 8, 2025
b6a4de8
add preprocess2 and hack lint
jaekwon May 8, 2025
dc00ab6
...
jaekwon May 8, 2025
cc0842f
refactor
jaekwon May 8, 2025
32e2e78
gnomod/lint/transpile etc
jaekwon May 10, 2025
17faaca
improve flow and documentation
jaekwon May 10, 2025
4fc804c
gimp
jaekwon May 10, 2025
77e5e28
fix multi error passthrough
jaekwon May 11, 2025
4911675
added adr/lint_transpile.md; naming fixes; lint/test works
jaekwon May 11, 2025
56b6cdb
...
jaekwon May 11, 2025
cbba489
xpiling works ish
jaekwon May 12, 2025
7cf9fc1
...
jaekwon May 12, 2025
07086ad
...
jaekwon May 12, 2025
7fcfae4
...
jaekwon May 12, 2025
ca1ebe0
...
jaekwon May 12, 2025
18159fd
fix tests/files
jaekwon May 12, 2025
cae70df
separate _test and filetest files
jaekwon May 13, 2025
f7688c5
fix tests
jaekwon May 13, 2025
f8bfd7b
fix tests
jaekwon May 13, 2025
c3ef149
fix gnovm tests; type-checking for test files work
jaekwon May 14, 2025
da16108
intermediate...
jaekwon May 15, 2025
6c37d67
intermediate...
jaekwon May 15, 2025
3bc9349
fix more tests
jaekwon May 16, 2025
48675f0
fix all file tests
jaekwon May 16, 2025
6dee37a
recursive10.gno; recursive11.gno
jaekwon May 16, 2025
40e90e3
remove spurious files from testing/base
jaekwon May 16, 2025
4f970ec
...
jaekwon May 16, 2025
36e2213
...
jaekwon May 16, 2025
fe061b5
...
jaekwon May 16, 2025
64b048a
...
jaekwon May 16, 2025
086ff7e
...
jaekwon May 16, 2025
a27e8ed
fix stdlibs/fmt test
jaekwon May 17, 2025
495f2c3
fix stdlib tests except one re: genstd
jaekwon May 18, 2025
8b2b7f2
lint.*Error -> gno.*Error
jaekwon May 18, 2025
33454fb
fix all gnovm tests; FINALLY
jaekwon May 18, 2025
113825e
gno fix
jaekwon May 19, 2025
7f280ba
fix tests related to span/location StringXXX().
jaekwon May 19, 2025
ce758b8
replaceWithDirPath -> guessFilePathLoc; reParseRecover works with Span
jaekwon May 19, 2025
1184e22
don't skip preprocessing for funclitexpr inside a func decl
jaekwon May 19, 2025
36f4f39
add two funclit tests
ltzmaxwell May 20, 2025
6dce366
check parent blocknode to ensure correct skip for funcLit
ltzmaxwell May 20, 2025
1ed62d7
fix grc20
ltzmaxwell May 20, 2025
3bac84a
fix p/moul/collection
ltzmaxwell May 20, 2025
6b39db0
fix p/moul/txlink
ltzmaxwell May 20, 2025
1743abf
fix r/demo/atomicswap
ltzmaxwell May 20, 2025
5a953fa
fix p/moul/helplink
ltzmaxwell May 20, 2025
e8c6bbc
fix r/gnoland/monit
ltzmaxwell May 20, 2025
b653d6c
fix r/gov/dao/v3/memberstore
moul May 20, 2025
a7d74e7
fix: generate missing gno.mod files
moul May 20, 2025
9d643a8
fix: p/moul/helplink
moul May 20, 2025
6aac30c
a few more simple typecheck fix
ltzmaxwell May 20, 2025
edb8830
Revert "fix: generate missing gno.mod files"
moul May 20, 2025
009e942
merge master
ltzmaxwell May 20, 2025
54a2a35
fix r/x/nir1218_evaluation_
ltzmaxwell May 20, 2025
584b4b8
Merge commit 'refs/pull/4264/head' of github.com:gnolang/gno into pr-…
ltzmaxwell May 20, 2025
427ac06
Revert "fix: generate missing gno.mod files"
moul May 20, 2025
241cbbe
fix printf usage in gno fix
moul May 20, 2025
c7bf362
Make filetests go .Check with completely separate go fileset
jaekwon May 20, 2025
85c6d69
add back .gnobuiltins.go for filetests
jaekwon May 20, 2025
0c1be82
...
jaekwon May 20, 2025
6461424
...
jaekwon May 20, 2025
8d0bf15
future-proof ATTR_PREPROCESS_SKIPPED
jaekwon May 20, 2025
14d28e8
lint and fix fixes regarding preprocessed package node and store caching
jaekwon May 21, 2025
c7763c8
chore: lint
gfanton May 20, 2025
fef0553
fix: gnoland
gfanton May 20, 2025
2b8794e
fix: gnodev
gfanton May 20, 2025
c3ed31f
fix: keeper load
gfanton May 21, 2025
371d6a2
...
jaekwon May 21, 2025
136e0fe
...
jaekwon May 21, 2025
8fd6cb5
property sort normal/_test/filetests
jaekwon May 21, 2025
28f6382
type-check fix examples more
jaekwon May 21, 2025
76fb198
fix one r/leon/hor test
jaekwon May 21, 2025
afbac72
Merge commit 'refs/pull/4264/head' of github.com:gnolang/gno into pr-…
ltzmaxwell May 21, 2025
54bc6eb
fix import name issue
ltzmaxwell May 21, 2025
3becb1c
chore(examples): add 'make fix'
moul May 21, 2025
6b551a4
p/*_test.gno can import r/
moul May 21, 2025
09fa106
validate mempackage
jaekwon May 22, 2025
d9ee35a
fix(gnodev): validate mpkg function
gfanton May 22, 2025
82efcb3
fix: add ParseMode argument to `TypeCheckMemPackage`
gfanton May 21, 2025
51635be
fix gno lint xxx_test
jaekwon May 23, 2025
c604710
chore: lint
gfanton May 23, 2025
3ca93f7
chore: lint pt2
gfanton May 23, 2025
c673fd1
fix: integration gas update
gfanton May 23, 2025
2cc60ed
Apply suggestions from code review
jaekwon May 24, 2025
385d108
Merge remote-tracking branch 'origin/master' into fix/crossrealm/xform
jaekwon May 24, 2025
075b205
let file names have some more dots
jaekwon May 24, 2025
40a1c61
...
jaekwon May 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ issues:
linters:
- errorlint # Disabled linting of error comparisons, because of lacking std lib support
- path: gnovm/pkg/gnolang
text: "string `(cross|.no realm.|crossing)` has (\\d+) occurrences, make it a constant"
text: "string `(realm|cross|.no realm.|crossing)` has (\\d+) occurrences, make it a constant"
9 changes: 4 additions & 5 deletions contribs/gnodev/cmd/gnodev/setup_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,11 @@ func setupPackagesResolver(logger *slog.Logger, cfg *AppConfig, dirs ...string)
}

func guessPathGnoMod(dir string) (path string, ok bool) {
modfile, err := gnomod.ParseAt(dir)
if err == nil {
return modfile.Module.Mod.Path, true
modfile, err := gnomod.ParseDir(dir)
if err != nil {
return "", false
}

return "", false
return modfile.Module.Mod.Path, true
}

var reInvalidChar = regexp.MustCompile(`[^\w_-]`)
Expand Down
42 changes: 21 additions & 21 deletions contribs/gnodev/pkg/packages/package.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package packages

import (
"errors"
"fmt"
"go/parser"
"go/token"
"os"
"path/filepath"

"github.com/gnolang/gno/gnovm/pkg/gnolang"
"github.com/gnolang/gno/gnovm/pkg/gnomod"
Expand All @@ -27,19 +27,19 @@ type Package struct {
}

func ReadPackageFromDir(fset *token.FileSet, path, dir string) (*Package, error) {
modpath := filepath.Join(dir, "gno.mod")
if _, err := os.Stat(modpath); err == nil {
draft, err := isDraftFile(modpath)
if err != nil {
return nil, err
}

// Skip draft package
// XXX: We could potentially do that in a middleware, but doing this
// here avoid to potentially parse broken files
if draft {
mod, err := gnomod.ParseDir(dir)
switch {
case err == nil:
if mod.Draft {
// Skip draft package
// XXX: We could potentially do that in a middleware, but doing this
// here avoid to potentially parse broken files
return nil, ErrResolverPackageSkip
}
case errors.Is(err, os.ErrNotExist), errors.Is(err, gnomod.ErrGnoModNotFound):
// gno.mod is not present, continue anyway
default:
return nil, err
}

mempkg, err := gnolang.ReadMemPackage(dir, path)
Expand All @@ -63,7 +63,7 @@ func ReadPackageFromDir(fset *token.FileSet, path, dir string) (*Package, error)
}

func validateMemPackage(fset *token.FileSet, mempkg *std.MemPackage) error {
if mempkg.IsEmpty() {
if isMemPackageEmpty(mempkg) {
return fmt.Errorf("empty package: %w", ErrResolverPackageSkip)
}

Expand All @@ -87,16 +87,16 @@ func validateMemPackage(fset *token.FileSet, mempkg *std.MemPackage) error {
return nil
}

func isDraftFile(modpath string) (bool, error) {
modfile, err := os.ReadFile(modpath)
if err != nil {
return false, fmt.Errorf("unable to read file %q: %w", modpath, err)
func isMemPackageEmpty(mempkg *std.MemPackage) bool {
if mempkg.IsEmpty() {
return true
}

mod, err := gnomod.Parse(modpath, modfile)
if err != nil {
return false, fmt.Errorf("unable to parse `gno.mod`: %w", err)
for _, file := range mempkg.Files {
if isGnoFile(file.Name) || file.Name == "gno.mod" {
return false
}
}

return mod.Draft, nil
return true
}
4 changes: 0 additions & 4 deletions contribs/gnodev/pkg/packages/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,6 @@ func PackageCheckerMiddleware(logger *slog.Logger) MiddlewareHandler {
return nil, err
}

if err := pkg.Validate(); err != nil {
return nil, fmt.Errorf("invalid package %q: %w", path, err)
}

// Post-process each file in the package.
for _, file := range pkg.Files {
fname := file.Name
Expand Down
4 changes: 4 additions & 0 deletions examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ test.fast:
lint:
go run ../gnovm/cmd/gno lint -v .

.PHONY: fix
fix:
go run ../gnovm/cmd/gno fix -v .

.PHONY: test.sync
test.sync:
go run ../gnovm/cmd/gno test -v --update-golden-tests ./...
Expand Down
5 changes: 2 additions & 3 deletions examples/gno.land/p/demo/grc/grc20/token_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,8 @@ func TestMintOverflow(t *testing.T) {

func TestTransferFromAtomicity(t *testing.T) {
var (
owner = testutils.TestAddress("owner")
spender = testutils.TestAddress("spender")
recipient = testutils.TestAddress("recipient")
owner = testutils.TestAddress("owner")
spender = testutils.TestAddress("spender")

invalidRecipient = std.Address("")
)
Expand Down
10 changes: 5 additions & 5 deletions examples/gno.land/p/moul/collection/collection_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func TestUpdates(t *testing.T) {
p2 := &Person{Name: "Bob", Username: "bob456"}

id1 := c.Set(p1)
id2 := c.Set(p2)
c.Set(p2)

tests := []struct {
name string
Expand Down Expand Up @@ -254,7 +254,7 @@ func TestEdgeCases(t *testing.T) {
if entry == nil {
return false
}
id, err := seqid.FromString(entry.ID)
_, err := seqid.FromString(entry.ID)
if err != nil {
return false
}
Expand Down Expand Up @@ -330,7 +330,7 @@ func TestIndexOptions(t *testing.T) {
return v.(*Person).Username
}, UniqueIndex)

id1 := c.Set(&Person{Username: "Alice"})
c.Set(&Person{Username: "Alice"})
return c.Set(&Person{Username: "Alice"}) // Should fail
},
wantID: false,
Expand All @@ -342,7 +342,7 @@ func TestIndexOptions(t *testing.T) {
return v.(*Person).Email
}, UniqueIndex|CaseInsensitiveIndex)

id1 := c.Set(&Person{Email: "[email protected]"})
c.Set(&Person{Email: "[email protected]"})
return c.Set(&Person{Email: "[email protected]"}) // Should fail
},
wantID: false,
Expand Down Expand Up @@ -372,7 +372,7 @@ func TestIndexOptions(t *testing.T) {
return v.(*Person).Name
}, UniqueIndex|CaseInsensitiveIndex|SparseIndex)

id1 := c.Set(&Person{Name: "Alice"})
c.Set(&Person{Name: "Alice"})
return c.Set(&Person{Name: "ALICE"}) // Should fail
},
wantID: false,
Expand Down
8 changes: 4 additions & 4 deletions examples/gno.land/p/moul/helplink/helplink.gno
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ func (r Realm) prefix() string {
}

// local realm -> /realm
realm := string(r)
if strings.HasPrefix(realm, chainDomain) {
return strings.TrimPrefix(realm, chainDomain)
rlmstr := string(r)
if strings.HasPrefix(rlmstr, chainDomain) {
return strings.TrimPrefix(rlmstr, chainDomain)
}

// remote realm -> https://remote.land/realm
return "https://" + string(r)
return "https://" + rlmstr
}

// Func returns a markdown link for the specified function with optional
Expand Down
6 changes: 3 additions & 3 deletions examples/gno.land/p/moul/txlink/txlink.gno
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ func (r Realm) prefix() string {
}

// local realm -> /realm
realm := string(r)
if strings.HasPrefix(realm, chainDomain) {
return strings.TrimPrefix(realm, chainDomain)
rlm := string(r)
if strings.HasPrefix(rlm, chainDomain) {
return strings.TrimPrefix(rlm, chainDomain)
}

// remote realm -> https://remote.land/realm
Expand Down
1 change: 0 additions & 1 deletion examples/gno.land/r/demo/atomicswap/atomicswap_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,6 @@ func TestNewGRC20Swap_Refund(t *testing.T) {
rlm := std.DerivePkgAddr("gno.land/r/demo/atomicswap")
hashlock := sha256.Sum256([]byte("secret"))
hashlockHex := hex.EncodeToString(hashlock[:])
timelock := time.Now().Add(defaultTimelockDuration)

test20.PrivateLedger.Mint(sender, 100_000)
test20.PrivateLedger.Approve(sender, rlm, 70_000)
Expand Down
4 changes: 2 additions & 2 deletions examples/gno.land/r/demo/boards/z_5_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ func init() {
bid = cross(boards.CreateBoard)("test_board")
cross(boards.CreateThread)(bid, "First Post (title)", "Body of the first post. (body)")
pid = cross(boards.CreateThread)(bid, "Second Post (title)", "Body of the second post. (body)")
rid := cross(boards.CreateReply)(bid, pid, pid, "Reply of the second post")
_ = cross(boards.CreateReply)(bid, pid, pid, "Reply of the second post")
}

func main() {
testing.SetRealm(std.NewUserRealm(std.Address("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm")))
rid2 := cross(boards.CreateReply)(bid, pid, pid, "Second reply of the second post\n")
_ = cross(boards.CreateReply)(bid, pid, pid, "Second reply of the second post\n")
println(boards.Render("test_board/" + strconv.Itoa(int(pid))))
}

Expand Down
4 changes: 2 additions & 2 deletions examples/gno.land/r/demo/tests/z2_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
// When 2 or more realms in the frames, PreviousRealm returns the second to last
func main() {
var (
eoa = testutils.TestAddress("someone")
rTestsAddr = std.DerivePkgAddr("gno.land/r/demo/tests")
eoa = testutils.TestAddress("someone")
_ = std.DerivePkgAddr("gno.land/r/demo/tests")
)
testing.SetOriginCaller(eoa)
println("tests.GetPreviousRealm().Address(): ", cross(tests.GetPreviousRealm)().Address())
Expand Down
2 changes: 1 addition & 1 deletion examples/gno.land/r/gnoland/faucet/z3_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func main() {
controlleraddr1 = testutils.TestAddress("controller1")
controlleraddr2 = testutils.TestAddress("controller2")
testaddr1 = testutils.TestAddress("test1")
testaddr2 = testutils.TestAddress("test2")
_ = testutils.TestAddress("test2")
)
testing.SetRealm(std.NewUserRealm(adminaddr))
err := cross(faucet.AdminAddController)(controlleraddr1)
Expand Down
1 change: 0 additions & 1 deletion examples/gno.land/r/gnoland/monit/monit_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ func TestReset(t *testing.T) {
// Initial state check
initialCounter := counter
initialLastUpdate := lastUpdate
initialLastCaller := lastCaller
initialStatus := wd.Status()

// Call Incr to change the state
Expand Down
4 changes: 2 additions & 2 deletions examples/gno.land/r/gnoland/users/v1/z_0_prop1_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (
"gno.land/p/demo/testutils"
users "gno.land/r/gnoland/users/v1"
"gno.land/r/gov/dao"
"gno.land/r/gov/dao/v3/init"
daov3init "gno.land/r/gov/dao/v3/init"
susers "gno.land/r/sys/users"
)

// Test updating a name via GovDAO
var c std.Address = std.OriginCaller()

func init() {
init.InitWithUsers(c)
daov3init.InitWithUsers(c)

alice := testutils.TestAddress("alice")

Expand Down
4 changes: 2 additions & 2 deletions examples/gno.land/r/gnoland/users/v1/z_1_prop2_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"gno.land/p/demo/testutils"
users "gno.land/r/gnoland/users/v1"
"gno.land/r/gov/dao"
"gno.land/r/gov/dao/v3/init"
daov3init "gno.land/r/gov/dao/v3/init"
susers "gno.land/r/sys/users"
)

Expand All @@ -18,7 +18,7 @@ import (
var c std.Address = std.OriginCaller()

func init() {
init.InitWithUsers(c)
daov3init.InitWithUsers(c)

alice := testutils.TestAddress("alice")

Expand Down
4 changes: 2 additions & 2 deletions examples/gno.land/r/gnoland/users/z_0_filetest.gno
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"gno.land/p/demo/testutils"
"gno.land/r/gnoland/users"
"gno.land/r/gov/dao"
"gno.land/r/gov/dao/v3/init"
ini "gno.land/r/gov/dao/v3/init"
)

var (
Expand All @@ -17,7 +17,7 @@ var (
func init() {
testing.SetRealm(std.NewUserRealm(alice))
c := std.OriginCaller()
init.InitWithUsers(c)
ini.InitWithUsers(c)

pReq := users.ProposeNewRelease("gno.land/r/gnoland/users/v2", "This is a note!")

Expand Down
10 changes: 3 additions & 7 deletions examples/gno.land/r/gnoland/valopers_proposal/proposal_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ func TestValopers_ProposeNewValidator(t *testing.T) {
cross(valopers.UpdateKeepRunning)(g1user, false)
})

var valoper valopers.Valoper

urequire.NotPanics(t, func() {
valoper = valopers.GetByAddr(g1user)
valopers.GetByAddr(g1user)
})

// Send coins to be able to make a proposal
Expand Down Expand Up @@ -79,7 +77,7 @@ func TestValopers_ProposeNewValidator(t *testing.T) {
urequire.NotPanics(t, func() {
pr := NewValidatorProposalRequest(g1user)

pid := cross(dao.MustCreateProposal)(pr)
pid = cross(dao.MustCreateProposal)(pr)
})

proposal, err := cross(dao.GetProposal)(pid) // index starts from 0
Expand All @@ -99,10 +97,8 @@ func TestValopers_ProposeNewValidator(t *testing.T) {
// Send coins to be able to register a valoper
testing.SetOriginSend(std.Coins{std.NewCoin("ugnot", registerMinFee)})

var valoper valopers.Valoper

urequire.NotPanics(t, func() {
valoper = valopers.GetByAddr(g1user)
valopers.GetByAddr(g1user)
})

urequire.NotPanics(t, func() {
Expand Down
6 changes: 3 additions & 3 deletions examples/gno.land/r/gov/dao/v3/memberstore/memberstore.gno
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ func Render(string) string {

// Get gets the Members store
func Get() MembersByTier {
realm := std.CurrentRealm().PkgPath()
if !dao.InAllowedDAOs(realm) {
panic("this Realm is not allowed to get the Members data: " + realm)
currealm := std.CurrentRealm().PkgPath()
if !dao.InAllowedDAOs(currealm) {
panic("this Realm is not allowed to get the Members data: " + currealm)
}

return members
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"strconv"
"testing"

"gno.land/p/demo/avl"
"gno.land/p/demo/urequire"
)

Expand Down Expand Up @@ -115,7 +114,7 @@ func TestCreateMembers(t *testing.T) {
}

func addMembers(ms MembersByTier, c int, tier string) {
mt := avl.NewTree()
// mt := avl.NewTree() XXX
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

examples *_test.gno files were never type-checked, and mt isn't used.

ms.SetTier(tier)
for i := 0; i < c; i++ {
addr := std.Address(strconv.Itoa(i) + tier)
Expand Down
2 changes: 1 addition & 1 deletion examples/gno.land/r/leon/hor/datasource_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func TestItemRecord(t *testing.T) {
wantContent := `### [Test Realm](/r/demo/test)
This is a test realm in the Hall of Fame

by demo
by [@demo](/r/gnoland/users/v1:demo)

Submitted at Block #42

Expand Down
Loading
Loading