Skip to content

Commit b4450d6

Browse files
committed
v3.1.1
1 parent 7f19236 commit b4450d6

File tree

4 files changed

+85
-44
lines changed

4 files changed

+85
-44
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ install:
3535
script:
3636
# - travis_wait 100 dub test --arch "$ARCH"
3737
- travis_wait 100 dub test --arch "$ARCH" --build=unittest-cov
38+
- travis_wait 100 dub test --arch "$ARCH" -c dips
3839
- ./test_examples.sh
3940
- meson build && cd build && ninja -j4 && ninja -j4 test -v && cd .. # TODO: 32bit meson test
4041
# - travis_wait 100 dub test --arch "$ARCH" --build=unittest-release

source/mir/ndslice/slice.d

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ Slice!(Iterator, N, kind)
345345
(Slice!(Iterator, 1, kind) slice, size_t[N] lengths...)
346346
if (N)
347347
{
348-
typeof(return)._Structure structure;
348+
auto structure = typeof(return)._Structure.init;
349349
structure[0] = lengths;
350350
static if (kind != Contiguous)
351351
{
@@ -908,14 +908,12 @@ public:
908908
///
909909
auto lightImmutable()() scope return immutable @property
910910
{
911-
import mir.qualifier: LightImmutableOf, lightImmutable;
912911
return Slice!(LightImmutableOf!Iterator, N, kind)(_structure, _iterator.lightImmutable);
913912
}
914913

915914
/// ditto
916915
auto lightConst()() scope return const @property
917916
{
918-
import mir.qualifier: LightConstOf, lightConst;
919917
return Slice!(LightConstOf!Iterator, N, kind)(_structure, _iterator.lightConst);
920918
}
921919

@@ -1418,7 +1416,7 @@ public:
14181416
if (dimension < N)
14191417
{
14201418
assert(!empty!dimension);
1421-
typeof(return)._Structure structure_;
1419+
auto structure_ = typeof(return)._Structure.init;
14221420

14231421
foreach (i; Iota!(typeof(return).N))
14241422
{
@@ -1836,10 +1834,19 @@ public:
18361834
&& __traits(compiles, this._iterator == rslice._iterator)
18371835
)
18381836
{
1839-
foreach (i; Iota!N)
1840-
if (this._lengths[i] != rslice._lengths[i])
1837+
if (this._lengths != rslice._lengths)
1838+
return false;
1839+
static if (kind == rkind)
1840+
{
1841+
if (this._strides != rslice._strides)
18411842
return false;
1842-
if (this._strides == rslice._strides && this._iterator == rslice._iterator)
1843+
}
1844+
else
1845+
{
1846+
if (this.strides != rslice.strides)
1847+
return false;
1848+
}
1849+
if (this._iterator == rslice._iterator)
18431850
return true;
18441851
}
18451852
import mir.algorithm.iteration : equal;
@@ -1981,7 +1988,7 @@ public:
19811988
else
19821989
enum K = Canonical;
19831990
alias Ret = Slice!(Iterator, N - F, K);
1984-
Ret._Structure structure_;
1991+
auto structure_ = Ret._Structure.init;
19851992

19861993
enum bool shrink = kind == Canonical && slices.length == N;
19871994
static if (shrink)

source/mir/ndslice/topology.d

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ Slice!(Iterator, M, kind) reshape
12251225
else
12261226
{
12271227
alias Ret = typeof(return);
1228-
Ret._Structure structure;
1228+
auto structure = Ret._Structure.init;
12291229
alias lengths = structure[0];
12301230
foreach (i; Iota!M)
12311231
lengths[i] = rlengths[i];
@@ -2111,7 +2111,7 @@ auto bitwise
21112111
alias It = FieldIterator!(BitField!Iterator);
21122112
}
21132113
alias Ret = Slice!(It, N, kind);
2114-
Ret._Structure structure_;
2114+
auto structure_ = Ret._Structure.init;
21152115
foreach(i; Iota!(Ret.N))
21162116
structure_[0][i] = slice._lengths[i];
21172117
structure_[0][$ - 1] *= I.sizeof * 8;
@@ -2213,7 +2213,7 @@ auto bitpack
22132213
alias It = FieldIterator!(BitpackField!(Iterator, pack));
22142214
}
22152215
alias Ret = Slice!(It, N, kind);
2216-
Ret._Structure structure;
2216+
auto structure = Ret._Structure.init;
22172217
foreach(i; Iota!(Ret.N))
22182218
structure[0][i] = slice._lengths[i];
22192219
structure[0][$ - 1] *= I.sizeof * 8;
@@ -3195,7 +3195,7 @@ auto zip
31953195
enum kind = maxElem(staticMap!(kindOf, Slices));
31963196
alias Iterator = ZipIterator!(staticMap!(_IteratorOf, Slices));
31973197
alias Ret = Slice!(Iterator, N, kind);
3198-
Ret._Structure structure;
3198+
auto structure = Ret._Structure.init;
31993199
structure[0] = slices[0]._lengths;
32003200
foreach (i; Iota!(Ret.S))
32013201
structure[1][i] = slices[0]._strides[i];

source/mir/rcarray.d

Lines changed: 65 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ struct mir_rcarray(T)
7373
static assert(Context.sizeof % 16 == 0);
7474

7575
///
76-
private Context* _context;
76+
private T* _payload;
77+
private ref inout(Context*) _context() inout scope return pure nothrow @nogc @trusted @property
78+
{
79+
return *cast(inout(Context*)*)&_payload;
80+
}
7781

7882
// private inout(Context)* _context() inout @trusted pure nothrow @nogc scope
7983
// {
@@ -86,7 +90,7 @@ struct mir_rcarray(T)
8690
// }
8791

8892
///
89-
this(this) scope @safe pure nothrow @nogc
93+
this(this) scope @trusted pure nothrow @nogc
9094
{
9195
import core.atomic: atomicOp;
9296
if (_context !is null) with(*_context)
@@ -111,8 +115,8 @@ struct mir_rcarray(T)
111115
T[] array;
112116
()@trusted { array = (cast(T*)(_context + 1))[0 .. length]; }();
113117
xdestroy(array);
114-
auto p = cast(void*) _context;
115118
() @trusted {
119+
auto p = cast(void*) _payload;
116120
with(*_context)
117121
{
118122
if (_delegateContext !is null)
@@ -142,7 +146,7 @@ struct mir_rcarray(T)
142146
{
143147
///
144148
pragma(inline, false)
145-
~this() scope nothrow @nogc
149+
~this() scope nothrow @nogc @safe
146150
{
147151
dec();
148152
}
@@ -154,17 +158,17 @@ struct mir_rcarray(T)
154158
return initializeImpl(length, alignment, deallocate);
155159
}
156160

157-
// ///
158-
// this(ref typeof(this) rhs) @safe pure nothrow @nogc
159-
// {
160-
// this._context = rhs._context;
161-
// this.__xpostblit;
162-
// }
161+
///
162+
this(ref typeof(this) rhs) @safe pure nothrow @nogc
163+
{
164+
this._context = rhs._context;
165+
this.__xpostblit;
166+
}
163167
}
164168
else
165169
{
166170
pragma(inline, false)
167-
~this() scope nothrow @nogc
171+
~this() scope nothrow @nogc @safe
168172
{
169173
dec();
170174
}
@@ -240,13 +244,13 @@ struct mir_rcarray(T)
240244
}
241245

242246
///
243-
size_t length() @safe scope pure nothrow @nogc @property
247+
size_t length() @trusted scope pure nothrow @nogc @property
244248
{
245249
return _context !is null ? _context.length : 0;
246250
}
247251

248252
///
249-
size_t counter() @safe scope pure nothrow @nogc @property
253+
size_t counter() @trusted scope pure nothrow @nogc @property
250254
{
251255
return _context !is null ? _context.counter : 0;
252256
}
@@ -260,7 +264,7 @@ struct mir_rcarray(T)
260264
///
261265
ref opIndex(size_t i) @trusted scope inout
262266
{
263-
assert(_context);
267+
assert(_payload);
264268
assert(i < _context.length);
265269
return (cast(inout(T)*)(_context + 1))[i];
266270
}
@@ -277,17 +281,14 @@ struct mir_rcarray(T)
277281
return _context !is null ? (cast(inout(T)*)(_context + 1))[0 .. _context.length] : null;
278282
}
279283

280-
mir_rcarray!(const T) lightConst() const @nogc nothrow @trusted
281-
{
282-
return cast(typeof(return)) this;
283-
}
284+
///
285+
mir_rcarray!(const T) lightConst()() scope return const @nogc nothrow @trusted @property
286+
{ return cast(typeof(return)) this; }
284287

285-
mir_rcarray!(immutable T) lightImmutable() immutable @nogc nothrow @trusted
286-
{
287-
return cast(typeof(return)) this;
288-
}
288+
mir_rcarray!(immutable T) lightImmutable()() scope return immutable @nogc nothrow @trusted @property
289+
{ return cast(typeof(return)) this; }
289290

290-
size_t opDollar(size_t pos : 0)() @safe scope pure nothrow @nogc
291+
size_t opDollar(size_t pos : 0)() @trusted scope pure nothrow @nogc
291292
{
292293
return _context !is null ? _context.length : 0;
293294
}
@@ -300,11 +301,15 @@ struct mir_rcarray(T)
300301
}
301302
}
302303

304+
/// ditto
305+
alias RCArray = mir_rcarray;
306+
303307
///
308+
version(mir_test)
304309
@safe pure @nogc
305310
unittest
306311
{
307-
auto a = mir_rcarray!double(10);
312+
auto a = RCArray!double(10);
308313
foreach(i, ref e; a)
309314
e = i;
310315
auto b = a;
@@ -339,14 +344,13 @@ struct mir_rci(T)
339344
// }
340345

341346
///
342-
mir_rcarray!T _array;
347+
RCArray!T _array;
343348

344-
///
345-
mir_rci!(const T) lightConst()() const @property
349+
350+
mir_rci!(const T) lightConst() scope return const @nogc nothrow @trusted @property
346351
{ return typeof(return)(_iterator, _array.lightConst); }
347352

348-
///
349-
mir_rci!(immutable T) lightImmutable()() immutable @property
353+
mir_rci!(immutable T) lightImmutable() scope return immutable @nogc nothrow @trusted @property
350354
{ return typeof(return)(_iterator, _array.lightImmutable); }
351355

352356
///
@@ -367,7 +371,7 @@ struct mir_rci(T)
367371
if (op == "-" || op == "+")
368372
{ mixin("_iterator " ~ op ~ "= index;"); }
369373

370-
///
374+
///
371375
mir_rci!T opBinary(string op)(ptrdiff_t index)
372376
if (op == "+" || op == "-")
373377
{ return mir_rci!T(_iterator + index, _array); }
@@ -399,9 +403,10 @@ struct mir_rci(T)
399403
alias RCI = mir_rci;
400404

401405
///
406+
version(mir_test)
402407
@nogc unittest
403408
{
404-
import mir.ndslice;
409+
import mir.ndslice.slice;
405410
import mir.rcarray;
406411
auto array = mir_rcarray!double(10);
407412
auto slice = array.asSlice;
@@ -413,9 +418,10 @@ alias RCI = mir_rci;
413418
}
414419

415420
///
421+
version(mir_test)
416422
@nogc unittest
417423
{
418-
import mir.ndslice;
424+
import mir.ndslice.slice;
419425
import mir.rcarray;
420426

421427
alias rcvec = Slice!(RCI!double);
@@ -431,3 +437,30 @@ alias RCI = mir_rci;
431437
x = x.save;
432438
}
433439
}
440+
441+
version(mir_test)
442+
@safe @nogc unittest
443+
{
444+
import mir.ndslice;
445+
import mir.rcarray;
446+
447+
@safe void bar(ref const mir_rcarray!(const double) a, ref mir_rcarray!(const double) b)
448+
{
449+
b = a;
450+
}
451+
452+
@safe void bari(ref immutable mir_rcarray!(immutable double) a, ref mir_rcarray!(immutable double) b)
453+
{
454+
b = a;
455+
}
456+
457+
@safe void foo(ref const RCI!(const double) a, ref RCI!(const double) b)
458+
{
459+
b = a;
460+
}
461+
462+
@safe void fooi(ref immutable RCI!(immutable double) a, ref RCI!(immutable double) b)
463+
{
464+
b = a;
465+
}
466+
}

0 commit comments

Comments
 (0)