Skip to content

Commit 9a31328

Browse files
committed
Do not deep-clone nodes
1 parent 53a03d5 commit 9a31328

1 file changed

Lines changed: 9 additions & 21 deletions

File tree

src/Analyser/NodeScopeResolver.php

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3194,20 +3194,15 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
31943194
$impurePoints = array_merge($impurePoints, $result->getImpurePoints());
31953195
$isAlwaysTerminating = $isAlwaysTerminating || $result->isAlwaysTerminating();
31963196
} elseif ($expr instanceof Expr\NullsafeMethodCall) {
3197-
$this->processExprNode($stmt, new MethodCall(
3198-
$expr->var,
3199-
$expr->name,
3200-
$expr->args,
3201-
), $scope, $storage, new NoopNodeCallback(), $context);
32023197
$nonNullabilityResult = $this->ensureShallowNonNullability($scope, $scope, $expr->var);
32033198
$attributes = array_merge($expr->getAttributes(), ['virtualNullsafeMethodCall' => true]);
32043199
unset($attributes[ExprPrinter::ATTRIBUTE_CACHE_KEY]);
32053200
$exprResult = $this->processExprNode(
32063201
$stmt,
32073202
new MethodCall(
3208-
$this->deepNodeCloner->cloneNode($expr->var),
3209-
$this->deepNodeCloner->cloneNode($expr->name),
3210-
array_map(fn ($node) => $this->deepNodeCloner->cloneNode($node), $expr->args),
3203+
$expr->var,
3204+
$expr->name,
3205+
$expr->args,
32113206
$attributes,
32123207
),
32133208
$nonNullabilityResult->getScope(),
@@ -3424,16 +3419,12 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
34243419
}
34253420
}
34263421
} elseif ($expr instanceof Expr\NullsafePropertyFetch) {
3427-
$this->processExprNode($stmt, new PropertyFetch(
3428-
$expr->var,
3429-
$expr->name,
3430-
), $scope, $storage, new NoopNodeCallback(), $context);
34313422
$nonNullabilityResult = $this->ensureShallowNonNullability($scope, $scope, $expr->var);
34323423
$attributes = array_merge($expr->getAttributes(), ['virtualNullsafePropertyFetch' => true]);
34333424
unset($attributes[ExprPrinter::ATTRIBUTE_CACHE_KEY]);
34343425
$exprResult = $this->processExprNode($stmt, new PropertyFetch(
3435-
$this->deepNodeCloner->cloneNode($expr->var),
3436-
$this->deepNodeCloner->cloneNode($expr->name),
3426+
$expr->var,
3427+
$expr->name,
34373428
$attributes,
34383429
), $nonNullabilityResult->getScope(), $storage, $nodeCallback, $context);
34393430
$scope = $this->revertNonNullability($exprResult->getScope(), $nonNullabilityResult->getSpecifiedExpressions());
@@ -3625,10 +3616,9 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
36253616
static fn (): MutatingScope => $rightResult->getScope()->filterByFalseyValue($expr),
36263617
);
36273618
} elseif ($expr instanceof Coalesce) {
3628-
$this->processExprNode($stmt, $expr->left, $scope, $storage, new NoopNodeCallback(), $context->enterDeep());
36293619
$nonNullabilityResult = $this->ensureNonNullability($scope, $expr->left);
36303620
$condScope = $this->lookForSetAllowedUndefinedExpressions($nonNullabilityResult->getScope(), $expr->left);
3631-
$condResult = $this->processExprNode($stmt, $this->deepNodeCloner->cloneNode($expr->left), $condScope, $storage, $nodeCallback, $context->enterDeep());
3621+
$condResult = $this->processExprNode($stmt, $expr->left, $condScope, $storage, $nodeCallback, $context->enterDeep());
36323622
$scope = $this->revertNonNullability($condResult->getScope(), $nonNullabilityResult->getSpecifiedExpressions());
36333623
$scope = $this->lookForUnsetAllowedUndefinedExpressions($scope, $expr->left);
36343624

@@ -3825,10 +3815,9 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
38253815
$this->callNodeCallback($nodeCallback, $expr->name, $scope, $storage);
38263816
}
38273817
} elseif ($expr instanceof Expr\Empty_) {
3828-
$this->processExprNode($stmt, $expr->expr, $scope, $storage, new NoopNodeCallback(), $context->enterDeep());
38293818
$nonNullabilityResult = $this->ensureNonNullability($scope, $expr->expr);
38303819
$scope = $this->lookForSetAllowedUndefinedExpressions($nonNullabilityResult->getScope(), $expr->expr);
3831-
$result = $this->processExprNode($stmt, $this->deepNodeCloner->cloneNode($expr->expr), $scope, $storage, $nodeCallback, $context->enterDeep());
3820+
$result = $this->processExprNode($stmt, $expr->expr, $scope, $storage, $nodeCallback, $context->enterDeep());
38323821
$scope = $result->getScope();
38333822
$hasYield = $result->hasYield();
38343823
$throwPoints = $result->getThrowPoints();
@@ -3843,10 +3832,9 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto
38433832
$nonNullabilityResults = [];
38443833
$isAlwaysTerminating = false;
38453834
foreach ($expr->vars as $var) {
3846-
$this->processExprNode($stmt, $var, $scope, $storage, new NoopNodeCallback(), $context->enterDeep());
38473835
$nonNullabilityResult = $this->ensureNonNullability($scope, $var);
38483836
$scope = $this->lookForSetAllowedUndefinedExpressions($nonNullabilityResult->getScope(), $var);
3849-
$result = $this->processExprNode($stmt, $this->deepNodeCloner->cloneNode($var), $scope, $storage, $nodeCallback, $context->enterDeep());
3837+
$result = $this->processExprNode($stmt, $var, $scope, $storage, $nodeCallback, $context->enterDeep());
38503838
$scope = $result->getScope();
38513839
$hasYield = $hasYield || $result->hasYield();
38523840
$throwPoints = array_merge($throwPoints, $result->getThrowPoints());
@@ -6819,7 +6807,7 @@ private function processStmtVarAnnotation(MutatingScope $scope, ExpressionResult
68196807
$originalType = $scope->getType($defaultExpr);
68206808
$varTag = $variableLessTags[0];
68216809
if (!$originalType->equals($varTag->getType())) {
6822-
$this->callNodeCallback($nodeCallback, new VarTagChangedExpressionTypeNode($varTag, $this->deepNodeCloner->cloneNode($defaultExpr)), $scope, $storage);
6810+
$this->callNodeCallback($nodeCallback, new VarTagChangedExpressionTypeNode($varTag, $defaultExpr), $scope, $storage);
68236811
}
68246812
$scope = $scope->assignExpression($defaultExpr, $varTag->getType(), new MixedType());
68256813
}

0 commit comments

Comments
 (0)