also note that you cannot use arc with default asyncdispatch since it needs a cycle collector to free memory, there are other async implenetations that can be used with arc but not the default one as far as i know, you may also need that cycle collector for your own code as well if your code produces cycles, more on that here
https://nim-lang.org/docs/mm.html
and there
https://nim-lang.org/blog/2020/10/15/introduction-to-arc-orc-in-nim.html
As opposed to what? Sorry but you've no clue about these things.
If it's "manual" it cannot be "safe", by definition "manual" must allow for var x = alloc(10); dealloc(x); use x[] which is the classic "use after free" bug.
Oh, sorry, I did not express myself completely. I wasn't looking for "safe" nor was I assessing Nim's safety. I was doing the opposite. I am glad to know that the compiler doesn't restrict me in any way (w.r.t. memory management); if I read and understood everything mentioned by people here correctly. It should be free fall. Nim is my first systems programming language. I've learnt C and C++ but have never used or done anything much with them.
I'm just glad that I have unrestricted access to the inner components of a compiler through Nim with its awesome syntax.
That said for core cryptography, it's all stack objects. I could use destructors hook for more "automated manual" memory management.
I do pass a lot of flags for ensuring correctness in my test suite: https://github.com/mratsim/constantine/blob/0a17002/constantine.nimble#L636-L661
const stackHardening =
" --passC:-fstack-protector-strong " &
# Fortify source wouldn't help us detect errors in Constantine
# because everything is stack allocated
# except with the threadpool:
# - https://developers.redhat.com/blog/2021/04/16/broadening-compiler-checks-for-buffer-overflows-in-_fortify_source#what_s_next_for__fortify_source
# - https://developers.redhat.com/articles/2023/02/06/how-improve-application-security-using-fortifysource3#how_to_improve_application_fortification
# We also don't use memcpy as it is not constant-time and our copy is compile-time sized.
" --passC:-D_FORTIFY_SOURCE=3 "
const sanitizers =
# Sanitizers are incompatible with nim default GC
# The conservative stack scanning of Nim default GC triggers, alignment UB and stack-buffer-overflow check.
# Address sanitizer requires free registers and needs to be disabled for some inline assembly files.
# Ensure you use --mm:arc -d:useMalloc
#
# Sanitizers are deactivated by default as they slow down CI by at least 6x
" --mm:arc -d:useMalloc" &
" --passC:-fsanitize=undefined --passL:-fsanitize=undefined" &
" --passC:-fsanitize=address --passL:-fsanitize=address" &
" --passC:-fno-sanitize-recover" # Enforce crash on undefined behaviour