From 51772c1e279ba48008f31bee820ae8b5a0373bc9 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Wed, 10 Jun 2026 16:03:00 +0800 Subject: [PATCH] =?UTF-8?q?refactor(php):=20=E4=BC=98=E5=8C=96SSA=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E4=BC=98=E5=8C=96=E5=99=A8=E4=BB=A3=E7=A0=81=E7=BB=93?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除未使用的 Expr 导入并添加 SsaVar 导入 - 简化 detectSsaDefType 方法中的类型声明 - 移除 Foreach 和 Switch 语句中冗余的节点类型检查 - 提高代码可读性和维护性 --- src/Php/Optimizer/SsaTypeOptimizer.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Php/Optimizer/SsaTypeOptimizer.php b/src/Php/Optimizer/SsaTypeOptimizer.php index f247c823..42950f7d 100644 --- a/src/Php/Optimizer/SsaTypeOptimizer.php +++ b/src/Php/Optimizer/SsaTypeOptimizer.php @@ -11,8 +11,8 @@ namespace PhpAot\Php\Optimizer; use PhpAot\Php\Analysis\SsaBuilder; use PhpAot\Php\Analysis\SsaFlags; +use PhpAot\Php\Analysis\SsaVar; use PhpParser\Node; -use PhpParser\Node\Expr; use PhpParser\NodeAbstract; trait SsaTypeOptimizer @@ -190,7 +190,7 @@ trait SsaTypeOptimizer * Detect the type produced by a single SSA variable definition. * Returns null if the type cannot be determined from the AST. */ - protected function detectSsaDefType(\PhpAot\Php\Analysis\SsaVar $ssaVar): ?string + protected function detectSsaDefType(SsaVar $ssaVar): ?string { $def = $ssaVar->definition; if (!$def) { @@ -412,13 +412,13 @@ trait SsaTypeOptimizer } } - if ($stmt instanceof Node\Stmt\Foreach_ && $stmt->expr instanceof Node) { + if ($stmt instanceof Node\Stmt\Foreach_) { if ($this->exprHasIntHazard($stmt->expr, $varName)) { return true; } } - if ($stmt instanceof Node\Stmt\Switch_ && $stmt->cond instanceof Node) { + if ($stmt instanceof Node\Stmt\Switch_) { if ($this->exprHasIntHazard($stmt->cond, $varName)) { return true; } @@ -621,13 +621,13 @@ trait SsaTypeOptimizer } } - if ($stmt instanceof Node\Stmt\Foreach_ && $stmt->expr instanceof Node) { + if ($stmt instanceof Node\Stmt\Foreach_) { if ($this->exprHasFloatHazard($stmt->expr, $varName)) { return true; } } - if ($stmt instanceof Node\Stmt\Switch_ && $stmt->cond instanceof Node) { + if ($stmt instanceof Node\Stmt\Switch_) { if ($this->exprHasFloatHazard($stmt->cond, $varName)) { return true; }