Skip to content
This repository was archived by the owner on Dec 1, 2024. It is now read-only.

Commit 2339345

Browse files
authored
Random bug fixes (#542)
* Document bug comparison empty statements The operators `<=` and `>=` should be treated as empty. They are currently treated as assignments. * Fix false negative, `<=` and `>=` in NoEmptyStatementsLinter * Document bug NodeList::getChildrenOfItemsOfType() does not refine * Fix type refinement of NodeList::getChildrenOfItemsOfType<T>() * Add NodeList::getChildrenOfItemsByType<T>() This completes this list: - Node->getChildrenOfType<T>() - Node->getDescendantsOfType<T>() - Node->getFirstDescendantOfType<T>() - NodeList->getChildrenOfItemsByType<T>() * Remove reference in comment to createMaybeEmptyList This function does not exist anymore. * Post commit formatting * Lint clean * Lint clean (with HHClientLinter) * Post commit formatting * One (last) lint error from HHClientLinter * Demonstrate the `() ==> constant` can not be parsed * Regenerate codegen, allowing constants as lambda bodies The Package* classes were deleted by codegen. I have ignored these deletions for backwards compat. * Limit semaphore to cpu count I don't got no 32 hardware threads * Fix lint error in syntax example
1 parent d2345af commit 2339345

17 files changed

+198
-44
lines changed

codegen/inferred_relationships.hack

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

codegen/syntax/LambdaExpression.hack

Lines changed: 7 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

codegen/syntax/QualifiedName.hack

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

codegen/tokens/NameToken.hack

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Linters/NoEmptyStatementsLinter.hack

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ final class NoEmptyStatementsLinter extends AutoFixingASTLinter {
131131
/**
132132
* Returns whether the given token is an assignment operator.
133133
*
134-
* This list is all the types returned from ExpressionStatement::getOperator
134+
* This list is all the types returned from BinaryExpression::getOperator
135135
* that include "Equal" and are not comparison operators (==, >=, etc.);
136136
*/
137137
private function isAssignmentOperator(Token $op): bool {
@@ -140,9 +140,7 @@ final class NoEmptyStatementsLinter extends AutoFixingASTLinter {
140140
$op is CaratEqualToken ||
141141
$op is DotEqualToken ||
142142
$op is EqualToken ||
143-
$op is GreaterThanEqualToken ||
144143
$op is GreaterThanGreaterThanEqualToken ||
145-
$op is LessThanEqualToken ||
146144
$op is LessThanLessThanEqualToken ||
147145
$op is MinusEqualToken ||
148146
$op is PercentEqualToken ||

src/Linters/UnusedUseClauseLinter.hack

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ final class UnusedUseClauseLinter extends AutoFixingASTLinter {
5555
$as = $name->getText();
5656
} else {
5757
invariant($name is QualifiedName, 'Unhandled name type');
58-
$as = $name->getParts()->getChildrenOfItemsOfType(NameToken::class)
59-
|> (C\lastx($$) as nonnull)->getText();
58+
$as = $name->getParts()->getChildrenOfItemsByType<NameToken>()
59+
|> C\lastx($$)->getText();
6060
}
6161
}
6262
if ($kind is NamespaceToken) {

src/Linters/UseStatementWIthoutKindLinter.hack

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,8 @@ final class UseStatementWithoutKindLinter extends AutoFixingASTLinter {
5555
}
5656
$name = $clause->getName();
5757
if ($name is QualifiedName) {
58-
return (
59-
C\lastx(
60-
$name->getParts()->getChildrenOfItemsOfType(NameToken::class),
61-
) as nonnull
58+
return C\lastx(
59+
$name->getParts()->getChildrenOfItemsByType<NameToken>(),
6260
)->getText();
6361
}
6462
invariant(
@@ -73,10 +71,8 @@ final class UseStatementWithoutKindLinter extends AutoFixingASTLinter {
7371
// We need to look at the full file to figure out if this should be a
7472
// `use type`, or `use namespace`
7573
$used = $this->getUnresolvedReferencedNames();
76-
$used_as_ns = C\any(
77-
$names,
78-
$name ==> C\contains($used['namespaces'], $name),
79-
);
74+
$used_as_ns =
75+
C\any($names, $name ==> C\contains($used['namespaces'], $name));
8076
$used_as_type = C\any($names, $name ==> C\contains($used['types'], $name));
8177

8278
$leading = $node->getClauses()->getFirstTokenx()->getLeadingWhitespace();
@@ -94,8 +90,7 @@ final class UseStatementWithoutKindLinter extends AutoFixingASTLinter {
9490
}
9591

9692
<<__Memoize>>
97-
private function getUnresolvedReferencedNames(
98-
): shape(
93+
private function getUnresolvedReferencedNames(): shape(
9994
'namespaces' => keyset<string>,
10095
'types' => keyset<string>,
10196
'functions' => keyset<string>,

src/Migrations/HSLMigration.hack

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ final class HSLMigration extends BaseMigration {
523523
}
524524
$found_prefix = true;
525525
foreach ($parts as $i => $token) {
526-
if ($token?->getText() === $search[$i]) {
526+
if ($token->getText() === $search[$i]) {
527527
continue;
528528
}
529529
$found_prefix = false;
@@ -569,14 +569,14 @@ final class HSLMigration extends BaseMigration {
569569
}
570570

571571
foreach ($parts as $i => $token) {
572-
if ($i < 2 && $token?->getText() !== $search[$i]) {
572+
if ($i < 2 && $token->getText() !== $search[$i]) {
573573
break;
574574
}
575575

576576
if ($i === 2) {
577577
// we found an HH\Lib\* use statement, add the node and suffix
578578
$nodes[] = $decl;
579-
$ns = HslNamespace::coerce($token?->getText());
579+
$ns = HslNamespace::coerce($token->getText());
580580
if ($ns !== null) {
581581
$suffixes[] = $ns;
582582
}

src/__Private/codegen/CodegenBase.hack

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ abstract class CodegenBase {
217217
HHAST\ILambdaBody::class => keyset[
218218
HHAST\IExpression::class,
219219
HHAST\CompoundStatement::class,
220+
// Constants are not wrapped in a name expression on the RHS of `==>`.
221+
HHAST\NameToken::class,
222+
HHAST\QualifiedName::class,
220223
],
221224
HHAST\ILambdaSignature::class => keyset[
222225
HHAST\VariableExpression::class,
@@ -239,8 +242,6 @@ abstract class CodegenBase {
239242
HHAST\ParameterDeclaration::class,
240243
HHAST\PropertyDeclaration::class,
241244
HHAST\LambdaExpression::class,
242-
// HHAST\Php7AnonymousFunction::class : not valid in hack. No attributes
243-
// if not hack
244245
],
245246
HHAST\INameishNode::class => keyset[
246247
HHAST\NameToken::class,

src/__Private/codegen/CodegenRelations.hack

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ final class CodegenRelations extends CodegenBase {
6060

6161
$relationships = new Ref(dict[]);
6262
$queue = new Async\Semaphore(
63-
/* limit = */ 32,
63+
\cpu_get_count(),
6464
async $file ==> {
6565
try {
6666
$links = await $this->getRelationsInFileAsync($file);

0 commit comments

Comments
 (0)