| 4911 | } |
| 4912 | |
| 4913 | function reverseBody(body: AST, edge: Suspend["thunk"]): AST { |
| 4914 | if (types.get(body) !== body) return stripEncoding(flip(body)) |
| 4915 | const existing = reversed.get(body) |
| 4916 | if (existing) return existing |
| 4917 | // A projected body can close its own cycle if all suspended edges lead back here |
| 4918 | // and reversing it preserves the checks and declaration callbacks. |
| 4919 | if (canReuse(body, edge)) { |
| 4920 | reversed.set(body, body) |
| 4921 | return body |
| 4922 | } |
| 4923 | const out = stripEncoding(flip(body)) |
| 4924 | // The first reversal can discard checks. Further reversals can reuse the pair. |
| 4925 | if (reprojected.has(body) && !reversed.has(out)) reversed.set(out, body) |
| 4926 | reprojected.add(out) |
| 4927 | return out |
| 4928 | } |
| 4929 | |
| 4930 | function fromConst<const T>( |
| 4931 | ast: AST, |