diff --git a/src/d/ast/expression.d b/src/d/ast/expression.d index 1bcfb4f08..6efad985e 100644 --- a/src/d/ast/expression.d +++ b/src/d/ast/expression.d @@ -126,9 +126,7 @@ unittest { } } -AstBinaryOp getBaseOp(AstBinaryOp op) in { - assert(isAssign(op)); -} do { +AstBinaryOp getBaseOp(AstBinaryOp op) in(isAssign(op)) { return op + AstBinaryOp.Add - AstBinaryOp.AddAssign; } diff --git a/src/d/ir/instruction.d b/src/d/ir/instruction.d index 53af7abeb..6ff078782 100644 --- a/src/d/ir/instruction.d +++ b/src/d/ir/instruction.d @@ -12,10 +12,8 @@ private: BasicBlock[] basicBlocks; public: - ref inout(BasicBlock) opIndex(BasicBlockRef i) inout in { - assert(i, "null block ref"); - assert(i.index <= basicBlocks.length, "Out of bounds block ref"); - } do { + ref inout(BasicBlock) opIndex(BasicBlockRef i) inout in(i, "null block ref") + in(i.index <= basicBlocks.length, "Out of bounds block ref") { return basicBlocks.ptr[i.index - 1]; } @@ -226,9 +224,7 @@ private: @disable this(this); - void add(Instruction i) in { - assert(!terminate, "block does terminate already"); - } do { + void add(Instruction i) in(!terminate, "block does terminate already") { instructions ~= i; } @@ -353,9 +349,8 @@ private: expr = e; } - this(Location location, Variable v) in { - assert(v.step == Step.Processed, "Variable is not processed"); - } do { + this(Location location, Variable v) + in(v.step == Step.Processed, "Variable is not processed") { this.location = location; op = OpCode.Alloca; var = v; @@ -367,10 +362,9 @@ private: return i; } - this(Location location, Symbol s) in { - assert(s.step == Step.Processed, "Symbol is not processed"); - assert(!cast(Variable) s, "Use alloca for variables"); - } do { + this(Location location, Symbol s) + in(s.step == Step.Processed, "Symbol is not processed") + in(!cast(Variable) s, "Use alloca for variables") { this.location = location; op = OpCode.Declare; sym = s; diff --git a/src/d/ir/symbol.d b/src/d/ir/symbol.d index 72db9560b..cf3906f88 100644 --- a/src/d/ir/symbol.d +++ b/src/d/ir/symbol.d @@ -136,10 +136,9 @@ class Function : ValueSymbol, Scope { } @property - Intrinsic intrinsicID(Intrinsic id) in { - assert(!hasThis, "Method can't be intrinsic"); - assert(intrinsicID == Intrinsic.None, "This is already an intrinsic"); - } do { + Intrinsic intrinsicID(Intrinsic id) + in(!hasThis, "Method can't be intrinsic") + in(intrinsicID == Intrinsic.None, "This is already an intrinsic") { derived = id; return intrinsicID; } diff --git a/src/d/llvm/evaluator.d b/src/d/llvm/evaluator.d index fdd318c96..b3208e2b3 100644 --- a/src/d/llvm/evaluator.d +++ b/src/d/llvm/evaluator.d @@ -98,14 +98,11 @@ final class LLVMEvaluator : Evaluator { auto et = t.element.getCanonical(); assert(et.builtin = BuiltinType.Char); } do { - return jit!(function string(CodeGen pass, Expression e, void[] p) in { - assert(p.length == string.sizeof); - } do { - auto s = *(cast(string*) p.ptr); - return s.idup; - } - - )(e); + return jit!(function string(CodeGen pass, Expression e, void[] p) + in (p.length == string.sizeof) { + auto s = *(cast(string*) p.ptr); + return s.idup; + })(e); } private diff --git a/src/d/llvm/expression.d b/src/d/llvm/expression.d index 5c58b8a5b..62f68d4c7 100644 --- a/src/d/llvm/expression.d +++ b/src/d/llvm/expression.d @@ -913,10 +913,9 @@ struct AddressOfGen { return ExpressionGen(pass).visit(e); } - LLVMValueRef visit(VariableExpression e) in { - assert(e.var.storage != Storage.Enum, "enum have no address."); - assert(!e.var.isFinal, "finals have no address."); - } do { + LLVMValueRef visit(VariableExpression e) + in(e.var.storage != Storage.Enum, "enum have no address.") + in(!e.var.isFinal, "finals have no address.") { return declare(e.var); } diff --git a/src/d/llvm/global.d b/src/d/llvm/global.d index 6f17e5dbd..f10269e37 100644 --- a/src/d/llvm/global.d +++ b/src/d/llvm/global.d @@ -49,11 +49,9 @@ struct GlobalGen { return LocalGen(pass).define(f); } - LLVMValueRef declare(Variable v) in { - assert(v.storage.isGlobal, "locals not supported"); - assert(!v.isFinal); - assert(!v.isRef); - } do { + LLVMValueRef declare(Variable v) + in(v.storage.isGlobal, "locals not supported") in(!v.isFinal) + in(!v.isRef) { auto var = globals.get(v, { if (v.storage == Storage.Enum) { import d.llvm.constant; @@ -78,11 +76,9 @@ struct GlobalGen { return var; } - LLVMValueRef define(Variable v) in { - assert(v.storage.isGlobal, "locals not supported"); - assert(!v.isFinal); - assert(!v.isRef); - } do { + LLVMValueRef define(Variable v) + in(v.storage.isGlobal, "locals not supported") in(!v.isFinal) + in(!v.isRef) { auto var = declare(v); if (!v.value || v.storage == Storage.Enum) { return var; @@ -100,12 +96,10 @@ struct GlobalGen { return var; } - bool maybeDefine(Variable v, LLVMValueRef var) in { - assert(v.storage.isGlobal, "locals not supported"); - assert(v.storage != Storage.Enum, "enum do not have a storage"); - assert(!v.isFinal); - assert(!v.isRef); - } do { + bool maybeDefine(Variable v, LLVMValueRef var) + in(v.storage.isGlobal, "locals not supported") + in(v.storage != Storage.Enum, "enum do not have a storage") + in(!v.isFinal) in(!v.isRef) { if (LLVMGetInitializer(var)) { return false; } @@ -118,10 +112,9 @@ struct GlobalGen { return true; } - private LLVMValueRef createVariableStorage(Variable v) in { - assert(v.storage.isGlobal, "locals not supported"); - assert(v.storage != Storage.Enum, "enum do not have a storage"); - } do { + private LLVMValueRef createVariableStorage(Variable v) + in(v.storage.isGlobal, "locals not supported") + in(v.storage != Storage.Enum, "enum do not have a storage") { auto qualifier = v.type.qualifier; import d.llvm.type; diff --git a/src/d/llvm/local.d b/src/d/llvm/local.d index d9a207ed1..142db0758 100644 --- a/src/d/llvm/local.d +++ b/src/d/llvm/local.d @@ -191,13 +191,11 @@ struct LocalGen { return true; } - private void genBody(Function f, LLVMValueRef fun) in { - assert(LLVMCountBasicBlocks(fun) == 0, - f.mangle.toString(context) ~ " body is already defined"); - - assert(f.step == Step.Processed, "f is not processed"); - assert(f.fbody || f.intrinsicID, "f must have a body"); - } do { + private void genBody(Function f, LLVMValueRef fun) + in(LLVMCountBasicBlocks(fun) == 0, + f.mangle.toString(context) ~ " body is already defined") + in(f.step == Step.Processed, "f is not processed") + in(f.fbody || f.intrinsicID, "f must have a body") { scope(failure) f.dump(context); // Alloca and instruction block. @@ -401,9 +399,7 @@ struct LocalGen { return locals.get(v, define(v)); } - LLVMValueRef define(Variable v) in { - assert(!v.isFinal); - } do { + LLVMValueRef define(Variable v) in(!v.isFinal) { if (v.storage.isGlobal) { import d.llvm.global; return GlobalGen(pass, mode).define(v); diff --git a/src/d/semantic/dtemplate.d b/src/d/semantic/dtemplate.d index 00a65146f..a9a977384 100644 --- a/src/d/semantic/dtemplate.d +++ b/src/d/semantic/dtemplate.d @@ -120,11 +120,9 @@ struct TemplateInstancier { private: bool matchArguments(Template t, TemplateArgument[] args, Expression[] fargs, - TemplateArgument[] matchedArgs) in { - assert(t.step == Step.Processed); - assert(t.parameters.length >= args.length); - assert(matchedArgs.length == t.parameters.length); - } do { + TemplateArgument[] matchedArgs) + in(t.step == Step.Processed) in(t.parameters.length >= args.length) + in(matchedArgs.length == t.parameters.length) { uint i = 0; foreach (a; args) { if (!matchArgument(t.parameters[i++], a, matchedArgs)) { @@ -185,11 +183,11 @@ private: })(); } - auto instanciateFromResolvedArgs(Location location, Template t, - TemplateArgument[] args) in { - assert(t.step == Step.Processed); - assert(t.parameters.length == args.length); - } do { + auto instanciateFromResolvedArgs( + Location location, + Template t, + TemplateArgument[] args + ) in(t.step == Step.Processed) in(t.parameters.length == args.length) { auto i = 0; Symbol[] argSyms; diff --git a/src/d/semantic/expression.d b/src/d/semantic/expression.d index 45d7f84f0..1a1d4f105 100644 --- a/src/d/semantic/expression.d +++ b/src/d/semantic/expression.d @@ -572,11 +572,10 @@ public: return getFromImpl(location, f, ctxs); } - private Expression getFromImpl(Location location, Function f, - Expression[] ctxs) in { - assert(f.step >= Step.Signed); - assert(ctxs.length >= f.hasContext + f.hasThis); - } do { + private + Expression getFromImpl(Location location, Function f, Expression[] ctxs) + in(f.step >= Step.Signed) + in(ctxs.length >= f.hasContext + f.hasThis) { foreach (i, ref c; ctxs) { c = buildArgument(c, f.type.parameters[i]); } diff --git a/src/d/semantic/symbol.d b/src/d/semantic/symbol.d index 85e8bf97a..29db6de29 100644 --- a/src/d/semantic/symbol.d +++ b/src/d/semantic/symbol.d @@ -1062,10 +1062,8 @@ struct SymbolAnalyzer { e.step = Step.Processed; } - void analyze(AstExpression dv, Variable v) in { - assert(v.storage == Storage.Enum); - assert(v.type.kind == TypeKind.Enum); - } do { + void analyze(AstExpression dv, Variable v) in(v.storage == Storage.Enum) + in(v.type.kind == TypeKind.Enum) { auto e = v.type.denum; if (dv !is null) { diff --git a/src/d/semantic/vrp.d b/src/d/semantic/vrp.d index aa853710b..b925aa58d 100644 --- a/src/d/semantic/vrp.d +++ b/src/d/semantic/vrp.d @@ -39,10 +39,9 @@ struct ValueRangePropagator(T) if (is(T == uint) || is(T == ulong)) { return canFit(e, getBuiltin(t)); } - bool canFit(Expression e, BuiltinType t) in { - assert(isValidExpr(e), "VRP expect integral types."); - assert(canConvertToIntegral(t), "VRP only supports integral types."); - } do { + bool canFit(Expression e, BuiltinType t) + in(isValidExpr(e), "VRP expect integral types.") + in(canConvertToIntegral(t), "VRP only supports integral types.") { static canFitDMDMonkeyDance(R)(R r, BuiltinType t) { auto mask = cast(R.U) ((1UL << t.getBits()) - 1); @@ -1054,11 +1053,9 @@ struct ValueRange(T) if (is(uint : T) && isIntegral!T) { return ValueRange(-neg.max, pos.max); } - auto urem()(ValueRange rhs) const if (isUnsigned!T) in { - assert(this != ValueRange(0)); - assert(rhs is rhs.normalized); - assert(rhs.min > 0); - } do { + auto urem()(ValueRange rhs) const if (isUnsigned!T) + in(this != ValueRange(0)) in(rhs is rhs.normalized) + in(rhs.min > 0) { auto lhs = this.normalized; // If lhs is within the bound of rhs. @@ -1118,11 +1115,9 @@ struct ValueRange(T) if (is(uint : T) && isIntegral!T) { return ValueRange(v1.min, v0.max); } - auto ushl()(ValueRange rhs) const if (isUnsigned!T) in { - assert(rhs is rhs.normalized); - assert(rhs.max < Bits); - assert(this.min <= Signed!T.max); - } do { + auto ushl()(ValueRange rhs) const if (isUnsigned!T) + in(rhs is rhs.normalized) in(rhs.max < Bits) + in(this.min <= Signed!T.max) { auto minhi = rhs.min ? (min >> (Bits - rhs.min)) : 0; auto maxhi = rhs.max ? (max >> (Bits - rhs.max)) : 0; if (minhi != maxhi) { diff --git a/src/format/rulevalues.d b/src/format/rulevalues.d index aa4e1b0ee..332d082e5 100644 --- a/src/format/rulevalues.d +++ b/src/format/rulevalues.d @@ -66,10 +66,7 @@ public: } @property - size_t frozen(size_t f) in { - assert(f > 0 && f <= capacity); - assert(this[f - 1]); - } do { + size_t frozen(size_t f) in(f > 0 && f <= capacity) in(this[f - 1]) { if (isDirect()) { // Replace the previous frozen value. direct[1] &= (size_t(1) << DirectShift) - 1; diff --git a/src/format/span.d b/src/format/span.d index 3a53ee830..9b5645710 100644 --- a/src/format/span.d +++ b/src/format/span.d @@ -330,10 +330,9 @@ final class ListSpan : Span { return trailingSplit != size_t.max; } - void registerElement(size_t i) in { - assert(elements.length == 0 || elements[$ - 1] <= i); - assert(!hasTrailingSplit); - } do { + void registerElement(size_t i) + in(elements.length == 0 || elements[$ - 1] <= i) + in(!hasTrailingSplit) { import std.algorithm; headerSplit = min(i, headerSplit); @@ -345,11 +344,8 @@ final class ListSpan : Span { headerSplit = i; } - void registerTrailingSplit(size_t i) in { - assert(elements.length > 0); - assert(elements[$ - 1] <= i); - assert(!hasTrailingSplit); - } do { + void registerTrailingSplit(size_t i) in(elements.length > 0) + in(elements[$ - 1] <= i) in(!hasTrailingSplit) { trailingSplit = i; if (elements.length > 1) { diff --git a/src/source/lexbase.d b/src/source/lexbase.d index 212021c85..58b32e40a 100644 --- a/src/source/lexbase.d +++ b/src/source/lexbase.d @@ -130,12 +130,8 @@ mixin template LexBaseImpl(Token, alias BaseMap, alias KeywordMap, // +/ } - void moveTo(ref TokenRange fr) in { - assert(base is fr.base); - assert(context is fr.context); - assert(content is fr.content); - assert(index < fr.index); - } do { + void moveTo(ref TokenRange fr) in(base is fr.base) in(context is fr.context) + in(content is fr.content) in(index < fr.index) { index = fr.index; t = fr.t; previous = fr.previous; diff --git a/src/source/location.d b/src/source/location.d index 716072b1c..dac41d1c1 100644 --- a/src/source/location.d +++ b/src/source/location.d @@ -2,6 +2,9 @@ module source.location; import source.context; +version(D_PreConditions) + import std.conv; + /** * Struct representing a location in a source file. * Effectively a pair of Position within the source file. @@ -12,10 +15,8 @@ package: Position _stop; public: - this(Position start, Position stop) in { - assert(start.isMixin() == stop.isMixin()); - assert(start.offset <= stop.offset); - } do { + this(Position start, Position stop) in(start.isMixin() == stop.isMixin()) + in(start.offset <= stop.offset) { this._start = start; this._stop = stop; } @@ -45,19 +46,15 @@ public: return start.isMixin(); } - auto spanTo(Location end) in { - import std.conv; - assert(stop.offset <= end.stop.offset, - to!string(stop.offset) ~ " > " ~ to!string(end.stop.offset)); - } do { + auto spanTo(Location end) + in(stop.offset <= end.stop.offset, + to!string(stop.offset) ~ " > " ~ to!string(end.stop.offset)) { return spanTo(end.stop); } - auto spanTo(Position end) const in { - import std.conv; - assert(stop.offset <= end.offset, - to!string(stop.offset) ~ " > " ~ to!string(end.offset)); - } do { + auto spanTo(Position end) const + in(stop.offset <= end.offset, + to!string(stop.offset) ~ " > " ~ to!string(end.offset)) { return Location(start, end); } diff --git a/src/source/manager.d b/src/source/manager.d index 97911fe10..a57672bcd 100644 --- a/src/source/manager.d +++ b/src/source/manager.d @@ -235,10 +235,8 @@ struct SourceEntries { : (offset < sourceEntries[fileID + 1].offset); } - FileID getFileID(Position p) in { - assert(p.isMixin() == nextSourcePos.isMixin()); - assert(p.offset < nextSourcePos.offset); - } do { + FileID getFileID(Position p) in(p.isMixin() == nextSourcePos.isMixin()) + in(p.offset < nextSourcePos.offset) { // It is common to query the same file many time, // so we have a one entry cache for it. if (isPositionInFileID(p, lastFileID)) { diff --git a/src/source/util/lookup.d b/src/source/util/lookup.d index ad7473692..bb28ac856 100644 --- a/src/source/util/lookup.d +++ b/src/source/util/lookup.d @@ -6,10 +6,9 @@ */ module source.util.lookup; -uint lookup(alias f, uint N, T)(T[] items, uint needle, uint pivot) in { - assert(items.length > 0, "items must not be empty"); - assert(pivot < items.length); -} do { +uint lookup(alias f, uint N, T)(T[] items, uint needle, uint pivot) + in(items.length > 0, "items must not be empty") + in(pivot < items.length) { return (needle > f(items[pivot])) ? forwardLinearLookup!(f, N, binaryLookup)(items, needle, pivot) : backwardLinearLookup!(f, N, binaryLookup)(items, needle, pivot); @@ -36,11 +35,10 @@ unittest { private: uint forwardLinearLookup(alias f, uint N, alias fallback, - T)(T[] items, uint needle, uint first) in { - assert(items.length > 0, "items must not be empty"); - assert(first < items.length - 1, "first is out of bound"); - assert(needle >= f(items[first + 1]), "needle is before first"); -} do { + T)(T[] items, uint needle, uint first) + in(items.length > 0, "items must not be empty") + in(first < items.length - 1, "first is out of bound") + in(needle >= f(items[first + 1]), "needle is before first") { auto l = cast(uint) items.length; uint stop = first + N + 2; @@ -81,12 +79,11 @@ unittest { } uint backwardLinearLookup(alias f, uint N, alias fallback, - T)(T[] items, uint needle, uint last) in { - assert(items.length > 0, "items must not be empty"); - assert(last > 0 && last < items.length, "last is out of bound"); - assert(needle >= f(items[0]), "needle is before first"); - assert(needle < f(items[last]), "needle is past last"); -} do { + T)(T[] items, uint needle, uint last) + in(items.length > 0, "items must not be empty") + in(last > 0 && last < items.length, "last is out of bound") + in(needle >= f(items[0]), "needle is before first") + in(needle < f(items[last]), "needle is past last") { auto stop = (last < N) ? 0 : last - N; auto i = last - 1; @@ -120,12 +117,11 @@ unittest { assert(bll8(items, 3, 7) == 1); } -uint binaryLookup(alias f, T)(T[] items, uint needle, uint min, uint max) in { - assert(items.length > 0, "items must not be empty"); - assert(needle >= f(items[min]), "needle is before first"); - assert(max == items.length || needle < f(items[max]), - "needle is past last"); -} do { +uint binaryLookup(alias f, T)(T[] items, uint needle, uint min, uint max) + in(items.length > 0, "items must not be empty") + in(needle >= f(items[min]), "needle is before first") + in(max == items.length || needle < f(items[max]), + "needle is past last") { min++; while (min < max) { auto i = (min + max - 1) / 2; diff --git a/src/util/fastcast.d b/src/util/fastcast.d index c3cff2840..e04253742 100644 --- a/src/util/fastcast.d +++ b/src/util/fastcast.d @@ -1,8 +1,7 @@ module util.fastcast; -U fastCast(U, T)(T t) if (is(T == class) && is(U == class) && is(U : T)) in { - assert(cast(U) t); -} do { +U fastCast(U, T)(T t) if (is(T == class) && is(U == class) && is(U : T)) + in(cast(U) t) { return *(cast(U*) &t); } diff --git a/src/util/visitor.d b/src/util/visitor.d index aee1c9119..c885c5fad 100644 --- a/src/util/visitor.d +++ b/src/util/visitor.d @@ -20,10 +20,11 @@ auto dispatch(alias unhandled = function void(t) { } // XXX: is @trusted if visitor.visit is @safe . -private auto dispatchImpl(alias unhandled, V, T, Args...)(auto ref V visitor, - Args args, T t) in { - assert(t, "You can't dispatch null"); -} do { +private auto dispatchImpl(alias unhandled, V, T, Args...)( + auto ref V visitor, + Args args, + T t +) in(t, "You can't dispatch null") { static if (is(T == class)) { alias o = t; } else {