Skip to content

Create a single source scope for promoteds #77947

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions compiler/rustc_mir/src/transform/promote_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ impl Candidate {
Candidate::Argument { .. } | Candidate::InlineAsm { .. } => true,
}
}

fn source_info(&self, body: &Body<'_>) -> SourceInfo {
match self {
Candidate::Ref(location) | Candidate::Repeat(location) => *body.source_info(*location),
Candidate::Argument { bb, .. } | Candidate::InlineAsm { bb, .. } => {
*body.source_info(body.terminator_loc(*bb))
}
}
}
}

fn args_required_const(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Vec<usize>> {
Expand Down Expand Up @@ -953,6 +962,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
from_hir_call,
fn_span,
},
source_info: SourceInfo::outermost(terminator.source_info.span),
..terminator
};
}
Expand Down Expand Up @@ -1163,12 +1173,13 @@ pub fn promote_candidates<'tcx>(
// Declare return place local so that `mir::Body::new` doesn't complain.
let initial_locals = iter::once(LocalDecl::new(tcx.types.never, body.span)).collect();

let mut scope = body.source_scopes[candidate.source_info(body).scope].clone();
scope.parent_scope = None;

let mut promoted = Body::new(
body.source, // `promoted` gets filled in below
IndexVec::new(),
// FIXME: maybe try to filter this to avoid blowing up
// memory usage?
body.source_scopes.clone(),
IndexVec::from_elem_n(scope, 1),
initial_locals,
IndexVec::new(),
0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ promoted[0] in FOO: &[&i32; 1] = {
let mut _1: [&i32; 1]; // in scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46
let mut _2: &i32; // in scope 0 at $DIR/const-promotion-extern-static.rs:13:32: 13:45
let mut _3: &i32; // in scope 0 at $DIR/const-promotion-extern-static.rs:13:42: 13:43
scope 1 {
}

bb0: {
_3 = const {alloc2: &i32}; // scope 0 at $DIR/const-promotion-extern-static.rs:13:42: 13:43
Expand Down