Merge pull request #9923 from stefantalpalaru/calldepth

replace misleading "stack overflow" message when reaching Nim's call depth limit
This commit is contained in:
Andreas Rumpf 2018-12-11 22:07:44 +01:00 • committed by GitHub
commit e3d91a5b74
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -454,16 +454,18 @@ when not defined(gcDestructors):
shallowCopy(result, e.trace) shallowCopy(result, e.trace)
when defined(nimRequiresNimFrame): when defined(nimRequiresNimFrame):
proc stackOverflow() {.noinline.} = const nimCallDepthLimit {.intdefine.} = 2000
proc callDepthLimitReached() {.noinline.} =
writeStackTrace() writeStackTrace()
showErrorMessage("Stack overflow\n") showErrorMessage("Error: call depth limit reached in a debug build (" & $nimCallDepthLimit & " function calls). You can change it with -d:nimCallDepthLimit=<int> or switch to a release build with -d:release.\n")
quitOrDebug() quitOrDebug()
proc nimFrame(s: PFrame) {.compilerRtl, inl, exportc: "nimFrame".} = proc nimFrame(s: PFrame) {.compilerRtl, inl, exportc: "nimFrame".} =
s.calldepth = if framePtr == nil: 0 else: framePtr.calldepth+1 s.calldepth = if framePtr == nil: 0 else: framePtr.calldepth+1
s.prev = framePtr s.prev = framePtr
framePtr = s framePtr = s
if s.calldepth == 2000: stackOverflow() if s.calldepth == nimCallDepthLimit: callDepthLimitReached()
else: else:
proc pushFrame(s: PFrame) {.compilerRtl, inl, exportc: "nimFrame".} = proc pushFrame(s: PFrame) {.compilerRtl, inl, exportc: "nimFrame".} =
# XXX only for backwards compatibility # XXX only for backwards compatibility