diff options
author | Ico Doornekamp <ico@pruts.nl> | 2020-01-23 14:25:22 +0100 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2020-01-23 14:25:22 +0100 |
commit | b68eb1cad0dc13d497ae0e620dd2178a6367644c (patch) | |
tree | 4456c09a2cf5a964cc1d6cb2cae16dabfa0ff2a8 /compiler | |
parent | f500895efe84525c131beadd2e83b30caa6674a3 (diff) | |
download | Nim-b68eb1cad0dc13d497ae0e620dd2178a6367644c.tar.gz |
Removed lib/system/allocators.nim. seqs_v2 and strs_v2 now uses allocShared0. (#13190)
* Cleanup, remove lib/system/allocators.nim. seqs_v2 and strs_v2 now use allocShared0 by default. * Fixed -d:useMalloc allocShared / reallocShared / deallocShared. These now use the alloc/dealloc/realloc implementation that also takes care of zeroing memory at realloc. * Removed debug printfs * Removed unpairedEnvAllocs() from tests/destructor/tnewruntime_misc * More mmdisp cleanups. The shared allocators do not need to zero memory or throw since the regular ones already do that * Introduced realloc0 and reallocShared0, these procs are now used by strs_v2 and seqs_v2. This also allowed the -d:useMalloc allocator to drop the extra header with allocation length. * Moved strs_v2/seqs_v2 'allocated' flag into 'cap' field * Added 'getAllocStats()' to get low level alloc/dealloc counters. Enable with -d:allocStats * *allocShared implementations for boehm and go allocators now depend on the proper *allocImpl procs
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/ccgexprs.nim | 12 | ||||
-rw-r--r-- | compiler/ccgliterals.nim | 4 | ||||
-rw-r--r-- | compiler/ccgtypes.nim | 2 |
3 files changed, 9 insertions, 9 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index d718eab42..c23b64257 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -2037,15 +2037,15 @@ proc genDestroy(p: BProc; n: PNode) = of tyString: var a: TLoc initLocExpr(p, arg, a) - linefmt(p, cpsStmts, "if ($1.p && $1.p->allocator) {$n" & - " $1.p->allocator->dealloc($1.p->allocator, $1.p, $1.p->cap + 1 + sizeof(NI) + sizeof(void*));$n" & + linefmt(p, cpsStmts, "if ($1.p && !($1.p->cap & NIM_STRLIT_FLAG)) {$n" & + " #deallocShared($1.p);$n" & " $1.p = NIM_NIL; }$n", [rdLoc(a)]) of tySequence: var a: TLoc initLocExpr(p, arg, a) - linefmt(p, cpsStmts, "if ($1.p && $1.p->allocator) {$n" & - " $1.p->allocator->dealloc($1.p->allocator, $1.p, ($1.p->cap * sizeof($2)) + sizeof(NI) + sizeof(void*));$n" & + linefmt(p, cpsStmts, "if ($1.p && !($1.p->cap & NIM_STRLIT_FLAG)) {$n" & + " #deallocShared($1.p);$n" & " $1.p = NIM_NIL; }$n", [rdLoc(a), getTypeDesc(p.module, t.lastSon)]) else: discard "nothing to do" @@ -2917,8 +2917,8 @@ proc genConstSeqV2(p: BProc, n: PNode, t: PType; isConst: bool): Rope = appcg(p.module, cfsData, "static $5 struct {$n" & - " NI cap; void* allocator; $1 data[$2];$n" & - "} $3 = {$2, NIM_NIL, $4};$n", [ + " NI cap; $1 data[$2];$n" & + "} $3 = {$2 | NIM_STRLIT_FLAG, $4};$n", [ getTypeDesc(p.module, base), n.len, payload, data, if isConst: "const" else: ""]) result = "{$1, ($2*)&$3}" % [rope(n.len), getSeqPayloadType(p.module, t), payload] diff --git a/compiler/ccgliterals.nim b/compiler/ccgliterals.nim index b51348508..ee56da586 100644 --- a/compiler/ccgliterals.nim +++ b/compiler/ccgliterals.nim @@ -55,8 +55,8 @@ proc genStringLiteralV1(m: BModule; n: PNode): Rope = proc genStringLiteralDataOnlyV2(m: BModule, s: string; result: Rope; isConst: bool) = m.s[cfsData].addf("static $4 struct {$n" & - " NI cap; void* allocator; NIM_CHAR data[$2+1];$n" & - "} $1 = { $2, NIM_NIL, $3 };$n", + " NI cap; NIM_CHAR data[$2+1];$n" & + "} $1 = { $2 | NIM_STRLIT_FLAG, $3 };$n", [result, rope(s.len), makeCString(s), rope(if isConst: "const" else: "")]) diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index 054aa2b7c..24551e7e5 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -432,7 +432,7 @@ proc seqV2ContentType(m: BModule; t: PType; check: var IntSet) = appcg(m, m.s[cfsTypes], """$N $3ifndef $2_Content_PP $3define $2_Content_PP -struct $2_Content { NI cap;#AllocatorObj* allocator;$1 data[SEQ_DECL_SIZE];}; +struct $2_Content { NI cap; $1 data[SEQ_DECL_SIZE];}; $3endif$N """, [getTypeDescAux(m, t.skipTypes(abstractInst)[0], check), result, rope"#"]) |