Use mapStmtExprChildrenM to simplify transformExpr#44
Use mapStmtExprChildrenM to simplify transformExpr#44keyboardDrummer-bot wants to merge 1 commit into
Conversation
…xpressions Add mapStmtExprChildrenM and mapStmtExprPrePostM to MapStmtExpr.lean: - mapStmtExprChildrenM: maps a function over immediate children of a node (one level, no recursion), with optional right-to-left traversal - mapStmtExprPrePostM: full traversal with pre/post hooks Refactor transformExpr in LiftImperativeExpressions.lean: - Remove explicit PrimitiveOp arm - Replace catch-all with mapStmtExprChildrenM transformExpr call - The pass no longer needs to enumerate language features it doesn't relate to (like PrimitiveOp) — new constructors are handled automatically by the generic traversal - Mark transformExpr as partial since mapStmtExprChildrenM is opaque to the termination checker Closes #40
|
I investigated the "Run internal benchmarks of Strata" CI failure. The benchmark job triggers an AWS CodeBuild build that runs internal tests. Finding: This failure is not caused by the code changes in this PR. The same benchmark job is also failing on other unrelated PRs:
The benchmark infrastructure appears to have a pre-existing issue (likely AWS credentials, CodeBuild configuration, or the benchmark environment itself). The failure happens quickly (~100 seconds), suggesting it fails during setup or early build rather than during actual test execution. Local verification:
|
|
@keyboardDrummer-bot are there other passes that can make use of the new utilities that this PR introduces? |
|
Yes, several other passes could benefit from the new utilities introduced here:
|
Addresses #40.
Summary
Adds
mapStmtExprChildrenMtoMapStmtExpr.lean— a utility that maps a function over the immediate children of aStmtExprMdnode (one level, no recursion), with an optionalreverseChildrenflag for right-to-left traversal.Uses it in
LiftImperativeExpressions.leanto replace the explicitPrimitiveOparm intransformExprwith a generic catch-all:This means the pass no longer needs to enumerate language features it doesn't relate to. If a new
StmtExprconstructor is added, it will be traversed automatically without updatingtransformExpr.Changes
MapStmtExpr.lean:
mapStmtExprChildrenM: one-level child mapping with optional right-to-left ordermapStmtExprPrePostM: full traversal with pre/post hooks (useful for other passes)LiftImperativeExpressions.lean:
PrimitiveOparm fromtransformExpr| _ => return exprwithmapStmtExprChildrenM transformExpr (reverseChildren := true) expr| .Assert _ | .Assume _ => return exprsince these are statement-like constructs lifted out of blocks and should not have substitutions appliedmutualblock (no longer needed sincetransformStmtdoesn't need mutual recursion withtransformExpr)transformExpraspartialsincemapStmtExprChildrenMis opaque to the termination checkerTrade-off
The use of
partialis a trade-off: we lose the termination proof fortransformExprin exchange for not needing to enumerate every constructor. The termination checker cannot see throughmapStmtExprChildrenMto verify thattransformExpris only called on structurally smaller values. The original code avoided this by listing every constructor with.attachproofs.Testing
All 591 test jobs pass.
"