Skip to content

Commit

Permalink
Revert "caching AOT hash for structures"
Browse files Browse the repository at this point in the history
  • Loading branch information
borisbat authored Oct 30, 2024
1 parent fc16735 commit 7f0b984
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 37 deletions.
3 changes: 0 additions & 3 deletions include/daScript/ast/ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ namespace das
string getMangledName() const;
bool hasAnyInitializers() const;
void serialize( AstSerializer & ser );
uint64_t getSemanticHash(HashBuilder & hb,das_set<Structure *> & dep, das_set<Annotation *> & adep) const;
public:
string name;
vector<FieldDeclaration> fields;
Expand All @@ -281,7 +280,6 @@ namespace das
Module * module = nullptr;
Structure * parent = nullptr;
AnnotationList annotations;
uint64_t ownSemanticHash = 0;
union {
struct {
bool isClass : 1;
Expand Down Expand Up @@ -1565,7 +1563,6 @@ namespace das
void visitModules(Visitor & vis, bool visitGenerics = false);
void visit(Visitor & vis, bool visitGenerics = false);
void setPrintFlags();
void cacheAotHash();
void aotCpp ( Context & context, TextWriter & logs );
void writeStandaloneContext ( TextWriter & logs );
void writeStandaloneContextMethods ( TextWriter & logs );
Expand Down
14 changes: 0 additions & 14 deletions src/ast/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,20 +217,6 @@ namespace das {

// structure

uint64_t Structure::getSemanticHash(HashBuilder & hb,das_set<Structure *> & dep, das_set<Annotation *> & adep) const {
if ( ownSemanticHash ) {
hb.update(ownSemanticHash);
} else {
hb.updateString(getMangledName());
hb.update(fields.size());
for ( auto & fld : fields ) {
hb.updateString(fld.name);
hb.update(fld.type->getSemanticHash(hb, dep, adep));
}
}
return hb.getHash();
}

StructurePtr Structure::clone() const {
auto cs = make_smart<Structure>(name);
cs->fields.reserve(fields.size());
Expand Down
14 changes: 0 additions & 14 deletions src/ast/ast_aot_cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3970,19 +3970,6 @@ namespace das {
gen.run();
}

void Program::cacheAotHash() {
for (auto & pm : library.modules) {
pm->structures.foreach([&](auto ps){
if ( !ps->ownSemanticHash ) {
HashBuilder hb;
das_set<Structure *> dep;
das_set<Annotation *> adep;
ps->ownSemanticHash = ps->getSemanticHash(hb,dep,adep);
}
});
}
}

void Program::aotCpp ( Context & context, TextWriter & logs ) {
// run no-aot marker
NoAotMarker marker;
Expand All @@ -3991,7 +3978,6 @@ namespace das {
PrologueMarker pmarker;
visit(pmarker);
// compute semantic hash for each used function
cacheAotHash(); // first we cache hashes for all structures
int fni = 0;
for (auto & pm : library.modules) {
pm->functions.foreach([&](auto pfun){
Expand Down
2 changes: 0 additions & 2 deletions src/ast/ast_simulate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3539,8 +3539,6 @@ void Program::buildGMNLookup ( Context & context, TextWriter & logs ) {

void Program::linkCppAot ( Context & context, AotLibrary & aotLib, TextWriter & logs ) {
bool logIt = options.getBoolOption("log_aot",false);
// first we cache semantic hashes
cacheAotHash();
// make list of functions
vector<Function *> fnn; fnn.reserve(totalFunctions);
das_hash_map<int,Function *> indexToFunction;
Expand Down
13 changes: 12 additions & 1 deletion src/ast/ast_typedecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,12 @@ namespace das
if ( structType ) {
if ( dep.find(structType) == dep.end() ) {
dep.insert(structType);
structType->getSemanticHash(hb, dep, adep);
hb.updateString(structType->getMangledName());
hb.update(structType->fields.size());
for ( auto & fld : structType->fields ) {
hb.updateString(fld.name);
hb.update(fld.type->getSemanticHash(hb, dep, adep));
}
}
} else if ( enumType ) {
hb.updateString(enumType->getMangledName());
Expand All @@ -407,21 +412,27 @@ namespace das
annotation->getSemanticHash(hb, dep, adep);
}
}
hb.update(firstType != nullptr);
if ( firstType ) {
firstType->getSemanticHash(hb, dep, adep);
}
hb.update(secondType != nullptr);
if ( secondType ) {
secondType->getSemanticHash(hb, dep, adep);
}
hb.update(argTypes.size());
for ( auto & argT : argTypes ) {
argT->getSemanticHash(hb, dep, adep);
}
hb.update(argNames.size());
for ( auto & argN : argNames ) {
hb.updateString(argN);
}
hb.update(dim.size());
for ( auto & d : dim ) {
hb.update(d);
}
hb.update(dimExpr.size());
for ( auto & de : dimExpr ) {
hb.update(de != nullptr);
if ( de ) {
Expand Down
5 changes: 2 additions & 3 deletions src/builtin/module_builtin_ast_serialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1141,8 +1141,7 @@ namespace das {
ser << fields << fieldLookup;
ser << parent // parent could be in the current module or in some other
// module
<< flags
<< ownSemanticHash;
<< flags;
serializeAnnotationList(ser, annotations);
ptr_ref_count::serialize(ser);
}
Expand Down Expand Up @@ -2194,7 +2193,7 @@ namespace das {
}

uint32_t AstSerializer::getVersion () {
static constexpr uint32_t currentVersion = 37;
static constexpr uint32_t currentVersion = 36;
return currentVersion;
}

Expand Down

0 comments on commit 7f0b984

Please sign in to comment.