Skip to content

Commit

Permalink
Housekeeping: rename struct Facts -> FactsExtension
Browse files Browse the repository at this point in the history
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
  • Loading branch information
edwinsmith authored and facebook-github-bot committed May 17, 2023
1 parent b92dd03 commit 8f468f9
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 35 deletions.
28 changes: 12 additions & 16 deletions hphp/runtime/base/autoload-handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,14 @@ Array AutoloadHandler::getSymbols(const String& path,
}

template <class T>
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.
Expand Down Expand Up @@ -275,54 +275,50 @@ AutoloadHandler::loadFromMapImpl(const String& clsName,
}
if (ok && checkExists()) {
onPostAutoload(kind, clsName);
return AutoloadMap::Result::Success;
return true;
}
return AutoloadMap::Result::Failure;
return false;
}

template <class T>
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) {
tracing::BlockNoTrace _{(m_map) ? "autoload-native" : "autoload"};
return m_map &&
loadFromMap(String{name},
AutoloadMap::KindOf::Function,
FuncExistsChecker(name)) != AutoloadMap::Result::Failure;
FuncExistsChecker(name));
}

bool AutoloadHandler::autoloadConstant(StringData* name) {
tracing::BlockNoTrace _{(m_map) ? "autoload-native" : "autoload"};
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) {
tracing::BlockNoTrace _{(m_map) ? "autoload-native" : "autoload"};
return m_map &&
loadFromMap(String{name},
AutoloadMap::KindOf::Module,
ModuleExistsChecker(name)) != AutoloadMap::Result::Failure;
ModuleExistsChecker(name));
}

/**
Expand Down Expand Up @@ -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) {
Expand All @@ -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<RepoAutoloadMap> map) {
Expand Down
14 changes: 6 additions & 8 deletions hphp/runtime/base/autoload-handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <class T>
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 <class T>
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.
Expand Down
6 changes: 0 additions & 6 deletions hphp/runtime/base/autoload-map.h
Original file line number Diff line number Diff line change
Expand Up @@ -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`
*/
Expand Down
6 changes: 3 additions & 3 deletions hphp/runtime/ext/facts/ext_facts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion hphp/runtime/ext/random/ext_random.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion hphp/runtime/server/host-health-monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 8f468f9

Please sign in to comment.