diff --git a/std/parallelism.d b/std/parallelism.d index 683a3cf8757..fc994f82c69 100644 --- a/std/parallelism.d +++ b/std/parallelism.d @@ -82,11 +82,9 @@ import core.thread; import std.algorithm; import std.conv; -import std.exception; import std.functional; -import std.math; import std.meta; -import std.range; +import std.range.primitives; import std.traits; import std.typecons; @@ -537,6 +535,7 @@ struct Task(alias fun, Args...) private void enforcePool() { + import std.exception : enforce; enforce(this.pool !is null, "Job not submitted yet."); } @@ -1529,6 +1528,7 @@ public: */ ParallelForeach!R parallel(R)(R range, size_t workUnitSize) { + import std.exception : enforce; enforce(workUnitSize > 0, "workUnitSize must be > 0."); alias RetType = ParallelForeach!R; return RetType(this, range, workUnitSize); @@ -1653,6 +1653,7 @@ public: is(MapType!(Args[0], functions) : ElementType!(Args[$ - 1])) ) { + import std.exception : enforce; alias buf = args[$ - 1]; alias args2 = args[0..$ - 1]; alias Args2 = Args[0..$ - 1]; @@ -1666,6 +1667,8 @@ public: } else { + import std.array : uninitializedArray; + auto buf = uninitializedArray!(MapType!(Args[0], functions)[])(len); alias args2 = args; alias Args2 = Args; @@ -1826,6 +1829,8 @@ public: map(S)(S source, size_t bufSize = 100, size_t workUnitSize = size_t.max) if (isInputRange!S) { + import std.exception : enforce; + enforce(workUnitSize == size_t.max || workUnitSize <= bufSize, "Work unit size must be smaller than buffer size."); alias fun = adjoin!(staticMap!(unaryFun, functions)); @@ -1978,6 +1983,7 @@ public: { static if (isRandomAccessRange!S) { + import std.range : take; auto toMap = take(source, buf.length); scope(success) popSource(); } @@ -2476,6 +2482,8 @@ public: } else { + import std.exception : enforce; + static assert(args2.length == 1); alias range = args2[0]; @@ -3183,6 +3191,7 @@ public: @trusted void put(alias fun, Args...)(Task!(fun, Args)* task) if (isSafeReturn!(typeof(*task))) { + import std.exception : enforce; enforce(task !is null, "Cannot put a null Task on a TaskPool queue."); put(*task); } @@ -3611,6 +3620,7 @@ enum string parallelApplyMixinInputRange = q{ size_t makeTemp() { import std.algorithm.internal : addressOf; + import std.array : uninitializedArray; if (temp is null) { @@ -3642,6 +3652,8 @@ enum string parallelApplyMixinInputRange = q{ // Returns: The previous value of nPopped. static if (!bufferTrick) size_t makeTemp() { + import std.array : uninitializedArray; + if (temp is null) { temp = uninitializedArray!Temp(workUnitSize); @@ -3897,6 +3909,10 @@ version(unittest) // These are the tests that should be run every time Phobos is compiled. unittest { + import std.exception : assertThrown; + import std.math : log, approxEqual, sqrt; + import std.range : iota; + poolInstance = new TaskPool(2); scope(exit) poolInstance.stop(); @@ -4151,6 +4167,7 @@ unittest )); { + import std.array : join, split; import std.file : deleteme; string temp_file = deleteme ~ "-tempDelMe.txt";