Internals: Make the constant pool a regular package (#8512)

The constant pool is now an ordinary package, created with the netlist
and instantiated under $root like any other package, and most special
handling has been removed, including AstConstPool. Lookups go through
V3ConstPool, which has a singleton instance owned by V3Global. Static
methods on V3Common form the public interfce to add/find constant pool
entries.

With that, the constant pool is usable at any stage during compilation,
so enum and dimension tables created by V3Width, and enum value tables
created by V3Randomize now also live in the constant pool instead of
$unit, so identical tables are shared.

Associative array constants are handled separately from unpacked
tables, which used to be broken but unused.

Emitted constant pool variables use direct initialization, and
`constinit` with C++20 where the type allows it. This ensures we don't
change a run-time in a way that would result in unintended code size
increase.

-fno-merge-const-pool, which was introduced years ago but never prompted
a bug report is deprecated and has no effect.

This is also prep for future work.
This commit is contained in:
Geza Lore
2026-09-27 13:25:41 +01:00
committed by GitHub
parent d234caafc1
commit 348b9b6209
68 changed files with 1239 additions and 930 deletions
+20
View File
@@ -497,12 +497,32 @@ void testEntryLifetime() {
}
UASSERT_SELFTEST(set.begin() == set.end(), true); // Erased down to empty
UASSERT_SELFTEST(alive, 0); // With every entry destroyed
// Clearing destroys every entry at once, and leaves a usable, empty set
for (size_t i = 0; i < N; ++i) set.insert(NoDefault{&alive, 7, i});
UASSERT_SELFTEST(alive, N); // Filled up again
set.clear();
UASSERT_SELFTEST(set.size(), 0); // Nothing left
UASSERT_SELFTEST(set.empty(), true); // Says so
UASSERT_SELFTEST(set.begin() == set.end(), true); // Iterates nothing
UASSERT_SELFTEST(alive, 0); // With every entry destroyed
UASSERT_SELFTEST(set.contains(size_t{7}, size_t{0}), false); // Nor finds any
set.clear(); // Clearing an empty set does nothing
UASSERT_SELFTEST(set.empty(), true); // Still empty
// Leave entries in the set, so its destructor has some to destroy
for (size_t i = 0; i < N; ++i) set.insert(NoDefault{&alive, 7, i});
UASSERT_SELFTEST(alive, N); // Live as the set goes out of scope
}
// The set is gone, so every entry it still held has been destroyed
UASSERT_SELFTEST(alive, 0); // Leaking none of them
// Clearing a set that never allocated a table does nothing
{
Set set;
set.clear();
UASSERT_SELFTEST(set.empty(), true); // Still empty
set.insert(NoDefault{&alive, 7, 0});
UASSERT_SELFTEST(set.size(), 1); // And still usable
}
UASSERT_SELFTEST(alive, 0); // Leaking nothing
}
//######################################################################