|
6 | 6 | use rustc_middle::mir::{Body, LocalKind, Location, START_BLOCK};
|
7 | 7 | use rustc_mir_dataflow::move_paths::{InitKind, InitLocation, MoveData};
|
8 | 8 |
|
| 9 | +use crate::borrow_set::BorrowSet; |
9 | 10 | use crate::facts::AllFacts;
|
10 | 11 | use crate::location::LocationTable;
|
| 12 | +use crate::type_check::free_region_relations::UniversalRegionRelations; |
| 13 | +use crate::universal_regions::UniversalRegions; |
11 | 14 |
|
12 |
| -/// Emit polonius facts needed for move/init analysis: moves and assignments. |
| 15 | +/// Emit facts needed for move/init analysis: moves and assignments. |
13 | 16 | pub(crate) fn emit_move_facts(
|
14 | 17 | all_facts: &mut AllFacts,
|
15 | 18 | move_data: &MoveData<'_>,
|
@@ -82,3 +85,44 @@ pub(crate) fn emit_move_facts(
|
82 | 85 | .path_moved_at_base
|
83 | 86 | .extend(move_data.moves.iter().map(|mo| (mo.path, location_table.mid_index(mo.source))));
|
84 | 87 | }
|
| 88 | + |
| 89 | +/// Emit universal regions facts, and their relations. |
| 90 | +pub(crate) fn emit_universal_region_facts( |
| 91 | + all_facts: &mut AllFacts, |
| 92 | + borrow_set: &BorrowSet<'_>, |
| 93 | + universal_regions: &UniversalRegions<'_>, |
| 94 | + universal_region_relations: &UniversalRegionRelations<'_>, |
| 95 | +) { |
| 96 | + // 1: universal regions are modeled in Polonius as a pair: |
| 97 | + // - the universal region vid itself. |
| 98 | + // - a "placeholder loan" associated to this universal region. Since they don't exist in |
| 99 | + // the `borrow_set`, their `BorrowIndex` are synthesized as the universal region index |
| 100 | + // added to the existing number of loans, as if they succeeded them in the set. |
| 101 | + // |
| 102 | + all_facts.universal_region.extend(universal_regions.universal_regions()); |
| 103 | + let borrow_count = borrow_set.len(); |
| 104 | + debug!( |
| 105 | + "emit_universal_region_facts: polonius placeholders, num_universals={}, borrow_count={}", |
| 106 | + universal_regions.len(), |
| 107 | + borrow_count |
| 108 | + ); |
| 109 | + |
| 110 | + for universal_region in universal_regions.universal_regions() { |
| 111 | + let universal_region_idx = universal_region.index(); |
| 112 | + let placeholder_loan_idx = borrow_count + universal_region_idx; |
| 113 | + all_facts.placeholder.push((universal_region, placeholder_loan_idx.into())); |
| 114 | + } |
| 115 | + |
| 116 | + // 2: the universal region relations `outlives` constraints are emitted as |
| 117 | + // `known_placeholder_subset` facts. |
| 118 | + for (fr1, fr2) in universal_region_relations.known_outlives() { |
| 119 | + if fr1 != fr2 { |
| 120 | + debug!( |
| 121 | + "emit_universal_region_facts: emitting polonius `known_placeholder_subset` \ |
| 122 | + fr1={:?}, fr2={:?}", |
| 123 | + fr1, fr2 |
| 124 | + ); |
| 125 | + all_facts.known_placeholder_subset.push((fr1, fr2)); |
| 126 | + } |
| 127 | + } |
| 128 | +} |
0 commit comments