Skip to content

Commit 85c4254

Browse files
authored
Merge pull request #4848 from YosysHQ/emil/fix-hash-ops-discard
Stop and prevent discarding hash_into values
2 parents 6225abe + 4dbef95 commit 85c4254

File tree

21 files changed

+63
-63
lines changed

21 files changed

+63
-63
lines changed

frontends/ast/ast.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ namespace AST
177177
{
178178
// for dict<> and pool<>
179179
unsigned int hashidx_;
180-
Hasher hash_into(Hasher h) const { h.eat(hashidx_); return h; }
180+
[[nodiscard]] Hasher hash_into(Hasher h) const { h.eat(hashidx_); return h; }
181181

182182
// this nodes type
183183
AstNodeType type;

kernel/bitpattern.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ struct BitPatternPool
4343
return false;
4444
return bitdata == other.bitdata;
4545
}
46-
Hasher hash_into(Hasher h) const {
46+
[[nodiscard]] Hasher hash_into(Hasher h) const {
4747
if (!cached_hash)
4848
cached_hash = run_hash(bitdata);
4949
h.eat(cached_hash);

kernel/cellaigs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct AigNode
3434

3535
AigNode();
3636
bool operator==(const AigNode &other) const;
37-
Hasher hash_into(Hasher h) const;
37+
[[nodiscard]] Hasher hash_into(Hasher h) const;
3838
};
3939

4040
struct Aig
@@ -44,7 +44,7 @@ struct Aig
4444
Aig(Cell *cell);
4545

4646
bool operator==(const Aig &other) const;
47-
Hasher hash_into(Hasher h) const;
47+
[[nodiscard]] Hasher hash_into(Hasher h) const;
4848
};
4949

5050
YOSYS_NAMESPACE_END

kernel/drivertools.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ struct DriveBitWire
7474
return offset < other.offset;
7575
}
7676

77-
Hasher hash_into(Hasher h) const;
77+
[[nodiscard]] Hasher hash_into(Hasher h) const;
7878

7979

8080
operator SigBit() const
@@ -105,7 +105,7 @@ struct DriveBitPort
105105
return offset < other.offset;
106106
}
107107

108-
Hasher hash_into(Hasher h) const;
108+
[[nodiscard]] Hasher hash_into(Hasher h) const;
109109

110110
};
111111

@@ -129,7 +129,7 @@ struct DriveBitMarker
129129
return offset < other.offset;
130130
}
131131

132-
Hasher hash_into(Hasher h) const;
132+
[[nodiscard]] Hasher hash_into(Hasher h) const;
133133

134134
};
135135

@@ -164,7 +164,7 @@ struct DriveBitMultiple
164164
return multiple_ == other.multiple_;
165165
}
166166

167-
Hasher hash_into(Hasher h) const;
167+
[[nodiscard]] Hasher hash_into(Hasher h) const;
168168
};
169169

170170
struct DriveBit
@@ -352,7 +352,7 @@ struct DriveBit
352352
return *this;
353353
}
354354

355-
Hasher hash_into(Hasher h) const;
355+
[[nodiscard]] Hasher hash_into(Hasher h) const;
356356

357357
bool operator==(const DriveBit &other) const
358358
{
@@ -473,7 +473,7 @@ struct DriveChunkWire
473473
return offset < other.offset;
474474
}
475475

476-
Hasher hash_into(Hasher h) const;
476+
[[nodiscard]] Hasher hash_into(Hasher h) const;
477477

478478
explicit operator SigChunk() const
479479
{
@@ -531,7 +531,7 @@ struct DriveChunkPort
531531
return offset < other.offset;
532532
}
533533

534-
Hasher hash_into(Hasher h) const;
534+
[[nodiscard]] Hasher hash_into(Hasher h) const;
535535
};
536536

537537

@@ -572,7 +572,7 @@ struct DriveChunkMarker
572572
return offset < other.offset;
573573
}
574574

575-
Hasher hash_into(Hasher h) const;
575+
[[nodiscard]] Hasher hash_into(Hasher h) const;
576576
};
577577

578578
struct DriveChunkMultiple
@@ -612,7 +612,7 @@ struct DriveChunkMultiple
612612
return false; // TODO implement, canonicalize order
613613
}
614614

615-
Hasher hash_into(Hasher h) const;
615+
[[nodiscard]] Hasher hash_into(Hasher h) const;
616616
};
617617

618618
struct DriveChunk
@@ -863,7 +863,7 @@ struct DriveChunk
863863
bool try_append(DriveBit const &bit);
864864
bool try_append(DriveChunk const &chunk);
865865

866-
Hasher hash_into(Hasher h) const;
866+
[[nodiscard]] Hasher hash_into(Hasher h) const;
867867

868868
bool operator==(const DriveChunk &other) const
869869
{
@@ -1074,7 +1074,7 @@ struct DriveSpec
10741074
hash_ |= (hash_ == 0);
10751075
}
10761076

1077-
Hasher hash_into(Hasher h) const;
1077+
[[nodiscard]] Hasher hash_into(Hasher h) const;
10781078

10791079
bool operator==(DriveSpec const &other) const {
10801080
updhash();
@@ -1112,7 +1112,7 @@ struct DriverMap
11121112
bool operator==(const DriveBitId &other) const { return id == other.id; }
11131113
bool operator!=(const DriveBitId &other) const { return id != other.id; }
11141114
bool operator<(const DriveBitId &other) const { return id < other.id; }
1115-
Hasher hash_into(Hasher h) const;
1115+
[[nodiscard]] Hasher hash_into(Hasher h) const;
11161116
};
11171117
// Essentially a dict<DriveBitId, pool<DriveBitId>> but using less memory
11181118
// and fewer allocations

kernel/functional.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ namespace Functional {
151151
// returns the data width of a bitvector sort, errors out for other sorts
152152
int data_width() const { return std::get<1>(_v).second; }
153153
bool operator==(Sort const& other) const { return _v == other._v; }
154-
Hasher hash_into(Hasher h) const { h.eat(_v); return h; }
154+
[[nodiscard]] Hasher hash_into(Hasher h) const { h.eat(_v); return h; }
155155
};
156156
class IR;
157157
class Factory;
@@ -225,7 +225,7 @@ namespace Functional {
225225
const RTLIL::Const &as_const() const { return std::get<RTLIL::Const>(_extra); }
226226
std::pair<IdString, IdString> as_idstring_pair() const { return std::get<std::pair<IdString, IdString>>(_extra); }
227227
int as_int() const { return std::get<int>(_extra); }
228-
Hasher hash_into(Hasher h) const {
228+
[[nodiscard]] Hasher hash_into(Hasher h) const {
229229
h.eat((unsigned int) _fn);
230230
h.eat(_extra);
231231
return h;

kernel/hashlib.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ struct hash_ops {
162162
static inline bool cmp(const T &a, const T &b) {
163163
return a == b;
164164
}
165-
static inline Hasher hash_into(const T &a, Hasher h) {
165+
[[nodiscard]] static inline Hasher hash_into(const T &a, Hasher h) {
166166
if constexpr (std::is_integral_v<T>) {
167167
static_assert(sizeof(T) <= sizeof(uint64_t));
168168
if (sizeof(T) == sizeof(uint64_t))
@@ -189,7 +189,7 @@ template<typename P, typename Q> struct hash_ops<std::pair<P, Q>> {
189189
static inline bool cmp(std::pair<P, Q> a, std::pair<P, Q> b) {
190190
return a == b;
191191
}
192-
static inline Hasher hash_into(std::pair<P, Q> a, Hasher h) {
192+
[[nodiscard]] static inline Hasher hash_into(std::pair<P, Q> a, Hasher h) {
193193
h = hash_ops<P>::hash_into(a.first, h);
194194
h = hash_ops<Q>::hash_into(a.second, h);
195195
return h;
@@ -217,7 +217,7 @@ template<typename T> struct hash_ops<std::vector<T>> {
217217
static inline bool cmp(std::vector<T> a, std::vector<T> b) {
218218
return a == b;
219219
}
220-
static inline Hasher hash_into(std::vector<T> a, Hasher h) {
220+
[[nodiscard]] static inline Hasher hash_into(std::vector<T> a, Hasher h) {
221221
h.eat((uint32_t)a.size());
222222
for (auto k : a)
223223
h.eat(k);
@@ -229,7 +229,7 @@ template<typename T, size_t N> struct hash_ops<std::array<T, N>> {
229229
static inline bool cmp(std::array<T, N> a, std::array<T, N> b) {
230230
return a == b;
231231
}
232-
static inline Hasher hash_into(std::array<T, N> a, Hasher h) {
232+
[[nodiscard]] static inline Hasher hash_into(std::array<T, N> a, Hasher h) {
233233
for (const auto& k : a)
234234
h = hash_ops<T>::hash_into(k, h);
235235
return h;
@@ -240,7 +240,7 @@ struct hash_cstr_ops {
240240
static inline bool cmp(const char *a, const char *b) {
241241
return strcmp(a, b) == 0;
242242
}
243-
static inline Hasher hash_into(const char *a, Hasher h) {
243+
[[nodiscard]] static inline Hasher hash_into(const char *a, Hasher h) {
244244
while (*a)
245245
h.hash32(*(a++));
246246
return h;
@@ -253,7 +253,7 @@ struct hash_ptr_ops {
253253
static inline bool cmp(const void *a, const void *b) {
254254
return a == b;
255255
}
256-
static inline Hasher hash_into(const void *a, Hasher h) {
256+
[[nodiscard]] static inline Hasher hash_into(const void *a, Hasher h) {
257257
return hash_ops<uintptr_t>::hash_into((uintptr_t)a, h);
258258
}
259259
};
@@ -263,9 +263,9 @@ struct hash_obj_ops {
263263
return a == b;
264264
}
265265
template<typename T>
266-
static inline Hasher hash_into(const T *a, Hasher h) {
266+
[[nodiscard]] static inline Hasher hash_into(const T *a, Hasher h) {
267267
if (a)
268-
a->hash_into(h);
268+
h = a->hash_into(h);
269269
else
270270
h.eat(0);
271271
return h;
@@ -295,7 +295,7 @@ template<> struct hash_ops<std::monostate> {
295295
static inline bool cmp(std::monostate a, std::monostate b) {
296296
return a == b;
297297
}
298-
static inline Hasher hash_into(std::monostate, Hasher h) {
298+
[[nodiscard]] static inline Hasher hash_into(std::monostate, Hasher h) {
299299
return h;
300300
}
301301
};
@@ -304,7 +304,7 @@ template<typename... T> struct hash_ops<std::variant<T...>> {
304304
static inline bool cmp(std::variant<T...> a, std::variant<T...> b) {
305305
return a == b;
306306
}
307-
static inline Hasher hash_into(std::variant<T...> a, Hasher h) {
307+
[[nodiscard]] static inline Hasher hash_into(std::variant<T...> a, Hasher h) {
308308
std::visit([& h](const auto &v) { h.eat(v); }, a);
309309
h.eat(a.index());
310310
return h;
@@ -315,7 +315,7 @@ template<typename T> struct hash_ops<std::optional<T>> {
315315
static inline bool cmp(std::optional<T> a, std::optional<T> b) {
316316
return a == b;
317317
}
318-
static inline Hasher hash_into(std::optional<T> a, Hasher h) {
318+
[[nodiscard]] static inline Hasher hash_into(std::optional<T> a, Hasher h) {
319319
if(a.has_value())
320320
h.eat(*a);
321321
else
@@ -788,7 +788,7 @@ class dict {
788788
return !operator==(other);
789789
}
790790

791-
Hasher hash_into(Hasher h) const {
791+
[[nodiscard]] Hasher hash_into(Hasher h) const {
792792
for (auto &it : entries) {
793793
Hasher entry_hash;
794794
entry_hash.eat(it.udata.first);
@@ -1158,7 +1158,7 @@ class pool
11581158
return !operator==(other);
11591159
}
11601160

1161-
Hasher hash_into(Hasher h) const {
1161+
[[nodiscard]] Hasher hash_into(Hasher h) const {
11621162
for (auto &it : entries) {
11631163
h.commutative_eat(ops.hash(it.udata).yield());
11641164
}

kernel/modtools.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ struct ModIndex : public RTLIL::Monitor
4848
return cell == other.cell && port == other.port && offset == other.offset;
4949
}
5050

51-
Hasher hash_into(Hasher h) const {
51+
[[nodiscard]] Hasher hash_into(Hasher h) const {
5252
h.eat(cell->name);
5353
h.eat(port);
5454
h.eat(offset);
@@ -321,7 +321,7 @@ struct ModWalker
321321
return cell == other.cell && port == other.port && offset == other.offset;
322322
}
323323

324-
Hasher hash_into(Hasher h) const {
324+
[[nodiscard]] Hasher hash_into(Hasher h) const {
325325
h.eat(cell->name);
326326
h.eat(port);
327327
h.eat(offset);

kernel/rtlil.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,9 @@ struct RTLIL::IdString
362362
*this = IdString();
363363
}
364364

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

367-
Hasher hash_top() const {
367+
[[nodiscard]] Hasher hash_top() const {
368368
Hasher h;
369369
h.force((Hasher::hash_t) index_);
370370
return h;
@@ -821,7 +821,7 @@ struct RTLIL::Const
821821
bv.resize(width, bv.empty() ? RTLIL::State::Sx : bv.back());
822822
}
823823

824-
inline Hasher hash_into(Hasher h) const {
824+
[[nodiscard]] Hasher hash_into(Hasher h) const {
825825
h.eat(size());
826826
for (auto b : *this)
827827
h.eat(b);
@@ -914,8 +914,8 @@ struct RTLIL::SigBit
914914
bool operator <(const RTLIL::SigBit &other) const;
915915
bool operator ==(const RTLIL::SigBit &other) const;
916916
bool operator !=(const RTLIL::SigBit &other) const;
917-
Hasher hash_into(Hasher h) const;
918-
Hasher hash_top() const;
917+
[[nodiscard]] Hasher hash_into(Hasher h) const;
918+
[[nodiscard]] Hasher hash_top() const;
919919
};
920920

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

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

11201120
#ifndef NDEBUG
11211121
void check(Module *mod = nullptr) const;
@@ -1157,7 +1157,7 @@ struct RTLIL::Selection
11571157
struct RTLIL::Monitor
11581158
{
11591159
Hasher::hash_t hashidx_;
1160-
Hasher hash_into(Hasher h) const { h.eat(hashidx_); return h; }
1160+
[[nodiscard]] Hasher hash_into(Hasher h) const { h.eat(hashidx_); return h; }
11611161

11621162
Monitor() {
11631163
static unsigned int hashidx_count = 123456789;
@@ -1180,7 +1180,7 @@ struct define_map_t;
11801180
struct RTLIL::Design
11811181
{
11821182
Hasher::hash_t hashidx_;
1183-
Hasher hash_into(Hasher h) const { h.eat(hashidx_); return h; }
1183+
[[nodiscard]] Hasher hash_into(Hasher h) const { h.eat(hashidx_); return h; }
11841184

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

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

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

16841684
Memory();
16851685

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

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

18091809
protected:
18101810
// use module->addProcess() and module->remove() to create or destroy processes

0 commit comments

Comments
 (0)