stdx.allocator.common 0/55(0%) line coverage

      
10
20
30
40
50
60
70
80
90
100
110
120
130
140
150
160
170
180
190
200
210
220
230
240
250
260
270
280
290
300
310
320
330
340
350
360
370
380
390
400
410
420
430
440
450
460
470
480
490
500
510
520
530
540
550
560
570
580
590
600
610
620
630
640
650
660
670
680
690
700
710
720
730
740
750
760
770
780
790
800
810
820
830
840
850
860
870
880
890
900
910
920
930
940
950
960
970
980
990
1000
1010
1020
1030
1040
1050
1060
1070
1080
1090
1100
1110
1120
1130
1140
1150
1160
1170
1180
1190
1200
1210
1220
1230
1240
1250
1260
1270
1280
1290
1300
1310
1320
1330
1340
1350
1360
1370
1380
1390
1400
1410
1420
1430
1440
1450
1460
1470
1480
1490
1500
1510
1520
1530
1540
1550
1560
1570
1580
1590
1600
1610
1620
1630
1640
1650
1660
1670
1680
1690
1700
1710
1720
1730
1740
1750
1760
1770
1780
1790
1800
1810
1820
1830
1840
1850
1860
1870
1880
1890
1900
1910
1920
1930
1940
1950
1960
1970
1980
1990
2000
2010
2020
2030
2040
2050
2060
2070
2080
2090
2100
2110
2120
2130
2140
2150
2160
2170
2180
2190
2200
2210
2220
2230
2240
2250
2260
2270
2280
2290
2300
2310
2320
2330
2340
2350
2360
2370
2380
2390
2400
2410
2420
2430
2440
2450
2460
2470
2480
2490
2500
2510
2520
2530
2540
2550
2560
2570
2580
2590
2600
2610
2620
2630
2640
2650
2660
2670
2680
2690
2700
2710
2720
2730
2740
2750
2760
2770
2780
2790
2800
2810
2820
2830
2840
2850
2860
2870
2880
2890
2900
2910
2920
2930
2940
2950
2960
2970
2980
2990
3000
3010
3020
3030
3040
3050
3060
3070
3080
3090
3100
3110
3120
3130
3140
3150
3160
3170
3180
3190
3200
3210
3220
3230
3240
3250
3260
3270
3280
3290
3300
3310
3320
3330
3340
3350
3360
3370
3380
3390
3400
3410
3420
3430
3440
3450
3460
3470
3480
3490
3500
3510
3520
3530
3540
3550
3560
3570
3580
3590
3600
3610
3620
3630
3640
3650
3660
3670
3680
3690
3700
3710
3720
3730
3740
3750
3760
3770
3780
3790
3800
3810
3820
3830
3840
3850
3860
3870
3880
3890
3900
3910
3920
3930
3940
3950
3960
3970
3980
3990
4000
4010
4020
4030
4040
4050
4060
4070
4080
4090
4100
4110
4120
4130
4140
4150
4160
4170
4180
4190
4200
4210
4220
4230
4240
4250
4260
4270
4280
4290
4300
4310
4320
4330
4340
4350
4360
4370
4380
4390
4400
4410
4420
4430
4440
4450
4460
4470
4480
4490
4500
4510
4520
4530
4540
4550
4560
4570
4580
4590
4600
4610
4620
4630
4640
4650
4660
4670
4680
4690
4700
4710
4720
4730
4740
4750
4760
4770
4780
4790
4800
4810
4820
4830
4840
4850
4860
4870
4880
4890
4900
4910
4920
4930
4940
4950
4960
4970
4980
4990
5000
5010
5020
5030
5040
5050
5060
5070
5080
5090
5100
5110
5120
5130
5140
5150
5160
5170
5180
5190
5200
5210
5220
5230
5240
5250
5260
5270
5280
5290
5300
5310
5320
5330
5340
5350
5360
5370
5380
5390
5400
5410
5420
5430
5440
5450
5460
5470
5480
5490
5500
5510
5520
5530
5540
5550
5560
5570
5580
5590
5600
5610
5620
5630
5640
5650
5660
5670
5680
5690
5700
5710
5720
5730
5740
5750
5760
5770
5780
5790
5800
5810
5820
5830
5840
5850
5860
5870
5880
5890
5900
5910
5920
5930
5940
5950
5960
5970
5980
5990
6000
6010
6020
6030
6040
6050
6060
6070
6080
6090
6100
6110
6120
6130
6140
6150
6160
6170
6180
6190
6200
6210
6220
6230
6240
6250
6260
6270
6280
6290
6300
6310
6320
6330
6340
6350
6360
6370
6380
6390
6400
6410
6420
6430
6440
6450
6460
6470
6480
6490
6500
6510
6520
6530
6540
6550
6560
6570
6580
6590
6600
6610
6620
6630
6640
6650
6660
6670
6680
6690
6700
6710
6720
6730
6740
6750
6760
6770
6780
6790
6800
6810
6820
6830
/** Utility and ancillary artifacts of `stdx.allocator`. This module shouldn't be used directly; its functionality will be migrated into more appropriate parts of `std`. Authors: $(HTTP erdani.com, Andrei Alexandrescu), Timon Gehr (`Ternary`) */ module stdx.allocator.common; import std.algorithm.comparison, std.traits; /** Returns the size in bytes of the state that needs to be allocated to hold an object of type $(D T). $(D stateSize!T) is zero for $(D struct)s that are not nested and have no nonstatic member variables. */ template stateSize(T) { static if (is(T == class) || is(T == interface)) enum stateSize = __traits(classInstanceSize, T); else static if (is(T == struct) || is(T == union)) enum stateSize = Fields!T.length || isNested!T ? T.sizeof : 0; else static if (is(T == void)) enum size_t stateSize = 0; else enum stateSize = T.sizeof; } @safe @nogc nothrow pure unittest { static assert(stateSize!void == 0); struct A {} static assert(stateSize!A == 0); struct B { int x; } static assert(stateSize!B == 4); interface I1 {} //static assert(stateSize!I1 == 2 * size_t.sizeof); class C1 {} static assert(stateSize!C1 == 3 * size_t.sizeof); class C2 { char c; } static assert(stateSize!C2 == 4 * size_t.sizeof); static class C3 { char c; } static assert(stateSize!C3 == 2 * size_t.sizeof + char.sizeof); } /** Returns `true` if the `Allocator` has the alignment known at compile time; otherwise it returns `false`. */ template hasStaticallyKnownAlignment(Allocator) { enum hasStaticallyKnownAlignment = __traits(compiles, {enum x = Allocator.alignment;}); } /** $(D chooseAtRuntime) is a compile-time constant of type $(D size_t) that several parameterized structures in this module recognize to mean deferral to runtime of the exact value. For example, $(D BitmappedBlock!(Allocator, 4096)) (described in detail below) defines a block allocator with block size of 4096 bytes, whereas $(D BitmappedBlock!(Allocator, chooseAtRuntime)) defines a block allocator that has a field storing the block size, initialized by the user. */ enum chooseAtRuntime = size_t.max - 1; /** $(D unbounded) is a compile-time constant of type $(D size_t) that several parameterized structures in this module recognize to mean "infinite" bounds for the parameter. For example, $(D Freelist) (described in detail below) accepts a $(D maxNodes) parameter limiting the number of freelist items. If $(D unbounded) is passed for $(D maxNodes), then there is no limit and no checking for the number of nodes. */ enum unbounded = size_t.max; /** The alignment that is guaranteed to accommodate any D object allocation on the current platform. */ enum uint platformAlignment = std.algorithm.comparison.max(double.alignof, real.alignof); /** The default good size allocation is deduced as $(D n) rounded up to the allocator's alignment. */ size_t goodAllocSize(A)(auto ref A a, size_t n) { return n.roundUpToMultipleOf(a.alignment); } /** Returns s rounded up to a multiple of base. */ @safe @nogc nothrow pure package size_t roundUpToMultipleOf(size_t s, uint base) { assert(base); auto rem = s % base; return rem ? s + base - rem : s; } @safe @nogc nothrow pure unittest { assert(10.roundUpToMultipleOf(11) == 11); assert(11.roundUpToMultipleOf(11) == 11); assert(12.roundUpToMultipleOf(11) == 22); assert(118.roundUpToMultipleOf(11) == 121); } /** Returns `n` rounded up to a multiple of alignment, which must be a power of 2. */ @safe @nogc nothrow pure package size_t roundUpToAlignment(size_t n, uint alignment) { import std.math : isPowerOf2; assert(alignment.isPowerOf2); immutable uint slack = cast(uint) n & (alignment - 1); const result = slack ? n + alignment - slack : n; assert(result >= n); return result; } @safe @nogc nothrow pure unittest { assert(10.roundUpToAlignment(4) == 12); assert(11.roundUpToAlignment(2) == 12); assert(12.roundUpToAlignment(8) == 16); assert(118.roundUpToAlignment(64) == 128); } /** Returns `n` rounded down to a multiple of alignment, which must be a power of 2. */ @safe @nogc nothrow pure package size_t roundDownToAlignment(size_t n, uint alignment) { import std.math : isPowerOf2; assert(alignment.isPowerOf2); return n & ~size_t(alignment - 1); } @safe @nogc nothrow pure unittest { assert(10.roundDownToAlignment(4) == 8); assert(11.roundDownToAlignment(2) == 10); assert(12.roundDownToAlignment(8) == 8); assert(63.roundDownToAlignment(64) == 0); } /** Advances the beginning of `b` to start at alignment `a`. The resulting buffer may therefore be shorter. Returns the adjusted buffer, or null if obtaining a non-empty buffer is impossible. */ @nogc nothrow pure package void[] roundUpToAlignment(void[] b, uint a) { auto e = b.ptr + b.length; auto p = cast(void*) roundUpToAlignment(cast(size_t) b.ptr, a); if (e <= p) return null; return p[0 .. e - p]; } @nogc nothrow pure @system unittest { void[] empty; assert(roundUpToAlignment(empty, 4) == null); char[128] buf; // At least one pointer inside buf is 128-aligned assert(roundUpToAlignment(buf, 128) !is null); } /** Like `a / b` but rounds the result up, not down. */ @safe @nogc nothrow pure package size_t divideRoundUp(size_t a, size_t b) { assert(b); return (a + b - 1) / b; } /** Returns `s` rounded up to a multiple of `base`. */ @nogc nothrow pure package void[] roundStartToMultipleOf(void[] s, uint base) { assert(base); auto p = cast(void*) roundUpToMultipleOf( cast(size_t) s.ptr, base); auto end = s.ptr + s.length; return p[0 .. end - p]; } nothrow pure @system unittest { void[] p; assert(roundStartToMultipleOf(p, 16) is null); p = new ulong[10]; assert(roundStartToMultipleOf(p, 16) is p); } /** Returns $(D s) rounded up to the nearest power of 2. */ @safe @nogc nothrow pure package size_t roundUpToPowerOf2(size_t s) { import std.meta : AliasSeq; assert(s <= (size_t.max >> 1) + 1); --s; static if (size_t.sizeof == 4) alias Shifts = AliasSeq!(1, 2, 4, 8, 16); else alias Shifts = AliasSeq!(1, 2, 4, 8, 16, 32); foreach (i; Shifts) { s |= s >> i; } return s + 1; } @safe @nogc nothrow pure unittest { assert(0.roundUpToPowerOf2 == 0); assert(1.roundUpToPowerOf2 == 1); assert(2.roundUpToPowerOf2 == 2); assert(3.roundUpToPowerOf2 == 4); assert(7.roundUpToPowerOf2 == 8); assert(8.roundUpToPowerOf2 == 8); assert(10.roundUpToPowerOf2 == 16); assert(11.roundUpToPowerOf2 == 16); assert(12.roundUpToPowerOf2 == 16); assert(118.roundUpToPowerOf2 == 128); assert((size_t.max >> 1).roundUpToPowerOf2 == (size_t.max >> 1) + 1); assert(((size_t.max >> 1) + 1).roundUpToPowerOf2 == (size_t.max >> 1) + 1); } /** Returns the number of trailing zeros of $(D x). */ @safe @nogc nothrow pure package uint trailingZeros(ulong x) { uint result; while (result < 64 && !(x & (1UL << result))) { ++result; } return result; } @safe @nogc nothrow pure unittest { assert(trailingZeros(0) == 64); assert(trailingZeros(1) == 0); assert(trailingZeros(2) == 1); assert(trailingZeros(3) == 0); assert(trailingZeros(4) == 2); } /** Returns `true` if `ptr` is aligned at `alignment`. */ @nogc nothrow pure package bool alignedAt(T)(T* ptr, uint alignment) { return cast(size_t) ptr % alignment == 0; } /** Returns the effective alignment of `ptr`, i.e. the largest power of two that is a divisor of `ptr`. */ @nogc nothrow pure package uint effectiveAlignment(void* ptr) { return 1U << trailingZeros(cast(size_t) ptr); } @nogc nothrow pure @system unittest { int x; assert(effectiveAlignment(&x) >= int.alignof); } /** Aligns a pointer down to a specified alignment. The resulting pointer is less than or equal to the given pointer. */ @nogc nothrow pure package void* alignDownTo(void* ptr, uint alignment) { import std.math : isPowerOf2; assert(alignment.isPowerOf2); return cast(void*) (cast(size_t) ptr & ~(alignment - 1UL)); } /** Aligns a pointer up to a specified alignment. The resulting pointer is greater than or equal to the given pointer. */ @nogc nothrow pure package void* alignUpTo(void* ptr, uint alignment) { import std.math : isPowerOf2; assert(alignment.isPowerOf2); immutable uint slack = cast(size_t) ptr & (alignment - 1U); return slack ? ptr + alignment - slack : ptr; } @safe @nogc nothrow pure package bool isGoodStaticAlignment(uint x) { import std.math : isPowerOf2; return x.isPowerOf2; } @safe @nogc nothrow pure package bool isGoodDynamicAlignment(uint x) { import std.math : isPowerOf2; return x.isPowerOf2 && x >= (void*).sizeof; } /** The default $(D reallocate) function first attempts to use $(D expand). If $(D Allocator.expand) is not defined or returns $(D false), $(D reallocate) allocates a new block of memory of appropriate size and copies data from the old block to the new block. Finally, if $(D Allocator) defines $(D deallocate), $(D reallocate) uses it to free the old memory block. $(D reallocate) does not attempt to use $(D Allocator.reallocate) even if defined. This is deliberate so allocators may use it internally within their own implementation of $(D reallocate). */ bool reallocate(Allocator)(ref Allocator a, ref void[] b, size_t s) { if (b.length == s) return true; static if (hasMember!(Allocator, "expand")) { if (b.length <= s && a.expand(b, s - b.length)) return true; } auto newB = a.allocate(s); if (newB.length != s) return false; if (newB.length <= b.length) newB[] = b[0 .. newB.length]; else newB[0 .. b.length] = b[]; static if (hasMember!(Allocator, "deallocate")) a.deallocate(b); b = newB; return true; } /** The default $(D alignedReallocate) function first attempts to use $(D expand). If $(D Allocator.expand) is not defined or returns $(D false), $(D alignedReallocate) allocates a new block of memory of appropriate size and copies data from the old block to the new block. Finally, if $(D Allocator) defines $(D deallocate), $(D alignedReallocate) uses it to free the old memory block. $(D alignedReallocate) does not attempt to use $(D Allocator.reallocate) even if defined. This is deliberate so allocators may use it internally within their own implementation of $(D reallocate). */ bool alignedReallocate(Allocator)(ref Allocator alloc, ref void[] b, size_t s, uint a) { static if (hasMember!(Allocator, "expand")) { if (b.length <= s && b.ptr.alignedAt(a) && alloc.expand(b, s - b.length)) return true; } else { if (b.length == s) return true; } auto newB = alloc.alignedAllocate(s, a); if (newB.length <= b.length) newB[] = b[0 .. newB.length]; else newB[0 .. b.length] = b[]; static if (hasMember!(Allocator, "deallocate")) alloc.deallocate(b); b = newB; return true; } /** Forwards each of the methods in `funs` (if defined) to `member`. */ /*package*/ string forwardToMember(string member, string[] funs...) { string result = " import std.traits : hasMember, Parameters;\n"; foreach (fun; funs) { result ~= " static if (hasMember!(typeof("~member~"), `"~fun~"`)) auto ref "~fun~"(Parameters!(typeof("~member~"."~fun~")) args) { return "~member~"."~fun~"(args); }\n"; } return result; } version(unittest) { import stdx.allocator : IAllocator, ISharedAllocator; package void testAllocator(alias make)() { import std.conv : text; import std.math : isPowerOf2; import std.stdio : writeln, stderr; import std.typecons : Ternary; alias A = typeof(make()); scope(failure) stderr.writeln("testAllocator failed for ", A.stringof); auto a = make(); // Test alignment static assert(A.alignment.isPowerOf2); // Test goodAllocSize assert(a.goodAllocSize(1) >= A.alignment, text(a.goodAllocSize(1), " < ", A.alignment)); assert(a.goodAllocSize(11) >= 11.roundUpToMultipleOf(A.alignment)); assert(a.goodAllocSize(111) >= 111.roundUpToMultipleOf(A.alignment)); // Test allocate assert(a.allocate(0) is null); auto b1 = a.allocate(1); assert(b1.length == 1); auto b2 = a.allocate(2); assert(b2.length == 2); assert(b2.ptr + b2.length <= b1.ptr || b1.ptr + b1.length <= b2.ptr); // Test alignedAllocate static if (hasMember!(A, "alignedAllocate")) {{ auto b3 = a.alignedAllocate(1, 256); assert(b3.length <= 1); assert(b3.ptr.alignedAt(256)); assert(a.alignedReallocate(b3, 2, 512)); assert(b3.ptr.alignedAt(512)); static if (hasMember!(A, "alignedDeallocate")) { a.alignedDeallocate(b3); } }} else { static assert(!hasMember!(A, "alignedDeallocate")); // This seems to be a bug in the compiler: //static assert(!hasMember!(A, "alignedReallocate"), A.stringof); } static if (hasMember!(A, "allocateAll")) {{ auto aa = make(); if (aa.allocateAll().ptr) { // Can't get any more memory assert(!aa.allocate(1).ptr); } auto ab = make(); const b4 = ab.allocateAll(); assert(b4.length); // Can't get any more memory assert(!ab.allocate(1).ptr); }} static if (hasMember!(A, "expand")) {{ assert(a.expand(b1, 0)); auto len = b1.length; if (a.expand(b1, 102)) { assert(b1.length == len + 102, text(b1.length, " != ", len + 102)); } auto aa = make(); void[] b5 = null; assert(aa.expand(b5, 0)); assert(b5 is null); assert(!aa.expand(b5, 1)); assert(b5.length == 0); }} void[] b6 = null; assert(a.reallocate(b6, 0)); assert(b6.length == 0); assert(a.reallocate(b6, 1)); assert(b6.length == 1, text(b6.length)); assert(a.reallocate(b6, 2)); assert(b6.length == 2); // Test owns static if (hasMember!(A, "owns")) {{ assert(a.owns(null) == Ternary.no); assert(a.owns(b1) == Ternary.yes); assert(a.owns(b2) == Ternary.yes); assert(a.owns(b6) == Ternary.yes); }} static if (hasMember!(A, "resolveInternalPointer")) {{ void[] p; assert(a.resolveInternalPointer(null, p) == Ternary.no); Ternary r = a.resolveInternalPointer(b1.ptr, p); assert(p.ptr is b1.ptr && p.length >= b1.length); r = a.resolveInternalPointer(b1.ptr + b1.length / 2, p); assert(p.ptr is b1.ptr && p.length >= b1.length); r = a.resolveInternalPointer(b2.ptr, p); assert(p.ptr is b2.ptr && p.length >= b2.length); r = a.resolveInternalPointer(b2.ptr + b2.length / 2, p); assert(p.ptr is b2.ptr && p.length >= b2.length); r = a.resolveInternalPointer(b6.ptr, p); assert(p.ptr is b6.ptr && p.length >= b6.length); r = a.resolveInternalPointer(b6.ptr + b6.length / 2, p); assert(p.ptr is b6.ptr && p.length >= b6.length); static int[10] b7 = [ 1, 2, 3 ]; assert(a.resolveInternalPointer(b7.ptr, p) == Ternary.no); assert(a.resolveInternalPointer(b7.ptr + b7.length / 2, p) == Ternary.no); assert(a.resolveInternalPointer(b7.ptr + b7.length, p) == Ternary.no); int[3] b8 = [ 1, 2, 3 ]; assert(a.resolveInternalPointer(b8.ptr, p) == Ternary.no); assert(a.resolveInternalPointer(b8.ptr + b8.length / 2, p) == Ternary.no); assert(a.resolveInternalPointer(b8.ptr + b8.length, p) == Ternary.no); }} } package void testAllocatorObject(AllocInterface)(AllocInterface a) if (is(AllocInterface : IAllocator) || is (AllocInterface : shared ISharedAllocator)) { import std.conv : text; import std.math : isPowerOf2; import std.stdio : writeln, stderr; import std.typecons : Ternary; scope(failure) stderr.writeln("testAllocatorObject failed for ", AllocInterface.stringof); assert(a); // Test alignment assert(a.alignment.isPowerOf2); // Test goodAllocSize assert(a.goodAllocSize(1) >= a.alignment, text(a.goodAllocSize(1), " < ", a.alignment)); assert(a.goodAllocSize(11) >= 11.roundUpToMultipleOf(a.alignment)); assert(a.goodAllocSize(111) >= 111.roundUpToMultipleOf(a.alignment)); // Test empty assert(a.empty != Ternary.no); // Test allocate assert(a.allocate(0) is null); auto b1 = a.allocate(1); assert(b1.length == 1); auto b2 = a.allocate(2); assert(b2.length == 2); assert(b2.ptr + b2.length <= b1.ptr || b1.ptr + b1.length <= b2.ptr); // Test alignedAllocate { // If not implemented it will return null, so those should pass auto b3 = a.alignedAllocate(1, 256); assert(b3.length <= 1); assert(b3.ptr.alignedAt(256)); if (a.alignedReallocate(b3, 1, 256)) { // If it is false, then the wrapped allocator did not implement // this assert(a.alignedReallocate(b3, 2, 512)); assert(b3.ptr.alignedAt(512)); } } // Test allocateAll { auto aa = a.allocateAll(); if (aa.ptr) { // Can't get any more memory assert(!a.allocate(1).ptr); a.deallocate(aa); } const b4 = a.allocateAll(); if (b4.ptr) { // Can't get any more memory assert(!a.allocate(1).ptr); } } // Test expand { assert(a.expand(b1, 0)); auto len = b1.length; if (a.expand(b1, 102)) { assert(b1.length == len + 102, text(b1.length, " != ", len + 102)); } } void[] b6 = null; assert(a.reallocate(b6, 0)); assert(b6.length == 0); assert(a.reallocate(b6, 1)); assert(b6.length == 1, text(b6.length)); assert(a.reallocate(b6, 2)); assert(b6.length == 2); // Test owns { if (a.owns(null) != Ternary.unknown) { assert(a.owns(null) == Ternary.no); assert(a.owns(b1) == Ternary.yes); assert(a.owns(b2) == Ternary.yes); assert(a.owns(b6) == Ternary.yes); } } // Test resolveInternalPointer { void[] p; if (a.resolveInternalPointer(null, p) != Ternary.unknown) { assert(a.resolveInternalPointer(null, p) == Ternary.no); Ternary r = a.resolveInternalPointer(b1.ptr, p); assert(p.ptr is b1.ptr && p.length >= b1.length); r = a.resolveInternalPointer(b1.ptr + b1.length / 2, p); assert(p.ptr is b1.ptr && p.length >= b1.length); r = a.resolveInternalPointer(b2.ptr, p); assert(p.ptr is b2.ptr && p.length >= b2.length); r = a.resolveInternalPointer(b2.ptr + b2.length / 2, p); assert(p.ptr is b2.ptr && p.length >= b2.length); r = a.resolveInternalPointer(b6.ptr, p); assert(p.ptr is b6.ptr && p.length >= b6.length); r = a.resolveInternalPointer(b6.ptr + b6.length / 2, p); assert(p.ptr is b6.ptr && p.length >= b6.length); static int[10] b7 = [ 1, 2, 3 ]; assert(a.resolveInternalPointer(b7.ptr, p) == Ternary.no); assert(a.resolveInternalPointer(b7.ptr + b7.length / 2, p) == Ternary.no); assert(a.resolveInternalPointer(b7.ptr + b7.length, p) == Ternary.no); int[3] b8 = [ 1, 2, 3 ]; assert(a.resolveInternalPointer(b8.ptr, p) == Ternary.no); assert(a.resolveInternalPointer(b8.ptr + b8.length / 2, p) == Ternary.no); assert(a.resolveInternalPointer(b8.ptr + b8.length, p) == Ternary.no); } } // Test deallocateAll { if (a.deallocateAll()) { if (a.empty != Ternary.unknown) { assert(a.empty == Ternary.yes); } } } } }