From 82414b91119f6cc52bed7b49e8facc76cdc6e359 Mon Sep 17 00:00:00 2001 From: Dominik Gleich Date: Fri, 24 Feb 2017 10:15:18 +0100 Subject: [PATCH] Fix naming of asserts.runtime_assert & assert -> debug_assert Summary: Merge branch 'dev' into rename_assert Fix new files. Remove cassert. Reviewers: buda Reviewed By: buda Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D66 --- CMakeLists.txt | 12 +++--- src/communication/bolt/v1/server/server.hpp | 4 +- .../bolt/v1/transport/chunked_decoder.hpp | 1 - src/data_structures/bitset/dynamic_bitset.hpp | 10 ++--- .../concurrent/concurrent_list.hpp | 14 +++---- src/data_structures/concurrent/skiplist.hpp | 37 ++++++++++--------- .../concurrent/skiplist_gc.hpp | 3 +- src/data_structures/map/rh_common.hpp | 11 ++++-- src/data_structures/map/rh_hashmultimap.hpp | 3 +- src/data_structures/static_array.hpp | 4 +- src/database/graph_db_accessor.cpp | 3 +- src/import/csv_import.hpp | 3 +- src/import/element_skeleton.hpp | 13 +++---- src/import/fillings/id.hpp | 5 ++- src/io/network/socket.hpp | 1 - src/logging/log.cpp | 2 +- src/logging/logger.hpp | 2 +- src/memory/hp.hpp | 1 - src/mvcc/hints.hpp | 5 ++- src/mvcc/record.hpp | 3 +- src/mvcc/version_list.hpp | 17 +++++---- src/query/backend/cpp/cypher_main_visitor.cpp | 4 +- src/storage/record_accessor.cpp | 5 ++- src/storage/record_accessor.hpp | 15 +++++--- src/storage/typed_value.cpp | 8 ++-- src/storage/typed_value.hpp | 1 - src/threading/thread.cpp | 3 +- src/threading/thread.hpp | 1 - src/transactions/lock_store.hpp | 4 +- src/utils/assert.hpp | 10 ++--- src/utils/fswatcher.hpp | 4 +- src/utils/ioc/container.hpp | 8 ++-- src/utils/iterator/range_iterator.hpp | 9 +++-- src/utils/option.hpp | 8 ++-- src/utils/option_ptr.hpp | 4 +- src/utils/placeholder.hpp | 4 +- src/utils/string/weak_string.hpp | 8 ++-- src/utils/sys.hpp | 1 - tests/manual/xorshift.cpp | 3 +- 39 files changed, 137 insertions(+), 117 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 49e66bb16..c37ef95a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -181,12 +181,12 @@ endif() # custom assert control parameters -# Runtime assert, if value is OFF runtime asserts will be inactive during -# runtime. Default value is ON. -option(RUNTIME_ASSERT "Enable runtime assertions" ON) -message(STATUS "RUNTIME_ASSERT: ${RUNTIME_ASSERT}") -if(RUNTIME_ASSERT) - add_definitions(-DRUNTIME_ASSERT_ON) +# Debug assert, if value is OFF debug asserts will be inactive. +# Default value is ON. +option(DEBUG_ASSERT "Enable debug assertions" ON) +message(STATUS "DEBUG_ASSERT: ${DEBUG_ASSERT}") +if(DEBUG_ASSERT) + add_definitions(-DDEBUG_ASSERT_ON) endif() # by default on custom assert only the message, filename and line number will be diff --git a/src/communication/bolt/v1/server/server.hpp b/src/communication/bolt/v1/server/server.hpp index 79e130afd..5f5aac2e7 100644 --- a/src/communication/bolt/v1/server/server.hpp +++ b/src/communication/bolt/v1/server/server.hpp @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include #include @@ -9,6 +8,7 @@ #include "communication/bolt/v1/bolt.hpp" #include "io/network/server.hpp" #include "logging/default.hpp" +#include "utils/assert.hpp" namespace bolt { @@ -39,7 +39,7 @@ class Server : public io::Server> { } void on_connect() { - assert(idx < workers.size()); + debug_assert(idx < workers.size(), "Invalid worker id."); logger.trace("on connect"); diff --git a/src/communication/bolt/v1/transport/chunked_decoder.hpp b/src/communication/bolt/v1/transport/chunked_decoder.hpp index 33354a60c..4f498bc92 100644 --- a/src/communication/bolt/v1/transport/chunked_decoder.hpp +++ b/src/communication/bolt/v1/transport/chunked_decoder.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include #include diff --git a/src/data_structures/bitset/dynamic_bitset.hpp b/src/data_structures/bitset/dynamic_bitset.hpp index e7415322b..a4324bbad 100644 --- a/src/data_structures/bitset/dynamic_bitset.hpp +++ b/src/data_structures/bitset/dynamic_bitset.hpp @@ -1,10 +1,10 @@ #pragma once #include -#include #include "threading/sync/lockable.hpp" #include "threading/sync/spinlock.hpp" +#include "utils/assert.hpp" template class DynamicBitset : Lockable { @@ -21,17 +21,17 @@ class DynamicBitset : Lockable { } block_t at(size_t k, size_t n, std::memory_order order) { - assert(k + n - 1 < size); + debug_assert(k + n - 1 < size, "Invalid index."); return (block.load(order) >> k) & bitmask(n); } void set(size_t k, size_t n, std::memory_order order) { - assert(k + n - 1 < size); + debug_assert(k + n - 1 < size, "Invalid index."); block.fetch_or(bitmask(n) << k, order); } void clear(size_t k, size_t n, std::memory_order order) { - assert(k + n - 1 < size); + debug_assert(k + n - 1 < size, "Invalid index."); block.fetch_and(~(bitmask(n) << k), order); } @@ -130,7 +130,7 @@ class DynamicBitset : Lockable { chunk->next.store(new Chunk()); } - assert(chunk != nullptr); + debug_assert(chunk != nullptr, "Chunk is nullptr."); return *chunk; } diff --git a/src/data_structures/concurrent/concurrent_list.hpp b/src/data_structures/concurrent/concurrent_list.hpp index ab942c794..b28e88fb7 100644 --- a/src/data_structures/concurrent/concurrent_list.hpp +++ b/src/data_structures/concurrent/concurrent_list.hpp @@ -1,8 +1,8 @@ #pragma once #include -#include #include +#include "utils/assert.hpp" #include "utils/crtp.hpp" // TODO: reimplement this. It's correct but somewhat inefecient and it could be @@ -63,7 +63,7 @@ class ConcurrentList { IteratorBase() : list(nullptr), curr(nullptr) {} IteratorBase(ConcurrentList *list) : list(list) { - assert(list != nullptr); + debug_assert(list != nullptr, "List is nullptr."); // Increment number of iterators accessing list. list->active_threads_no_++; // Start from the begining of list. @@ -113,11 +113,11 @@ class ConcurrentList { IteratorBase &operator=(IteratorBase &&other) = delete; T &operator*() const { - assert(valid()); + debug_assert(valid(), "Not valid data."); return curr->data; } T *operator->() const { - assert(valid()); + debug_assert(valid(), "Not valid data."); return &(curr->data); } @@ -125,7 +125,7 @@ class ConcurrentList { // Iterating is wait free. It &operator++() { - assert(valid()); + debug_assert(valid(), "Not valid data."); do { prev = curr; curr = load(curr->next); @@ -137,7 +137,7 @@ class ConcurrentList { It &operator++(int) { return operator++(); } bool is_removed() { - assert(valid()); + debug_assert(valid(), "Not valid data."); return load(curr->removed); } @@ -176,7 +176,7 @@ class ConcurrentList { // This can be improved with combinig the removed flag with prev.next or // curr.next bool remove() { - assert(valid()); + debug_assert(valid(), "Not valid data."); // Try to logically remove it. if (cas(curr->removed, false, true)) { // I removed it!!! diff --git a/src/data_structures/concurrent/skiplist.hpp b/src/data_structures/concurrent/skiplist.hpp index 05783a8ac..426d92ce1 100644 --- a/src/data_structures/concurrent/skiplist.hpp +++ b/src/data_structures/concurrent/skiplist.hpp @@ -1,10 +1,10 @@ #pragma once #include -#include #include #include +#include "utils/assert.hpp" #include "utils/placeholder.hpp" #include "utils/random/fast_binomial.hpp" @@ -242,28 +242,28 @@ class SkipList : private Lockable { IteratorBase(const IteratorBase &) = default; T &operator*() { - assert(node != nullptr); + debug_assert(node != nullptr, "Node is nullptr."); return node->value(); } T *operator->() { - assert(node != nullptr); + debug_assert(node != nullptr, "Node is nullptr."); return &node->value(); } operator T &() { - assert(node != nullptr); + debug_assert(node != nullptr, "Node is nullptr."); return node->value(); } It &operator++() { - assert(node != nullptr); + debug_assert(node != nullptr, "Node is nullptr."); node = node->forward(0); return this->derived(); } bool has_next() { - assert(node != nullptr); + debug_assert(node != nullptr, "Node is nullptr."); return node->forward(0) != nullptr; } @@ -329,22 +329,22 @@ class SkipList : private Lockable { } T &operator*() { - assert(node_ != nullptr); + debug_assert(node_ != nullptr, "Node is nullptr."); return node_->value(); } T *operator->() { - assert(node_ != nullptr); + debug_assert(node_ != nullptr, "Node is nullptr."); return &node_->value(); } operator T &() { - assert(node_ != nullptr); + debug_assert(node_ != nullptr, "Node is nullptr."); return node_->value(); } ReverseIterator &operator++() { - assert(node_ != nullptr); + debug_assert(node_ != nullptr, "Node is nullptr."); do { next(); } while (node_->flags.is_marked()); @@ -436,24 +436,24 @@ class SkipList : private Lockable { MultiIterator(const MultiIterator &) = default; T &operator*() { - assert(succs[0] != nullptr); + debug_assert(succs[0] != nullptr, "Node is nullptr."); return succs[0]->value(); } T *operator->() { - assert(succs[0] != nullptr); + debug_assert(succs[0] != nullptr, "Node is nullptr."); return &succs[0]->value(); } operator T &() { - assert(succs[0] != nullptr); + debug_assert(succs[0] != nullptr, "Node is nullptr."); return succs[0]->value(); } bool has_value() { return succs[0] != nullptr; } MultiIterator &operator++() { - assert(succs[0] != nullptr); + debug_assert(succs[0] != nullptr, "Node is nullptr."); // NOTE: This whole method can be optimized if it's valid to expect // height // of 1 on same key elements. @@ -500,14 +500,14 @@ class SkipList : private Lockable { } bool is_removed() { - assert(succs[0] != nullptr); + debug_assert(succs[0] != nullptr, "Node is nullptr."); return succs[0]->flags.is_marked(); } // True if this call successfuly removed value. ITERATOR IS'T ADVANCED. // False may mean that data has already been removed. bool remove() { - assert(succs[0] != nullptr); + debug_assert(succs[0] != nullptr, "Node is nullptr."); // Calls skiplist remove method. return skiplist->template remove( @@ -529,7 +529,8 @@ class SkipList : private Lockable { // true. That way that doesnt have to be done in constructor and // ++ operator. int level_found = succs[0]->height - 1; - assert(succs[0] == succs[level_found]); + + debug_assert(succs[0] == succs[level_found], "Node is initialized."); for (auto it = MultiIterator(skiplist, item); it.has_value(); it++) { if (it.succs[0] == succs[0]) { // Found it @@ -567,7 +568,7 @@ class SkipList : private Lockable { friend class SkipList; Accessor(SkipList *skiplist) : skiplist(skiplist) { - assert(skiplist != nullptr); + debug_assert(skiplist != nullptr, "Skiplist is nullptr."); skiplist->gc.add_ref(); } diff --git a/src/data_structures/concurrent/skiplist_gc.hpp b/src/data_structures/concurrent/skiplist_gc.hpp index c5c4098f7..d3dd1f700 100644 --- a/src/data_structures/concurrent/skiplist_gc.hpp +++ b/src/data_structures/concurrent/skiplist_gc.hpp @@ -7,6 +7,7 @@ #include "memory/freelist.hpp" #include "memory/lazy_gc.hpp" #include "threading/sync/spinlock.hpp" +#include "utils/assert.hpp" template class SkiplistGC : public LazyGC, lock_t>, @@ -27,7 +28,7 @@ class SkiplistGC : public LazyGC, lock_t>, // take freelist if there is no more threads { auto lock = this->acquire_unique(); - assert(this->count > 0); + debug_assert(this->count > 0, "Count is equal to zero."); --this->count; if (this->count == 0) { freelist.swap(local_freelist); diff --git a/src/data_structures/map/rh_common.hpp b/src/data_structures/map/rh_common.hpp index c9a7c91eb..252e28f49 100644 --- a/src/data_structures/map/rh_common.hpp +++ b/src/data_structures/map/rh_common.hpp @@ -1,7 +1,7 @@ #pragma once -#include #include #include +#include "utils/assert.hpp" #include "utils/crtp.hpp" #include "utils/option_ptr.hpp" @@ -93,17 +93,20 @@ class RhBase { IteratorBase(IteratorBase &&) = default; D *operator*() { - assert(index < map->capacity && map->array[index].valid()); + debug_assert(index < map->capacity && map->array[index].valid(), + "Either index is invalid or data is not valid."); return map->array[index].ptr(); } D *operator->() { - assert(index < map->capacity && map->array[index].valid()); + debug_assert(index < map->capacity && map->array[index].valid(), + "Either index is invalid or data is not valid."); return map->array[index].ptr(); } It &operator++() { - assert(index < map->capacity && map->array[index].valid()); + debug_assert(index < map->capacity && map->array[index].valid(), + "Either index is invalid or data is not valid."); auto mask = map->mask(); do { advanced++; diff --git a/src/data_structures/map/rh_hashmultimap.hpp b/src/data_structures/map/rh_hashmultimap.hpp index 994965d2e..60781e883 100644 --- a/src/data_structures/map/rh_hashmultimap.hpp +++ b/src/data_structures/map/rh_hashmultimap.hpp @@ -3,6 +3,7 @@ #include #include #include "data_structures/map/rh_common.hpp" +#include "utils/assert.hpp" #include "utils/crtp.hpp" #include "utils/likely.hpp" #include "utils/option.hpp" @@ -122,7 +123,7 @@ class RhHashMultiMap : public RhBase { // Inserts element with the given key. void add(const K &key_in, D *data) { - assert(key_in == data->get_key()); + debug_assert(key_in == data->get_key(), "Key doesn't match data key."); if (count < capacity) { auto key = std::ref(key_in); diff --git a/src/data_structures/static_array.hpp b/src/data_structures/static_array.hpp index 78bef417b..91ecc952c 100644 --- a/src/data_structures/static_array.hpp +++ b/src/data_structures/static_array.hpp @@ -30,13 +30,13 @@ class static_array { // returns element reference on specific index T &operator[](size_t index) { - runtime_assert(index < N, "Index " << index << " must be less than " << N); + debug_assert(index < N, "Index " << index << " must be less than " << N); return data[index]; } // returns const element reference on specific index const T &operator[](size_t index) const { - runtime_assert(index < N, "Index " << index << " must be less than " << N); + debug_assert(index < N, "Index " << index << " must be less than " << N); return data[index]; } diff --git a/src/database/graph_db_accessor.cpp b/src/database/graph_db_accessor.cpp index b431db2b7..154b16c61 100644 --- a/src/database/graph_db_accessor.cpp +++ b/src/database/graph_db_accessor.cpp @@ -5,6 +5,7 @@ #include "storage/edge_accessor.hpp" #include "storage/vertex.hpp" #include "storage/vertex_accessor.hpp" +#include "utils/assert.hpp" GraphDbAccessor::GraphDbAccessor(GraphDb& db) : db_(db), transaction_(std::move(db.tx_engine.begin())) {} @@ -93,7 +94,7 @@ EdgeAccessor GraphDbAccessor::insert_edge(VertexAccessor& from, void swap_out_edge(std::vector*>& edges, mvcc::VersionList* edge) { auto found = std::find(edges.begin(), edges.end(), edge); - assert(found != edges.end()); + debug_assert(found != edges.end(), "Edge doesn't exist."); std::swap(*found, edges.back()); edges.pop_back(); } diff --git a/src/import/csv_import.hpp b/src/import/csv_import.hpp index c284e8150..6f56c871e 100644 --- a/src/import/csv_import.hpp +++ b/src/import/csv_import.hpp @@ -31,6 +31,7 @@ #include "storage/model/properties/all.hpp" #include "storage/model/properties/flags.hpp" #include "storage/vertex_accessor.hpp" +#include "utils/assert.hpp" #include "utils/command_line/arguments.hpp" #include "utils/option.hpp" @@ -180,7 +181,7 @@ class CSVImporter : public BaseImporter { template typename PropertyFamily::PropertyType::PropertyFamilyKey property_key( const char *name, Flags type) { - assert(false); + debug_assert(false, "Fail."); } // Returns filler for name:type in header_part. None if error occured. diff --git a/src/import/element_skeleton.hpp b/src/import/element_skeleton.hpp index 5fa1b3461..c14fb1b6d 100644 --- a/src/import/element_skeleton.hpp +++ b/src/import/element_skeleton.hpp @@ -1,11 +1,10 @@ #pragma once -#include - #include "database/db_accessor.hpp" #include "storage/model/typed_value.hpp" #include "storage/model/typed_value_store.hpp" #include "storage/vertex_accessor.hpp" +#include "utils/assert.hpp" // Holder for element data which he can then insert as a vertex or edge into the // database depending on the available data and called add_* method. @@ -36,7 +35,7 @@ class ElementSkeleton { } VertexAccessor add_vertex() { - assert(properties_e.empty()); + debug_assert(properties_e.empty(), "Properties aren't empty."); auto va = db.vertex_insert(); @@ -55,15 +54,15 @@ class ElementSkeleton { // Return error msg if unsuccessful Option add_edge() { if (!from_va.is_present()) { - return make_option(std::string("From field must be seted")); + return make_option(std::string("From field must be set")); } if (!to_va.is_present()) { - return make_option(std::string("To field must be seted")); + return make_option(std::string("To field must be set")); } if (!type.is_present()) { - return make_option(std::string("Type field must be seted")); + return make_option(std::string("Type field must be set")); } - assert(properties_v.empty()); + debug_assert(properties_v.empty(), "Properties aren't empty."); auto ve = db.edge_insert(from_va.get(), to_va.get()); ve.edge_type(*type.get()); diff --git a/src/import/fillings/id.hpp b/src/import/fillings/id.hpp index b22a92d57..4f45ec59d 100644 --- a/src/import/fillings/id.hpp +++ b/src/import/fillings/id.hpp @@ -1,6 +1,7 @@ #pragma once #include "import/fillings/filler.hpp" +#include "utils/assert.hpp" // Parses import local Id. // TG - Type group @@ -14,7 +15,9 @@ class IdFiller : public Filler { IdFiller( Option::PropertyType::PropertyFamilyKey> key) : key(key) { - assert(!key.is_present() || key.get().prop_type() == Type(Flags::Int64)); + debug_assert( + !key.is_present() || key.get().prop_type() == Type(Flags::Int64), + "Invalid key property type."); } // Fills skeleton with data from str. Returns error description if diff --git a/src/io/network/socket.hpp b/src/io/network/socket.hpp index b474994f1..e8b4db96e 100644 --- a/src/io/network/socket.hpp +++ b/src/io/network/socket.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include #include #include diff --git a/src/logging/log.cpp b/src/logging/log.cpp index 3ab46e0a6..030b8f7d1 100644 --- a/src/logging/log.cpp +++ b/src/logging/log.cpp @@ -6,7 +6,7 @@ Logger Log::logger(const std::string &name) { // TODO: once when properties are refactored enable this - // runtime_assert(this != nullptr, + // debug_assert(this != nullptr, // "This shouldn't be null. This method is " // "called before the log object is created. " // "E.g. static variables before main method."); diff --git a/src/logging/logger.hpp b/src/logging/logger.hpp index 59f0e862a..068b9465b 100644 --- a/src/logging/logger.hpp +++ b/src/logging/logger.hpp @@ -36,7 +36,7 @@ class Logger { template void emit(Args&&... args) { - runtime_assert(log != nullptr, "Log object has to be defined."); + debug_assert(log != nullptr, "Log object has to be defined."); auto message = std::make_unique>( Timestamp::now(), name, fmt::format(std::forward(args)...)); diff --git a/src/memory/hp.hpp b/src/memory/hp.hpp index c3adc1023..b3227d57b 100644 --- a/src/memory/hp.hpp +++ b/src/memory/hp.hpp @@ -2,7 +2,6 @@ #include #include -#include #include namespace memory { diff --git a/src/mvcc/hints.hpp b/src/mvcc/hints.hpp index e13335361..6c771aa6e 100644 --- a/src/mvcc/hints.hpp +++ b/src/mvcc/hints.hpp @@ -4,6 +4,7 @@ #include #include "transactions/commit_log.hpp" +#include "utils/assert.hpp" namespace mvcc { @@ -66,7 +67,9 @@ class Hints { }; public: - Hints() : cre(bits), exp(bits) { assert(bits.is_lock_free()); } + Hints() : cre(bits), exp(bits) { + debug_assert(bits.is_lock_free(), "Bits are not lock free."); + } union HintBits { uint8_t bits; diff --git a/src/mvcc/record.hpp b/src/mvcc/record.hpp index 6f7911662..1d114b58c 100644 --- a/src/mvcc/record.hpp +++ b/src/mvcc/record.hpp @@ -144,7 +144,8 @@ class Record : public Version { if (info.is_committed()) return hints.set_committed(), true; - assert(info.is_aborted()); + debug_assert(info.is_aborted(), + "Info isn't aborted, but function would return as aborted."); return hints.set_aborted(), false; } }; diff --git a/src/mvcc/version_list.hpp b/src/mvcc/version_list.hpp index 1be2ec867..a659e30f1 100644 --- a/src/mvcc/version_list.hpp +++ b/src/mvcc/version_list.hpp @@ -6,6 +6,7 @@ #include "memory/lazy_gc.hpp" #include "mvcc/serialization_error.hpp" #include "storage/locking/record_lock.hpp" +#include "utils/assert.hpp" namespace mvcc { @@ -124,7 +125,7 @@ class VersionList { */ template T *insert(tx::Transaction &t, Args &&... args) { - assert(head == nullptr); + debug_assert(head == nullptr, "Head is not nullptr on creation."); // create a first version of the record // TODO replace 'new' with something better @@ -139,7 +140,7 @@ class VersionList { } T *update(tx::Transaction &t) { - assert(head != nullptr); + debug_assert(head != nullptr, "Head is nullptr on update."); auto record = find(t); // check if we found any visible records @@ -149,7 +150,7 @@ class VersionList { } T *update(T *record, tx::Transaction &t) { - assert(record != nullptr); + debug_assert(record != nullptr, "Record is nullptr on update."); lock_and_validate(record, t); // It could be done with unique_ptr but while this could mean memory @@ -167,7 +168,7 @@ class VersionList { } bool remove(tx::Transaction &t) { - assert(head != nullptr); + debug_assert(head != nullptr, "Head is nullptr on removal."); auto record = find(t); if (!record) return false; @@ -178,14 +179,15 @@ class VersionList { } void remove(T *record, tx::Transaction &t) { - assert(record != nullptr); + debug_assert(record != nullptr, "Record is nullptr on removal."); lock_and_validate(record, t); record->mark_deleted(t); } private: void lock_and_validate(T *record, tx::Transaction &t) { - assert(record != nullptr); + debug_assert(record != nullptr, + "Record is nullptr on lock and validation."); // take a lock on this node t.take_lock(lock); @@ -195,7 +197,8 @@ class VersionList { if (!record->tx.exp() || !record->exp_committed(t)) return; // if it committed, then we have a serialization conflict - assert(record->hints.load().exp.is_committed()); + debug_assert(record->hints.load().exp.is_committed(), + "Serialization conflict."); throw SerializationError(); } diff --git a/src/query/backend/cpp/cypher_main_visitor.cpp b/src/query/backend/cpp/cypher_main_visitor.cpp index 32326c6ad..6fe2d205b 100644 --- a/src/query/backend/cpp/cypher_main_visitor.cpp +++ b/src/query/backend/cpp/cypher_main_visitor.cpp @@ -1,6 +1,5 @@ #include "query/backend/cpp/cypher_main_visitor.hpp" -#include #include #include #include @@ -8,6 +7,7 @@ #include #include "query/backend/cpp/compiler_structures.hpp" +#include "utils/assert.hpp" namespace { // List of unnamed tokens visitor needs to use. This should be reviewed on every @@ -148,7 +148,7 @@ antlrcpp::Any CypherMainVisitor::visitRelationshipPattern( antlrcpp::Any CypherMainVisitor::visitRelationshipDetail( CypherParser::RelationshipDetailContext *) { - assert(false); + debug_assert(false, "Unimplemented."); return 0; } diff --git a/src/storage/record_accessor.cpp b/src/storage/record_accessor.cpp index e27426c0c..999cb9ad5 100644 --- a/src/storage/record_accessor.cpp +++ b/src/storage/record_accessor.cpp @@ -1,6 +1,7 @@ #include "storage/record_accessor.hpp" #include "storage/edge.hpp" #include "storage/vertex.hpp" +#include "utils/assert.hpp" template RecordAccessor::RecordAccessor(mvcc::VersionList &vlist, @@ -8,7 +9,7 @@ RecordAccessor::RecordAccessor(mvcc::VersionList &vlist, : vlist_(vlist), record_(vlist_.find(db_accessor.transaction_)), db_accessor_(db_accessor) { - assert(record_ != nullptr); + debug_assert(record_ != nullptr, "Record is nullptr."); } template @@ -16,7 +17,7 @@ RecordAccessor::RecordAccessor(mvcc::VersionList &vlist, TRecord &record, GraphDbAccessor &db_accessor) : vlist_(vlist), record_(&record), db_accessor_(db_accessor) { - assert(record_ != nullptr); + debug_assert(record_ != nullptr, "Record is nullptr."); } template diff --git a/src/storage/record_accessor.hpp b/src/storage/record_accessor.hpp index 2e62a4326..25e0cdf90 100644 --- a/src/storage/record_accessor.hpp +++ b/src/storage/record_accessor.hpp @@ -92,20 +92,23 @@ class RecordAccessor { * not actual values inside RecordAccessors. */ friend bool operator<(const RecordAccessor& a, const RecordAccessor& b) { - assert(&a.db_accessor_ == - &b.db_accessor_); // assume the same db_accessor / transaction + debug_assert(&a.db_accessor_ == &b.db_accessor_, + "Not in the same transaction."); // assume the same + // db_accessor / transaction return &a.vlist_ < &b.vlist_; } friend bool operator==(const RecordAccessor& a, const RecordAccessor& b) { - assert(&a.db_accessor_ == - &b.db_accessor_); // assume the same db_accessor / transaction + debug_assert(&a.db_accessor_ == &b.db_accessor_, + "Not in the same transaction."); // assume the same + // db_accessor / transaction return &a.vlist_ == &b.vlist_; } friend bool operator!=(const RecordAccessor& a, const RecordAccessor& b) { - assert(&a.db_accessor_ == - &b.db_accessor_); // assume the same db_accessor / transaction + debug_assert(&a.db_accessor_ == &b.db_accessor_, + "Not in the same transaction."); // assume the same + // db_accessor / transaction return !(a == b); } diff --git a/src/storage/typed_value.cpp b/src/storage/typed_value.cpp index d86908b90..a0cac33bd 100644 --- a/src/storage/typed_value.cpp +++ b/src/storage/typed_value.cpp @@ -9,28 +9,28 @@ // Value extraction template instantiations template <> bool TypedValue::Value() const { - runtime_assert(type_ == TypedValue::Type::Bool, + debug_assert(type_ == TypedValue::Type::Bool, "Incompatible template param and type"); return bool_v; } template <> std::string TypedValue::Value() const { - runtime_assert(type_ == TypedValue::Type::String, + debug_assert(type_ == TypedValue::Type::String, "Incompatible template param and type"); return *string_v; } template <> int TypedValue::Value() const { - runtime_assert(type_ == TypedValue::Type::Int, + debug_assert(type_ == TypedValue::Type::Int, "Incompatible template param and type"); return int_v; } template <> float TypedValue::Value() const { - runtime_assert(type_ == TypedValue::Type::Float, + debug_assert(type_ == TypedValue::Type::Float, "Incompatible template param and type"); return float_v; } diff --git a/src/storage/typed_value.hpp b/src/storage/typed_value.hpp index e56ee86e5..49c878e21 100644 --- a/src/storage/typed_value.hpp +++ b/src/storage/typed_value.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include #include #include diff --git a/src/threading/thread.cpp b/src/threading/thread.cpp index fcb4fdf49..0769063db 100644 --- a/src/threading/thread.cpp +++ b/src/threading/thread.cpp @@ -1,7 +1,8 @@ #include "thread.hpp" +#include "utils/assert.hpp" Thread::Thread(Thread &&other) { - assert(thread_id == UNINITIALIZED); + debug_assert(thread_id == UNINITIALIZED, "Thread was initialized before."); thread_id = other.thread_id; thread = std::move(other.thread); } diff --git a/src/threading/thread.hpp b/src/threading/thread.hpp index d8aeedc34..d2d9dcb56 100644 --- a/src/threading/thread.hpp +++ b/src/threading/thread.hpp @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include "utils/underlying_cast.hpp" diff --git a/src/transactions/lock_store.hpp b/src/transactions/lock_store.hpp index 7877a57ed..e34e12825 100644 --- a/src/transactions/lock_store.hpp +++ b/src/transactions/lock_store.hpp @@ -1,9 +1,9 @@ #pragma once -#include #include #include #include "storage/locking/lock_status.hpp" +#include "utils/assert.hpp" namespace tx { @@ -15,7 +15,7 @@ class LockStore { template LockHolder(T *lock, Args &&... args) noexcept : lock(lock) { - assert(lock != nullptr); + debug_assert(lock != nullptr, "Lock is nullptr."); auto status = lock->lock(std::forward(args)...); if (status != LockStatus::Acquired) lock = nullptr; diff --git a/src/utils/assert.hpp b/src/utils/assert.hpp index 209fba750..8630225f4 100644 --- a/src/utils/assert.hpp +++ b/src/utils/assert.hpp @@ -1,6 +1,6 @@ /** * Permanent Assert -> always active - * Runtime Assert -> active only if RUNTIME_ASSERT_ON is present + * Debug Assert -> active only if DEBUG_ASSERT_ON is present */ #pragma once @@ -50,10 +50,10 @@ * define which controls when the assertion will be active \ * \ * could be used wherever the standard C assert is used but \ - * the user should not forget about RUNTIME_ASSERT_ON define \ + * the user should not forget about DEBUG_ASSERT_ON define \ */ -#ifdef RUNTIME_ASSERT_ON -#define runtime_assert(condition, message) permanent_assert(condition, message) +#ifdef DEBUG_ASSERT_ON +#define debug_assert(condition, message) permanent_assert(condition, message) #else -#define runtime_assert(condition, message) +#define debug_assert(condition, message) #endif diff --git a/src/utils/fswatcher.hpp b/src/utils/fswatcher.hpp index d9833c2a2..f9d62b3bd 100644 --- a/src/utils/fswatcher.hpp +++ b/src/utils/fswatcher.hpp @@ -111,7 +111,7 @@ struct FSEventBase { struct WatchDescriptor : public FSEventBase { WatchDescriptor(const fs::path &directory, const FSEventType type) : FSEventBase(directory, type) { - runtime_assert(fs::is_directory(path), + debug_assert(fs::is_directory(path), "The path parameter should be directory"); } }; @@ -318,7 +318,7 @@ class FSWatcher : public Loggable { // TODO: figure out why (it is not easy) if (((p - buffer_) + in_event_length) > IN_BUFF_LEN) break; // here should be an assertion - // runtime_assert(in_event_length <= IN_BUFF_SLOT_LEN, + // debug_assert(in_event_length <= IN_BUFF_SLOT_LEN, // "Inotify event length cannot be bigger // than " // "Inotify slot length"); diff --git a/src/utils/ioc/container.hpp b/src/utils/ioc/container.hpp index 20634ecf7..fd24439fc 100644 --- a/src/utils/ioc/container.hpp +++ b/src/utils/ioc/container.hpp @@ -1,9 +1,9 @@ #pragma once -#include #include #include #include +#include "utils/assert.hpp" namespace ioc { @@ -26,7 +26,7 @@ class Container { Instance(std::shared_ptr&& item) : item(item) {} std::shared_ptr get() override { - assert(item != nullptr); + debug_assert(item != nullptr, "Item is nullptr."); return item; } @@ -48,11 +48,11 @@ class Container { template std::shared_ptr resolve() { auto it = items.find(key()); - assert(it != items.end()); + debug_assert(it != items.end(), "Key not found."); // try to cast Holdable* to Item* auto item = dynamic_cast*>(it->second.get()); - assert(item != nullptr); + debug_assert(item != nullptr, "Item is nullptr."); return item->get(); } diff --git a/src/utils/iterator/range_iterator.hpp b/src/utils/iterator/range_iterator.hpp index e1bf69255..c60aa160e 100644 --- a/src/utils/iterator/range_iterator.hpp +++ b/src/utils/iterator/range_iterator.hpp @@ -1,5 +1,6 @@ #pragma once +#include "utils/assert.hpp" #include "utils/option.hpp" namespace iter { @@ -16,22 +17,22 @@ class RangeIterator { : value(iter.next()), iter(Option(std::move(iter))) {} T &operator*() { - assert(value.is_present()); + debug_assert(value.is_present(), "No value."); return value.get(); } T *operator->() { - assert(value.is_present()); + debug_assert(value.is_present(), "No value."); return &value.get(); } operator T &() { - assert(value.is_present()); + debug_assert(value.is_present(), "No value."); return value.get(); } RangeIterator &operator++() { - assert(iter.is_present()); + debug_assert(iter.is_present(), "No value."); value = iter.get().next(); return (*this); } diff --git a/src/utils/option.hpp b/src/utils/option.hpp index 9c087419a..9cf58277f 100644 --- a/src/utils/option.hpp +++ b/src/utils/option.hpp @@ -1,9 +1,9 @@ #pragma once #include -#include #include #include +#include "utils/assert.hpp" // Optional object storage. It maybe has and maybe // dosent have objet of type T. @@ -85,7 +85,7 @@ class Option { bool is_present() const { return initialized; } T &get() noexcept { - assert(initialized); + debug_assert(initialized, "Not initialized."); return *data._M_ptr(); } @@ -107,7 +107,7 @@ class Option { } const T &get() const noexcept { - assert(initialized); + debug_assert(initialized, "Not initialized."); return *data._M_ptr(); } @@ -148,7 +148,7 @@ class Option { } T take() { - assert(initialized); + debug_assert(initialized, "Not initialized."); initialized = false; return std::move(*data._M_ptr()); } diff --git a/src/utils/option_ptr.hpp b/src/utils/option_ptr.hpp index 41c1ca340..4e1d16279 100644 --- a/src/utils/option_ptr.hpp +++ b/src/utils/option_ptr.hpp @@ -1,5 +1,7 @@ #pragma once +#include "utils/assert.hpp" + // Like option just for pointers. More efficent than option. template class OptionPtr { @@ -10,7 +12,7 @@ class OptionPtr { bool is_present() { return ptr != nullptr; } T *get() { - assert(is_present()); + debug_assert(is_present(), "Data is not present."); return ptr; } diff --git a/src/utils/placeholder.hpp b/src/utils/placeholder.hpp index 16eeace75..1eb09c8a9 100644 --- a/src/utils/placeholder.hpp +++ b/src/utils/placeholder.hpp @@ -38,7 +38,7 @@ class Placeholder { bool is_initialized() { return initialized; } T &get() noexcept { - runtime_assert(initialized, "Placeholder object not initialized"); + debug_assert(initialized, "Placeholder object not initialized"); return *data._M_ptr(); } @@ -46,7 +46,7 @@ class Placeholder { * @return const reference to object. */ const T &get() const noexcept { - runtime_assert(initialized, "Placeholder object not initialized"); + debug_assert(initialized, "Placeholder object not initialized"); return *data._M_ptr(); } diff --git a/src/utils/string/weak_string.hpp b/src/utils/string/weak_string.hpp index 1f1e2d2c5..18eaa0d87 100644 --- a/src/utils/string/weak_string.hpp +++ b/src/utils/string/weak_string.hpp @@ -1,9 +1,9 @@ #pragma once -#include #include #include +#include "utils/assert.hpp" #include "utils/total_ordering.hpp" #include "utils/total_ordering_with.hpp" @@ -18,17 +18,17 @@ class WeakString { constexpr WeakString(const char* str, size_t len) : str(str), len(len) {} const char& operator[](size_t idx) const { - assert(idx < len); + debug_assert(idx < len, "Index not smaller than length."); return str[idx]; } const char& front() const { - assert(len > 0); + debug_assert(len > 0, "String is empty."); return str[0]; } const char& back() const { - assert(len > 0); + debug_assert(len > 0, "String is empty."); return str[len - 1]; } diff --git a/src/utils/sys.hpp b/src/utils/sys.hpp index 59bdaa4d4..959d2d1dd 100644 --- a/src/utils/sys.hpp +++ b/src/utils/sys.hpp @@ -8,7 +8,6 @@ #include #include #include -#include #include namespace sys { diff --git a/tests/manual/xorshift.cpp b/tests/manual/xorshift.cpp index d680a1553..ef38f649e 100644 --- a/tests/manual/xorshift.cpp +++ b/tests/manual/xorshift.cpp @@ -10,6 +10,7 @@ #include #include +#include "utils/assert.hpp" #include "utils/random/xorshift128plus.hpp" static thread_local Xorshift128plus rnd; @@ -43,7 +44,7 @@ int main(void) { auto max = std::accumulate( buckets.begin(), buckets.end(), 0u, [](auto& acc, auto& x) { return std::max(acc, x.load()); }); - assert(max != 0u); + debug_assert(max != 0u, "max is 0."); std::cout << std::fixed;