The resulting C code for the following code example code produces an expensive, unnecessary copy of a `Position` in the function `inCheck` when compiled with `nim c -d:danger -d:lto --panics:on --gc:arc --run main.nim` type Position* = object pieces: array[6, uint64] colors: array[2, uint64] func isAttacked*(position: Position, target: int8): bool = false func kingSquare*(position: Position): int8 = 12 func inCheck*(position: Position): bool = position.isAttacked(position.kingSquare) var p: Position echo p.inCheck() Run
Resulting C code: N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, isAttacked_main_4)(tyObject_Position__XJEOqi2mMysguMih68T9bQg* position, NI8 target) { NIM_BOOL result; result = (NIM_BOOL)0; result = NIM_FALSE; return result; } N_LIB_PRIVATE N_NIMCALL(NI8, kingSquare_main_8)(tyObject_Position__XJEOqi2mMysguMih68T9bQg* position) { NI8 result; result = (NI8)0; result = ((NI8) 12); return result; } N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, inCheck_main_11)(tyObject_Position__XJEOqi2mMysguMih68T9bQg* position) { NIM_BOOL result; tyObject_Position__XJEOqi2mMysguMih68T9bQg T1_; NI8 T2_; result = (NIM_BOOL)0; T1_ = (*position); // I believe this is the expensive copy T2_ = (NI8)0; T2_ = kingSquare_main_8(position); result = isAttacked_main_4((&T1_), T2_); return result; } Run The expensive copy is omitted when compiling with `nim c -d:danger -d:lto --gc:refc --run main.nim`: N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, isAttacked_main_4)(tyObject_Position__XJEOqi2mMysguMih68T9bQg* position, NI8 target) { NIM_BOOL result; result = (NIM_BOOL)0; result = NIM_FALSE; return result; } N_LIB_PRIVATE N_NIMCALL(NI8, kingSquare_main_8)(tyObject_Position__XJEOqi2mMysguMih68T9bQg* position) { NI8 result; result = (NI8)0; result = ((NI8) 12); return result; } N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, inCheck_main_11)(tyObject_Position__XJEOqi2mMysguMih68T9bQg* position) { NIM_BOOL result; NI8 T1_; result = (NIM_BOOL)0; T1_ = (NI8)0; T1_ = kingSquare_main_8(position); result = isAttacked_main_4(position, T1_); return result; } Run Is this a bug that can be fixed (because I suspect that this issue is the reason why my program is slower with `--gc:arc` than with the default GC), or is this inherent to the design of ARC?