77//! `'tcx`.
88
99use prusti_rustc_interface:: {
10- borrowck:: consumers:: BodyWithBorrowckFacts , data_structures:: fx:: FxHashMap ,
11- hir:: def_id:: LocalDefId , middle:: ty:: TyCtxt ,
10+ borrowck:: consumers:: BodyWithBorrowckFacts ,
11+ data_structures:: fx:: FxHashMap ,
12+ hir:: def_id:: LocalDefId ,
13+ middle:: { mir, ty:: TyCtxt } ,
1214} ;
1315use std:: { cell:: RefCell , thread_local} ;
1416
1517thread_local ! {
16- pub static SHARED_STATE :
18+ pub static SHARED_STATE_WITH_FACTS :
1719 RefCell <FxHashMap <LocalDefId , BodyWithBorrowckFacts <' static >>> =
1820 RefCell :: new( FxHashMap :: default ( ) ) ;
21+ pub static SHARED_STATE_WITHOUT_FACTS :
22+ RefCell <FxHashMap <LocalDefId , mir:: Body <' static >>> =
23+ RefCell :: new( FxHashMap :: default ( ) ) ;
1924}
2025
2126/// # Safety
@@ -29,7 +34,7 @@ pub unsafe fn store_mir_body<'tcx>(
2934 // SAFETY: See the module level comment.
3035 let body_with_facts: BodyWithBorrowckFacts < ' static > =
3136 unsafe { std:: mem:: transmute ( body_with_facts) } ;
32- SHARED_STATE . with ( |state| {
37+ SHARED_STATE_WITH_FACTS . with ( |state| {
3338 let mut map = state. borrow_mut ( ) ;
3439 assert ! ( map. insert( def_id, body_with_facts) . is_none( ) ) ;
3540 } ) ;
@@ -46,10 +51,39 @@ pub(super) unsafe fn retrieve_mir_body<'tcx>(
4651 _tcx : TyCtxt < ' tcx > ,
4752 def_id : LocalDefId ,
4853) -> BodyWithBorrowckFacts < ' tcx > {
49- let body_with_facts: BodyWithBorrowckFacts < ' static > = SHARED_STATE . with ( |state| {
54+ let body_with_facts: BodyWithBorrowckFacts < ' static > = SHARED_STATE_WITH_FACTS . with ( |state| {
5055 let mut map = state. borrow_mut ( ) ;
5156 map. remove ( & def_id) . unwrap ( )
5257 } ) ;
5358 // SAFETY: See the module level comment.
5459 unsafe { std:: mem:: transmute ( body_with_facts) }
5560}
61+
62+ /// # Safety
63+ ///
64+ /// See the module level comment.
65+ pub unsafe fn store_promoted_mir_body < ' tcx > (
66+ _tcx : TyCtxt < ' tcx > ,
67+ def_id : LocalDefId ,
68+ body : mir:: Body < ' tcx > ,
69+ ) {
70+ // SAFETY: See the module level comment.
71+ let body: mir:: Body < ' static > = unsafe { std:: mem:: transmute ( body) } ;
72+ SHARED_STATE_WITHOUT_FACTS . with ( |state| {
73+ let mut map = state. borrow_mut ( ) ;
74+ assert ! ( map. insert( def_id, body) . is_none( ) ) ;
75+ } ) ;
76+ }
77+
78+ #[ allow( clippy:: needless_lifetimes) ] // We want to be very explicit about lifetimes here.
79+ pub ( super ) unsafe fn retrieve_promoted_mir_body < ' tcx > (
80+ _tcx : TyCtxt < ' tcx > ,
81+ def_id : LocalDefId ,
82+ ) -> mir:: Body < ' tcx > {
83+ let body_without_facts: mir:: Body < ' static > = SHARED_STATE_WITHOUT_FACTS . with ( |state| {
84+ let mut map = state. borrow_mut ( ) ;
85+ map. remove ( & def_id) . unwrap ( )
86+ } ) ;
87+ // SAFETY: See the module level comment.
88+ unsafe { std:: mem:: transmute ( body_without_facts) }
89+ }
0 commit comments