arr-ai / arrai

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

Non-deterministic behaviour #555

Closed anzboi closed 4 years ago

anzboi commented 4 years ago

Please do not post any internal, closed source snippets on this public issue tracker!

Description

I was creating a semver parser and found my resulting arrai code had some non-deterministic behaviour.

Source code here

Steps to Reproduce

  1. Copy the two arrai files from the above source (semver.arrai and script.arrai)
  2. Run arrai script.arrai multiple times
  3. See three distinct outputs

Expected behavior

script.arrai should produce a consistent representation of the semver string v1.2.3-rc1.f2

Expected output

$ arrai script.arrai
(build: {}, maj: 1, min: 2, patch: 3, prerelease: 'rc1.f2', string: 'v1.2.3-rc1.f2')

Actual behavior

On top of the correct output, I saw two other incorrect outputs

Case 2: Did not panic but the prerelease string contains a hex encoded character

$ arrai script.arrai
(build: {}, maj: 1, min: 2, patch: 3, prerelease: 'rc1\x00f2', string: 'v1.2.3-rc1.f2')

Case 3: panics with index out of range

$ arrai script.arrai
panic: runtime error: index out of range [10] with length 10

goroutine 1 [running]:
github.com/arr-ai/arrai/rel.AsString(0x19d2960, 0xc0002ff780, 0xc0002ea0b0, 0x19d2960, 0xc0002ff780, 0x28, 0x180a960)
        /Users/cantosd/github.com/arr-ai/arrai/rel/value_set_str.go:54 +0x402
github.com/arr-ai/arrai/rel.NewSet(0xc0006c1180, 0x5, 0x5, 0xc00022dbc0, 0xc0002fec00)
        /Users/cantosd/github.com/arr-ai/arrai/rel/value_set_generic.go:46 +0x848
github.com/arr-ai/arrai/rel.CanonicalSet(0x19d2960, 0xc0002fec00, 0xc0002ea0d0, 0x19d2960)
        /Users/cantosd/github.com/arr-ai/arrai/rel/value_set_generic.go:90 +0x23d
github.com/arr-ai/arrai/rel.Union(0x19d2960, 0xc0002fec00, 0x19d2a20, 0xc00065f560, 0x1, 0x19d2a20)
        /Users/cantosd/github.com/arr-ai/arrai/rel/ops_set.go:41 +0x125
github.com/arr-ai/arrai/rel.newSetBinExprNoError.func1(0x19d2a20, 0xc00065ed00, 0x19d2a20, 0xc00065f560, 0xc00065f560, 0x19cea01, 0xc00065f560, 0x0)
        /Users/cantosd/github.com/arr-ai/arrai/rel/expr_rel.go:88 +0x4d
github.com/arr-ai/arrai/rel.newSetBinExpr.func1(0x19cea60, 0xc00065ed00, 0x19cea60, 0xc00065f560, 0xc0006b8000, 0x5, 0x0, 0x26d7d38, 0x7, 0xc000cfe3a0)
        /Users/cantosd/github.com/arr-ai/arrai/rel/expr_rel.go:78 +0x2c0
github.com/arr-ai/arrai/rel.(*BinExpr).Eval(0xc0000c8380, 0xc0006b8000, 0x5, 0x2, 0xc0006b8000, 0x5, 0x0)
        /Users/cantosd/github.com/arr-ai/arrai/rel/expr_binary.go:286 +0x12c
github.com/arr-ai/arrai/rel.PatternExprPair.Eval(...)
        /Users/cantosd/github.com/arr-ai/arrai/rel/pattern_expr_pair.go:26
github.com/arr-ai/arrai/rel.CondPatternControlVarExpr.Eval(0x19c5ee0, 0xc00016f4c0, 0x1fd, 0x57, 0x19c3560, 0xc0007b8660, 0xc000da69c0, 0x2, 0x2, 0xc0006b5810, ...)
        /Users/cantosd/github.com/arr-ai/arrai/rel/expr_cond_pattern_control_var.go:58 +0x21f
github.com/arr-ai/arrai/rel.Closure.CallAll(0xc0006b5400, 0x2, 0xc000da7340, 0x19ce560, 0xc00022c5a0, 0x19ce760, 0xc00065e7c0, 0x19ce760, 0xc00065e900)
        /Users/cantosd/github.com/arr-ai/arrai/rel/value_set_closure.go:144 +0x1fc
github.com/arr-ai/arrai/rel.SetCall(0x19d2720, 0xc00065e900, 0x19ce560, 0xc00022c5a0, 0xc00065e900, 0xc00093ec01, 0x1e, 0x1)
        /Users/cantosd/github.com/arr-ai/arrai/rel/value.go:133 +0x63
github.com/arr-ai/arrai/rel.Call(0x19ce760, 0xc00065e900, 0x19ce560, 0xc00022c5a0, 0xc0006b4dc0, 0x3, 0x0, 0xc000527208, 0x19c5ee0, 0xc0006b4b90)
        /Users/cantosd/github.com/arr-ai/arrai/rel/expr_binary.go:252 +0x107
github.com/arr-ai/arrai/rel.(*BinExpr).Eval(0xc0000cc1c0, 0xc0006b4dc0, 0x3, 0x1, 0xc0006b4dc0, 0x3, 0x1)
        /Users/cantosd/github.com/arr-ai/arrai/rel/expr_binary.go:286 +0x12c
github.com/arr-ai/arrai/rel.Closure.CallAll(0xc000c7cf50, 0x2, 0xc0006ce880, 0x19ce560, 0xc00022c1e0, 0x180a8a0, 0xc000cfecb0, 0x100e386, 0xc0006703c0)
        /Users/cantosd/github.com/arr-ai/arrai/rel/value_set_closure.go:144 +0x1fc
github.com/arr-ai/arrai/rel.SetCall(0x19d2720, 0xc000646ce0, 0x19ce560, 0xc00022c1e0, 0xc000646ce0, 0xc00016f401, 0x2f2, 0xb)
        /Users/cantosd/github.com/arr-ai/arrai/rel/value.go:133 +0x63
github.com/arr-ai/arrai/rel.Call(0x19ce760, 0xc000646ce0, 0x19ce560, 0xc00022c1e0, 0xc0006703c0, 0x5, 0x0, 0xc00063da50, 0xc000cfee60, 0x11e7190)
        /Users/cantosd/github.com/arr-ai/arrai/rel/expr_binary.go:252 +0x107
github.com/arr-ai/arrai/rel.(*BinExpr).Eval(0xc0000c84d0, 0xc0006703c0, 0x5, 0x19c5ee0, 0xc000670230, 0x0, 0x0)
        /Users/cantosd/github.com/arr-ai/arrai/rel/expr_binary.go:286 +0x12c
github.com/arr-ai/arrai/rel.(*ArrowExpr).Eval(0xc000d87440, 0xc0006703c0, 0x5, 0x1, 0xc0006703c0, 0x5, 0x1)
        /Users/cantosd/github.com/arr-ai/arrai/rel/expr_arrow.go:31 +0x63
github.com/arr-ai/arrai/rel.(*ArrowExpr).Eval(0xc000d87f40, 0xc000666c80, 0x4, 0x1, 0xc000666c80, 0x4, 0x1)
        /Users/cantosd/github.com/arr-ai/arrai/rel/expr_arrow.go:39 +0x21a
github.com/arr-ai/arrai/rel.(*ArrowExpr).Eval(0xc000d64f40, 0xc000666aa0, 0x3, 0x1, 0xc000666aa0, 0x3, 0x1)
        /Users/cantosd/github.com/arr-ai/arrai/rel/expr_arrow.go:39 +0x21a
github.com/arr-ai/arrai/rel.Closure.CallAll(0xc000c7d180, 0x2, 0xc000d52440, 0x19ce460, 0xc000b8a600, 0xc00063c800, 0x0, 0xf14f0e1f45638d0c, 0xc000cff1f8)
        /Users/cantosd/github.com/arr-ai/arrai/rel/value_set_closure.go:144 +0x1fc
github.com/arr-ai/arrai/rel.SetCall(0x19d2720, 0xc0006396e0, 0x19ce460, 0xc000b8a600, 0xc0006396e0, 0xc00016f401, 0x5d9, 0x4)
        /Users/cantosd/github.com/arr-ai/arrai/rel/value.go:133 +0x63
github.com/arr-ai/arrai/rel.Call(0x19ce760, 0xc0006396e0, 0x19ce460, 0xc000b8a600, 0xc0006668c0, 0x7, 0x0, 0x26d4f88, 0xb, 0xc000cff0a8)
        /Users/cantosd/github.com/arr-ai/arrai/rel/expr_binary.go:252 +0x107
github.com/arr-ai/arrai/rel.(*BinExpr).Eval(0xc0000c9260, 0xc0006668c0, 0x7, 0x1, 0xc0006668c0, 0x7, 0x0)
        /Users/cantosd/github.com/arr-ai/arrai/rel/expr_binary.go:286 +0x12c
github.com/arr-ai/arrai/rel.PatternExprPair.Eval(...)
        /Users/cantosd/github.com/arr-ai/arrai/rel/pattern_expr_pair.go:26
github.com/arr-ai/arrai/rel.CondPatternControlVarExpr.Eval(0x19c5ee0, 0xc00016f4c0, 0x59a, 0x4f, 0x19c3560, 0xc0007b98f0, 0xc00097d4e0, 0x1, 0x1, 0xc00048d180, ...)
        /Users/cantosd/github.com/arr-ai/arrai/rel/expr_cond_pattern_control_var.go:58 +0x21f
github.com/arr-ai/arrai/rel.(*AttrExpr).Apply(0xc000cff5c0, 0xc00048d180, 0x6, 0x19d3da0, 0xc0004e4960, 0x19d3da0, 0xc0004e4960, 0x0, 0x0)
        /Users/cantosd/github.com/arr-ai/arrai/rel/expr_tuple.go:54 +0x52
github.com/arr-ai/arrai/rel.(*TupleExpr).Eval(0xc000b09400, 0xc00048d180, 0x6, 0x1, 0xc00048d180, 0x6, 0x1)
        /Users/cantosd/github.com/arr-ai/arrai/rel/expr_tuple.go:145 +0x116
github.com/arr-ai/arrai/rel.(*ArrowExpr).Eval(0xc000b09480, 0xc000653450, 0x5, 0x1, 0xc000653450, 0x5, 0x1)
        /Users/cantosd/github.com/arr-ai/arrai/rel/expr_arrow.go:39 +0x21a
github.com/arr-ai/arrai/rel.Closure.CallAll(0xc000c7d400, 0x4, 0xc000aa7180, 0x19cea60, 0xc00093e900, 0x0, 0x0, 0x0, 0xc000915ce0)
        /Users/cantosd/github.com/arr-ai/arrai/rel/value_set_closure.go:144 +0x1fc
github.com/arr-ai/arrai/rel.SetCall(0x19d2720, 0xc0009143a0, 0x19cea60, 0xc00093e900, 0xc0009143a0, 0xc0004ccf01, 0x2f, 0xf)
        /Users/cantosd/github.com/arr-ai/arrai/rel/value.go:133 +0x63
github.com/arr-ai/arrai/rel.Call(0x19ce760, 0xc0009143a0, 0x19cea60, 0xc00093e900, 0xc000653130, 0x1, 0x0, 0xc000595098, 0x19c5ee0, 0xc0004ccf80)
        /Users/cantosd/github.com/arr-ai/arrai/rel/expr_binary.go:252 +0x107
github.com/arr-ai/arrai/rel.(*BinExpr).Eval(0xc0000cc5b0, 0xc000653130, 0x1, 0x1, 0xc000653130, 0x1, 0x1)
        /Users/cantosd/github.com/arr-ai/arrai/rel/expr_binary.go:286 +0x12c
github.com/arr-ai/arrai/rel.(*ArrowExpr).Eval(0xc000931f80, 0x0, 0x0, 0x40, 0x19c1ca0, 0xc000931f80, 0x0)
        /Users/cantosd/github.com/arr-ai/arrai/rel/expr_arrow.go:39 +0x21a
github.com/arr-ai/arrai/syntax.EvalWithScope(0x7ffeefbff72e, 0xc, 0xc000258f80, 0x40, 0x0, 0x0, 0xc000258f80, 0x18ce4c0, 0xc00091fbc0, 0x1f285c0)
        /Users/cantosd/github.com/arr-ai/arrai/syntax/eval.go:13 +0x88
github.com/arr-ai/arrai/syntax.EvaluateExpr(...)
        /Users/cantosd/github.com/arr-ai/arrai/syntax/eval.go:22
main.evalExpr(0x7ffeefbff72e, 0xc, 0xc000258f80, 0x40, 0x19b3aa0, 0xc000010018, 0x0, 0x0)
        /Users/cantosd/github.com/arr-ai/arrai/cmd/arrai/eval.go:27 +0x6f
main.evalFile(0x7ffeefbff72e, 0xc, 0x19b3aa0, 0xc000010018, 0x0, 0xc0004b7190)
        /Users/cantosd/github.com/arr-ai/arrai/cmd/arrai/run.go:47 +0x1c1
main.run(0xc000362ac0, 0x1, 0x1)
        /Users/cantosd/github.com/arr-ai/arrai/cmd/arrai/run.go:24 +0x12f
github.com/urfave/cli/v2.(*Command).Run(0x1f19480, 0xc000362a00, 0x0, 0x0)
        /Users/cantosd/go/pkg/mod/github.com/urfave/cli/v2@v2.2.0/command.go:164 +0x4e0
github.com/urfave/cli/v2.(*App).RunContext(0xc000583080, 0x19c53a0, 0xc00003a098, 0xc000362740, 0x3, 0x4, 0x0, 0x0)
        /Users/cantosd/go/pkg/mod/github.com/urfave/cli/v2@v2.2.0/app.go:306 +0x814
github.com/urfave/cli/v2.(*App).Run(...)
        /Users/cantosd/go/pkg/mod/github.com/urfave/cli/v2@v2.2.0/app.go:215
main.main()
        /Users/cantosd/github.com/arr-ai/arrai/cmd/arrai/main.go:95 +0x155

Your Environment

NOTE: I built arrai from source so this was filled out manually with my current environment setup.

Version    : v0.118.0
Git commit : fa52d98ecb2b75c81dcd59650cc2d6dfd1a867d7
Date       : 09/08/2020
OS/arch    : darwin/amd64
Go version : 1.14.3
marcelocantos commented 4 years ago
expression fails...
"a" \| 1\"b" never
"a" \| 1\"b" \| 2\"d" occasionally
"a" \| 2\"b" usually
"a" \| 4\"b" always
marcelocantos commented 4 years ago

This was because sparse string support wasn't implemented. PR on the way.