Substitute `Get{id}` expressions for any proposed expressions. The proposed expressions can be proposed either to be taken or cloned.
(
expr: &mut MirRelationExpr,
inline_offer: &mut BTreeMap<LocalId, InlineOffer>,
)
| 893 | /// |
| 894 | /// The proposed expressions can be proposed either to be taken or cloned. |
| 895 | fn inline_lets_helper( |
| 896 | expr: &mut MirRelationExpr, |
| 897 | inline_offer: &mut BTreeMap<LocalId, InlineOffer>, |
| 898 | ) -> Result<(), crate::TransformError> { |
| 899 | let mut worklist = vec![expr]; |
| 900 | while let Some(expr) = worklist.pop() { |
| 901 | if let MirRelationExpr::Get { |
| 902 | id: Id::Local(id), .. |
| 903 | } = expr |
| 904 | { |
| 905 | if let Some(offer) = inline_offer.get_mut(id) { |
| 906 | // It is important that we *not* continue to iterate |
| 907 | // on the contents of `offer`, which has already been |
| 908 | // maximally inlined. If we did, we could mis-inline |
| 909 | // bindings into bodies that precede them, which would |
| 910 | // change the semantics of the expression. |
| 911 | match offer { |
| 912 | InlineOffer::Take(value, _max_iter) => { |
| 913 | *expr = value.take().ok_or_else(|| { |
| 914 | crate::TransformError::Internal(format!( |
| 915 | "Value already taken for {:?}", |
| 916 | id |
| 917 | )) |
| 918 | })?; |
| 919 | } |
| 920 | InlineOffer::Clone(value, _max_iter) => { |
| 921 | *expr = value.clone(); |
| 922 | } |
| 923 | InlineOffer::Unavailable(_, _) => { |
| 924 | // Do nothing. |
| 925 | } |
| 926 | } |
| 927 | } else { |
| 928 | // Presumably a reference to an outer scope. |
| 929 | } |
| 930 | } else { |
| 931 | worklist.extend(expr.children_mut().rev()); |
| 932 | } |
| 933 | } |
| 934 | Ok(()) |
| 935 | } |
| 936 | } |
| 937 | |
| 938 | mod renumbering { |
no test coverage detected