Update docs and changelog

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

View file

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