arr-ai / arrai

The ultimate data engine.
http://arr.ai
Apache License 2.0
20 stars 15 forks source link

Rebound name to a new value in grammar pattern matching #464

Open ChloePlanet opened 4 years ago

ChloePlanet commented 4 years ago

Description

Related pr #447.

If a new name is used, it works fine, even through the pattern matching machinery:

@> let (a: g, b: x) = (a: {://grammar.lang.wbnf.grammar: expr -> @:[-+] > @:[/*] > \d+; :}, b: 42);
 > let (:h) = (h: g);
 > {:h.expr:1+2*3:}
('': [107\'+'], @rule: 'expr', expr: [(expr: [('': 106\'1')]), ('': [109\'*'], expr: [('': 108\'2'), ('': 110\'3')])])

But it affects scenarios where a name is re-bound to a new value:

@> let (a: g, b: x) = (a: {://grammar.lang.wbnf.grammar: expr -> @:[-+] > @:[/*] > \d+; :}, b: 42);
 > let g = g;
 > {:g.expr:1+2*3:}

Expected behavior: output

('': [107\'+'], @rule: 'expr', expr: [(expr: [('': 106\'1')]), ('': [109\'*'], expr: [('': 108\'2'), ('': 110\'3')])])

Actual behavior: runtime: goroutine stack exceeds 1000000000-byte limit fatal error: stack overflow

runtime stack: runtime.throw(0x182c051, 0xe) /Users/zhangx19/.gvm/gos/go1.13/src/runtime/panic.go:774 +0x72 runtime.newstack() /Users/zhangx19/.gvm/gos/go1.13/src/runtime/stack.go:1046 +0x6e9 runtime.morestack() /Users/zhangx19/.gvm/gos/go1.13/src/runtime/asm_amd64.s:449 +0x8f

goroutine 1 [running]: runtime.assertE2I2(0x1751c60, 0x16ffee0, 0xc0003e3bc0, 0x0, 0x0, 0x0) /Users/zhangx19/.gvm/gos/go1.13/src/runtime/iface.go:482 +0x9e fp=0xc02089a328 sp=0xc02089a320 pc=0x100c20e github.com/arr-ai/hash.Interface(0x16ffee0, 0xc0003e3bc0, 0x0, 0x231a038) /Users/zhangx19/Code/go/pkg/mod/github.com/arr-ai/hash@v0.5.0/hash.go:12 +0x14a fp=0xc02089a3e8 sp=0xc02089a328 pc=0x11da04a github.com/arr-ai/frozen.KeyValue.Hash(...) /Users/zhangx19/Code/go/pkg/mod/github.com/arr-ai/frozen@v0.14.0/map.go:21 github.com/arr-ai/frozen.(*KeyValue).Hash(0xc00044b500, 0x0, 0xc00044b500)

:1 +0x4f fp=0xc02089a418 sp=0xc02089a3e8 pc=0x11ed33f github.com/arr-ai/hash.Interface(0x17b3600, 0xc00044b500, 0x0, 0xc02089a540) /Users/zhangx19/Code/go/pkg/mod/github.com/arr-ai/hash@v0.5.0/hash.go:14 +0xbef fp=0xc02089a4d8 sp=0xc02089a418 pc=0x11daaef github.com/arr-ai/frozen.newHasher(...) /Users/zhangx19/Code/go/pkg/mod/github.com/arr-ai/frozen@v0.14.0/hasher.go:19 github.com/arr-ai/frozen.(*node).get(0xc0005d6410, 0x17b3600, 0xc00044b500, 0xc00044b500, 0x100bb9b) /Users/zhangx19/Code/go/pkg/mod/github.com/arr-ai/frozen@v0.14.0/node.go:151 +0x3e fp=0xc02089a518 sp=0xc02089a4d8 pc=0x11e29ae github.com/arr-ai/frozen.Map.Get(0xc0005d6410, 0x1, 0x16ffee0, 0xc0003e3bc0, 0x1751be0, 0x16ffee0, 0x1) /Users/zhangx19/Code/go/pkg/mod/github.com/arr-ai/frozen@v0.14.0/map.go:122 +0x79 fp=0xc02089a570 sp=0xc02089a518 pc=0x11e00b9 github.com/arr-ai/arrai/rel.Scope.Get(0xc0005d6410, 0x1, 0x7ffeefbff2ba, 0x1, 0x1, 0x0, 0xc000020000) /Users/zhangx19/Code/go/src/github.com/arr-ai/arrai/rel/scope.go:64 +0x67 fp=0xc02089a5b8 sp=0xc02089a570 pc=0x14803f7 github.com/arr-ai/arrai/rel.IdentExpr.Eval(0x193aae0, 0xc000519520, 0x56, 0x1, 0x7ffeefbff2ba, 0x1, 0xc0005d6410, 0x1, 0xc00044b4e0, 0x18563f0, ...) /Users/zhangx19/Code/go/src/github.com/arr-ai/arrai/rel/expr_ident.go:39 +0x67 fp=0xc02089a6b0 sp=0xc02089a5b8 pc=0x1463f87 github.com/arr-ai/arrai/rel.(*IdentExpr).Eval(0xc0006d35c0, 0xc0005d6410, 0x1, 0xc0005d6410, 0x17b3600, 0xc00044b4e0, 0xc02089a7b0) :1 +0xa9 fp=0xc02089a750 sp=0xc02089a6b0 pc=0x14a51a9 github.com/arr-ai/arrai/rel.(*ArrowExpr).Eval(0xc000214dc0, 0xc0005d6410, 0x1, 0x1, 0x1936a60, 0xc000214dc0, 0xc000020001) /Users/zhangx19/Code/go/src/github.com/arr-ai/arrai/rel/expr_arrow.go:34 +0x63 fp=0xc02089a808 sp=0xc02089a750 pc=0x145c263 github.com/arr-ai/arrai/rel.IdentExpr.Eval(0x193aae0, 0xc000519520, 0x56, 0x1, 0x7ffeefbff2ba, 0x1, 0xc0005d6410, 0x1, 0xc00044b4c0, 0x18563f0, ...) /Users/zhangx19/Code/go/src/github.com/arr-ai/arrai/rel/expr_ident.go:43 +0x2cd fp=0xc02089a900 sp=0xc02089a808 pc=0x14641ed github.com/arr-ai/arrai/rel.(*IdentExpr).Eval(0xc0006d35c0, 0xc0005d6410, 0x1, 0xc0005d6410, 0x17b3600, 0xc00044b4c0, 0xc02089aa00) :1 +0xa9 fp=0xc02089a9a0 sp=0xc02089a900 pc=0x14a51a9 ... goroutine 9 [syscall]: os/signal.signal_recv(0x0) /Users/zhangx19/.gvm/gos/go1.13/src/runtime/sigqueue.go:144 +0x96 os/signal.loop() /Users/zhangx19/.gvm/gos/go1.13/src/os/signal/signal_unix.go:23 +0x22 created by os/signal.init.0 /Users/zhangx19/.gvm/gos/go1.13/src/os/signal/signal_unix.go:29 +0x41 exit status 2 ```