mvdan / goreduce

Reduce Go programs
BSD 3-Clause "New" or "Revised" License
216 stars 7 forks source link

panic: could not remove name declaration #28

Open dkegel-fastly opened 3 years ago

dkegel-fastly commented 3 years ago

Now, uh, do I use goreduce to find the minimal source that causes the goreduce panic? :-)

panic: could not remove name declaration

goroutine 1 [running]:
main.(*reducer).removeDecl(0xc00012c7e0, 0xc0000681a0, 0xc001121500)
    /Users/dkegel/go/pkg/mod/mvdan.cc/goreduce@v0.0.0-20201225105240-9763df993ebd/rules.go:509 +0x645
main.(*reducer).afterDelete(0xc00012c7e0, 0xc0011215e8, 0x1, 0x1)
    /Users/dkegel/go/pkg/mod/mvdan.cc/goreduce@v0.0.0-20201225105240-9763df993ebd/rules.go:755 +0x2d0
main.(*reducer).removeStmt(0xc00012c7e0, 0xc00007f058)
    /Users/dkegel/go/pkg/mod/mvdan.cc/goreduce@v0.0.0-20201225105240-9763df993ebd/rules.go:598 +0x2b7
main.(*reducer).reduceNode(0xc00012c7e0, 0x1272320, 0xc00007f058, 0xc000197301)
    /Users/dkegel/go/pkg/mod/mvdan.cc/goreduce@v0.0.0-20201225105240-9763df993ebd/rules.go:78 +0xc9c
main.(*walker).walkSingle(0xc00012c8d8, 0x1272320, 0xc00007f058)
    /Users/dkegel/go/pkg/mod/mvdan.cc/goreduce@v0.0.0-20201225105240-9763df993ebd/walk.go:60 +0x5b
main.(*walker).walk(0xc00012c8d8, 0x128c200, 0xc00007f830, 0xc0005b9a40)
    /Users/dkegel/go/pkg/mod/mvdan.cc/goreduce@v0.0.0-20201225105240-9763df993ebd/walk.go:27 +0xaa
main.(*reducer).reduceLoop(0xc00012c7e0, 0x0)
    /Users/dkegel/go/pkg/mod/mvdan.cc/goreduce@v0.0.0-20201225105240-9763df993ebd/reduce.go:254 +0x185
main.reduce(0x7ffeefbffb9e, 0x1, 0x7ffeefbffb28, 0xf, 0x13228b0, 0xc000010020, 0x7ffeefbffb3d, 0x60, 0x0, 0x0)
    /Users/dkegel/go/pkg/mod/mvdan.cc/goreduce@v0.0.0-20201225105240-9763df993ebd/reduce.go:146 +0xa28
main.main()
    /Users/dkegel/go/pkg/mod/mvdan.cc/goreduce@v0.0.0-20201225105240-9763df993ebd/main.go:58 +0x135
dkegel-fastly commented 3 years ago

Happy to rerun with a debugging branch.

Here's the output with -v (it changes a bit on each run):

fooi.go:61: removed const decl (first try)
bar.go:3: removed const decl (first try)
bletch.go:168: removed const decl (first try)
panic: could not remove name declaration

goroutine 1 [running]:
main.(*reducer).removeDecl(0xc00012e7e0, 0xc0003699c0, 0xc00112d500)
    /Users/dkegel/go/pkg/mod/mvdan.cc/goreduce@v0.0.0-20201225105240-9763df993ebd/rules.go:509 +0x645
...

although once there was something worse:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x12564e7]

goroutine 1 [running]:
main.(*reducer).replaceStmts(0xc0001507e0, 0x1326560, 0xc00013f5c0, 0x0, 0x0, 0x0, 0x20)
    /Users/dkegel/go/pkg/mod/mvdan.cc/goreduce@v0.0.0-20201225105240-9763df993ebd/rules.go:861 +0xe7
main.(*reducer).removeDecl(0xc0001507e0, 0xc0001410e0, 0xc000f2d500)
    /Users/dkegel/go/pkg/mod/mvdan.cc/goreduce@v0.0.0-20201225105240-9763df993ebd/rules.go:494 +0x585
main.(*reducer).afterDelete(0xc0001507e0, 0xc000f2d5e8, 0x1, 0x1)
    /Users/dkegel/go/pkg/mod/mvdan.cc/goreduce@v0.0.0-20201225105240-9763df993ebd/rules.go:755 +0x2d0
main.(*reducer).removeStmt(0xc0001507e0, 0xc000113e08)
    /Users/dkegel/go/pkg/mod/mvdan.cc/goreduce@v0.0.0-20201225105240-9763df993ebd/rules.go:598 +0x2b7
main.(*reducer).reduceNode(0xc0001507e0, 0x1272320, 0xc000113e08, 0xc000244001)
...
mvdan commented 3 years ago

It shouldn't come as a surprise that I don't develop this project actively at the moment :) This sounds like a syntax edge case that we don't handle properly.

Happy to review a patch and test if you'd like to look into it. ~Assuming that you're using the rewrite/substitution feature, I think https://github.com/rsc/rf is a better design long-term, but it's quite experimental at the moment.~

Edit: I got confused with a different project. Ignore that last line. goreduce and rf are entirely different.