mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
streamlining of some script optimization APIs
This commit is contained in:
parent
f7b739a47d
commit
896238c173
3 changed files with 13 additions and 12 deletions
|
@ -550,22 +550,23 @@ static std::unordered_map<std::string, unsigned int> func_attrs = {
|
||||||
// Some of these have side effects that could be checked for in a specific
|
// Some of these have side effects that could be checked for in a specific
|
||||||
// context, but the gains from doing so likely aren't worth the complexity.
|
// context, but the gains from doing so likely aren't worth the complexity.
|
||||||
|
|
||||||
bool is_special_script_func(std::string func_name) {
|
bool is_special_script_func(const std::string& func_name) {
|
||||||
auto f_attr = func_attrs.find(func_name);
|
auto f_attr = func_attrs.find(func_name);
|
||||||
return f_attr != func_attrs.end() && (f_attr->second & ATTR_SPECIAL_SCRIPT_FUNC) != 0;
|
return f_attr != func_attrs.end() && (f_attr->second & ATTR_SPECIAL_SCRIPT_FUNC) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_idempotent(std::string func_name) {
|
bool is_idempotent(const std::string& func_name) {
|
||||||
auto f_attr = func_attrs.find(func_name);
|
auto f_attr = func_attrs.find(func_name);
|
||||||
return f_attr != func_attrs.end() && (f_attr->second & ATTR_IDEMPOTENT) != 0;
|
return f_attr != func_attrs.end() && (f_attr->second & ATTR_IDEMPOTENT) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool has_no_script_side_effects(std::string func_name) {
|
bool has_script_side_effects(const std::string& func_name) {
|
||||||
auto f_attr = func_attrs.find(func_name);
|
auto f_attr = func_attrs.find(func_name);
|
||||||
if ( f_attr == func_attrs.end() )
|
if ( f_attr == func_attrs.end() )
|
||||||
return false;
|
// We don't know about it, so be conservative.
|
||||||
|
return true;
|
||||||
|
|
||||||
return (f_attr->second & (ATTR_NO_SCRIPT_SIDE_EFFECTS | ATTR_NO_ZEEK_SIDE_EFFECTS | ATTR_IDEMPOTENT)) != 0;
|
return (f_attr->second & (ATTR_NO_SCRIPT_SIDE_EFFECTS | ATTR_NO_ZEEK_SIDE_EFFECTS | ATTR_IDEMPOTENT)) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace zeek::detail
|
} // namespace zeek::detail
|
||||||
|
|
|
@ -10,15 +10,15 @@ namespace zeek::detail {
|
||||||
|
|
||||||
// A "special script function" is one that the event engine explicitly
|
// A "special script function" is one that the event engine explicitly
|
||||||
// knows about.
|
// knows about.
|
||||||
extern bool is_special_script_func(std::string func_name);
|
extern bool is_special_script_func(const std::string& func_name);
|
||||||
|
|
||||||
// An idempotent function returns the same value when called with the
|
// An idempotent function returns the same value when called with the
|
||||||
// same arguments (and has no meaningful side effects in terms of script-level
|
// same arguments (and has no meaningful side effects in terms of script-level
|
||||||
// or Zeek-internal state).
|
// or Zeek-internal state).
|
||||||
extern bool is_idempotent(std::string func_name);
|
extern bool is_idempotent(const std::string& func_name);
|
||||||
|
|
||||||
// Whether the given function (currently, just BiFs) has no Zeek-script-level
|
// Whether the given function (currently, just BiFs) has Zeek-script-level
|
||||||
// side effects.
|
// side effects.
|
||||||
extern bool has_no_script_side_effects(std::string func_name);
|
extern bool has_script_side_effects(const std::string& func_name);
|
||||||
|
|
||||||
} // namespace zeek::detail
|
} // namespace zeek::detail
|
||||||
|
|
|
@ -635,7 +635,7 @@ bool ProfileFuncs::GetCallSideEffects(const NameExpr* n, IDSet& non_local_ids, T
|
||||||
|
|
||||||
auto func = fv->AsFunc();
|
auto func = fv->AsFunc();
|
||||||
if ( func->GetKind() == Func::BUILTIN_FUNC ) {
|
if ( func->GetKind() == Func::BUILTIN_FUNC ) {
|
||||||
if ( ! has_no_script_side_effects(func->Name()) )
|
if ( has_script_side_effects(func->Name()) )
|
||||||
is_unknown = true;
|
is_unknown = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1168,7 +1168,7 @@ bool ProfileFuncs::DefinitelyHasNoSideEffects(const ExprPtr& e) const {
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for ( auto& b : pf->BiFGlobals() )
|
for ( auto& b : pf->BiFGlobals() )
|
||||||
if ( ! has_no_script_side_effects(b->Name()) )
|
if ( has_script_side_effects(b->Name()) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -1259,7 +1259,7 @@ bool ProfileFuncs::AssessSideEffects(const ProfileFunc* pf, IDSet& non_local_ids
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( auto& b : pf->BiFGlobals() )
|
for ( auto& b : pf->BiFGlobals() )
|
||||||
if ( ! has_no_script_side_effects(b->Name()) ) {
|
if ( has_script_side_effects(b->Name()) ) {
|
||||||
is_unknown = true;
|
is_unknown = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue