d5 / tengo

A fast script language for Go

Home Page:https://tengolang.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

a map with 10000 keys: panic: runtime error: index out of range [2048] with length 2048

txthinking opened this issue · comments

Thanks for tengo script

go install github.com/d5/tengo/v2/cmd/tengo@v2.13.0

a.tengo, create a map with 10000 keys

a := {
    "a": 1,
    "a": 1,
    "a": 1,
    "a": 1,
    // ... 10000 lines
    "a": 1,
    "a": 1,
    "a": 1
}

run

tengo a.tengo

panic

panic: runtime error: index out of range [2048] with length 2048

goroutine 1 [running]:
github.com/d5/tengo/v2.(*VM).run(0x14000264000)
        /Users/fuck/go/pkg/mod/github.com/d5/tengo/v2@v2.13.0/vm.go:106 +0x5738
github.com/d5/tengo/v2.(*VM).Run(0x14000264000)
        /Users/fuck/go/pkg/mod/github.com/d5/tengo/v2@v2.13.0/vm.go:77 +0xdc
main.CompileAndRun(0x16f3a3a76?, {0x14000100000?, 0x100bbf241?, 0x4?}, {0x140000ea000?, 0x5?})
        /Users/fuck/go/pkg/mod/github.com/d5/tengo/v2@v2.13.0/cmd/tengo/main.go:144 +0x1dc
main.main()
        /Users/fuck/go/pkg/mod/github.com/d5/tengo/v2@v2.13.0/cmd/tengo/main.go:83 +0x5b0

I'm not in any way part of the dev team. But why are you creating a map with the same key 10,000 times? What is the possible use case? Do you need to script maps with over 2048 keys? I don't know if that is the actual limit but it would be a reasonable one. What is your actual goal?

Pretty sure this is related to stack size which is default if 2048

It’s the stack size. I suppose it could be made variable so it could be increased.

That said, a more sensible way would’ve been to do

m := {}
for i in range(1, 10000) {
    m[i] = “something”
}

which wouldn’t be affected by the stack size limit