From 7f0b984e6485bd83328da3d56112733ae5fcd29c Mon Sep 17 00:00:00 2001 From: Boris Batkin Date: Wed, 30 Oct 2024 07:03:46 -0700 Subject: [PATCH] Revert "caching AOT hash for structures" --- include/daScript/ast/ast.h | 3 --- src/ast/ast.cpp | 14 -------------- src/ast/ast_aot_cpp.cpp | 14 -------------- src/ast/ast_simulate.cpp | 2 -- src/ast/ast_typedecl.cpp | 13 ++++++++++++- src/builtin/module_builtin_ast_serialize.cpp | 5 ++--- 6 files changed, 14 insertions(+), 37 deletions(-) diff --git a/include/daScript/ast/ast.h b/include/daScript/ast/ast.h index 1c215ddec..88a972e02 100644 --- a/include/daScript/ast/ast.h +++ b/include/daScript/ast/ast.h @@ -272,7 +272,6 @@ namespace das string getMangledName() const; bool hasAnyInitializers() const; void serialize( AstSerializer & ser ); - uint64_t getSemanticHash(HashBuilder & hb,das_set & dep, das_set & adep) const; public: string name; vector fields; @@ -281,7 +280,6 @@ namespace das Module * module = nullptr; Structure * parent = nullptr; AnnotationList annotations; - uint64_t ownSemanticHash = 0; union { struct { bool isClass : 1; @@ -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 ); diff --git a/src/ast/ast.cpp b/src/ast/ast.cpp index c85544ac1..031620a68 100644 --- a/src/ast/ast.cpp +++ b/src/ast/ast.cpp @@ -217,20 +217,6 @@ namespace das { // structure - uint64_t Structure::getSemanticHash(HashBuilder & hb,das_set & dep, das_set & 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(name); cs->fields.reserve(fields.size()); diff --git a/src/ast/ast_aot_cpp.cpp b/src/ast/ast_aot_cpp.cpp index 910b4400d..b061e52a0 100644 --- a/src/ast/ast_aot_cpp.cpp +++ b/src/ast/ast_aot_cpp.cpp @@ -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 dep; - das_set adep; - ps->ownSemanticHash = ps->getSemanticHash(hb,dep,adep); - } - }); - } - } - void Program::aotCpp ( Context & context, TextWriter & logs ) { // run no-aot marker NoAotMarker marker; @@ -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){ diff --git a/src/ast/ast_simulate.cpp b/src/ast/ast_simulate.cpp index decdcb578..bbab2a1e1 100644 --- a/src/ast/ast_simulate.cpp +++ b/src/ast/ast_simulate.cpp @@ -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 fnn; fnn.reserve(totalFunctions); das_hash_map indexToFunction; diff --git a/src/ast/ast_typedecl.cpp b/src/ast/ast_typedecl.cpp index f85ba59b0..b9831abf6 100644 --- a/src/ast/ast_typedecl.cpp +++ b/src/ast/ast_typedecl.cpp @@ -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()); @@ -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 ) { diff --git a/src/builtin/module_builtin_ast_serialize.cpp b/src/builtin/module_builtin_ast_serialize.cpp index 5ee0362c0..450d4a39a 100644 --- a/src/builtin/module_builtin_ast_serialize.cpp +++ b/src/builtin/module_builtin_ast_serialize.cpp @@ -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); } @@ -2194,7 +2193,7 @@ namespace das { } uint32_t AstSerializer::getVersion () { - static constexpr uint32_t currentVersion = 37; + static constexpr uint32_t currentVersion = 36; return currentVersion; }