Skip to content

Commit

Permalink
Merge pull request #312 from Nadrieril/stealing
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadrieril authored Aug 14, 2024
2 parents d8a0249 + a772db3 commit 7728aa1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
14 changes: 9 additions & 5 deletions charon/src/bin/charon-driver/translate/get_mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,20 @@ pub fn get_mir_for_def_id_and_level(
match level {
MirLevel::Built => {
let body = tcx.mir_built(local_def_id);
// We clone to be sure there are no problems with locked values
body.borrow().clone()
if !body.is_stolen() {
return Some(body.borrow().clone());
}
}
MirLevel::Promoted => {
let (body, _) = tcx.mir_promoted(local_def_id);
// We clone to be sure there are no problems with locked values
body.borrow().clone()
if !body.is_stolen() {
return Some(body.borrow().clone());
}
}
MirLevel::Optimized => tcx.optimized_mir(def_id).clone(),
MirLevel::Optimized => {}
}
// Use the optimized MIR if it was requested or if the requested body was stolen.
tcx.optimized_mir(def_id).clone()
} else {
// There are only two MIRs we can fetch for non-local bodies: CTFE mir for globals and
// const fns, and optimized MIR for inlinable functions. The rest don't have MIR in the
Expand Down
22 changes: 22 additions & 0 deletions charon/tests/ui/stealing.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Final LLBC before serialization:

global test_crate::SLICE {
let @0: Array<(), 4 : usize>; // return
let @1: (); // anonymous local

@1 := ()
@0 := @ArrayRepeat<'_, (), 4 : usize>(move (@1))
drop @1
return
}

fn test_crate::four() -> usize
{
let @0: usize; // return

@0 := const (4 : usize)
return
}



7 changes: 7 additions & 0 deletions charon/tests/ui/stealing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Translating this needs the evaluatable MIR of `fn four()`, which steals its `mir_built` body.
// There's no simple ordering of the translation of items that can avoid all stealing.
static SLICE: [(); four()] = [(); 4];

const fn four() -> usize {
2 + 2
}

0 comments on commit 7728aa1

Please sign in to comment.