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

Merge shared parts from polysat branch (#7063)

* sat_literal: make constants constexpr

* dlist: rename elem -> list

* tbv: use get_bit

* additional pdd and rational tests

* egraph: callback setters take functions by value

This allows to set callbacks without defining a separate variable for
the callback lambda.

(previous usage does one copy of the function, exactly as before)

* cmake: enable compiler error when non-void function does not return value
This commit is contained in:
Jakob Rath 2023-12-28 20:11:53 +01:00 committed by GitHub
parent 53c95e3627
commit ec2b8eb4ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 101 additions and 43 deletions

View file

@ -188,14 +188,14 @@ class dll_iterator {
dll_iterator(T const* elem, bool first): m_elem(elem), m_first(first) { }
public:
static dll_iterator mk_begin(T const* elem) {
// Setting first==(bool)elem makes this also work for elem==nullptr;
static dll_iterator mk_begin(T const* list) {
// Setting first==(bool)list makes this also work for list==nullptr;
// but we can't implement top-level begin/end for pointers because it clashes with the definition for arrays.
return {elem, (bool)elem};
return {list, (bool)list};
}
static dll_iterator mk_end(T const* elem) {
return {elem, false};
static dll_iterator mk_end(T const* list) {
return {list, false};
}
using value_type = T;
@ -232,18 +232,17 @@ public:
dll_iterator<T> end() const { return dll_iterator<T>::mk_end(m_list); }
};
template < typename T
, typename U = std::enable_if_t<std::is_base_of_v<dll_base<T>, T>> // should only match if T actually inherits from dll_base<T>
>
dll_iterator<T> begin(T const& elem) {
return dll_iterator<T>::mk_begin(&elem);
dll_iterator<T> begin(T const& list) {
return dll_iterator<T>::mk_begin(&list);
}
template < typename T
, typename U = std::enable_if_t<std::is_base_of_v<dll_base<T>, T>> // should only match if T actually inherits from dll_base<T>
>
dll_iterator<T> end(T const& elem)
dll_iterator<T> end(T const& list)
{
return dll_iterator<T>::mk_end(&elem);
return dll_iterator<T>::mk_end(&list);
}

View file

@ -30,7 +30,7 @@ namespace sat {
typedef svector<bool_var> bool_var_vector;
const bool_var null_bool_var = UINT_MAX >> 1;
inline constexpr bool_var null_bool_var = UINT_MAX >> 1;
/**
\brief The literal b is represented by the value 2*b, and
@ -39,9 +39,7 @@ namespace sat {
class literal {
unsigned m_val;
public:
literal():m_val(null_bool_var << 1) {
SASSERT(var() == null_bool_var && !sign());
}
constexpr literal(): m_val(null_bool_var << 1) { }
explicit literal(bool_var v, bool _sign = false):
m_val((v << 1) + static_cast<unsigned>(_sign)) {
@ -49,11 +47,11 @@ namespace sat {
SASSERT(sign() == _sign);
}
bool_var var() const {
constexpr bool_var var() const {
return m_val >> 1;
}
bool sign() const {
constexpr bool sign() const {
return m_val & 1ul;
}
@ -86,7 +84,10 @@ namespace sat {
friend bool operator!=(literal const & l1, literal const & l2);
};
const literal null_literal;
inline constexpr literal null_literal;
static_assert(null_literal.var() == null_bool_var);
static_assert(!null_literal.sign());
using literal_hash = obj_hash<literal>;
inline literal to_literal(unsigned x) { literal l; l.m_val = x; return l; }

View file

@ -142,12 +142,8 @@ void tbv_manager::set(tbv& dst, rational const& r, unsigned hi, unsigned lo) {
set(dst, r.get_uint64(), hi, lo);
return;
}
for (unsigned i = 0; i < hi - lo + 1; ++i) {
if (bitwise_and(r, rational::power_of_two(i)).is_zero())
set(dst, lo + i, BIT_0);
else
set(dst, lo + i, BIT_1);
}
for (unsigned i = 0; i < hi - lo + 1; ++i)
set(dst, lo + i, r.get_bit(i) ? BIT_1 : BIT_0);
}
void tbv_manager::set(tbv& dst, tbv const& other, unsigned hi, unsigned lo) {