From 0b682eb01aa45661f9b3c172497009ecfb27be6b Mon Sep 17 00:00:00 2001 From: Lexidor Digital <31805625+lexidor@users.noreply.github.com> Date: Wed, 18 Nov 2020 21:41:22 +0100 Subject: [PATCH] Clean up dependencies of xhp-lib (#286) This composer.json did not mention that we depended on the hsl. The hsl came for free with type-assert. We don't need TypeAssert, since we don't depend on varrayness. This also improves perf, since we are not spinning in a loop validating that all elements are mixed, which they always are. --- composer.json | 2 +- .../ReflectionXHPChildrenDeclaration.hack | 73 +++++++++---------- 2 files changed, 36 insertions(+), 39 deletions(-) diff --git a/composer.json b/composer.json index 230f40f1..99a6f260 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "license": ["MIT"], "require": { "hhvm": "^4.73", - "hhvm/type-assert": "^3.0|^4.0" + "hhvm/hsl": "^4.36.0" }, "require-dev": { "facebook/fbexpect": "^2.0.0", diff --git a/src/Reflection/ReflectionXHPChildrenDeclaration.hack b/src/Reflection/ReflectionXHPChildrenDeclaration.hack index 00c643c7..3a99feef 100644 --- a/src/Reflection/ReflectionXHPChildrenDeclaration.hack +++ b/src/Reflection/ReflectionXHPChildrenDeclaration.hack @@ -10,7 +10,6 @@ namespace Facebook\XHP; use type Facebook\TypeAssert\IncorrectTypeException; -use namespace Facebook\TypeSpec; enum XHPChildrenDeclarationType: int { NO_CHILDREN = 0; @@ -52,18 +51,17 @@ class ReflectionXHPChildrenDeclaration { <<__Memoize>> public function getExpression(): ReflectionXHPChildrenExpression { try { - $data = TypeSpec\varray(TypeSpec\mixed()) - ->assertType($this->data); - return new ReflectionXHPChildrenExpression($this->context, $data); - } catch (IncorrectTypeException $_) { - // handled below + return new ReflectionXHPChildrenExpression( + $this->context, + $this->data as KeyedContainer<_, _>, + ); + } catch (\TypeAssertionException $_) { + throw new \Exception( + 'Tried to get child expression for XHP class '. + $this->context. + ', but it does not have an expressions.', + ); } - - throw new \Exception( - 'Tried to get child expression for XHP class '. - \get_class($this->context). - ', but it does not have an expressions.', - ); } public function __toString(): string { @@ -80,7 +78,7 @@ class ReflectionXHPChildrenDeclaration { class ReflectionXHPChildrenExpression { public function __construct( private string $context, - private varray $data, + private KeyedContainer $data, ) { } @@ -97,22 +95,22 @@ class ReflectionXHPChildrenExpression { $type === XHPChildrenExpressionType::SUB_EXPR_SEQUENCE || $type === XHPChildrenExpressionType::SUB_EXPR_DISJUNCTION, 'Only disjunctions and sequences have two sub-expressions - in %s', - \get_class($this->context), + $this->context, ); try { - $sub_expr_1 = TypeSpec\varray(TypeSpec\mixed()) - ->assertType($this->data[1]); - $sub_expr_2 = TypeSpec\varray(TypeSpec\mixed()) - ->assertType($this->data[2]); return tuple( - new ReflectionXHPChildrenExpression($this->context, $sub_expr_1), - new ReflectionXHPChildrenExpression($this->context, $sub_expr_2), + new ReflectionXHPChildrenExpression( + $this->context, + $this->data[1] as KeyedContainer<_, _>, + ), + new ReflectionXHPChildrenExpression( + $this->context, + $this->data[2] as KeyedContainer<_, _>, + ), ); - } catch (IncorrectTypeException $_) { - // handled below + } catch (\TypeAssertionException $_) { + throw new \Exception('Data is not subexpressions - in '.$this->context); } - - throw new \Exception('Data is not subexpressions - in '.$this->context); } <<__Memoize>> @@ -122,7 +120,7 @@ class ReflectionXHPChildrenExpression { $type !== XHPChildrenExpressionType::SUB_EXPR_SEQUENCE && $type !== XHPChildrenExpressionType::SUB_EXPR_DISJUNCTION, 'Disjunctions and sequences do not have a constraint type - in %s', - \get_class($this->context), + $this->context, ); return XHPChildrenConstraintType::assert($this->data[1]); } @@ -134,7 +132,7 @@ class ReflectionXHPChildrenExpression { $type === XHPChildrenConstraintType::ELEMENT || $type === XHPChildrenConstraintType::CATEGORY, 'Only element and category constraints have string data - in %s', - \get_class($this->context), + $this->context, ); $data = $this->data[2]; invariant($data is string, 'Expected string data'); @@ -150,19 +148,18 @@ class ReflectionXHPChildrenExpression { ); $data = $this->data[2]; try { - $data = TypeSpec\varray(TypeSpec\mixed()) - ->assertType($this->data[2]); - return new ReflectionXHPChildrenExpression($this->context, $data); - } catch (IncorrectTypeException $_) { - // handled below + return new ReflectionXHPChildrenExpression( + $this->context, + $data as KeyedContainer<_, _>, + ); + } catch (\TypeAssertionException $_) { + throw new \Exception( + 'Expected a sub-expression, got a '. + (\is_object($data) ? \get_class($data) : \gettype($data)). + ' - in '. + $this->context, + ); } - - throw new \Exception( - 'Expected a sub-expression, got a '. - (\is_object($data) ? \get_class($data) : \gettype($data)). - ' - in '. - $this->context, - ); } public function __toString(): string {