Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new contract syntax for non-complex contracts #330

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/d/ast/expression.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
22 changes: 8 additions & 14 deletions src/d/ir/instruction.d
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
7 changes: 3 additions & 4 deletions src/d/ir/symbol.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
13 changes: 5 additions & 8 deletions src/d/llvm/evaluator.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions src/d/llvm/expression.d
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
33 changes: 13 additions & 20 deletions src/d/llvm/global.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}
Expand All @@ -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;
Expand Down
16 changes: 6 additions & 10 deletions src/d/llvm/local.d
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
18 changes: 8 additions & 10 deletions src/d/semantic/dtemplate.d
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;

Expand Down
9 changes: 4 additions & 5 deletions src/d/semantic/expression.d
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down
6 changes: 2 additions & 4 deletions src/d/semantic/symbol.d
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
23 changes: 9 additions & 14 deletions src/d/semantic/vrp.d
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 1 addition & 4 deletions src/format/rulevalues.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 5 additions & 9 deletions src/format/span.d
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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) {
Expand Down
8 changes: 2 additions & 6 deletions src/source/lexbase.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading