new minor language feature: .noSideEffect blocks like .gcsafe blocks

This commit is contained in:
Andreas Rumpf 2018-11-26 23:28:02 +01:00
commit 413580bc04
7 changed files with 30 additions and 12 deletions

View file

@ -82,7 +82,7 @@ type
cap: int
region: Allocator
proc newSeqPayload(cap, elemSize: int): pointer {.compilerRtl.} =
proc newSeqPayload(cap, elemSize: int): pointer {.compilerRtl, noSideEffect.} =
# we have to use type erasure here as Nim does not support generic
# compilerProcs. Oh well, this will all be inlined anyway.
if cap <= 0:
@ -94,7 +94,8 @@ proc newSeqPayload(cap, elemSize: int): pointer {.compilerRtl.} =
else:
result = nil
proc prepareSeqAdd(len: int; p: pointer; addlen, elemSize: int): pointer {.compilerRtl.} =
proc prepareSeqAdd(len: int; p: pointer; addlen, elemSize: int): pointer {.
compilerRtl, noSideEffect.} =
if len+addlen <= len:
result = p
elif p == nil:
@ -128,7 +129,7 @@ proc grow*[T](x: var seq[T]; newLen: Natural; value: T) =
xu.p = cast[typeof(xu.p)](prepareSeqAdd(oldLen, xu.p, newLen - oldLen, sizeof(T)))
xu.len = newLen
for i in oldLen .. newLen-1:
x.data[i] = value
xu.p.data[i] = value
proc setLen[T](s: var seq[T], newlen: Natural) =
if newlen < s.len: