Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop and prevent discarding hash_into values #4848

Merged
merged 3 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontends/ast/ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ namespace AST
{
// for dict<> and pool<>
unsigned int hashidx_;
Hasher hash_into(Hasher h) const { h.eat(hashidx_); return h; }
[[nodiscard]] Hasher hash_into(Hasher h) const { h.eat(hashidx_); return h; }

// this nodes type
AstNodeType type;
Expand Down
2 changes: 1 addition & 1 deletion kernel/bitpattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct BitPatternPool
return false;
return bitdata == other.bitdata;
}
Hasher hash_into(Hasher h) const {
[[nodiscard]] Hasher hash_into(Hasher h) const {
if (!cached_hash)
cached_hash = run_hash(bitdata);
h.eat(cached_hash);
Expand Down
4 changes: 2 additions & 2 deletions kernel/cellaigs.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct AigNode

AigNode();
bool operator==(const AigNode &other) const;
Hasher hash_into(Hasher h) const;
[[nodiscard]] Hasher hash_into(Hasher h) const;
};

struct Aig
Expand All @@ -44,7 +44,7 @@ struct Aig
Aig(Cell *cell);

bool operator==(const Aig &other) const;
Hasher hash_into(Hasher h) const;
[[nodiscard]] Hasher hash_into(Hasher h) const;
};

YOSYS_NAMESPACE_END
Expand Down
24 changes: 12 additions & 12 deletions kernel/drivertools.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ struct DriveBitWire
return offset < other.offset;
}

Hasher hash_into(Hasher h) const;
[[nodiscard]] Hasher hash_into(Hasher h) const;


operator SigBit() const
Expand Down Expand Up @@ -105,7 +105,7 @@ struct DriveBitPort
return offset < other.offset;
}

Hasher hash_into(Hasher h) const;
[[nodiscard]] Hasher hash_into(Hasher h) const;

};

Expand All @@ -129,7 +129,7 @@ struct DriveBitMarker
return offset < other.offset;
}

Hasher hash_into(Hasher h) const;
[[nodiscard]] Hasher hash_into(Hasher h) const;

};

Expand Down Expand Up @@ -164,7 +164,7 @@ struct DriveBitMultiple
return multiple_ == other.multiple_;
}

Hasher hash_into(Hasher h) const;
[[nodiscard]] Hasher hash_into(Hasher h) const;
};

struct DriveBit
Expand Down Expand Up @@ -352,7 +352,7 @@ struct DriveBit
return *this;
}

Hasher hash_into(Hasher h) const;
[[nodiscard]] Hasher hash_into(Hasher h) const;

bool operator==(const DriveBit &other) const
{
Expand Down Expand Up @@ -473,7 +473,7 @@ struct DriveChunkWire
return offset < other.offset;
}

Hasher hash_into(Hasher h) const;
[[nodiscard]] Hasher hash_into(Hasher h) const;

explicit operator SigChunk() const
{
Expand Down Expand Up @@ -531,7 +531,7 @@ struct DriveChunkPort
return offset < other.offset;
}

Hasher hash_into(Hasher h) const;
[[nodiscard]] Hasher hash_into(Hasher h) const;
};


Expand Down Expand Up @@ -572,7 +572,7 @@ struct DriveChunkMarker
return offset < other.offset;
}

Hasher hash_into(Hasher h) const;
[[nodiscard]] Hasher hash_into(Hasher h) const;
};

struct DriveChunkMultiple
Expand Down Expand Up @@ -612,7 +612,7 @@ struct DriveChunkMultiple
return false; // TODO implement, canonicalize order
}

Hasher hash_into(Hasher h) const;
[[nodiscard]] Hasher hash_into(Hasher h) const;
};

struct DriveChunk
Expand Down Expand Up @@ -863,7 +863,7 @@ struct DriveChunk
bool try_append(DriveBit const &bit);
bool try_append(DriveChunk const &chunk);

Hasher hash_into(Hasher h) const;
[[nodiscard]] Hasher hash_into(Hasher h) const;

bool operator==(const DriveChunk &other) const
{
Expand Down Expand Up @@ -1074,7 +1074,7 @@ struct DriveSpec
hash_ |= (hash_ == 0);
}

Hasher hash_into(Hasher h) const;
[[nodiscard]] Hasher hash_into(Hasher h) const;

bool operator==(DriveSpec const &other) const {
updhash();
Expand Down Expand Up @@ -1112,7 +1112,7 @@ struct DriverMap
bool operator==(const DriveBitId &other) const { return id == other.id; }
bool operator!=(const DriveBitId &other) const { return id != other.id; }
bool operator<(const DriveBitId &other) const { return id < other.id; }
Hasher hash_into(Hasher h) const;
[[nodiscard]] Hasher hash_into(Hasher h) const;
};
// Essentially a dict<DriveBitId, pool<DriveBitId>> but using less memory
// and fewer allocations
Expand Down
4 changes: 2 additions & 2 deletions kernel/functional.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ namespace Functional {
// returns the data width of a bitvector sort, errors out for other sorts
int data_width() const { return std::get<1>(_v).second; }
bool operator==(Sort const& other) const { return _v == other._v; }
Hasher hash_into(Hasher h) const { h.eat(_v); return h; }
[[nodiscard]] Hasher hash_into(Hasher h) const { h.eat(_v); return h; }
};
class IR;
class Factory;
Expand Down Expand Up @@ -225,7 +225,7 @@ namespace Functional {
const RTLIL::Const &as_const() const { return std::get<RTLIL::Const>(_extra); }
std::pair<IdString, IdString> as_idstring_pair() const { return std::get<std::pair<IdString, IdString>>(_extra); }
int as_int() const { return std::get<int>(_extra); }
Hasher hash_into(Hasher h) const {
[[nodiscard]] Hasher hash_into(Hasher h) const {
h.eat((unsigned int) _fn);
h.eat(_extra);
return h;
Expand Down
26 changes: 13 additions & 13 deletions kernel/hashlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ struct hash_ops {
static inline bool cmp(const T &a, const T &b) {
return a == b;
}
static inline Hasher hash_into(const T &a, Hasher h) {
[[nodiscard]] static inline Hasher hash_into(const T &a, Hasher h) {
if constexpr (std::is_integral_v<T>) {
static_assert(sizeof(T) <= sizeof(uint64_t));
if (sizeof(T) == sizeof(uint64_t))
Expand All @@ -189,7 +189,7 @@ template<typename P, typename Q> struct hash_ops<std::pair<P, Q>> {
static inline bool cmp(std::pair<P, Q> a, std::pair<P, Q> b) {
return a == b;
}
static inline Hasher hash_into(std::pair<P, Q> a, Hasher h) {
[[nodiscard]] static inline Hasher hash_into(std::pair<P, Q> a, Hasher h) {
h = hash_ops<P>::hash_into(a.first, h);
h = hash_ops<Q>::hash_into(a.second, h);
return h;
Expand Down Expand Up @@ -217,7 +217,7 @@ template<typename T> struct hash_ops<std::vector<T>> {
static inline bool cmp(std::vector<T> a, std::vector<T> b) {
return a == b;
}
static inline Hasher hash_into(std::vector<T> a, Hasher h) {
[[nodiscard]] static inline Hasher hash_into(std::vector<T> a, Hasher h) {
h.eat((uint32_t)a.size());
for (auto k : a)
h.eat(k);
Expand All @@ -229,7 +229,7 @@ template<typename T, size_t N> struct hash_ops<std::array<T, N>> {
static inline bool cmp(std::array<T, N> a, std::array<T, N> b) {
return a == b;
}
static inline Hasher hash_into(std::array<T, N> a, Hasher h) {
[[nodiscard]] static inline Hasher hash_into(std::array<T, N> a, Hasher h) {
for (const auto& k : a)
h = hash_ops<T>::hash_into(k, h);
return h;
Expand All @@ -240,7 +240,7 @@ struct hash_cstr_ops {
static inline bool cmp(const char *a, const char *b) {
return strcmp(a, b) == 0;
}
static inline Hasher hash_into(const char *a, Hasher h) {
[[nodiscard]] static inline Hasher hash_into(const char *a, Hasher h) {
while (*a)
h.hash32(*(a++));
return h;
Expand All @@ -253,7 +253,7 @@ struct hash_ptr_ops {
static inline bool cmp(const void *a, const void *b) {
return a == b;
}
static inline Hasher hash_into(const void *a, Hasher h) {
[[nodiscard]] static inline Hasher hash_into(const void *a, Hasher h) {
return hash_ops<uintptr_t>::hash_into((uintptr_t)a, h);
}
};
Expand All @@ -263,9 +263,9 @@ struct hash_obj_ops {
return a == b;
}
template<typename T>
static inline Hasher hash_into(const T *a, Hasher h) {
[[nodiscard]] static inline Hasher hash_into(const T *a, Hasher h) {
if (a)
a->hash_into(h);
h = a->hash_into(h);
else
h.eat(0);
return h;
Expand Down Expand Up @@ -295,7 +295,7 @@ template<> struct hash_ops<std::monostate> {
static inline bool cmp(std::monostate a, std::monostate b) {
return a == b;
}
static inline Hasher hash_into(std::monostate, Hasher h) {
[[nodiscard]] static inline Hasher hash_into(std::monostate, Hasher h) {
return h;
}
};
Expand All @@ -304,7 +304,7 @@ template<typename... T> struct hash_ops<std::variant<T...>> {
static inline bool cmp(std::variant<T...> a, std::variant<T...> b) {
return a == b;
}
static inline Hasher hash_into(std::variant<T...> a, Hasher h) {
[[nodiscard]] static inline Hasher hash_into(std::variant<T...> a, Hasher h) {
std::visit([& h](const auto &v) { h.eat(v); }, a);
h.eat(a.index());
return h;
Expand All @@ -315,7 +315,7 @@ template<typename T> struct hash_ops<std::optional<T>> {
static inline bool cmp(std::optional<T> a, std::optional<T> b) {
return a == b;
}
static inline Hasher hash_into(std::optional<T> a, Hasher h) {
[[nodiscard]] static inline Hasher hash_into(std::optional<T> a, Hasher h) {
if(a.has_value())
h.eat(*a);
else
Expand Down Expand Up @@ -788,7 +788,7 @@ class dict {
return !operator==(other);
}

Hasher hash_into(Hasher h) const {
[[nodiscard]] Hasher hash_into(Hasher h) const {
for (auto &it : entries) {
Hasher entry_hash;
entry_hash.eat(it.udata.first);
Expand Down Expand Up @@ -1158,7 +1158,7 @@ class pool
return !operator==(other);
}

Hasher hash_into(Hasher h) const {
[[nodiscard]] Hasher hash_into(Hasher h) const {
for (auto &it : entries) {
h.commutative_eat(ops.hash(it.udata).yield());
}
Expand Down
4 changes: 2 additions & 2 deletions kernel/modtools.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct ModIndex : public RTLIL::Monitor
return cell == other.cell && port == other.port && offset == other.offset;
}

Hasher hash_into(Hasher h) const {
[[nodiscard]] Hasher hash_into(Hasher h) const {
h.eat(cell->name);
h.eat(port);
h.eat(offset);
Expand Down Expand Up @@ -321,7 +321,7 @@ struct ModWalker
return cell == other.cell && port == other.port && offset == other.offset;
}

Hasher hash_into(Hasher h) const {
[[nodiscard]] Hasher hash_into(Hasher h) const {
h.eat(cell->name);
h.eat(port);
h.eat(offset);
Expand Down
26 changes: 13 additions & 13 deletions kernel/rtlil.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,9 @@ struct RTLIL::IdString
*this = IdString();
}

Hasher hash_into(Hasher h) const { return hash_ops<int>::hash_into(index_, h); }
[[nodiscard]] Hasher hash_into(Hasher h) const { return hash_ops<int>::hash_into(index_, h); }

Hasher hash_top() const {
[[nodiscard]] Hasher hash_top() const {
Hasher h;
h.force((Hasher::hash_t) index_);
return h;
Expand Down Expand Up @@ -821,7 +821,7 @@ struct RTLIL::Const
bv.resize(width, bv.empty() ? RTLIL::State::Sx : bv.back());
}

inline Hasher hash_into(Hasher h) const {
[[nodiscard]] Hasher hash_into(Hasher h) const {
h.eat(size());
for (auto b : *this)
h.eat(b);
Expand Down Expand Up @@ -914,8 +914,8 @@ struct RTLIL::SigBit
bool operator <(const RTLIL::SigBit &other) const;
bool operator ==(const RTLIL::SigBit &other) const;
bool operator !=(const RTLIL::SigBit &other) const;
Hasher hash_into(Hasher h) const;
Hasher hash_top() const;
[[nodiscard]] Hasher hash_into(Hasher h) const;
[[nodiscard]] Hasher hash_top() const;
};

namespace hashlib {
Expand Down Expand Up @@ -1115,7 +1115,7 @@ struct RTLIL::SigSpec
operator std::vector<RTLIL::SigBit>() const { return bits(); }
const RTLIL::SigBit &at(int offset, const RTLIL::SigBit &defval) { return offset < width_ ? (*this)[offset] : defval; }

Hasher hash_into(Hasher h) const { if (!hash_) updhash(); h.eat(hash_); return h; }
[[nodiscard]] Hasher hash_into(Hasher h) const { if (!hash_) updhash(); h.eat(hash_); return h; }

#ifndef NDEBUG
void check(Module *mod = nullptr) const;
Expand Down Expand Up @@ -1157,7 +1157,7 @@ struct RTLIL::Selection
struct RTLIL::Monitor
{
Hasher::hash_t hashidx_;
Hasher hash_into(Hasher h) const { h.eat(hashidx_); return h; }
[[nodiscard]] Hasher hash_into(Hasher h) const { h.eat(hashidx_); return h; }

Monitor() {
static unsigned int hashidx_count = 123456789;
Expand All @@ -1180,7 +1180,7 @@ struct define_map_t;
struct RTLIL::Design
{
Hasher::hash_t hashidx_;
Hasher hash_into(Hasher h) const { h.eat(hashidx_); return h; }
[[nodiscard]] Hasher hash_into(Hasher h) const { h.eat(hashidx_); return h; }

pool<RTLIL::Monitor*> monitors;
dict<std::string, std::string> scratchpad;
Expand Down Expand Up @@ -1285,7 +1285,7 @@ struct RTLIL::Design
struct RTLIL::Module : public RTLIL::AttrObject
{
Hasher::hash_t hashidx_;
Hasher hash_into(Hasher h) const { h.eat(hashidx_); return h; }
[[nodiscard]] Hasher hash_into(Hasher h) const { h.eat(hashidx_); return h; }

protected:
void add(RTLIL::Wire *wire);
Expand Down Expand Up @@ -1640,7 +1640,7 @@ void dump_wire(std::ostream &f, std::string indent, const RTLIL::Wire *wire);
struct RTLIL::Wire : public RTLIL::AttrObject
{
Hasher::hash_t hashidx_;
Hasher hash_into(Hasher h) const { h.eat(hashidx_); return h; }
[[nodiscard]] Hasher hash_into(Hasher h) const { h.eat(hashidx_); return h; }

protected:
// use module->addWire() and module->remove() to create or destroy wires
Expand Down Expand Up @@ -1679,7 +1679,7 @@ inline int GetSize(RTLIL::Wire *wire) {
struct RTLIL::Memory : public RTLIL::AttrObject
{
Hasher::hash_t hashidx_;
Hasher hash_into(Hasher h) const { h.eat(hashidx_); return h; }
[[nodiscard]] Hasher hash_into(Hasher h) const { h.eat(hashidx_); return h; }

Memory();

Expand All @@ -1694,7 +1694,7 @@ struct RTLIL::Memory : public RTLIL::AttrObject
struct RTLIL::Cell : public RTLIL::AttrObject
{
Hasher::hash_t hashidx_;
Hasher hash_into(Hasher h) const { h.eat(hashidx_); return h; }
[[nodiscard]] Hasher hash_into(Hasher h) const { h.eat(hashidx_); return h; }

protected:
// use module->addCell() and module->remove() to create or destroy cells
Expand Down Expand Up @@ -1804,7 +1804,7 @@ struct RTLIL::SyncRule
struct RTLIL::Process : public RTLIL::AttrObject
{
Hasher::hash_t hashidx_;
Hasher hash_into(Hasher h) const { h.eat(hashidx_); return h; }
[[nodiscard]] Hasher hash_into(Hasher h) const { h.eat(hashidx_); return h; }

protected:
// use module->addProcess() and module->remove() to create or destroy processes
Expand Down
Loading
Loading