From fb3e5228671afa4246d25f52a1a28ccba701b718 Mon Sep 17 00:00:00 2001 From: Petar Dambovaliev Date: Sat, 11 May 2024 13:08:49 +0200 Subject: [PATCH 1/7] save --- gnovm/pkg/gnolang/preprocess.go | 30 ++++++++++++++++++++++++++---- gnovm/tests/files/var19.gno | 14 ++++++++++++++ gnovm/tests/files/var20.gno | 17 +++++++++++++++++ 3 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 gnovm/tests/files/var19.gno create mode 100644 gnovm/tests/files/var20.gno diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index 12cf78cb7fa..93423f3a1da 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -81,15 +81,37 @@ func PredefineFileSet(store Store, pn *PackageNode, fset *FileSet) { // Finally, predefine other decls and // preprocess ValueDecls.. for _, fn := range fset.Files { - for i := 0; i < len(fn.Decls); i++ { + lenDecls := len(fn.Decls) + for i := 0; i < lenDecls; i++ { d := fn.Decls[i] if d.GetAttribute(ATTR_PREDEFINED) == true { // skip declarations already predefined (e.g. // through recursion for a dependent) } else { - // recursively predefine dependencies. - d2, _ := predefineNow(store, fn, d) - fn.Decls[i] = d2 + if vd, ok := d.(*ValueDecl); ok && len(vd.NameExprs) > 1 { + split := make([]Decl, len(vd.NameExprs)) + + for j := 0; j < len(vd.NameExprs); j++ { + base := vd.Copy().(*ValueDecl) + base.NameExprs = NameExprs{NameExpr{ + Attributes: base.NameExprs[j].Attributes, + Path: base.NameExprs[j].Path, + Name: base.NameExprs[j].Name, + }} + base.Values = Exprs{base.Values[j].Copy().(Expr)} + + split[j], _ = predefineNow(store, fn, base) + } + + fn.Decls = append(fn.Decls[:i], append(split, fn.Decls[i+1:]...)...) + i += len(vd.NameExprs) + lenDecls += len(vd.NameExprs) - 1 + } else { + // recursively predefine dependencies. + d2, _ := predefineNow(store, fn, d) + + fn.Decls[i] = d2 + } } } } diff --git a/gnovm/tests/files/var19.gno b/gnovm/tests/files/var19.gno new file mode 100644 index 00000000000..f26c230de0d --- /dev/null +++ b/gnovm/tests/files/var19.gno @@ -0,0 +1,14 @@ +package main + +func main() { + println(a) + println(b) + println(c) +} + +var a, b, c = 1, a + 1, b + 1 + +// Output: +// 1 +// 2 +// 3 diff --git a/gnovm/tests/files/var20.gno b/gnovm/tests/files/var20.gno new file mode 100644 index 00000000000..1aec4792fcb --- /dev/null +++ b/gnovm/tests/files/var20.gno @@ -0,0 +1,17 @@ +package main + +func main() { + println(a) + println(b) + println(c) + println(d) +} + +var a, b, c = 1, a + d, 3 +var d = a + +// Output: +// 1 +// 2 +// 3 +// 1 From 9f59ad56718c2e253d9b76d1257e1df8b436612c Mon Sep 17 00:00:00 2001 From: Petar Dambovaliev Date: Sat, 11 May 2024 21:32:39 +0200 Subject: [PATCH 2/7] save --- gnovm/pkg/gnolang/preprocess.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index 93423f3a1da..a44fa813977 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -98,12 +98,15 @@ func PredefineFileSet(store Store, pn *PackageNode, fset *FileSet) { Path: base.NameExprs[j].Path, Name: base.NameExprs[j].Name, }} - base.Values = Exprs{base.Values[j].Copy().(Expr)} + + if j < len(base.Values) { + base.Values = Exprs{base.Values[j].Copy().(Expr)} + } split[j], _ = predefineNow(store, fn, base) } - fn.Decls = append(fn.Decls[:i], append(split, fn.Decls[i+1:]...)...) + fn.Decls = append(fn.Decls[:i], append(split, fn.Decls[i+1:]...)...) //nolint:makezero i += len(vd.NameExprs) lenDecls += len(vd.NameExprs) - 1 } else { From 591369eedf08bdc4e6e4c56f13b7982a3692fd1d Mon Sep 17 00:00:00 2001 From: Petar Dambovaliev Date: Sat, 11 May 2024 21:36:26 +0200 Subject: [PATCH 3/7] save --- .github/golangci.yml | 1 - gnovm/pkg/gnolang/preprocess.go | 2 +- tm2/pkg/crypto/bip39/bip39.go | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/golangci.yml b/.github/golangci.yml index 8b38691ec75..8ad6bc6873d 100644 --- a/.github/golangci.yml +++ b/.github/golangci.yml @@ -26,7 +26,6 @@ linters: - predeclared # Finds code that shadows one of Go's predeclared identifiers - nolintlint # Ill-formed or insufficient nolint directives - misspell # Misspelled English words in comments - - makezero # Finds slice declarations with non-zero initial length - importas # Enforces consistent import aliases - gosec # Security problems - gofmt # Whether the code was gofmt-ed diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index a44fa813977..e848e347fec 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -106,7 +106,7 @@ func PredefineFileSet(store Store, pn *PackageNode, fset *FileSet) { split[j], _ = predefineNow(store, fn, base) } - fn.Decls = append(fn.Decls[:i], append(split, fn.Decls[i+1:]...)...) //nolint:makezero + fn.Decls = append(fn.Decls[:i], append(split, fn.Decls[i+1:]...)...) i += len(vd.NameExprs) lenDecls += len(vd.NameExprs) - 1 } else { diff --git a/tm2/pkg/crypto/bip39/bip39.go b/tm2/pkg/crypto/bip39/bip39.go index eb1dbe55ee4..9cc5fb6e8e2 100644 --- a/tm2/pkg/crypto/bip39/bip39.go +++ b/tm2/pkg/crypto/bip39/bip39.go @@ -201,7 +201,7 @@ func addChecksum(data []byte) []byte { func padByteSlice(slice []byte, length int) []byte { newSlice := make([]byte, length-len(slice)) - return append(newSlice, slice...) //nolint:makezero + return append(newSlice, slice...) } func validateEntropyBitSize(bitSize int) error { From 055fd6f9d5a9e12defa99c13ade567fe5f936ee4 Mon Sep 17 00:00:00 2001 From: Petar Dambovaliev Date: Sat, 11 May 2024 21:43:21 +0200 Subject: [PATCH 4/7] save --- gnovm/pkg/gnolang/preprocess.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index e848e347fec..26c9ad531aa 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -88,7 +88,7 @@ func PredefineFileSet(store Store, pn *PackageNode, fset *FileSet) { // skip declarations already predefined (e.g. // through recursion for a dependent) } else { - if vd, ok := d.(*ValueDecl); ok && len(vd.NameExprs) > 1 { + if vd, ok := d.(*ValueDecl); ok && len(vd.NameExprs) > 1 && len(vd.Values) == len(vd.NameExprs) { split := make([]Decl, len(vd.NameExprs)) for j := 0; j < len(vd.NameExprs); j++ { From 4dfa18da0a2ac091613e22f1ec14d2d34988e992 Mon Sep 17 00:00:00 2001 From: Petar Dambovaliev Date: Tue, 21 May 2024 16:50:21 +0200 Subject: [PATCH 5/7] save --- .github/golangci.yml | 2 +- gnovm/pkg/gnolang/preprocess.go | 73 ++++++++++++++++++--------------- tm2/pkg/crypto/bip39/bip39.go | 2 +- 3 files changed, 41 insertions(+), 36 deletions(-) diff --git a/.github/golangci.yml b/.github/golangci.yml index 8ad6bc6873d..95547e33cac 100644 --- a/.github/golangci.yml +++ b/.github/golangci.yml @@ -37,7 +37,7 @@ linters: - gofumpt # Stricter gofmt - unused # Checks Go code for unused constants, variables, functions and types - gomodguard # Enforces an allow and block list for direct Go module dependencies - + - makezero # Finds slice declarations with non-zero initial length linters-settings: gofmt: simplify: true diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index 26c9ad531aa..239b533b0a2 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -34,11 +34,12 @@ func PredefineFileSet(store Store, pn *PackageNode, fset *FileSet) { // skip declarations already predefined // (e.g. through recursion for a // dependent) - } else { - // recursively predefine dependencies. - d2, _ := predefineNow(store, fn, d) - fn.Decls[i] = d2 + continue } + + // recursively predefine dependencies. + d2, _ := predefineNow(store, fn, d) + fn.Decls[i] = d2 } } } @@ -52,11 +53,12 @@ func PredefineFileSet(store Store, pn *PackageNode, fset *FileSet) { // skip declarations already predefined // (e.g. through recursion for a // dependent) - } else { - // recursively predefine dependencies. - d2, _ := predefineNow(store, fn, d) - fn.Decls[i] = d2 + continue } + + // recursively predefine dependencies. + d2, _ := predefineNow(store, fn, d) + fn.Decls[i] = d2 } } } @@ -70,11 +72,12 @@ func PredefineFileSet(store Store, pn *PackageNode, fset *FileSet) { // skip declarations already predefined // (e.g. through recursion for a // dependent) - } else { - // recursively predefine dependencies. - d2, _ := predefineNow(store, fn, d) - fn.Decls[i] = d2 + continue } + + // recursively predefine dependencies. + d2, _ := predefineNow(store, fn, d) + fn.Decls[i] = d2 } } } @@ -87,35 +90,37 @@ func PredefineFileSet(store Store, pn *PackageNode, fset *FileSet) { if d.GetAttribute(ATTR_PREDEFINED) == true { // skip declarations already predefined (e.g. // through recursion for a dependent) - } else { - if vd, ok := d.(*ValueDecl); ok && len(vd.NameExprs) > 1 && len(vd.Values) == len(vd.NameExprs) { - split := make([]Decl, len(vd.NameExprs)) + continue + } - for j := 0; j < len(vd.NameExprs); j++ { - base := vd.Copy().(*ValueDecl) - base.NameExprs = NameExprs{NameExpr{ - Attributes: base.NameExprs[j].Attributes, - Path: base.NameExprs[j].Path, - Name: base.NameExprs[j].Name, - }} + if vd, ok := d.(*ValueDecl); ok && len(vd.NameExprs) > 1 && len(vd.Values) == len(vd.NameExprs) { + split := make([]Decl, len(vd.NameExprs)) - if j < len(base.Values) { - base.Values = Exprs{base.Values[j].Copy().(Expr)} - } + for j := 0; j < len(vd.NameExprs); j++ { + base := vd.Copy().(*ValueDecl) + base.NameExprs = NameExprs{NameExpr{ + Attributes: base.NameExprs[j].Attributes, + Path: base.NameExprs[j].Path, + Name: base.NameExprs[j].Name, + }} - split[j], _ = predefineNow(store, fn, base) + if j < len(base.Values) { + base.Values = Exprs{base.Values[j].Copy().(Expr)} } - fn.Decls = append(fn.Decls[:i], append(split, fn.Decls[i+1:]...)...) - i += len(vd.NameExprs) - lenDecls += len(vd.NameExprs) - 1 - } else { - // recursively predefine dependencies. - d2, _ := predefineNow(store, fn, d) - - fn.Decls[i] = d2 + split[j], _ = predefineNow(store, fn, base) } + + fn.Decls = append(fn.Decls[:i], append(split, fn.Decls[i+1:]...)...) //nolint:makezero + i += len(vd.NameExprs) + lenDecls += len(vd.NameExprs) - 1 + continue } + + // recursively predefine dependencies. + d2, _ := predefineNow(store, fn, d) + + fn.Decls[i] = d2 } } } diff --git a/tm2/pkg/crypto/bip39/bip39.go b/tm2/pkg/crypto/bip39/bip39.go index 9cc5fb6e8e2..eb1dbe55ee4 100644 --- a/tm2/pkg/crypto/bip39/bip39.go +++ b/tm2/pkg/crypto/bip39/bip39.go @@ -201,7 +201,7 @@ func addChecksum(data []byte) []byte { func padByteSlice(slice []byte, length int) []byte { newSlice := make([]byte, length-len(slice)) - return append(newSlice, slice...) + return append(newSlice, slice...) //nolint:makezero } func validateEntropyBitSize(bitSize int) error { From dd8124b6e9c2b6367db5a1db42ea1b547dee6cab Mon Sep 17 00:00:00 2001 From: Petar Dambovaliev Date: Tue, 21 May 2024 16:51:42 +0200 Subject: [PATCH 6/7] save --- .github/golangci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/golangci.yml b/.github/golangci.yml index 95547e33cac..2a845207278 100644 --- a/.github/golangci.yml +++ b/.github/golangci.yml @@ -26,6 +26,7 @@ linters: - predeclared # Finds code that shadows one of Go's predeclared identifiers - nolintlint # Ill-formed or insufficient nolint directives - misspell # Misspelled English words in comments + - makezero # Finds slice declarations with non-zero initial length - importas # Enforces consistent import aliases - gosec # Security problems - gofmt # Whether the code was gofmt-ed @@ -37,7 +38,6 @@ linters: - gofumpt # Stricter gofmt - unused # Checks Go code for unused constants, variables, functions and types - gomodguard # Enforces an allow and block list for direct Go module dependencies - - makezero # Finds slice declarations with non-zero initial length linters-settings: gofmt: simplify: true From 9b64257d78b2fe3ac5a58f9deb04d6e76a24e9be Mon Sep 17 00:00:00 2001 From: Petar Dambovaliev Date: Thu, 12 Sep 2024 05:04:05 +0700 Subject: [PATCH 7/7] save --- gnovm/pkg/gnolang/preprocess.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/gnovm/pkg/gnolang/preprocess.go b/gnovm/pkg/gnolang/preprocess.go index e3f37d97eb9..9168fc6f7c1 100644 --- a/gnovm/pkg/gnolang/preprocess.go +++ b/gnovm/pkg/gnolang/preprocess.go @@ -95,8 +95,7 @@ func PredefineFileSet(store Store, pn *PackageNode, fset *FileSet) { // Finally, predefine other decls and // preprocess ValueDecls.. for _, fn := range fset.Files { - lenDecls := len(fn.Decls) - for i := 0; i < lenDecls; i++ { + for i := 0; i < len(fn.Decls); i++ { d := fn.Decls[i] if d.GetAttribute(ATTR_PREDEFINED) == true { // skip declarations already predefined (e.g. @@ -124,7 +123,6 @@ func PredefineFileSet(store Store, pn *PackageNode, fset *FileSet) { fn.Decls = append(fn.Decls[:i], append(split, fn.Decls[i+1:]...)...) //nolint:makezero i += len(vd.NameExprs) - lenDecls += len(vd.NameExprs) - 1 continue }