final class LoopPasses
Restricted visibility: declared "@visibility root". Code outside that scope must not name this declaration.

Walks back through a loop one pass at a time.

A loop that builds part of a statement produces a different statement for every number of times it runs, so each number of passes is its own path: the statement as it is before the loop, after one pass, after two, up to the budget's limit. When a path could still have gone round again at the limit, it is marked as cut short, because the statements listed are not all of the ones the loop can produce. A foreach over an array written out in full runs exactly as many times as the array has elements, and only that number is taken.

Methods§

public function __construct(
    BackwardSlicer $slicer,
    FreeNames $names,
    ModifiedNames $modified,
    EvaluationBudget $budget,
)

Wires the loop walk to the slicer it walks bodies with.

Parameters

Calls 1
public function runs(Stmt $loop, array<string, true> $needs): list<Pending>
public function leaveBody(Stmt $loop, list<Pending> $paths): list<Arrival>

The paths carried out of the start of a loop body the point is written in.

Parameters

$loopStmt
$pathslist<Pending>Paths standing at the start of the pass the point is in

Returns

list<Arrival>
Test cases 1
Called from 1
Calls 8
public function pass(Stmt $loop, list<Pending> $paths): list<Pending>
public function bodyOf(Stmt $loop): list<Stmt>

The statements a loop repeats.

Parameters

$loopStmt

Returns

list<Stmt>
Test cases 1
Called from 1
Calls 1
public function entering(Stmt $loop, list<Pending> $paths): list<Pending>

The paths walked back over what runs before a loop's first pass.

A foreach reads the array it goes over once, before the first pass, whatever the passes then do to the variable holding it; so that is where the array is looked for, and only on a path that needed the loop's variables at all.

Parameters

$loopStmt
$pathslist<Pending>

Returns

list<Pending>
Test cases 1
Called from 3
Calls 5
public function bound(Foreach_ $loop, Pending $path): bool

Whether a path took one of a foreach's passes as a step.

Parameters

$loopForeach_
$pathPending

Returns

bool
Test cases 1
Called from 1
public function expressions(
    array<array-key, Expr> $expressions,
    list<Pending> $paths,
): list<Pending>

The paths walked back over a list of expressions, last first.

Parameters

$expressionsarray<array-key, Expr>
$pathslist<Pending>

Returns

list<Pending>
Test cases 1
Called from 2
Calls 4
public function writtenPasses(Stmt $loop): ?int

How many times a foreach over an array written out in full runs, or null when that is not known.

Parameters

$loopStmt

Returns

?int
Test cases 1
Called from 1
Calls 1

Private surface 5§

Implementation details, listed for orientation only.

private BackwardSlicer $slicer
private FreeNames $names
private ModifiedNames $modified
private EvaluationBudget $budget
private AssignmentSteps $steps

Test cases 41§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 14
Other tests reaching this symbol 27

Relations§

Instantiated in 1
Method calls 4
Type declarations 1