Replaces `LetRec` nodes with a stack of `Let` nodes. In each `Let` binding, uses of `Get` in `value` that are not at strictly greater identifiers are rewritten to be the constant collection. This makes the computation perform exactly "one" iteration. This was used only temporarily while developing `LetRec`.
(self: &mut MirRelationExpr)
| 2077 | /// |
| 2078 | /// This was used only temporarily while developing `LetRec`. |
| 2079 | pub fn make_nonrecursive(self: &mut MirRelationExpr) { |
| 2080 | let mut deadlist = BTreeSet::new(); |
| 2081 | let mut worklist = vec![self]; |
| 2082 | while let Some(expr) = worklist.pop() { |
| 2083 | if let MirRelationExpr::LetRec { |
| 2084 | ids, |
| 2085 | values, |
| 2086 | limits: _, |
| 2087 | body, |
| 2088 | } = expr |
| 2089 | { |
| 2090 | let ids_values = values |
| 2091 | .drain(..) |
| 2092 | .zip_eq(ids) |
| 2093 | .map(|(value, id)| (*id, value)) |
| 2094 | .collect::<Vec<_>>(); |
| 2095 | *expr = body.take_dangerous(); |
| 2096 | for (id, mut value) in ids_values.into_iter().rev() { |
| 2097 | // Remove references to potentially recursive identifiers. |
| 2098 | deadlist.insert(id); |
| 2099 | value.visit_pre_mut(|e| { |
| 2100 | if let MirRelationExpr::Get { |
| 2101 | id: crate::Id::Local(id), |
| 2102 | typ, |
| 2103 | .. |
| 2104 | } = e |
| 2105 | { |
| 2106 | let typ = typ.clone(); |
| 2107 | if deadlist.contains(id) { |
| 2108 | e.take_safely(Some(typ)); |
| 2109 | } |
| 2110 | } |
| 2111 | }); |
| 2112 | *expr = MirRelationExpr::Let { |
| 2113 | id, |
| 2114 | value: Box::new(value), |
| 2115 | body: Box::new(expr.take_dangerous()), |
| 2116 | }; |
| 2117 | } |
| 2118 | worklist.push(expr); |
| 2119 | } else { |
| 2120 | worklist.extend(expr.children_mut().rev()); |
| 2121 | } |
| 2122 | } |
| 2123 | } |
| 2124 | |
| 2125 | /// For each Id `id'` referenced in `expr`, if it is larger or equal than `id`, then record in |
| 2126 | /// `expire_whens` that when `id'` is redefined, then we should expire the information that |
nothing calls this directly
no test coverage detected