Skip to content
This repository has been archived by the owner on Sep 1, 2023. It is now read-only.

Commit

Permalink
Make locally clean without static locals (opt-in 4.1, banned in 4.2)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredemmott committed Mar 26, 2019
1 parent dbd50d7 commit 4f51096
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions .hhconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ disallow_destruct = true
disallow_stringish_magic = true
disable_primitive_refinement = true
user_attributes=
disable_static_local_variables = true
11 changes: 7 additions & 4 deletions src/HHClientFallbackHandler.hack
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -182,15 +184,16 @@ class HHClientFallbackHandler extends FailureHandler {
$this->requireFile($file);
}

static dict<string, ?string> $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;
Expand Down
11 changes: 8 additions & 3 deletions src/Writer.hack
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 4f51096

Please sign in to comment.