Skip to content

Commit

Permalink
Add syntax example for <<__Native>> functions
Browse files Browse the repository at this point in the history
`function foo();` is no longer valid - except if there's a
`<<__Native>>`, so it's no longer in Hack or HHVM's unit tests. It's
needed for generating docs.hhvm.com though

While I'm here:
- it's invalid hack outside of builtins, so make the typechecker ignore
all SyntaxExample files. we only need them to parser, we don't need them
to typecheck
- similarly, don't check for `hhvm -l` errors on syntax examples; if
  we've explicitly added them, we assume they're wanted, even if
 `hhvm -l` complains
- remove other example that no longer parses at all
  • Loading branch information
fredemmott committed Apr 8, 2022
1 parent 4016b04 commit 51987c2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .hhconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ignored_paths = [ "tests/examples/NonHackFileTest/php_files/*", "vendor/bin" ]
ignored_paths = [ "tests/examples/NonHackFileTest/php_files/.*", ".*SyntaxExample.*", "vendor/bin" ]
error_php_lambdas = true
disable_xhp_children_declarations = false
allowed_decl_fixme_codes=2053,4045,4047
Expand Down
7 changes: 6 additions & 1 deletion src/__Private/codegen/CodegenRelations.hack
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ final class CodegenRelations extends CodegenBase {
}
}
if ($new) {
await execute_async('hhvm', '-l', $file);
// Check that examples are actually valid before including them in
// relations; some parse correctly, but are only valid at runtime
// in special circumstances, e.g. builtins
if (!(Str\contains($file, __FILE__) || Str\contains($file, 'SyntaxExample'))) {
await execute_async('hhvm', '-l', $file);
}
foreach ($new as $key => $children) {
$relationships->v[$key] =
Keyset\union($relationships->v[$key], $children);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
*
*/

function php_anonymous_function_static(): void {
$_ = static function() {};
}
<<__Native>>
function some_hhvm_builtin();

0 comments on commit 51987c2

Please sign in to comment.