Closed stefantalpalaru closed 2 years ago
I was able to mostly minimize it -- no imports, no dependence on using a Nimbus build environment, et cetera:
type
Result*[T, E] = object
case o: bool
of false:
e: E
of true:
v: T
Opt*[T] = Result[T, void]
template ok*[T, E](R: type Result[T, E], x: untyped): R =
R(o: true, v: x)
template ok*[E](R: type Result[void, E]): R =
R(o: true)
template ok*[T: not void, E](self: var Result[T, E], x: untyped) =
self = ok(type self, x)
template ok*[E](self: var Result[void, E]) =
self = (type self).ok()
template err*[T](R: type Result[T, void]): R =
R(o: false)
template err*[T](self: var Result[T, void]) =
self = err(type self)
template ok*(): auto = ok(typeof(result))
func mapErr*[T, E0](
self: Result[T, E0], f: proc(x: E0)): Result[T, void] {.inline.} =
if self.o:
when T is void:
result.ok()
else:
result.ok(self.v)
else:
f(self.e)
result.err()
{.push raises: [Defect].}
type
Ver* = distinct array[4, byte]
ForkData* = object
current_version*: Ver
genesis_validators_root*: array[32, byte]
proc getBlockSSZ*(): Result[void, string] =
ok()
proc getBlock*(
T: type ForkData): Opt[T] =
discard getBlockSSZ().mapErr(proc(x: auto) = discard)
result.ok(default(T))
proc applyBlock() =
let data = getBlock(ForkData)
applyBlock()
which, when run with gdb, via PATH=${PATH_TO_NIM_DEVEL}:${PATH} gdb --args nim c --hints:off --compileOnly -o:/dev/null sigsegv.nim
shows:
Program received signal SIGSEGV, Segmentation fault.
0x0000555555896fb8 in allPathsAsgnResult__cgen_26861 ()
(gdb) bt
#0 0x0000555555896fb8 in allPathsAsgnResult__cgen_26861 ()
#1 0x00005555558979aa in allPathsAsgnResult__cgen_26861 ()
#2 0x00005555558979aa in allPathsAsgnResult__cgen_26861 ()
#3 0x00005555558979aa in allPathsAsgnResult__cgen_26861 ()
#4 0x00005555558979aa in allPathsAsgnResult__cgen_26861 ()
#5 0x00005555558979aa in allPathsAsgnResult__cgen_26861 ()
#6 0x00005555558979aa in allPathsAsgnResult__cgen_26861 ()
#7 0x00005555558979aa in allPathsAsgnResult__cgen_26861 ()
#8 0x0000555555897267 in allPathsAsgnResult__cgen_26861 ()
#9 0x000055555589e819 in genProcAux__cgen_27082 ()
#10 0x000055555589e8cf in genProc__cgen_422 ()
#11 0x00005555558bae3e in expr.cgen_11613 ()
#12 0x0000555555910c5c in genPrefixCall__cgen_12487 ()
#13 0x000055555591a8a3 in genSingleVar__cgen_14048.part.0 ()
#14 0x000055555591bd75 in genVarStmt__cgen_14293 ()
#15 0x000055555589c704 in genStmts__cgen_11610 ()
#16 0x000055555589d92e in genProcAux__cgen_27082 ()
#17 0x000055555589e8cf in genProc__cgen_422 ()
#18 0x00005555558bae3e in expr.cgen_11613 ()
#19 0x0000555555910c5c in genPrefixCall__cgen_12487 ()
#20 0x00005555558bb9c3 in expr.cgen_11613 ()
#21 0x000055555589c704 in genStmts__cgen_11610 ()
#22 0x00005555559256eb in myProcess__cgen_29584 ()
#23 0x00005555556e95a3 in processTopLevelStmt__passes_138 ()
#24 0x00005555556e9c83 in processModule__passes_231 ()
#25 0x000055555593008c in compileModule__modules_1709 ()
#26 0x00005555559bb9ca in commandCompileToC__main_363 ()
#27 0x00005555559bcb38 in mainCommand__main_504 ()
#28 0x00005555559bf310 in handleCmdLine__nim_41 ()
#29 0x00005555559bfaa1 in NimMainInner ()
#30 0x00005555559bfcc6 in NimMain ()
#31 0x000055555557091d in main ()
and appears to be the same issue.
Tested with
Nim Compiler Version 1.6.4 [Linux: amd64]
Compiled at 2022-02-10
Copyright (c) 2006-2021 by Andreas Rumpf
active boot switches: -d:release
and
Nim Compiler Version 1.7.1 [Linux: amd64]
Compiled at 2022-03-02
Copyright (c) 2006-2022 by Andreas Rumpf
git hash: 590d39785243afb6da3662cf77c842a5ff4e1412
active boot switches: -d:release
It does not occur on
Nim Compiler Version 1.2.16 [Linux: amd64]
Compiled at 2022-02-27
Copyright (c) 2006-2020 by Andreas Rumpf
git hash: c6a9f27b3e36bae9aacec1bd6c37893fb98fd33f
active boot switches: -d:release
but rather compiles successfully.
It works in 1.6.0 but fails in 1.6.2
It seems to be a regression related to https://github.com/nim-lang/Nim/pull/19115
Reduce further:
type
Result*[T] = object
v: T
func mapErr*[T](
self: Result[T], f: proc(x: T)): Result[T] {.inline.} =
discard
{.push raises: [Defect].}
type
ForkData* = object
root*: array[32, byte]
proc getBlock*(
T: type ForkData): Result[T] =
discard mapErr(default(Result[T]), proc(x: any) = discard)
discard getBlock(ForkData)
{.pop.}
Compiler segfault in both "version-1-6" and "devel" HEAD, triggered by this nimbus-eth2 PR: https://github.com/status-im/nimbus-eth2/pull/3394
GDB backtrace from latest Nim "devel", using
PATH="/src/77_DLD/CODE/status/Nim/bin:${PATH}" USE_SYSTEM_NIM=1 ./env.sh gdb --args nim c --compileOnly -o:build/nimbus_beacon_node -d:disableLTO --hints:off --warnings:off --verbosity:0 -d:chronicles_log_level=DEBUG -d:release --parallelBuild:1 -d:libp2p_agents_metrics -d:KnownLibP2PAgents=nimbus,lighthouse,prysm,teku -d:nimCachePathOverride=nimcache/release/nimbus_beacon_node beacon_chain/nimbus_beacon_node.nim
: