restored support for incremental compilation of scripts to C++

This commit is contained in:
Vern Paxson 2021-12-12 12:36:45 -08:00
parent 3b3cea799b
commit 2f7137999f
11 changed files with 37 additions and 56 deletions

View file

@ -23,7 +23,13 @@ p_hash_type p_hash(const Obj* o)
return p_hash(d.Description());
}
std::string script_specific_filename(const StmtPtr& body)
// Returns a filename associated with the given function body. Used to
// provide distinctness to identical function bodies seen in separate,
// potentially conflicting incremental compilations. An example of this
// is a function named foo() that calls bar(), for which in two different
// compilation contexts bar() has differing semantics, even though foo()'s
// (shallow) semantics are the same.
static std::string script_specific_filename(const Stmt* body)
{
// The specific filename is taken from the location filename, making
// it absolute if necessary.
@ -52,12 +58,15 @@ std::string script_specific_filename(const StmtPtr& body)
return bl_f;
}
p_hash_type script_specific_hash(const StmtPtr& body, p_hash_type generic_hash)
// Returns a incremental-compilation-specific hash for the given function
// body, given its non-specific hash is "generic_hash".
static p_hash_type script_specific_hash(const Stmt* body, p_hash_type generic_hash)
{
auto bl_f = script_specific_filename(body);
return merge_p_hashes(generic_hash, p_hash(bl_f));
}
ProfileFunc::ProfileFunc(const Func* func, const StmtPtr& body, bool _abs_rec_fields)
{
profiled_func = func;
@ -698,6 +707,9 @@ void ProfileFuncs::ComputeProfileHash(std::shared_ptr<ProfileFunc> pf)
for ( auto i : pf->AdditionalHashes() )
h = merge_p_hashes(h, i);
if ( ! pf->Stmts().empty() )
h = script_specific_hash(pf->Stmts()[0], h);
pf->SetHashVal(h);
}