122 changes: 2 additions & 120 deletions druntime/src/rt/lifetime.d
Original file line number Diff line number Diff line change
Expand Up @@ -1148,25 +1148,8 @@ extern (C) void[] _d_newarraymiTX(const TypeInfo ti, size_t[] dims) @weak
}

/**
Allocate an uninitialized non-array item.
This is an optimization to avoid things needed for arrays like the __arrayPad(size).
- `_d_newitemU` leaves the item uninitialized
- `_d_newitemT` zero initializes the item
- `_d_newitemiT` uses a non-zero initializer from `TypeInfo`
Used to allocate struct instances on the heap.
---
struct Sz {int x = 0;}
struct Si {int x = 3;}
void main()
{
new Sz(); // _d_newitemT(typeid(Sz))
new Si(); // _d_newitemiT(typeid(Si))
}
---
Non-template version of $(REF _d_newitemT, core,lifetime) that does not perform
initialization. Needed for $(REF allocEntry, rt,aaA).
Params:
_ti = `TypeInfo` of item to allocate
Expand Down Expand Up @@ -1196,26 +1179,6 @@ extern (C) void* _d_newitemU(scope const TypeInfo _ti) pure nothrow @weak
return p;
}

/// ditto
extern (C) void* _d_newitemT(const TypeInfo _ti) pure nothrow @weak
{
import core.stdc.string;
auto p = _d_newitemU(_ti);
memset(p, 0, _ti.tsize);
return p;
}

/// Same as above, for item with non-zero initializer.
extern (C) void* _d_newitemiT(const TypeInfo _ti) pure nothrow @weak
{
import core.stdc.string;
auto p = _d_newitemU(_ti);
auto init = _ti.initializer();
assert(init.length <= _ti.tsize);
memcpy(p, init.ptr, init.length);
return p;
}

debug(PRINTF)
{
extern(C) void printArrayCache()
Expand Down Expand Up @@ -2361,52 +2324,6 @@ unittest
testPostBlit!(const(S))();
}

// cannot define structs inside unit test block, or they become nested structs.
version (CoreUnittest)
{
struct S1
{
int x = 5;
}
struct S2
{
int x;
this(int x) {this.x = x;}
}
struct S3
{
int[4] x;
this(int x)
{this.x[] = x;}
}
struct S4
{
int *x;
}

}

unittest
{
auto s1 = new S1;
assert(s1.x == 5);
assert(GC.getAttr(s1) == BlkAttr.NO_SCAN);

auto s2 = new S2(3);
assert(s2.x == 3);
assert(GC.getAttr(s2) == BlkAttr.NO_SCAN);

auto s3 = new S3(1);
assert(s3.x == [1,1,1,1]);
assert(GC.getAttr(s3) == BlkAttr.NO_SCAN);
debug(SENTINEL) {} else
assert(GC.sizeOf(s3) == 16);

auto s4 = new S4;
assert(s4.x == null);
assert(GC.getAttr(s4) == 0);
}

unittest
{
// Bugzilla 3454 - Inconsistent flag setting in GC.realloc()
Expand Down Expand Up @@ -2731,41 +2648,6 @@ unittest
assert(!test!InvalidMemoryOperationError);
}

// test struct finalizers exception handling
debug(SENTINEL) {} else
unittest
{
bool test(E)()
{
import core.exception;
static struct S1
{
E exc;
~this() { throw exc; }
}

bool caught = false;
S1* s = new S1(new E("test onFinalizeError"));
try
{
GC.runFinalizers((cast(char*)(typeid(S1).xdtor))[0..1]);
}
catch (FinalizeError err)
{
caught = true;
}
catch (E)
{
}
GC.free(s);
return caught;
}

assert( test!Exception);
import core.exception : InvalidMemoryOperationError;
assert(!test!InvalidMemoryOperationError);
}

// test bug 14126
unittest
{
Expand Down
2 changes: 0 additions & 2 deletions druntime/src/rt/tracegc.d
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ extern (C) void[] _d_newarrayU(const scope TypeInfo ti, size_t length);
extern (C) void[] _d_newarrayiT(const TypeInfo ti, size_t length);
extern (C) void[] _d_newarraymTX(const TypeInfo ti, size_t[] dims);
extern (C) void[] _d_newarraymiTX(const TypeInfo ti, size_t[] dims);
extern (C) void* _d_newitemT(const TypeInfo ti);
extern (C) void* _d_newitemiT(const TypeInfo ti);
extern (C) void _d_callfinalizer(void* p);
extern (C) void _d_callinterfacefinalizer(void *p);
extern (C) void _d_delclass(Object* p);
Expand Down
3 changes: 2 additions & 1 deletion druntime/test/profile/bothgc.log.exp
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
bytes allocated, allocations, type, function, file:line
16000 1000 both.Num both.foo src/both.d:15
16000 1000 Num both.foo src/both.d:15
16000 1000 void[] core.lifetime._d_newitemT!(Num)._d_newitemT ../../src/core/lifetime.d:2829
3 changes: 3 additions & 0 deletions druntime/test/profile/bothnew.def.exp
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ FUNCTIONS
_Dmain
_D4both3fooFkZPSQo3Num
_D4both3Num6__ctorMFNckZSQxQu
_D4core8internal8lifetime__T18emplaceInitializerTS4both3NumZQBgFNaNbNiNeMKQzZv
_D4core8lifetime__T11_d_newitemTTS4both3NumZQzFNaNbNeZPQw
_D4core8lifetime__T16_d_newitemTTraceTS4both3NumZQBeFNaNbNeAyaiQeZPQBd
2 changes: 2 additions & 0 deletions druntime/test/profile/myprofilegc.log.freebsd.32.exp
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ bytes allocated, allocations, type, function, file:line
16 1 int[] D main src/profilegc.d:22
16 1 int[] D main src/profilegc.d:37
16 1 profilegc.main.C core.lifetime._d_newclassT!(C)._d_newclassT ../../src/core/lifetime.d:2755
16 1 void[] core.lifetime._d_newitemT!float._d_newitemT ../../src/core/lifetime.d:2829
16 1 void[] core.lifetime._d_newitemT!int._d_newitemT ../../src/core/lifetime.d:2829
16 1 wchar[] D main src/profilegc.d:35
2 changes: 2 additions & 0 deletions druntime/test/profile/myprofilegc.log.freebsd.64.exp
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ bytes allocated, allocations, type, function, file:line
16 1 int[] D main src/profilegc.d:14
16 1 int[] D main src/profilegc.d:22
16 1 int[] D main src/profilegc.d:37
16 1 void[] core.lifetime._d_newitemT!float._d_newitemT ../../src/core/lifetime.d:2829
16 1 void[] core.lifetime._d_newitemT!int._d_newitemT ../../src/core/lifetime.d:2829
16 1 wchar[] D main src/profilegc.d:35
2 changes: 2 additions & 0 deletions druntime/test/profile/myprofilegc.log.linux.32.exp
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ bytes allocated, allocations, type, function, file:line
16 1 int[] D main src/profilegc.d:22
16 1 int[] D main src/profilegc.d:37
16 1 profilegc.main.C core.lifetime._d_newclassT!(C)._d_newclassT ../../src/core/lifetime.d:2755
16 1 void[] core.lifetime._d_newitemT!float._d_newitemT ../../src/core/lifetime.d:2829
16 1 void[] core.lifetime._d_newitemT!int._d_newitemT ../../src/core/lifetime.d:2829
16 1 wchar[] D main src/profilegc.d:35
2 changes: 2 additions & 0 deletions druntime/test/profile/myprofilegc.log.linux.64.exp
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ bytes allocated, allocations, type, function, file:line
16 1 int[] D main src/profilegc.d:14
16 1 int[] D main src/profilegc.d:22
16 1 int[] D main src/profilegc.d:37
16 1 void[] core.lifetime._d_newitemT!float._d_newitemT ../../src/core/lifetime.d:2829
16 1 void[] core.lifetime._d_newitemT!int._d_newitemT ../../src/core/lifetime.d:2829
16 1 wchar[] D main src/profilegc.d:35
2 changes: 2 additions & 0 deletions druntime/test/profile/myprofilegc.log.osx.32.exp
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ bytes allocated, allocations, type, function, file:line
16 1 int[] D main src/profilegc.d:22
16 1 int[] D main src/profilegc.d:37
16 1 profilegc.main.C core.lifetime._d_newclassT!(C)._d_newclassT ../../src/core/lifetime.d:2755
16 1 void[] core.lifetime._d_newitemT!float._d_newitemT ../../src/core/lifetime.d:2829
16 1 void[] core.lifetime._d_newitemT!int._d_newitemT ../../src/core/lifetime.d:2829
16 1 wchar[] D main src/profilegc.d:35
2 changes: 2 additions & 0 deletions druntime/test/profile/myprofilegc.log.osx.64.exp
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ bytes allocated, allocations, type, function, file:line
16 1 int[] D main src/profilegc.d:14
16 1 int[] D main src/profilegc.d:22
16 1 int[] D main src/profilegc.d:37
16 1 void[] core.lifetime._d_newitemT!float._d_newitemT ../../src/core/lifetime.d:2829
16 1 void[] core.lifetime._d_newitemT!int._d_newitemT ../../src/core/lifetime.d:2829
16 1 wchar[] D main src/profilegc.d:35