From 4f510960e71adcad661c33ae355d0d9670d9c805 Mon Sep 17 00:00:00 2001 From: Fred Emmott Date: Tue, 26 Mar 2019 10:57:44 -0700 Subject: [PATCH] Make locally clean without static locals (opt-in 4.1, banned in 4.2) --- .hhconfig | 1 + src/HHClientFallbackHandler.hack | 11 +++++++---- src/Writer.hack | 11 ++++++++--- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/.hhconfig b/.hhconfig index 59681ca..1161bd5 100644 --- a/.hhconfig +++ b/.hhconfig @@ -7,3 +7,4 @@ disallow_destruct = true disallow_stringish_magic = true disable_primitive_refinement = true user_attributes= +disable_static_local_variables = true diff --git a/src/HHClientFallbackHandler.hack b/src/HHClientFallbackHandler.hack index 5582c88..b92fcd1 100644 --- a/src/HHClientFallbackHandler.hack +++ b/src/HHClientFallbackHandler.hack @@ -9,6 +9,8 @@ namespace Facebook\AutoloadMap; +use namespace HH\Lib\C; + /** * If a class/function/type isn't in the map, ask `hh_client` where it is. * @@ -182,15 +184,16 @@ class HHClientFallbackHandler extends FailureHandler { $this->requireFile($file); } + static dict $cache = dict[]; + private function lookupPath(string $kind, string $name): ?string { - static $cache = Map {}; $key = $kind.'!'.$name; - if ($cache->containsKey($key)) { - return $cache[$key]; + if (C\contains_key(static::$cache, $key)) { + return static::$cache[$key]; } $path = $this->lookupPathImpl($kind, $name); - $cache[$key] = $path; + static::$cache[$key] = $path; if ($path === null) { return $path; diff --git a/src/Writer.hack b/src/Writer.hack index a41076a..9c1ff5e 100644 --- a/src/Writer.hack +++ b/src/Writer.hack @@ -224,14 +224,19 @@ function map(): \Facebook\AutoloadMap\AutoloadMap { } // Generated\ +namespace Facebook\AutoloadMap\_Private { + final class GlobalState { + public static bool \$initialized = false; + } +} + namespace Facebook\AutoloadMap { function initialize(): void { - static \$first_time = true; - if (!\$first_time) { + if (_Private\GlobalState::\$initialized) { return; } - \$first_time = false; + _Private\GlobalState::\$initialized = true; \$map = Generated\\map(); \HH\autoload_set_paths(/* HH_FIXME[4110] */ \$map, Generated\\root());