Let-expression traversal¶
Binder-aware walks, free-name analysis, and substitution over the let-expression AST.
let_expr_traversal
¶
Exhaustive, binder-aware operations over the shared let-expression AST.
The native compiler, QIEC elaborator, and transpilation preflight all consume the same expression nodes. Keeping their recursive walks here makes adding a new node an explicit cross-surface change: an unrecognised variant raises instead of being silently treated as a leaf.
let_expr_children
¶
let_expr_children(expr: LetExprNode) -> tuple[LetExprNode, ...]
Return the immediate expression children of expr in source order.
| PARAMETER | DESCRIPTION |
|---|---|
expr
|
The expression to take apart.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[LetExprNode, ...]
|
The direct subexpressions, empty for a leaf. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If |
Source code in src/quivers/dsl/let_expr_traversal.py
walk_let_expr
¶
walk_let_expr(expr: LetExprNode) -> Iterator[LetExprNode]
Yield expr and all descendants in preorder.
| PARAMETER | DESCRIPTION |
|---|---|
expr
|
The root of the walk.
TYPE:
|
| YIELDS | DESCRIPTION |
|---|---|
LetExprNode
|
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the walk reaches an unsupported let-expression variant. |
Source code in src/quivers/dsl/let_expr_traversal.py
free_let_names
¶
free_let_names(expr: LetExprNode, *, bound: frozenset[str] = frozenset(), include_callees: bool = False) -> tuple[str, ...]
Return free value names in first-use order.
Lambda parameters and factor indices bind in their bodies. Call names are declarations by default; callers that model a callee as a host value can include them explicitly.
| PARAMETER | DESCRIPTION |
|---|---|
expr
|
The expression to scan.
TYPE:
|
bound
|
Names already bound around
TYPE:
|
include_callees
|
Whether the function name of a call counts as a free name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
Each free name once, in the order of its first occurrence. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the scan reaches an unsupported let-expression variant. |
Source code in src/quivers/dsl/let_expr_traversal.py
substitute_let_expr
¶
substitute_let_expr(expr: LetExprNode, substitution: Mapping[str, LetExprNode]) -> LetExprNode
Substitute expressions for free variables in expr without capture.
A lambda parameter or factor binder that would capture a free name of a replacement is renamed to a fresh name first.
| PARAMETER | DESCRIPTION |
|---|---|
expr
|
The expression to rewrite.
TYPE:
|
substitution
|
The replacement for each free variable name.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
LetExprNode
|
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the rewrite reaches an unsupported let-expression variant. |
Source code in src/quivers/dsl/let_expr_traversal.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | |