# partial_eval_loops

URL: /kida/api/compiler/partial_eval_loops/
Section: compiler
Description: Static for-loop unrolling for partial evaluation.

---

> For a complete page index, fetch /kida/llms.txt.

Open LLM text
(/kida/api/compiler/partial_eval_loops/index.txt)

Share with AI

Ask Claude
(https://claude.ai/new?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fkida%2Fapi%2Fcompiler%2Fpartial_eval_loops%2Findex.txt)

Ask ChatGPT
(https://chatgpt.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fkida%2Fapi%2Fcompiler%2Fpartial_eval_loops%2Findex.txt)

Ask Gemini
(https://gemini.google.com/app?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fkida%2Fapi%2Fcompiler%2Fpartial_eval_loops%2Findex.txt)

Ask Copilot
(https://copilot.microsoft.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fkida%2Fapi%2Fcompiler%2Fpartial_eval_loops%2Findex.txt)

Module

#
`compiler.partial_eval_loops`

Static for-loop unrolling for partial evaluation.

2Classes

## Classes

`LoopProperties`

7

▼

Compile-time stand-in for runtime loop-context properties.

Compile-time stand-in for runtime loop-context properties.

#### Attributes

Name
Type
Description

`index0`

`int`

—

`index`

`int`

—

`first`

`bool`

—

`last`

`bool`

—

`length`

`int`

—

`revindex`

`int`

—

`revindex0`

`int`

—

`LoopUnrollingMixin`

8

▼

Partial-evaluator phase for statically known for-loops.

Partial-evaluator phase for statically known for-loops.

#### Attributes

Name
Type
Description

`_ctx`

`dict[str, Any]`

—

`_defs`

`dict[str, Def]`

—

#### Methods

Internal Methods
6

▼

`_try_eval`

2

`Any`

▼

Evaluate an expression against the current static context.

abstract

`def _try_eval(self, expr: Expr, depth: int = 0) -> Any`

##### Parameters

Name
Type
Description

`expr`
`—`

`depth`
`—`

Default:`0`

##### Returns

`Any`

`_transform_body`

1

`Sequence[Node]`

▼

Transform a sequence of template nodes.

abstract

`def _transform_body(self, body: Sequence[Node]) -> Sequence[Node]`

##### Parameters

Name
Type
Description

`body`
`—`

##### Returns

`Sequence[Node]`

`_make_sub_evaluator`

1

`Self`

▼

Create an evaluator that shares this evaluator's configuration.

abstract

`def _make_sub_evaluator(self, ctx: dict[str, Any]) -> Self`

##### Parameters

Name
Type
Description

`ctx`
`—`

##### Returns

`Self`

`_transform_for`

1

`Node | None`

▼

Unroll a for-loop when its iterable is statically known.

`def _transform_for(self, node: For) -> Node | None`

##### Parameters

Name
Type
Description

`node`
`—`

##### Returns

`Node | None`

`_try_unroll_for`

2

`Node | None`

▼

Return statically expanded loop nodes when unrolling is safe.

`def _try_unroll_for(self, node: For, iter_val: Any) -> Node | None`

##### Parameters

Name
Type
Description

`node`
`—`

`iter_val`
`—`

##### Returns

`Node | None`

`_build_iter_context`

2

`dict[str, Any]`

▼

Map loop target names to one statically known item.

`def _build_iter_context(self, target_names: tuple[str, ...], item: Any) -> dict[str, Any]`

##### Parameters

Name
Type
Description

`target_names`
`—`

`item`
`—`

##### Returns

`dict[str, Any]`
