Internals: Make node type hashes stable with Ast changes

Instead of hashing node types by type id (which can change when
adding/removing Ast node types), astgen a stable hash based on node
name. This makes output more stable through Ast node
additions/deletions. Largely to help with 'make test-diff', should have
no user noticeable impact.
This commit is contained in:
Geza Lore
2026-09-26 10:37:56 +01:00
parent 33d63ac0b0
commit f2114d3dc3
3 changed files with 15 additions and 5 deletions
+2 -2
View File
@@ -59,7 +59,7 @@ class HasherVisitor final : public VNVisitorConst {
} else {
VL_RESTORER(m_hash);
// Reset accumulator
m_hash = V3Hash{nodep->type()}; // Node type
m_hash = V3Hash{nodep->type().hash()}; // Node type
f(); // Node-specific hash
if (hashDType && nodep != nodep->dtypep())
iterateConstNull(nodep->dtypep()); // Node dtype
@@ -77,7 +77,7 @@ class HasherVisitor final : public VNVisitorConst {
// Each visitor below contributes to the hash any node-specific content
// that is not dependent on either of the following, as these are
// included by default by hashNode:
// - Node type (as given by AstNode::type())
// - Node type (as given by AstNode::type().hash())
// - Node dtype (unless !hashDType)
// - child nodes (unless !hashChildren)
//
+10
View File
@@ -4,6 +4,7 @@
import argparse
import glob
import hashlib
import os
import re
import sys
@@ -881,6 +882,15 @@ def write_type_enum(prefix, nodeList):
fh.write(" return names[m_e];\n")
fh.write(" }\n")
fh.write(" uint32_t hash() const VL_MT_SAFE {\n")
fh.write(" static const uint32_t hashes[] = {\n")
for node in sorted(filter(lambda _: _.isLeaf, nodeList), key=lambda _: _.typeId):
digest = hashlib.md5((prefix + node.name).encode("ascii")).hexdigest()
fh.write(" 0x{h}U, // {p}{n}\n".format(h=digest[:8], p=prefix, n=node.name))
fh.write(" };\n")
fh.write(" return hashes[m_e];\n")
fh.write(" }\n")
def write_type_tests(prefix, nodeList):
with open_file("V3{p}__gen_type_tests.h".format(p=prefix)) as fh:
+3 -3
View File
@@ -56,8 +56,8 @@ module Vt_debug_emitv_t;
$write("");
end
$display("%p", $_EXPRSTMT(
__Venum_hf6514fb1__0 = (in);
, __Venum_hf6514fb1__0);
__Venum_h99905942__0 = (in);
, __Venum_h99905942__0);
);
if ((| $value$plusargs("TEST=%d", i1))) begin
$display("value was %d", i1);
@@ -1096,7 +1096,7 @@ module Vt_debug_emitv_t;
enum logic [2:0] {
ZERO = 3'h0,
ONE = 3'h1
} __Venum_hf6514fb1__0;
} __Venum_h99905942__0;
endmodule
package Vt_debug_emitv___024unit;
class Vt_debug_emitv_Cls;