3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-23 17:15:31 +00:00

merge duality changes with unstable

This commit is contained in:
Ken McMillan 2014-10-22 10:14:05 -07:00
commit d815af9f0f
194 changed files with 3554 additions and 1887 deletions

View file

@ -138,9 +138,8 @@ bool bit_vector::operator==(bit_vector const & source) const {
bit_vector & bit_vector::operator|=(bit_vector const & source) {
if (size() < source.size())
resize(source.size(), false);
unsigned n1 = num_words();
unsigned n2 = source.num_words();
SASSERT(n2 <= n1);
SASSERT(n2 <= num_words());
unsigned bit_rest = source.m_num_bits % 32;
if (bit_rest == 0) {
unsigned i = 0;

View file

@ -55,12 +55,12 @@ class cmd_exception : public default_exception {
}
public:
cmd_exception(char const * msg):default_exception(msg), m_line(-1), m_pos(-1) {}
cmd_exception(std::string const & msg):default_exception(msg.c_str()), m_line(-1), m_pos(-1) {}
cmd_exception(std::string const & msg, int line, int pos):default_exception(msg.c_str()), m_line(line), m_pos(pos) {}
cmd_exception(std::string const & msg):default_exception(msg), m_line(-1), m_pos(-1) {}
cmd_exception(std::string const & msg, int line, int pos):default_exception(msg), m_line(line), m_pos(pos) {}
cmd_exception(char const * msg, symbol const & s):
default_exception(compose(msg,s).c_str()),m_line(-1),m_pos(-1) {}
default_exception(compose(msg,s)),m_line(-1),m_pos(-1) {}
cmd_exception(char const * msg, symbol const & s, int line, int pos):
default_exception(compose(msg,s).c_str()),m_line(line),m_pos(pos) {}
default_exception(compose(msg,s)),m_line(line),m_pos(pos) {}
bool has_pos() const { return m_line >= 0; }
int line() const { SASSERT(has_pos()); return m_line; }

View file

@ -73,7 +73,7 @@ bool is_debug_enabled(const char * tag);
UNREACHABLE(); \
}
#else
#define VERIFY(_x_) (_x_)
#define VERIFY(_x_) (void)(_x_)
#endif
#define MAKE_NAME2(LINE) zofty_ ## LINE

View file

@ -201,7 +201,7 @@ public:
}
}
void throw_unknown_parameter(symbol const & param_name, symbol const & mod_name) {
void throw_unknown_parameter(symbol const & param_name, param_descrs const& d, symbol const & mod_name) {
if (mod_name == symbol::null) {
char const * new_name = get_new_param_name(param_name);
if (new_name) {
@ -213,11 +213,56 @@ public:
param_name.bare_str());
}
else {
throw exception("unknown parameter '%s'", param_name.bare_str());
std::stringstream strm;
strm << "unknown parameter '" << param_name << "'\n";
strm << "Legal parameters are:\n";
d.display(strm, 2, false, false);
throw default_exception(strm.str());
}
}
else {
throw exception("unknown parameter '%s' at module '%s'", param_name.bare_str(), mod_name.bare_str());
std::stringstream strm;
strm << "unknown parameter '" << param_name << "' ";
strm << "at module '" << mod_name << "'\n";
strm << "Legal parameters are:\n";
d.display(strm, 2, false, false);
throw default_exception(strm.str());
}
}
void validate_type(symbol const& name, char const* value, param_descrs const& d) {
param_kind k = d.get_kind(name);
std::stringstream strm;
char const* _value = value;
switch (k) {
case CPK_UINT:
for (; *value; ++value) {
if (!('0' <= *value && *value <= '9')) {
strm << "Expected values for parameter " << name
<< " is an unsigned integer. It was given argument '" << _value << "'";
throw default_exception(strm.str());
}
}
break;
case CPK_DOUBLE:
for (; *value; ++value) {
if (!('0' <= *value && *value <= '9') && *value != '.' && *value != '-' && *value != '/') {
strm << "Expected values for parameter " << name
<< " is a double. It was given argument '" << _value << "'";
throw default_exception(strm.str());
}
}
break;
case CPK_BOOL:
if (strcmp(value, "true") != 0 && strcmp(value, "false") != 0) {
strm << "Expected values for parameter " << name
<< " are 'true' or 'false'. It was given argument '" << value << "'";
throw default_exception(strm.str());
}
break;
default:
break;
}
}
@ -225,7 +270,7 @@ public:
param_kind k = d.get_kind(param_name);
params_ref & ps = get_params(mod_name);
if (k == CPK_INVALID) {
throw_unknown_parameter(param_name, mod_name);
throw_unknown_parameter(param_name, d, mod_name);
}
else if (k == CPK_UINT) {
long val = strtol(value, 0, 10);
@ -282,11 +327,13 @@ public:
symbol m, p;
normalize(name, m, p);
if (m == symbol::null) {
validate_type(p, value, get_param_descrs());
set(get_param_descrs(), p, value, m);
}
else {
param_descrs * d;
if (get_module_param_descrs().find(m, d)) {
validate_type(p, value, *d);
set(*d, p, value, m);
}
else {
@ -312,7 +359,7 @@ public:
std::string get_default(param_descrs const & d, symbol const & p, symbol const & m) {
if (!d.contains(p)) {
throw_unknown_parameter(p, m);
throw_unknown_parameter(p, d, m);
}
char const * r = d.get_default(p);
if (r == 0)
@ -478,7 +525,7 @@ public:
throw exception("unknown module '%s'", m.bare_str());
}
if (!d->contains(p))
throw_unknown_parameter(p, m);
throw_unknown_parameter(p, *d, m);
out << " name: " << p << "\n";
if (m != symbol::null) {
out << " module: " << m << "\n";

View file

@ -35,6 +35,7 @@ static long long g_memory_max_used_size = 0;
static long long g_memory_watermark = 0;
static bool g_exit_when_out_of_memory = false;
static char const * g_out_of_memory_msg = "ERROR: out of memory";
static volatile bool g_memory_fully_initialized = false;
void memory::exit_when_out_of_memory(bool flag, char const * msg) {
g_exit_when_out_of_memory = flag;
@ -83,10 +84,18 @@ void memory::initialize(size_t max_size) {
initialize = true;
}
}
if (!initialize)
return;
g_memory_out_of_memory = false;
mem_initialize();
if (initialize) {
g_memory_out_of_memory = false;
mem_initialize();
g_memory_fully_initialized = true;
}
else {
// Delay the current thread until the DLL is fully initialized
// Without this, multiple threads can start to call API functions
// before memory::initialize(...) finishes.
while (!g_memory_fully_initialized)
/* wait */ ;
}
}
bool memory::is_out_of_memory() {
@ -98,9 +107,9 @@ bool memory::is_out_of_memory() {
return r;
}
void memory::set_high_watermark(size_t watermak) {
void memory::set_high_watermark(size_t watermark) {
// This method is only safe to invoke at initialization time, that is, before the threads are created.
g_memory_watermark = watermak;
g_memory_watermark = watermark;
}
bool memory::above_high_watermark() {

View file

@ -120,7 +120,8 @@ void mpf_manager::set(mpf & o, unsigned ebits, unsigned sbits, double value) {
// double === mpf(11, 53)
COMPILE_TIME_ASSERT(sizeof(double) == 8);
uint64 raw = *reinterpret_cast<uint64*>(&value);
uint64 raw;
memcpy(&raw, &value, sizeof(double));
bool sign = (raw >> 63) != 0;
int64 e = ((raw & 0x7FF0000000000000ull) >> 52) - 1023;
uint64 s = raw & 0x000FFFFFFFFFFFFFull;
@ -155,7 +156,8 @@ void mpf_manager::set(mpf & o, unsigned ebits, unsigned sbits, float value) {
// single === mpf(8, 24)
COMPILE_TIME_ASSERT(sizeof(float) == 4);
unsigned int raw = *reinterpret_cast<unsigned int*>(&value);
unsigned int raw;
memcpy(&raw, &value, sizeof(float));
bool sign = (raw >> 31) != 0;
signed int e = ((raw & 0x7F800000) >> 23) - 127;
unsigned int s = raw & 0x007FFFFF;
@ -1288,7 +1290,9 @@ double mpf_manager::to_double(mpf const & x) {
if (x.sign)
raw = raw | 0x8000000000000000ull;
return *reinterpret_cast<double*>(&raw);
double ret;
memcpy(&ret, &raw, sizeof(double));
return ret;
}
float mpf_manager::to_float(mpf const & x) {
@ -1318,7 +1322,9 @@ float mpf_manager::to_float(mpf const & x) {
if (x.sign)
raw = raw | 0x80000000;
return *reinterpret_cast<float*>(&raw);
float ret;
memcpy(&ret, &raw, sizeof(float));
return ret;
}
bool mpf_manager::is_nan(mpf const & x) {
@ -1679,7 +1685,7 @@ void mpf_manager::round(mpf_rounding_mode rm, mpf & o) {
TRACE("mpf_dbg", tout << "OVF2 = " << OVF2 << std::endl;);
TRACE("mpf_dbg", tout << "o_has_max_exp = " << o_has_max_exp << std::endl;);
if (!OVFen && SIGovf && o_has_max_exp)
if (!OVFen && OVF2)
mk_round_inf(rm, o);
else {
const mpz & p = m_powers2(o.sbits-1);

View file

@ -43,8 +43,7 @@ mpff_manager::mpff_manager(unsigned prec, unsigned initial_capacity) {
for (unsigned i = 0; i < MPFF_NUM_BUFFERS; i++)
m_buffers[i].resize(2 * prec, 0);
// Reserve space for zero
unsigned zero_sig_idx = m_id_gen.mk();
SASSERT(zero_sig_idx == 0);
VERIFY(m_id_gen.mk() == 0);
set(m_one, 1);
}

View file

@ -38,8 +38,7 @@ mpfx_manager::mpfx_manager(unsigned int_sz, unsigned frac_sz, unsigned initial_c
m_buffer0.resize(2*m_total_sz, 0);
m_buffer1.resize(2*m_total_sz, 0);
m_buffer2.resize(2*m_total_sz, 0);
unsigned zero_sig_idx = m_id_gen.mk();
SASSERT(zero_sig_idx == 0);
VERIFY(m_id_gen.mk() == 0);
set(m_one, 1);
}

View file

@ -235,6 +235,9 @@ void mpq_manager<SYNCH>::set(mpq & a, char const * val) {
SASSERT(str[0] - '0' <= 9);
exp = (10*exp) + (str[0] - '0');
}
else if ('/' == str[0]) {
throw default_exception("mixing rational/scientific notation");
}
TRACE("mpq_set", tout << "[exp]: " << exp << ", str[0]: " << (str[0] - '0') << std::endl;);
++str;
}

View file

@ -51,31 +51,34 @@ struct param_descrs::imp {
param_kind m_kind;
char const * m_descr;
char const * m_default;
char const * m_module;
info(param_kind k, char const * descr, char const * def):
info(param_kind k, char const * descr, char const * def, char const* module):
m_kind(k),
m_descr(descr),
m_default(def) {
m_default(def),
m_module(module) {
}
info():
m_kind(CPK_INVALID),
m_descr(0),
m_default(0) {
m_default(0),
m_module(0) {
}
};
dictionary<info> m_info;
svector<symbol> m_names;
void insert(symbol const & name, param_kind k, char const * descr, char const * def) {
void insert(symbol const & name, param_kind k, char const * descr, char const * def, char const* module) {
SASSERT(!name.is_numerical());
info i;
if (m_info.find(name, i)) {
SASSERT(i.m_kind == k);
return;
}
m_info.insert(name, info(k, descr, def));
m_info.insert(name, info(k, descr, def, module));
m_names.push_back(name);
}
@ -94,6 +97,42 @@ struct param_descrs::imp {
return CPK_INVALID;
}
bool split_name(symbol const& name, symbol & prefix, symbol & suffix) const {
if (name.is_numerical()) return false;
char const* str = name.bare_str();
char const* period = strchr(str,'.');
if (!period) return false;
svector<char> prefix_((unsigned)(period-str), str);
prefix_.push_back(0);
prefix = symbol(prefix_.c_ptr());
suffix = symbol(period + 1);
return true;
}
param_kind get_kind_in_module(symbol & name) const {
param_kind k = get_kind(name);
symbol prefix, suffix;
if (k == CPK_INVALID && split_name(name, prefix, suffix)) {
k = get_kind(suffix);
if (k != CPK_INVALID) {
if (symbol(get_module(suffix)) == prefix) {
name = suffix;
}
else {
k = CPK_INVALID;
}
}
}
return k;
}
char const* get_module(symbol const& name) const {
info i;
if (m_info.find(name, i))
return i.m_module;
return 0;
}
char const * get_descr(symbol const & name) const {
info i;
if (m_info.find(name, i))
@ -162,7 +201,7 @@ struct param_descrs::imp {
dictionary<info>::iterator it = other.m_imp->m_info.begin();
dictionary<info>::iterator end = other.m_imp->m_info.end();
for (; it != end; ++it) {
insert(it->m_key, it->m_value.m_kind, it->m_value.m_descr, it->m_value.m_default);
insert(it->m_key, it->m_value.m_kind, it->m_value.m_descr, it->m_value.m_default, it->m_value.m_module);
}
}
@ -180,12 +219,12 @@ void param_descrs::copy(param_descrs & other) {
m_imp->copy(other);
}
void param_descrs::insert(symbol const & name, param_kind k, char const * descr, char const * def) {
m_imp->insert(name, k, descr, def);
void param_descrs::insert(symbol const & name, param_kind k, char const * descr, char const * def, char const* module) {
m_imp->insert(name, k, descr, def, module);
}
void param_descrs::insert(char const * name, param_kind k, char const * descr, char const * def) {
insert(symbol(name), k, descr, def);
void param_descrs::insert(char const * name, param_kind k, char const * descr, char const * def, char const* module) {
insert(symbol(name), k, descr, def, module);
}
bool param_descrs::contains(char const * name) const {
@ -220,6 +259,10 @@ void param_descrs::erase(char const * name) {
erase(symbol(name));
}
param_kind param_descrs::get_kind_in_module(symbol & name) const {
return m_imp->get_kind_in_module(name);
}
param_kind param_descrs::get_kind(symbol const & name) const {
return m_imp->get_kind(name);
}
@ -236,6 +279,10 @@ symbol param_descrs::get_param_name(unsigned i) const {
return m_imp->get_param_name(i);
}
char const* param_descrs::get_module(symbol const& name) const {
return m_imp->get_module(name);
}
void param_descrs::display(std::ostream & out, unsigned indent, bool smt2_style, bool include_descr) const {
return m_imp->display(out, indent, smt2_style, include_descr);
}
@ -297,15 +344,27 @@ public:
void reset(symbol const & k);
void reset(char const * k);
void validate(param_descrs const & p) const {
svector<params::entry>::const_iterator it = m_entries.begin();
svector<params::entry>::const_iterator end = m_entries.end();
void validate(param_descrs const & p) {
svector<params::entry>::iterator it = m_entries.begin();
svector<params::entry>::iterator end = m_entries.end();
symbol suffix, prefix;
for (; it != end; ++it) {
param_kind expected = p.get_kind(it->first);
if (expected == CPK_INVALID)
throw default_exception("unknown parameter '%s'", it->first.str().c_str());
if (it->second.m_kind != expected)
throw default_exception("parameter kind mismatch '%s'", it->first.str().c_str());
param_kind expected = p.get_kind_in_module(it->first);
if (expected == CPK_INVALID) {
std::stringstream strm;
strm << "unknown parameter '" << it->first.str() << "'\n";
strm << "Legal parameters are:\n";
p.display(strm, 2, false, false);
throw default_exception(strm.str());
}
if (it->second.m_kind != expected &&
!(it->second.m_kind == CPK_UINT && expected == CPK_NUMERAL)) {
std::stringstream strm;
strm << "Parameter " << it->first.str() << " was given argument of type ";
strm << it->second.m_kind << ", expected " << expected;
throw default_exception(strm.str());
}
}
}
@ -347,11 +406,11 @@ public:
out << "(params";
svector<params::entry>::const_iterator it = m_entries.begin();
svector<params::entry>::const_iterator end = m_entries.end();
for (; it != end; ++it) {
out << " " << it->first;
for (; it != end; ++it) {
out << " " << it->first;
switch (it->second.m_kind) {
case CPK_BOOL:
out << " " << it->second.m_bool_value;
out << " " << (it->second.m_bool_value?"true":"false");
break;
case CPK_UINT:
out << " " <<it->second.m_uint_value;
@ -376,6 +435,41 @@ public:
out << ")";
}
void display_smt2(std::ostream & out, char const* module, param_descrs& descrs) const {
svector<params::entry>::const_iterator it = m_entries.begin();
svector<params::entry>::const_iterator end = m_entries.end();
for (; it != end; ++it) {
if (!descrs.contains(it->first)) continue;
out << "(set-option :";
out << module << ".";
out << it->first;
switch (it->second.m_kind) {
case CPK_BOOL:
out << " " << (it->second.m_bool_value?"true":"false");
break;
case CPK_UINT:
out << " " <<it->second.m_uint_value;
break;
case CPK_DOUBLE:
out << " " << it->second.m_double_value;
break;
case CPK_NUMERAL:
out << " " << *(it->second.m_rat_value);
break;
case CPK_SYMBOL:
out << " " << symbol::mk_symbol_from_c_ptr(it->second.m_sym_value);
break;
case CPK_STRING:
out << " " << it->second.m_str_value;
break;
default:
UNREACHABLE();
break;
}
out << ")\n";
}
}
void display(std::ostream & out, symbol const & k) const {
svector<params::entry>::const_iterator it = m_entries.begin();
svector<params::entry>::const_iterator end = m_entries.end();
@ -423,10 +517,17 @@ params_ref::params_ref(params_ref const & p):
void params_ref::display(std::ostream & out) const {
if (m_params)
m_params->display(out);
else
else
out << "(params)";
}
void params_ref::display_smt2(std::ostream& out, char const* module, param_descrs& descrs) const {
if (m_params)
m_params->display_smt2(out, module, descrs);
}
void params_ref::display(std::ostream & out, char const * k) const {
display(out, symbol(k));
}
@ -438,7 +539,7 @@ void params_ref::display(std::ostream & out, symbol const & k) const {
out << "default";
}
void params_ref::validate(param_descrs const & p) const {
void params_ref::validate(param_descrs const & p) {
if (m_params)
m_params->validate(p);
}

View file

@ -90,8 +90,9 @@ public:
void set_sym(char const * k, symbol const & v);
void display(std::ostream & out) const;
void display_smt2(std::ostream& out, char const* module, param_descrs& module_desc) const;
void validate(param_descrs const & p) const;
void validate(param_descrs const & p);
/*
\brief Display the value of the given parameter.
@ -114,14 +115,15 @@ public:
param_descrs();
~param_descrs();
void copy(param_descrs & other);
void insert(char const * name, param_kind k, char const * descr, char const * def = 0);
void insert(symbol const & name, param_kind k, char const * descr, char const * def = 0);
void insert(char const * name, param_kind k, char const * descr, char const * def = 0, char const* module = 0);
void insert(symbol const & name, param_kind k, char const * descr, char const * def = 0, char const* module = 0);
bool contains(char const * name) const;
bool contains(symbol const & name) const;
void erase(char const * name);
void erase(symbol const & name);
param_kind get_kind(char const * name) const;
param_kind get_kind(symbol const & name) const;
param_kind get_kind_in_module(symbol & name) const;
char const * get_descr(char const * name) const;
char const * get_descr(symbol const & name) const;
char const * get_default(char const * name) const;
@ -129,6 +131,7 @@ public:
void display(std::ostream & out, unsigned indent = 0, bool smt2_style=false, bool include_descr=true) const;
unsigned size() const;
symbol get_param_name(unsigned idx) const;
char const * get_module(symbol const& name) const;
};
void insert_max_memory(param_descrs & r);

View file

@ -129,7 +129,7 @@ struct scoped_timer::imp {
WT_EXECUTEINTIMERTHREAD);
#elif defined(__APPLE__) && defined(__MACH__)
// Mac OS X
m_interval = ms;
m_interval = ms?ms:0xFFFFFFFF;
if (pthread_attr_init(&m_attributes) != 0)
throw default_exception("failed to initialize timer thread attributes");
if (pthread_cond_init(&m_condition_var, NULL) != 0)

View file

@ -90,7 +90,7 @@ public:
~stopwatch() {}
void reset() {
m_time = 0ull;
m_time = 0ull;
}
void start() {
@ -101,11 +101,11 @@ public:
}
void stop() {
if (m_running) {
if (m_running) {
mach_timespec_t _stop;
clock_get_time(m_host_clock, &_stop);
m_time += (_stop.tv_sec - m_start.tv_sec) * 1000000000ull;
m_time += (_stop.tv_nsec - m_start.tv_nsec);
m_time += (_stop.tv_nsec - m_start.tv_nsec);
m_running = false;
}
}
@ -120,7 +120,7 @@ public:
}
double get_current_seconds() const {
return get_seconds();
return get_seconds();
}
};
@ -141,22 +141,23 @@ public:
~stopwatch() {}
void reset() {
m_time = 0ull;
m_time = 0ull;
}
void start() {
if (!m_running) {
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &m_start);
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &m_start);
m_running = true;
}
}
void stop() {
if (m_running) {
if (m_running) {
struct timespec _stop;
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &_stop);
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &_stop);
m_time += (_stop.tv_sec - m_start.tv_sec) * 1000000000ull;
m_time += (_stop.tv_nsec - m_start.tv_nsec);
if (m_time != 0 || _stop.tv_nsec >= m_start.tv_nsec)
m_time += (_stop.tv_nsec - m_start.tv_nsec);
m_running = false;
}
}
@ -171,7 +172,7 @@ public:
}
double get_current_seconds() const {
return get_seconds();
return get_seconds();
}
};

View file

@ -95,7 +95,10 @@ unsigned uint64_log2(uint64 v);
COMPILE_TIME_ASSERT(sizeof(unsigned) == 4);
// Return the number of 1 bits in v.
inline unsigned get_num_1bits(unsigned v) {
static inline unsigned get_num_1bits(unsigned v) {
#ifdef __GNUC__
return __builtin_popcount(v);
#else
#ifdef Z3DEBUG
unsigned c;
unsigned v1 = v;
@ -108,15 +111,16 @@ inline unsigned get_num_1bits(unsigned v) {
unsigned r = (((v + (v >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24;
SASSERT(c == r);
return r;
#endif
}
// Remark: on gcc, the operators << and >> do not produce zero when the second argument >= 64.
// So, I'm using the following two definitions to fix the problem
inline uint64 shift_right(uint64 x, uint64 y) {
static inline uint64 shift_right(uint64 x, uint64 y) {
return y < 64ull ? (x >> y) : 0ull;
}
inline uint64 shift_left(uint64 x, uint64 y) {
static inline uint64 shift_left(uint64 x, uint64 y) {
return y < 64ull ? (x << y) : 0ull;
}
@ -255,10 +259,6 @@ inline std::ostream & operator<<(std::ostream & out, std::pair<T1, T2> const & p
return out;
}
#ifndef _WINDOWS
#define __forceinline inline
#endif
template<typename IT>
bool has_duplicates(const IT & begin, const IT & end) {
for (IT it1 = begin; it1 != end; ++it1) {