Skip to content

Commit b1be451

Browse files
committed
Replace assert with INVARIANT for variables used only there
This replaces instances of the form ``` x = f(..); assert(x); ``` with ``` x = f(..); INVARIANT(x, "..."); ```
1 parent 5dbd3a2 commit b1be451

File tree

11 files changed

+22
-10
lines changed

11 files changed

+22
-10
lines changed

src/ic3/build_prob/g3en_cnf.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Author: Eugene Goldberg, eu.goldberg@gmail.com
1010
#include <map>
1111
#include <algorithm>
1212
#include <queue>
13+
#include <util/invariant.h>
1314

1415
#include "minisat/core/Solver.h"
1516
#include "minisat/simp/SimpSolver.h"
@@ -48,7 +49,7 @@ void CompInfo::gen_constr_coi(CUBE &Gates,bool &tran_flag,bool &fun_flag,
4849

4950
assert(Stack.size() == 1);
5051
Gate &G = N->get_gate(Stack.back());
51-
assert(G.flags.label == 0);
52+
INVARIANT(G.flags.label == 0, "Gate label should be zero.");
5253

5354
CUBE Labelled;
5455

src/ic3/e4xclude_state.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Author: Eugene Goldberg, eu.goldberg@gmail.com
1111
#include <map>
1212
#include <algorithm>
1313
#include <iostream>
14+
#include <util/invariant.h>
1415
#include "minisat/core/Solver.h"
1516
#include "minisat/simp/SimpSolver.h"
1617
#include "dnf_io.hh"
@@ -91,7 +92,8 @@ void CompInfo::form_res_cnf(CNF &G,int tf_ind,CUBE &St_cube)
9192
add_assumps1(Assmps,St_cube);
9293

9394
bool sat_form = Slvr.Mst->solve(Assmps);
94-
assert(sat_form == false);
95+
INVARIANT(sat_form == false,
96+
"SAT check should fail here.");
9597
CLAUSE C;
9698
gen_assump_clause(C,Slvr,Assmps);
9799
G.push_back(C);

src/ic3/i1nit.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Author: Eugene Goldberg, eu.goldberg@gmail.com
1010
#include <set>
1111
#include <map>
1212
#include <algorithm>
13+
#include <util/invariant.h>
1314
#include "minisat/core/Solver.h"
1415
#include "minisat/simp/SimpSolver.h"
1516
#include "dnf_io.hh"
@@ -214,7 +215,7 @@ void CompInfo::form_cex()
214215
add_assumps1(Assmps,Cex[i]);
215216
add_assumps1(Assmps,Inp_trace[i]);
216217
bool sat_form = check_sat2(Gen_sat,Assmps);
217-
assert(sat_form);
218+
INVARIANT(sat_form, "SAT check should fail here.");
218219
CUBE Nst,St;
219220
extr_cut_assgns1(Nst,Next_svars,Gen_sat);
220221
conv_to_pres_state(St,Nst);

src/ic3/i2nit_sat_solvers.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Author: Eugene Goldberg, eu.goldberg@gmail.com
99
#include <set>
1010
#include <map>
1111
#include <algorithm>
12+
#include <util/invariant.h>
1213
#include "minisat/core/Solver.h"
1314
#include "minisat/simp/SimpSolver.h"
1415
#include "dnf_io.hh"
@@ -141,7 +142,8 @@ void CompInfo::init_lbs_sat_solver()
141142
for (size_t i=0; i < Fun_coi_lits.size(); i++) {
142143
int lit = Fun_coi_lits[i];
143144
int var_ind = abs(lit)-1;
144-
assert (Var_info[var_ind].type == INTERN);
145+
INVARIANT(Var_info[var_ind].type == INTERN,
146+
"Type of literal should be INTERN");
145147
U.push_back(-lit);
146148
}
147149

src/ic3/m1ain.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ int CompInfo::run_ic3()
195195

196196

197197
bool ok = check_init_states();
198-
assert(ok);
198+
INVARIANT(ok, "Initial states should be defined via single literal.");
199199
assign_var_type();
200200
assign_value();
201201
get_runtime (usrtime0, systime0);

src/ic3/my_printf.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Author: Eugene Goldberg, eu.goldberg@gmail.com
1414
#include <queue>
1515
#include <map>
1616
#include <iostream>
17+
#include <util/invariant.h>
1718
#include "dnf_io.hh"
1819
const int factor = 1000;
1920

@@ -65,7 +66,7 @@ void my_printf(const char *format,...)
6566
int c = *format++;
6667
if (c != '%') {printf("%c",c); continue;}
6768
int spec = *format++;
68-
assert(spec == 'm');
69+
INVARIANT(spec == 'm', "Character should be 'm' in format string.");
6970
int num = va_arg(ap,int);
7071
print_num_with_commas(num);
7172
// printf("%d",num);

src/ic3/p5ick_lit.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Author: Eugene Goldberg, eu.goldberg@gmail.com
1111
#include <map>
1212
#include <algorithm>
1313
#include <iostream>
14+
#include <util/invariant.h>
1415
#include "minisat/core/Solver.h"
1516
#include "minisat/simp/SimpSolver.h"
1617
#include "dnf_io.hh"

src/ic3/r0ead_input.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ void ic3_enginet::form_inputs()
128128
CCUBE Name;
129129
if (orig_names) {
130130
bool ok = form_orig_name(Name,lit);
131-
assert(ok);}
131+
INVARIANT(ok, "Literal should have an original name.");
132+
}
132133
else {
133134
char Inp_name[MAX_NAME];
134135
sprintf(Inp_name,"i%d",lit_val);

src/ic3/r4ead_input.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void ic3_enginet::form_latch_name(CCUBE &Latch_name,literalt &lit)
107107
{
108108
if (orig_names) {
109109
bool ok = form_orig_name(Latch_name,lit);
110-
assert(ok);
110+
INVARIANT(ok, "Literal should have original name.");
111111
return; }
112112

113113
char Buff[MAX_NAME];

src/ic3/s2horten_clause.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Author: Eugene Goldberg, eu.goldberg@gmail.com
1010
#include <map>
1111
#include <algorithm>
1212
#include <iostream>
13+
#include <util/invariant.h>
1314
#include "minisat/core/Solver.h"
1415
#include "minisat/simp/SimpSolver.h"
1516
#include "dnf_io.hh"
@@ -87,7 +88,7 @@ void CompInfo::find_fixed_pnt(CLAUSE &C,CLAUSE &C0,SatSolver &Slvr,
8788

8889
bool sat_form = check_sat2(Slvr,Assmps);
8990

90-
assert(sat_form == false);
91+
INVARIANT(sat_form == false, "SAT check should fail here.");
9192
CLAUSE B;
9293
gen_assump_clause(B,Slvr,Assmps);
9394
CLAUSE B1;

0 commit comments

Comments
 (0)