diff options
author | heterodoxic <122719743+heterodoxic@users.noreply.github.com> | 2024-04-18 21:58:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-18 21:58:01 +0200 |
commit | 318b2cfc5ebeee5e27982bb5a76fa4c00d523772 (patch) | |
tree | 91162b88c34c993b1d0afab0832a1a619597c1bc /compiler/cgen.nim | |
parent | 558bbb7426b21156b6ad5f8834a62cdf067a2ac3 (diff) | |
download | Nim-318b2cfc5ebeee5e27982bb5a76fa4c00d523772.tar.gz |
allow having {.noinit.} on a complex type avoid memsets to 0 for its … (#23388)
…instantiations (C/C++ backend) AFAIK, #22802 expanded `noinit`'s utility by allowing the pragma to be attached to types (thanks @jmgomez !). I suggest broadening the scope a bit further: try to avoid `nimZeroMem`s on a type level beyond imported C/C++ types[^1], saving us from annotating the type instantiations with `noinit`. If this change is deemed acceptable, I will also adjust the docs, of course. Adding tests for this change seems a bit problematic, as the effect of this type annotation will be to work with uninitialized memory, which *might* match 0 patterns. [^1]: "complex value types" as already defined here: https://github.com/nim-lang/Nim/blob/94c599687796f4ee3872c8aa866827b9ed33f52b/compiler/cgen.nim#L470-L471
Diffstat (limited to 'compiler/cgen.nim')
-rw-r--r-- | compiler/cgen.nim | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 043c014a2..e4ba41614 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -532,7 +532,7 @@ proc constructLoc(p: BProc, loc: var TLoc, isTemp = false) = linefmt(p, cpsStmts, "$1 = ($2)0;$n", [rdLoc(loc), getTypeDesc(p.module, typ, descKindFromSymKind mapTypeChooser(loc))]) else: - if not isTemp or containsGarbageCollectedRef(loc.t): + if (not isTemp or containsGarbageCollectedRef(loc.t)) and not hasNoInit(loc.t): # don't use nimZeroMem for temporary values for performance if we can # avoid it: if not isOrHasImportedCppType(typ): |