Update docs and changelog

This commit is contained in:
Clyybber
2020-07-09 17:59:40 +02:00
committed by Andreas Rumpf
parent 4a1128d16c
commit bf51cee431
2 changed files with 6 additions and 3 deletions

View File

@@ -143,6 +143,8 @@
## Language changes
- The `=destroy` hook no longer has to reset its target, as the compiler now automatically inserts
wasMoved calls where needed.
- In the newruntime it is now allowed to assign to the discriminator field
without restrictions as long as case object doesn't have custom destructor.
The discriminator value doesn't have to be a constant either. If you have a

View File

@@ -39,12 +39,12 @@ written as:
if x.data != nil:
for i in 0..<x.len: `=destroy`(x[i])
dealloc(x.data)
x.data = nil
proc `=`*[T](a: var myseq[T]; b: myseq[T]) =
# do nothing for self-assignments:
if a.data == b.data: return
`=destroy`(a)
wasMoved(a)
a.len = b.len
a.cap = b.cap
if b.data != nil:
@@ -56,6 +56,7 @@ written as:
# move assignment, optional.
# Compiler is using `=destroy` and `copyMem` when not provided
`=destroy`(a)
wasMoved(a)
a.len = b.len
a.cap = b.cap
a.data = b.data
@@ -120,7 +121,6 @@ The general pattern in ``=destroy`` looks like:
# first check if 'x' was moved to somewhere else:
if x.field != nil:
freeResource(x.field)
x.field = nil
@@ -149,6 +149,7 @@ The general pattern in ``=sink`` looks like:
proc `=sink`(dest: var T; source: T) =
`=destroy`(dest)
wasMoved(dest)
dest.field = source.field
@@ -178,6 +179,7 @@ The general pattern in ``=`` looks like:
# protect against self-assignments:
if dest.field != source.field:
`=destroy`(dest)
wasMoved(dest)
dest.field = duplicateResource(source.field)
@@ -522,7 +524,6 @@ Let ``W`` be an ``owned ref`` type. Conceptually its hooks look like:
if x != nil:
assert x.refcount == 0, "dangling unowned pointers exist!"
`=destroy`(x[])
x = nil
proc `=`(x: var W; y: W) {.error: "owned refs can only be moved".}