Skip to content

Commit 377b63d

Browse files
committed
Use new contract syntax for non-complex contracts
Resolves snazzy-d#249.
1 parent 62c0954 commit 377b63d

File tree

19 files changed

+107
-161
lines changed

19 files changed

+107
-161
lines changed

src/d/ast/expression.d

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,7 @@ unittest {
126126
}
127127
}
128128

129-
AstBinaryOp getBaseOp(AstBinaryOp op) in {
130-
assert(isAssign(op));
131-
} do {
129+
AstBinaryOp getBaseOp(AstBinaryOp op) in(isAssign(op)) {
132130
return op + AstBinaryOp.Add - AstBinaryOp.AddAssign;
133131
}
134132

src/d/ir/instruction.d

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ private:
1212
BasicBlock[] basicBlocks;
1313

1414
public:
15-
ref inout(BasicBlock) opIndex(BasicBlockRef i) inout in {
16-
assert(i, "null block ref");
17-
assert(i.index <= basicBlocks.length, "Out of bounds block ref");
18-
} do {
15+
ref inout(BasicBlock) opIndex(BasicBlockRef i) inout in(i, "null block ref")
16+
in(i.index <= basicBlocks.length, "Out of bounds block ref") {
1917
return basicBlocks.ptr[i.index - 1];
2018
}
2119

@@ -226,9 +224,7 @@ private:
226224
@disable
227225
this(this);
228226

229-
void add(Instruction i) in {
230-
assert(!terminate, "block does terminate already");
231-
} do {
227+
void add(Instruction i) in(!terminate, "block does terminate already") {
232228
instructions ~= i;
233229
}
234230

@@ -353,9 +349,8 @@ private:
353349
expr = e;
354350
}
355351

356-
this(Location location, Variable v) in {
357-
assert(v.step == Step.Processed, "Variable is not processed");
358-
} do {
352+
this(Location location, Variable v)
353+
in(v.step == Step.Processed, "Variable is not processed") {
359354
this.location = location;
360355
op = OpCode.Alloca;
361356
var = v;
@@ -367,10 +362,9 @@ private:
367362
return i;
368363
}
369364

370-
this(Location location, Symbol s) in {
371-
assert(s.step == Step.Processed, "Symbol is not processed");
372-
assert(!cast(Variable) s, "Use alloca for variables");
373-
} do {
365+
this(Location location, Symbol s)
366+
in(s.step == Step.Processed, "Symbol is not processed")
367+
in(!cast(Variable) s, "Use alloca for variables") {
374368
this.location = location;
375369
op = OpCode.Declare;
376370
sym = s;

src/d/ir/symbol.d

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,9 @@ class Function : ValueSymbol, Scope {
136136
}
137137

138138
@property
139-
Intrinsic intrinsicID(Intrinsic id) in {
140-
assert(!hasThis, "Method can't be intrinsic");
141-
assert(intrinsicID == Intrinsic.None, "This is already an intrinsic");
142-
} do {
139+
Intrinsic intrinsicID(Intrinsic id)
140+
in(!hasThis, "Method can't be intrinsic")
141+
in(intrinsicID == Intrinsic.None, "This is already an intrinsic") {
143142
derived = id;
144143
return intrinsicID;
145144
}

src/d/llvm/evaluator.d

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,11 @@ final class LLVMEvaluator : Evaluator {
9898
auto et = t.element.getCanonical();
9999
assert(et.builtin = BuiltinType.Char);
100100
} do {
101-
return jit!(function string(CodeGen pass, Expression e, void[] p) in {
102-
assert(p.length == string.sizeof);
103-
} do {
104-
auto s = *(cast(string*) p.ptr);
105-
return s.idup;
106-
}
107-
108-
)(e);
101+
return jit!(function string(CodeGen pass, Expression e, void[] p)
102+
in (p.length == string.sizeof) {
103+
auto s = *(cast(string*) p.ptr);
104+
return s.idup;
105+
})(e);
109106
}
110107

111108
private

src/d/llvm/expression.d

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -913,10 +913,9 @@ struct AddressOfGen {
913913
return ExpressionGen(pass).visit(e);
914914
}
915915

916-
LLVMValueRef visit(VariableExpression e) in {
917-
assert(e.var.storage != Storage.Enum, "enum have no address.");
918-
assert(!e.var.isFinal, "finals have no address.");
919-
} do {
916+
LLVMValueRef visit(VariableExpression e)
917+
in(e.var.storage != Storage.Enum, "enum have no address.")
918+
in(!e.var.isFinal, "finals have no address.") {
920919
return declare(e.var);
921920
}
922921

src/d/llvm/global.d

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,9 @@ struct GlobalGen {
4949
return LocalGen(pass).define(f);
5050
}
5151

52-
LLVMValueRef declare(Variable v) in {
53-
assert(v.storage.isGlobal, "locals not supported");
54-
assert(!v.isFinal);
55-
assert(!v.isRef);
56-
} do {
52+
LLVMValueRef declare(Variable v)
53+
in(v.storage.isGlobal, "locals not supported") in(!v.isFinal)
54+
in(!v.isRef) {
5755
auto var = globals.get(v, {
5856
if (v.storage == Storage.Enum) {
5957
import d.llvm.constant;
@@ -78,11 +76,9 @@ struct GlobalGen {
7876
return var;
7977
}
8078

81-
LLVMValueRef define(Variable v) in {
82-
assert(v.storage.isGlobal, "locals not supported");
83-
assert(!v.isFinal);
84-
assert(!v.isRef);
85-
} do {
79+
LLVMValueRef define(Variable v)
80+
in(v.storage.isGlobal, "locals not supported") in(!v.isFinal)
81+
in(!v.isRef) {
8682
auto var = declare(v);
8783
if (!v.value || v.storage == Storage.Enum) {
8884
return var;
@@ -100,12 +96,10 @@ struct GlobalGen {
10096
return var;
10197
}
10298

103-
bool maybeDefine(Variable v, LLVMValueRef var) in {
104-
assert(v.storage.isGlobal, "locals not supported");
105-
assert(v.storage != Storage.Enum, "enum do not have a storage");
106-
assert(!v.isFinal);
107-
assert(!v.isRef);
108-
} do {
99+
bool maybeDefine(Variable v, LLVMValueRef var)
100+
in(v.storage.isGlobal, "locals not supported")
101+
in(v.storage != Storage.Enum, "enum do not have a storage")
102+
in(!v.isFinal) in(!v.isRef) {
109103
if (LLVMGetInitializer(var)) {
110104
return false;
111105
}
@@ -118,10 +112,9 @@ struct GlobalGen {
118112
return true;
119113
}
120114

121-
private LLVMValueRef createVariableStorage(Variable v) in {
122-
assert(v.storage.isGlobal, "locals not supported");
123-
assert(v.storage != Storage.Enum, "enum do not have a storage");
124-
} do {
115+
private LLVMValueRef createVariableStorage(Variable v)
116+
in(v.storage.isGlobal, "locals not supported")
117+
in(v.storage != Storage.Enum, "enum do not have a storage") {
125118
auto qualifier = v.type.qualifier;
126119

127120
import d.llvm.type;

src/d/llvm/local.d

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,11 @@ struct LocalGen {
191191
return true;
192192
}
193193

194-
private void genBody(Function f, LLVMValueRef fun) in {
195-
assert(LLVMCountBasicBlocks(fun) == 0,
196-
f.mangle.toString(context) ~ " body is already defined");
197-
198-
assert(f.step == Step.Processed, "f is not processed");
199-
assert(f.fbody || f.intrinsicID, "f must have a body");
200-
} do {
194+
private void genBody(Function f, LLVMValueRef fun)
195+
in(LLVMCountBasicBlocks(fun) == 0,
196+
f.mangle.toString(context) ~ " body is already defined")
197+
in(f.step == Step.Processed, "f is not processed")
198+
in(f.fbody || f.intrinsicID, "f must have a body") {
201199
scope(failure) f.dump(context);
202200

203201
// Alloca and instruction block.
@@ -401,9 +399,7 @@ struct LocalGen {
401399
return locals.get(v, define(v));
402400
}
403401

404-
LLVMValueRef define(Variable v) in {
405-
assert(!v.isFinal);
406-
} do {
402+
LLVMValueRef define(Variable v) in(!v.isFinal) {
407403
if (v.storage.isGlobal) {
408404
import d.llvm.global;
409405
return GlobalGen(pass, mode).define(v);

src/d/semantic/dtemplate.d

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,9 @@ struct TemplateInstancier {
120120

121121
private:
122122
bool matchArguments(Template t, TemplateArgument[] args, Expression[] fargs,
123-
TemplateArgument[] matchedArgs) in {
124-
assert(t.step == Step.Processed);
125-
assert(t.parameters.length >= args.length);
126-
assert(matchedArgs.length == t.parameters.length);
127-
} do {
123+
TemplateArgument[] matchedArgs)
124+
in(t.step == Step.Processed) in(t.parameters.length >= args.length)
125+
in(matchedArgs.length == t.parameters.length) {
128126
uint i = 0;
129127
foreach (a; args) {
130128
if (!matchArgument(t.parameters[i++], a, matchedArgs)) {
@@ -185,11 +183,11 @@ private:
185183
})();
186184
}
187185

188-
auto instanciateFromResolvedArgs(Location location, Template t,
189-
TemplateArgument[] args) in {
190-
assert(t.step == Step.Processed);
191-
assert(t.parameters.length == args.length);
192-
} do {
186+
auto instanciateFromResolvedArgs(
187+
Location location,
188+
Template t,
189+
TemplateArgument[] args
190+
) in(t.step == Step.Processed) in(t.parameters.length == args.length) {
193191
auto i = 0;
194192
Symbol[] argSyms;
195193

src/d/semantic/expression.d

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -572,11 +572,10 @@ public:
572572
return getFromImpl(location, f, ctxs);
573573
}
574574

575-
private Expression getFromImpl(Location location, Function f,
576-
Expression[] ctxs) in {
577-
assert(f.step >= Step.Signed);
578-
assert(ctxs.length >= f.hasContext + f.hasThis);
579-
} do {
575+
private
576+
Expression getFromImpl(Location location, Function f, Expression[] ctxs)
577+
in(f.step >= Step.Signed)
578+
in(ctxs.length >= f.hasContext + f.hasThis) {
580579
foreach (i, ref c; ctxs) {
581580
c = buildArgument(c, f.type.parameters[i]);
582581
}

src/d/semantic/symbol.d

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,10 +1062,8 @@ struct SymbolAnalyzer {
10621062
e.step = Step.Processed;
10631063
}
10641064

1065-
void analyze(AstExpression dv, Variable v) in {
1066-
assert(v.storage == Storage.Enum);
1067-
assert(v.type.kind == TypeKind.Enum);
1068-
} do {
1065+
void analyze(AstExpression dv, Variable v) in(v.storage == Storage.Enum)
1066+
in(v.type.kind == TypeKind.Enum) {
10691067
auto e = v.type.denum;
10701068

10711069
if (dv !is null) {

src/d/semantic/vrp.d

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,9 @@ struct ValueRangePropagator(T) if (is(T == uint) || is(T == ulong)) {
3939
return canFit(e, getBuiltin(t));
4040
}
4141

42-
bool canFit(Expression e, BuiltinType t) in {
43-
assert(isValidExpr(e), "VRP expect integral types.");
44-
assert(canConvertToIntegral(t), "VRP only supports integral types.");
45-
} do {
42+
bool canFit(Expression e, BuiltinType t)
43+
in(isValidExpr(e), "VRP expect integral types.")
44+
in(canConvertToIntegral(t), "VRP only supports integral types.") {
4645
static canFitDMDMonkeyDance(R)(R r, BuiltinType t) {
4746
auto mask = cast(R.U) ((1UL << t.getBits()) - 1);
4847

@@ -1054,11 +1053,9 @@ struct ValueRange(T) if (is(uint : T) && isIntegral!T) {
10541053
return ValueRange(-neg.max, pos.max);
10551054
}
10561055

1057-
auto urem()(ValueRange rhs) const if (isUnsigned!T) in {
1058-
assert(this != ValueRange(0));
1059-
assert(rhs is rhs.normalized);
1060-
assert(rhs.min > 0);
1061-
} do {
1056+
auto urem()(ValueRange rhs) const if (isUnsigned!T)
1057+
in(this != ValueRange(0)) in(rhs is rhs.normalized)
1058+
in(rhs.min > 0) {
10621059
auto lhs = this.normalized;
10631060

10641061
// If lhs is within the bound of rhs.
@@ -1118,11 +1115,9 @@ struct ValueRange(T) if (is(uint : T) && isIntegral!T) {
11181115
return ValueRange(v1.min, v0.max);
11191116
}
11201117

1121-
auto ushl()(ValueRange rhs) const if (isUnsigned!T) in {
1122-
assert(rhs is rhs.normalized);
1123-
assert(rhs.max < Bits);
1124-
assert(this.min <= Signed!T.max);
1125-
} do {
1118+
auto ushl()(ValueRange rhs) const if (isUnsigned!T)
1119+
in(rhs is rhs.normalized) in(rhs.max < Bits)
1120+
in(this.min <= Signed!T.max) {
11261121
auto minhi = rhs.min ? (min >> (Bits - rhs.min)) : 0;
11271122
auto maxhi = rhs.max ? (max >> (Bits - rhs.max)) : 0;
11281123
if (minhi != maxhi) {

src/format/rulevalues.d

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,7 @@ public:
6666
}
6767

6868
@property
69-
size_t frozen(size_t f) in {
70-
assert(f > 0 && f <= capacity);
71-
assert(this[f - 1]);
72-
} do {
69+
size_t frozen(size_t f) in(f > 0 && f <= capacity) in(this[f - 1]) {
7370
if (isDirect()) {
7471
// Replace the previous frozen value.
7572
direct[1] &= (size_t(1) << DirectShift) - 1;

src/format/span.d

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,9 @@ final class ListSpan : Span {
330330
return trailingSplit != size_t.max;
331331
}
332332

333-
void registerElement(size_t i) in {
334-
assert(elements.length == 0 || elements[$ - 1] <= i);
335-
assert(!hasTrailingSplit);
336-
} do {
333+
void registerElement(size_t i)
334+
in(elements.length == 0 || elements[$ - 1] <= i)
335+
in(!hasTrailingSplit) {
337336
import std.algorithm;
338337
headerSplit = min(i, headerSplit);
339338

@@ -345,11 +344,8 @@ final class ListSpan : Span {
345344
headerSplit = i;
346345
}
347346

348-
void registerTrailingSplit(size_t i) in {
349-
assert(elements.length > 0);
350-
assert(elements[$ - 1] <= i);
351-
assert(!hasTrailingSplit);
352-
} do {
347+
void registerTrailingSplit(size_t i) in(elements.length > 0)
348+
in(elements[$ - 1] <= i) in(!hasTrailingSplit) {
353349
trailingSplit = i;
354350

355351
if (elements.length > 1) {

src/source/lexbase.d

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,8 @@ mixin template LexBaseImpl(Token, alias BaseMap, alias KeywordMap,
130130
// +/
131131
}
132132

133-
void moveTo(ref TokenRange fr) in {
134-
assert(base is fr.base);
135-
assert(context is fr.context);
136-
assert(content is fr.content);
137-
assert(index < fr.index);
138-
} do {
133+
void moveTo(ref TokenRange fr) in(base is fr.base) in(context is fr.context)
134+
in(content is fr.content) in(index < fr.index) {
139135
index = fr.index;
140136
t = fr.t;
141137
previous = fr.previous;

0 commit comments

Comments
 (0)