diff --git a/bin/hhast-inspect b/bin/hhast-inspect index 33bbebcfa..42bf26976 100755 --- a/bin/hhast-inspect +++ b/bin/hhast-inspect @@ -10,11 +10,13 @@ namespace Facebook\HHAST\__Private; -require_once(__DIR__.'/hhast-inspect.hack'); - // As this file does not have an extension, it is not typechecked. Delegate // to the typechecked one. <<__EntryPoint>> async function hhast_inspect_main_async_UNSAFE(): Awaitable { + (() ==> { + // HHAST-generated to avoid pseudomain local leaks + require_once(__DIR__.'/hhast-inspect.hack'); + })(); await hhast_inspect_main_async(); } diff --git a/bin/hhast-lint b/bin/hhast-lint index 7bbd08652..209dc03b6 100755 --- a/bin/hhast-lint +++ b/bin/hhast-lint @@ -10,11 +10,13 @@ namespace Facebook\HHAST\__Private; -require_once(__DIR__.'/hhast-lint.hack'); - // As this file does not have an extension, it is not typechecked. Delegate // to the typechecked one. <<__EntryPoint>> async function hhast_lint_main_async_UNSAFE(): Awaitable { + (() ==> { + // HHAST-generated to avoid pseudomain local leaks + require_once(__DIR__.'/hhast-lint.hack'); + })(); await hhast_lint_main_async(); } diff --git a/bin/hhast-migrate b/bin/hhast-migrate index 56e392a8e..413f0eb99 100755 --- a/bin/hhast-migrate +++ b/bin/hhast-migrate @@ -10,11 +10,13 @@ namespace Facebook\HHAST\__Private; -require_once(__DIR__.'/hhast-migrate.hack'); - // As this file does not have an extension, it is not typechecked. Delegate // to the typechecked one. <<__EntryPoint>> async function hhast_migrate_main_async_UNSAFE(): Awaitable { + (() ==> { + // HHAST-generated to avoid pseudomain local leaks + require_once(__DIR__.'/hhast-migrate.hack'); + })(); await hhast_migrate_main_async(); } diff --git a/bin/update-codegen b/bin/update-codegen index 3199f1b4f..a7dd762f7 100755 --- a/bin/update-codegen +++ b/bin/update-codegen @@ -10,11 +10,13 @@ namespace Facebook\HHAST\__Private; -require_once(__DIR__.'/update-codegen.hack'); - // As this file does not have an extension, it is not typechecked. Delegate // to the typechecked one. <<__EntryPoint>> async function update_codegen_async_UNSAFE(): Awaitable { + (() ==> { + // HHAST-generated to avoid pseudomain local leaks + require_once(__DIR__.'/update-codegen.hack'); + })(); await update_codegen_async(); } diff --git a/bin/update-codegen.hack b/bin/update-codegen.hack index 96015fee3..0efb7670b 100755 --- a/bin/update-codegen.hack +++ b/bin/update-codegen.hack @@ -10,10 +10,12 @@ namespace Facebook\HHAST\__Private; -require_once(__DIR__.'/../vendor/autoload.hack'); - <<__EntryPoint>> async function update_codegen_async(): Awaitable { + (() ==> { + // HHAST-generated to avoid pseudomain local leaks + require_once(__DIR__.'/../vendor/autoload.hack'); + })(); \Facebook\AutoloadMap\initialize(); $status = await CodegenCLI::runAsync(); exit($status); diff --git a/src/Migrations/BaseMigration.hack b/src/Migrations/BaseMigration.hack index 2baaf3f72..171bfade1 100644 --- a/src/Migrations/BaseMigration.hack +++ b/src/Migrations/BaseMigration.hack @@ -9,6 +9,7 @@ namespace Facebook\HHAST; +use namespace HH\Lib\C; use type Facebook\HHAST\Script; <<__ConsistentConstruct>> @@ -21,4 +22,27 @@ abstract class BaseMigration { } abstract public function migrateFile(string $path, Script $ast): Script; + + protected static async function expressionFromCodeAsync( + string $code, + ): Awaitable { + $script = await from_file_async( + File::fromPathAndContents('/dev/null', '$_='.$code.';'), + ); + return $script->getDeclarations() + ->getChildren() + |> C\firstx($$) as ExpressionStatement + |> $$->getExpression() as BinaryExpression + |> $$->getRightOperand(); + } + + protected static async function statementFromCodeAsync( + string $code, + ): Awaitable { + $script = await from_file_async( + File::fromPathAndContents('/dev/null', $code), + ); + return $script->getDeclarations()->getChildren() + |> C\firstx($$) as IStatement; + } } diff --git a/src/Migrations/HSLMigration.hack b/src/Migrations/HSLMigration.hack index bed5b035a..79a6c897c 100644 --- a/src/Migrations/HSLMigration.hack +++ b/src/Migrations/HSLMigration.hack @@ -689,7 +689,6 @@ final class HSLMigration extends BaseMigration { } protected function expressionFromCode(string $code): IExpression { - return $this->nodeFromCode('$_ = '.$code.';', BinaryExpression::class) - ->getRightOperand(); + return \HH\Asio\join(self::expressionFromCodeAsync($code)); } } diff --git a/src/Migrations/TopLevelRequiresMigration.hack b/src/Migrations/TopLevelRequiresMigration.hack new file mode 100644 index 000000000..298ab7009 --- /dev/null +++ b/src/Migrations/TopLevelRequiresMigration.hack @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2017-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + */ + +namespace Facebook\HHAST; + +use namespace HH\Lib\{C, Str, Vec}; + +/** Move requires to top-level `<<__EntryPoint>>` functions */ +final class TopLevelRequiresMigration extends BaseMigration { + <<__Override>> + public function migrateFile(string $_path, Script $script): Script { + return \HH\Asio\join($this->migrateFileAsync($script)); + } + + private async function migrateFileAsync(Script $script): Awaitable