-
-
Notifications
You must be signed in to change notification settings - Fork 84
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
GoAWK 1.23.X fails on gron.awk #183
Comments
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. |
When the AWK code defines mutually-recursive functions, the topological sort can't help us. So define all funcInfos in the initial call-graph pass before doing any resolver passes. This avoids the "undefined function" error in those cases. Add a minimal test for this, and also add a test of parsing/using the gron.awk code, as it's a nice, fairly complex test case. Fixes #183. Thanks @xonixx for the bug report!
Hey @benhoyt! Based on your comment
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 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. |
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:
I've added a couple of tests that exercise this behaviour to the test suite, to avoid regressions. #185 |
Per #183 (comment), and given the two passes we do, the current test suite doesn't have any tests which require topoSort (topological sort of functions based on the call graph). Add a couple of these tests in case of regressions. If you comment out the `topoSort` call, these tests fail with something like: ``` $ go run . -f t.awk panic: internal error: found scalar when expecting array "c" [recovered] panic: interface conversion: interface {} is string, not *compiler.compileError [recovered] panic: interface conversion: interface {} is *runtime.TypeAssertionError, not *ast.PositionError ... $ cat t.awk 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] } ```
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:
Also note, how it passes or fails sporadically with GoAWK. I think this is due to randomized map iteration in Go. |
https://github.com/xonixx/gron.awk
Correct:
Bug:
Also, note how the error changes from run to run.
I think this has something to do with the resolver rewrite #175
The text was updated successfully, but these errors were encountered: