Skip to content

Commit

Permalink
Merge pull request #1065 from otakubeam/builtin-module-hash
Browse files Browse the repository at this point in the history
compute cumulative hash for native builtin modules
  • Loading branch information
borisbat authored Apr 15, 2024
2 parents cb654a0 + 538f6a3 commit d9f6239
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/daScript/ast/ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,7 @@ namespace das
CommentReaderPtr commentReader; // /* blah */ or // blah
vector<pair<string,bool>> keywords; // keywords (and if they need oxford comma)
das_hash_map<string,Type> options; // options
uint64_t cumulativeHash = 0; // hash of all mangled names in this module (for builtin modules)
string name;
union {
struct {
Expand Down
3 changes: 3 additions & 0 deletions src/ast/ast_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,9 @@ namespace das {
if ( fn->builtIn && fn->sideEffectFlags==uint32_t(SideEffects::none) && fn->result->isVoid() ) {
DAS_FATAL_ERROR("can't add function %s to module %s; it has no side effects and no return type\n", mangledName.c_str(), name.c_str() );
}
if ( fn->builtIn ) {
cumulativeHash = wyhash(mangledName.c_str(), mangledName.size(), cumulativeHash);
}
if ( fn->builtIn && fn->sideEffectFlags==uint32_t(SideEffects::modifyArgument) ) {
bool anyRW = false;
for ( const auto & arg : fn->arguments ) {
Expand Down
13 changes: 12 additions & 1 deletion src/builtin/module_builtin_ast_serialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2047,6 +2047,7 @@ namespace das {
*this << m->name;

if ( m->builtIn && !m->promoted ) {
*this << m->cumulativeHash;
continue;
}

Expand All @@ -2069,6 +2070,16 @@ namespace das {

if ( builtin && !promoted ) {
auto m = Module::require(name);
uint64_t savedHash = 0, moduleHash = m->cumulativeHash;
*this << savedHash;

if ( moduleHash != savedHash ) {
LOG(LogLevel::warning) << "das: ser: cumulative hash for module " << m->name
<< " differs" << " ( " << moduleHash << " vs " << savedHash << " ) ";
program->failToCompile = true;
return;
}

program->library.addModule(m);
continue;
}
Expand All @@ -2094,7 +2105,7 @@ namespace das {
}

uint32_t AstSerializer::getVersion () {
static constexpr uint32_t currentVersion = 14;
static constexpr uint32_t currentVersion = 15;
return currentVersion;
}

Expand Down

0 comments on commit d9f6239

Please sign in to comment.