Comments (7)
Thanks for the report! Yes, this doesn't look good. Almost certainly related to the resolver rewrite. I'll try to get to this in the next few days.
from goawk.
@xonixx Does #184 look reasonable to you? If so, I'll merge and release 1.23.2.
from goawk.
Hey @benhoyt! Based on your comment
When the AWK code defines mutually-recursive functions, the topological
sort can't help us.
I was wondering if topological sort is needed at all. I did a small experiment and it looks like it's not needed.
I disabled the part that calls topoSort
And looks like the tests suite is overall passing (failed: 3, passed 3419), except for two cases
In these two cases I think it still catches the error, it's just the error text (and position) changes.
from goawk.
Thanks @xonixx. I decided to merge #184 to fix the immediate issue, but I'll reopen this one to look into the "do we actually need topoSort" issue further.
from goawk.
Okay, the reason you need topological sorting based on the call graph order is when you have multiple levels (more than two levels) of functions that only pass their arguments down:
function f1(a) { f2(a) }
function f2(b) { f3(b) }
function f3(c) { f4(c) }
function f4(d) { f5(d) }
function f5(i) { i[1]=42 }
BEGIN { x[1]=3; f5(x); print x[1] }
I've added a couple of tests that exercise this behaviour to the test suite, to avoid regressions. #185
from goawk.
Well, but topological sort can sort nodes only when there are no loops in the call graph. Since in the presence of mutual recursion there are loops in the graph I'm not sure that topoSort can help at all. I've played a bit with your example:
function f1(a) { if (0) f5(z1); f2(a) }
function f2(b) { if (0) f4(z2); f3(b) }
function f3(c) { if (0) f3(z3); f4(c) }
function f4(d) { if (0) f2(z4); f5(d) }
function f5(i) { if (0) f1(z5); i[1]=42 }
BEGIN { x[1]=3; f5(x); print x[1] }
Still fails:
$ ../../proj/gron.awk/soft/goawk1.23.2 -f delme.awk
42
$ ../../proj/gron.awk/soft/goawk1.23.2 -f delme.awk
42
$ ../../proj/gron.awk/soft/goawk1.23.2 -f delme.awk
panic: internal error: found scalar when expecting array "z3" [recovered]
panic: interface conversion: interface {} is string, not *compiler.compileError [recovered]
panic: interface conversion: interface {} is *runtime.TypeAssertionError, not *ast.PositionError
goroutine 1 [running]:
github.com/benhoyt/goawk/parser.ParseProgram.func1()
/home/ben/h/goawk/parser/parser.go:70 +0xf4
panic({0x54b7c0, 0xc0000a09f0})
/home/ben/sdk/go1.20.4/src/runtime/panic.go:884 +0x213
github.com/benhoyt/goawk/internal/compiler.Compile.func1()
/home/ben/h/goawk/internal/compiler/compiler.go:66 +0x78
panic({0x544880, 0xc00009e680})
/home/ben/sdk/go1.20.4/src/runtime/panic.go:884 +0x213
github.com/benhoyt/goawk/internal/compiler.(*compiler).arrayInfo(0x54a2c0?, {0xc0000b409a, 0x2})
/home/ben/h/goawk/internal/compiler/compiler.go:206 +0xd4
github.com/benhoyt/goawk/internal/compiler.(*compiler).expr(0xc0000e5640, {0x59e9f8?, 0xc0000b21c0?})
/home/ben/h/goawk/internal/compiler/compiler.go:895 +0x356a
github.com/benhoyt/goawk/internal/compiler.(*compiler).stmt(0xc0000e5640, {0x59ed00?, 0xc0000a04b0?})
/home/ben/h/goawk/internal/compiler/compiler.go:310 +0xd9f
github.com/benhoyt/goawk/internal/compiler.(*compiler).stmts(...)
/home/ben/h/goawk/internal/compiler/compiler.go:221
github.com/benhoyt/goawk/internal/compiler.(*compiler).stmt(0xc0000e5640, {0x59edc0?, 0xc0000cc700})
/home/ben/h/goawk/internal/compiler/compiler.go:335 +0x31c9
github.com/benhoyt/goawk/internal/compiler.(*compiler).stmts(...)
/home/ben/h/goawk/internal/compiler/compiler.go:221
github.com/benhoyt/goawk/internal/compiler.Compile(0xc0000cc930)
/home/ben/h/goawk/internal/compiler/compiler.go:104 +0x1709
github.com/benhoyt/goawk/parser.ParseProgram({0xc0000dc000?, 0x7ffc83d26ea8?, 0x9?}, 0xc0000e5dd0)
/home/ben/h/goawk/parser/parser.go:91 +0x19b
main.main()
/home/ben/h/goawk/goawk.go:269 +0x1fd3
$ gawk -f delme.awk
42
$ mawk -f delme.awk
42
Also note, how it passes or fails sporadically with GoAWK. I think this is due to randomized map iteration in Go.
from goawk.
Very good observation, thanks @xonixx! I've opened #186
from goawk.
Related Issues (20)
- Ensure we use value of FS at the time the record was read
- Allow outputting to /dev/stderr on Windows HOT 14
- Missing support for json input files HOT 1
- CSV - loss of double quote when dataset is updated HOT 2
- After Go 1.21 is out, build with PGO enabled HOT 1
- close() on pipe command does not return exit status HOT 2
- close() on input pipe does not cleanup child process HOT 5
- system() always returns -1 if process exits due to signal
- fflush() stops on first flush error HOT 2
- Add support for new \u Unicode escape sequence
- Windows error: flag provided but not defined: -encodedCommand HOT 3
- goawk CSV mode ignores specified field separator HOT 2
- Allow line break between `}` and `while` HOT 1
- parser: Discriminate between constant and dynamic regexps HOT 3
- Support for network? HOT 3
- What's the purpose of `testdata/echo` HOT 7
- {} behaves like 1, END{} doesn't exhaust input HOT 2
- Support for %i in format strings. HOT 3
- srand() initialization without an argument. HOT 2
- Test failures on Linux/i386 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from goawk.