From 8f468f9d7fbe1107fd0b7ab16f21b4772d693048 Mon Sep 17 00:00:00 2001 From: Edwin Smith Date: Wed, 17 May 2023 05:35:43 -0700 Subject: [PATCH] Housekeeping: rename struct Facts -> FactsExtension Summary: we use `namespace Facts` all over the place, so lets not also have a `struct Facts` to confuse things. Most other extensions use the naming convention `FooExtension`, so go with that. Drop a few unnecessary `public` qualifiers. AutoloadMap::Result was only used in AutoloadHandler code and only has one bit of state anyway, so replace it with `bool`. Reviewed By: paulbiss Differential Revision: D45909272 fbshipit-source-id: 404f13db959b887b5c0d62ba34dc6ef864c73e38 --- hphp/runtime/base/autoload-handler.cpp | 28 +++++++++------------ hphp/runtime/base/autoload-handler.h | 14 +++++------ hphp/runtime/base/autoload-map.h | 6 ----- hphp/runtime/ext/facts/ext_facts.cpp | 6 ++--- hphp/runtime/ext/random/ext_random.cpp | 2 +- hphp/runtime/server/host-health-monitor.cpp | 2 +- 6 files changed, 23 insertions(+), 35 deletions(-) diff --git a/hphp/runtime/base/autoload-handler.cpp b/hphp/runtime/base/autoload-handler.cpp index f18f976ef755c0..492d6693881cb1 100644 --- a/hphp/runtime/base/autoload-handler.cpp +++ b/hphp/runtime/base/autoload-handler.cpp @@ -215,14 +215,14 @@ Array AutoloadHandler::getSymbols(const String& path, } template -AutoloadMap::Result +bool AutoloadHandler::loadFromMapImpl(const String& clsName, AutoloadMap::KindOf kind, const T &checkExists, Variant& err) { auto fileRes = getFile(clsName, kind); if (!fileRes) { - return AutoloadMap::Result::Failure; + return false; } bool ok = false; // Utility for logging errors in server mode. @@ -275,23 +275,19 @@ AutoloadHandler::loadFromMapImpl(const String& clsName, } if (ok && checkExists()) { onPostAutoload(kind, clsName); - return AutoloadMap::Result::Success; + return true; } - return AutoloadMap::Result::Failure; + return false; } template -AutoloadMap::Result +bool AutoloadHandler::loadFromMap(const String& clsName, AutoloadMap::KindOf kind, const T &checkExists) { assertx(m_map); Variant err{Variant::NullInit()}; - AutoloadMap::Result res = loadFromMapImpl(clsName, kind, checkExists, err); - if (res == AutoloadMap::Result::Success) { - return AutoloadMap::Result::Success; - } - return AutoloadMap::Result::Failure; + return loadFromMapImpl(clsName, kind, checkExists, err); } bool AutoloadHandler::autoloadFunc(StringData* name) { @@ -299,7 +295,7 @@ bool AutoloadHandler::autoloadFunc(StringData* name) { return m_map && loadFromMap(String{name}, AutoloadMap::KindOf::Function, - FuncExistsChecker(name)) != AutoloadMap::Result::Failure; + FuncExistsChecker(name)); } bool AutoloadHandler::autoloadConstant(StringData* name) { @@ -307,14 +303,14 @@ bool AutoloadHandler::autoloadConstant(StringData* name) { return m_map && loadFromMap(String{name}, AutoloadMap::KindOf::Constant, - ConstExistsChecker(name)) != AutoloadMap::Result::Failure; + ConstExistsChecker(name)); } bool AutoloadHandler::autoloadTypeAlias(const String& name) { tracing::BlockNoTrace _{(m_map) ? "autoload-native" : "autoload"}; return m_map && loadFromMap(name, AutoloadMap::KindOf::TypeAlias, - TypeAliasExistsChecker(name)) != AutoloadMap::Result::Failure; + TypeAliasExistsChecker(name)); } bool AutoloadHandler::autoloadModule(StringData* name) { @@ -322,7 +318,7 @@ bool AutoloadHandler::autoloadModule(StringData* name) { return m_map && loadFromMap(String{name}, AutoloadMap::KindOf::Module, - ModuleExistsChecker(name)) != AutoloadMap::Result::Failure; + ModuleExistsChecker(name)); } /** @@ -354,7 +350,7 @@ bool AutoloadHandler::autoloadType(const String& clsName) { } return m_map && loadFromMap(className, AutoloadMap::KindOf::Type, - ClassExistsChecker(className)) != AutoloadMap::Result::Failure; + ClassExistsChecker(className)); } bool AutoloadHandler::autoloadTypeOrTypeAlias(const String& clsName) { @@ -365,7 +361,7 @@ bool AutoloadHandler::autoloadTypeOrTypeAlias(const String& clsName) { return m_map && loadFromMap(className, AutoloadMap::KindOf::TypeOrTypeAlias, - NamedTypeExistsChecker(className)) != AutoloadMap::Result::Failure; + NamedTypeExistsChecker(className)); } void AutoloadHandler::setRepoAutoloadMap(std::unique_ptr map) { diff --git a/hphp/runtime/base/autoload-handler.h b/hphp/runtime/base/autoload-handler.h index c10dea116c3664..5a43a15fdb58f3 100644 --- a/hphp/runtime/base/autoload-handler.h +++ b/hphp/runtime/base/autoload-handler.h @@ -87,21 +87,19 @@ struct AutoloadHandler final : RequestEventHandler { private: /** - * This method may return Success or Failure. + * This method may return true on success or false on failure. */ template - AutoloadMap::Result loadFromMapImpl(const String& name, - AutoloadMap::KindOf kind, - const T &checkExists, - Variant& err); + bool loadFromMapImpl(const String& name, AutoloadMap::KindOf kind, + const T &checkExists, Variant& err); /** * This method attempts to load the unit containing the given symbol, - * and will return Success or Failure. + * and will return true on success. */ template - AutoloadMap::Result loadFromMap(const String& name, AutoloadMap::KindOf kind, - const T &checkExists); + bool loadFromMap(const String& name, AutoloadMap::KindOf kind, + const T &checkExists); /** * Invoke `m_onPostAutoloadFunc` after autoloading a class. diff --git a/hphp/runtime/base/autoload-map.h b/hphp/runtime/base/autoload-map.h index 440dcbe7c8bedf..e065722c32b64d 100644 --- a/hphp/runtime/base/autoload-map.h +++ b/hphp/runtime/base/autoload-map.h @@ -35,12 +35,6 @@ struct Variant; struct RepoUnitInfo; struct AutoloadMap { - - enum class Result { - Failure, - Success, - }; - /** * Keep enum values in sync with `HH\Facts\SymbolKind` in `ext_facts.php` */ diff --git a/hphp/runtime/ext/facts/ext_facts.cpp b/hphp/runtime/ext/facts/ext_facts.cpp index 186318692db101..1897adc5d3bba8 100644 --- a/hphp/runtime/ext/facts/ext_facts.cpp +++ b/hphp/runtime/ext/facts/ext_facts.cpp @@ -489,8 +489,8 @@ struct WatchmanAutoloadMapFactory final : public FactsFactory { m_lastUsed; }; -struct Facts final : Extension { - Facts() : Extension("facts", "1.0", NO_ONCALL_YET) {} +struct FactsExtension final : Extension { + FactsExtension() : Extension("facts", "1.0", NO_ONCALL_YET) {} void moduleLoad(const IniSetting::Map& ini, Hdf config) override { if (!RuntimeOption::AutoloadEnabled) { @@ -1019,7 +1019,7 @@ Array HHVM_FUNCTION( namespace Facts { -void Facts::moduleInit() { +void FactsExtension::moduleInit() { // This, unfortunately, cannot be done in moduleLoad() due to the fact // that certain async loggers may create a new thread. HHVM will throw // if any threads have been created during the moduleLoad() step. diff --git a/hphp/runtime/ext/random/ext_random.cpp b/hphp/runtime/ext/random/ext_random.cpp index a14938226653c9..5d1cc3fcee38ba 100644 --- a/hphp/runtime/ext/random/ext_random.cpp +++ b/hphp/runtime/ext/random/ext_random.cpp @@ -92,7 +92,7 @@ int64_t HHVM_FUNCTION(random_int, int64_t min, int64_t max) { return getRandomInt(min, max); } -static struct RandomExtension final : public Extension { +static struct RandomExtension final : Extension { RandomExtension() : Extension("random", NO_EXTENSION_VERSION_YET, NO_ONCALL_YET) {} void moduleInit() override { HHVM_FE(random_bytes); diff --git a/hphp/runtime/server/host-health-monitor.cpp b/hphp/runtime/server/host-health-monitor.cpp index ccceb062301516..53580a743815e7 100644 --- a/hphp/runtime/server/host-health-monitor.cpp +++ b/hphp/runtime/server/host-health-monitor.cpp @@ -35,7 +35,7 @@ int32_t MaxUpdatePeriod; auto DampenTime = std::chrono::milliseconds{0}; int32_t ProcStatusUpdateSeconds; -struct HostHealthMonitorExtension final : public Extension { +struct HostHealthMonitorExtension final : Extension { HostHealthMonitorExtension() : Extension("hosthealthmonitor", "1.0", NO_ONCALL_YET) {} void moduleLoad(const IniSetting::Map& ini, Hdf globalConfig) override {