Skip to content

Commit

Permalink
fix(gnovm): revert "top sort var/const globals (#1854)"
Browse files Browse the repository at this point in the history
This reverts commit 3b95486.
  • Loading branch information
thehowl committed Apr 19, 2024
1 parent 5a976ef commit 1ff2ef3
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 341 deletions.
19 changes: 1 addition & 18 deletions gnovm/pkg/gnolang/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,23 +158,6 @@ type Attributes struct {
data map[interface{}]interface{} // not persisted
}

func (attr *Attributes) Copy() Attributes {
if attr == nil {
return Attributes{}
}

data := make(map[interface{}]interface{})
for k, v := range attr.data {
data[k] = v
}

return Attributes{
Line: attr.Line,
Label: attr.Label,
data: data,
}
}

func (attr *Attributes) GetLine() int {
return attr.Line
}
Expand Down Expand Up @@ -1631,7 +1614,7 @@ func (sb *StaticBlock) GetPathForName(store Store, n Name) ValuePath {
bp = bp.GetParentNode(store)
gen++
if 0xff < gen {
panic("GetPathForName: value path depth overflow")
panic("value path depth overflow")
}
}
}
Expand Down
35 changes: 19 additions & 16 deletions gnovm/pkg/gnolang/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,11 @@ import (
// Anything predefined or preprocessed here get skipped during the Preprocess
// phase.
func PredefineFileSet(store Store, pn *PackageNode, fset *FileSet) {
for _, fn := range fset.Files {
decls, err := sortValueDeps(fn.Decls)
if err != nil {
panic(err)
}

fn.Decls = decls
}

// First, initialize all file nodes and connect to package node.
for _, fn := range fset.Files {
SetNodeLocations(pn.PkgPath, string(fn.Name), fn)
fn.InitStaticBlock(fn, pn)
}

// NOTE: much of what follows is duplicated for a single *FileNode
// in the main Preprocess translation function. Keep synced.

Expand All @@ -40,22 +30,29 @@ func PredefineFileSet(store Store, pn *PackageNode, fset *FileSet) {
d := fn.Decls[i]
switch d.(type) {
case *ImportDecl:
if d.GetAttribute(ATTR_PREDEFINED) != true {
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
}
}
}
}

// Predefine all type decls decls.
for _, fn := range fset.Files {
for i := 0; i < len(fn.Decls); i++ {
d := fn.Decls[i]
switch d.(type) {
case *TypeDecl:
if d.GetAttribute(ATTR_PREDEFINED) != true {
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
Expand All @@ -69,21 +66,27 @@ func PredefineFileSet(store Store, pn *PackageNode, fset *FileSet) {
d := fn.Decls[i]
switch d.(type) {
case *FuncDecl:
if d.GetAttribute(ATTR_PREDEFINED) != true {
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
}
}
}
}

// Finally, predefine other decls and
// preprocess ValueDecls..
for _, fn := range fset.Files {
for i := 0; i < len(fn.Decls); i++ {
d := fn.Decls[i]
if d.GetAttribute(ATTR_PREDEFINED) != true {
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
Expand Down
245 changes: 0 additions & 245 deletions gnovm/pkg/gnolang/value_decl_dep_graph.go

This file was deleted.

14 changes: 0 additions & 14 deletions gnovm/tests/files/var18.gno

This file was deleted.

14 changes: 0 additions & 14 deletions gnovm/tests/files/var19.gno

This file was deleted.

Loading

0 comments on commit 1ff2ef3

Please sign in to comment.