I have below code that is throwing "SIGBUS: Illegal storage access. (Attempt to read from nil?)" at line 4, even though all arguments are not nil. If it's thrown from evaluator proc, should the stack be showing the line inside evaluator instead?
echo self == nil # false
echo frame == nil # false
echo expr.evaluator == nil # false
expr.evaluator(self, frame, expr)
Worked through this a bit with them in the real time chat, turns out they were using cast to convert a different inherited type to their desired type, minimal reproduction here:
type
A = ref object of RootObj
B = ref object of A
name: string
C = ref object of A
eval: proc()
var val = cast[C](B(name: "Hello"))
assert val.eval != nil
val.eval()
Thanks all!
Today I was able to fix it. I cast wrong Expr to ExIf in my code as ElegantBeef suggested. I would like to change cast to type conversion. However it has big impact to my app's performance.
My rough benchmark goes from 0.05s to 0.095s.
I'm using -d:release. It's a benchmark to calculate fibonacci of 24. It takes 0.05 second, 13 times slower than Ruby 2.6. If I change cast to type conversion, it takes 0.99 second. Below is the PR that contains the changes.