arc optimizations (#13325)

* scope based destructors
* handle 'or' and 'and' expressions properly, see the new test arc/tcontrolflow.nim
* make this branch mergable, logic is disabled for now
This commit is contained in:
Andreas Rumpf 2020-03-18 16:57:34 +01:00 • committed by GitHub
commit fb641483f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 312 additions and 95 deletions

View file

@ -32,7 +32,12 @@ proc serve(server: PAsyncHttpServer): PFutureBase =
yield acceptAddrFut
var fut = acceptAddrFut.value
# with the new scope based destruction, this cannot
# possibly work:
var f {.cursor.} = processClient()
# It also seems to be the wrong way how to avoid the
# cycle. The cycle is caused by capturing the 'env'
# part from 'env.f'.
when true:
f.callback =
proc () =

View file

@ -33,7 +33,7 @@ type
p: pointer
proc `=destroy`(o: var TMyObj) =
if o.p != nil:
if o.p != nil:
dealloc o.p
o.p = nil
echo "myobj destroyed"

View file

@ -22,7 +22,7 @@ proc `=`(dest: var Foo, src: Foo) =
assign_counter.inc
proc test(): auto =
var a,b : Foo
var a, b: Foo
return (a, b, Foo(boo: 5))
var (a, b, _) = test()

View file

@ -2,7 +2,7 @@ discard """
valgrind: true
cmd: '''nim c -d:nimAllocStats --newruntime $file'''
output: '''OK 3
(allocCount: 8, deallocCount: 3)'''
(allocCount: 8, deallocCount: 5)'''
"""
import strutils, math