@@ -10,7 +10,6 @@ use rustc::ty::subst::{self, Subst};
1010use rustc:: hir:: def_id:: DefId ;
1111use rustc:: mir:: visit:: { Visitor , LvalueContext } ;
1212use syntax:: codemap:: Span ;
13- use memory:: Pointer ;
1413use std:: rc:: Rc ;
1514
1615pub enum Event {
@@ -73,23 +72,11 @@ impl<'fncx, 'a, 'b: 'a + 'mir, 'mir, 'tcx: 'b> Stepper<'fncx, 'a, 'b, 'mir, 'tcx
7372 }
7473
7574 fn constant ( & mut self ) -> EvalResult < ( ) > {
76- match self . fncx . frame_mut ( ) . constants . pop ( ) {
77- Some ( ( ConstantId :: Promoted { index } , span, return_ptr, mir) ) => {
78- trace ! ( "adding promoted constant {}, {:?}" , index, span) ;
79- let substs = self . fncx . substs ( ) ;
80- // FIXME: somehow encode that this is a promoted constant's frame
81- let def_id = self . fncx . frame ( ) . def_id ;
82- self . fncx . push_stack_frame ( def_id, span, mir, substs, Some ( return_ptr) ) ;
83- self . mir = self . fncx . mir ( ) ;
84- } ,
85- Some ( ( ConstantId :: Static { def_id, substs } , span, return_ptr, mir) ) => {
86- trace ! ( "adding static {:?}, {:?}" , def_id, span) ;
87- self . fncx . gecx . statics . insert ( def_id, return_ptr) ;
88- self . fncx . push_stack_frame ( def_id, span, mir, substs, Some ( return_ptr) ) ;
89- self . mir = self . fncx . mir ( ) ;
90- } ,
91- None => unreachable ! ( ) ,
92- }
75+ let ( cid, span, return_ptr, mir) = self . fncx . frame_mut ( ) . constants . pop ( ) . expect ( "state machine broken" ) ;
76+ let def_id = cid. def_id ( ) ;
77+ let substs = cid. substs ( ) ;
78+ self . fncx . push_stack_frame ( def_id, span, mir, substs, Some ( return_ptr) ) ;
79+ self . mir = self . fncx . mir ( ) ;
9380 Ok ( ( ) )
9481 }
9582
@@ -164,16 +151,17 @@ struct ConstantExtractor<'a: 'c, 'b: 'a + 'mir + 'c, 'c, 'mir: 'c, 'tcx: 'a + 'b
164151}
165152
166153impl < ' a , ' b , ' c , ' mir , ' tcx > ConstantExtractor < ' a , ' b , ' c , ' mir , ' tcx > {
167- fn constant ( & mut self , def_id : DefId , substs : & ' tcx subst:: Substs < ' tcx > , span : Span ) {
168- if self . fncx . gecx . statics . contains_key ( & def_id) {
169- return ;
170- }
154+ fn static_item ( & mut self , def_id : DefId , substs : & ' tcx subst:: Substs < ' tcx > , span : Span ) {
171155 let cid = ConstantId :: Static {
172156 def_id : def_id,
173157 substs : substs,
174158 } ;
159+ if self . fncx . gecx . statics . contains_key ( & cid) {
160+ return ;
161+ }
175162 let mir = self . fncx . load_mir ( def_id) ;
176163 let ptr = self . fncx . alloc_ret_ptr ( mir. return_ty ) . expect ( "there's no such thing as an unreachable static" ) ;
164+ self . fncx . statics . insert ( cid. clone ( ) , ptr) ;
177165 self . fncx . frame_mut ( ) . constants . push ( ( cid, span, ptr, mir) ) ;
178166 }
179167}
@@ -189,19 +177,24 @@ impl<'a, 'b, 'c, 'mir, 'tcx> Visitor<'tcx> for ConstantExtractor<'a, 'b, 'c, 'mi
189177 if item_ty. ty . is_fn ( ) {
190178 // unimplemented
191179 } else {
192- self . constant ( def_id, substs, constant. span ) ;
180+ self . static_item ( def_id, substs, constant. span ) ;
193181 }
194182 } ,
195183 mir:: Literal :: Promoted { index } => {
196- if self . fncx . frame ( ) . promoted . contains_key ( & index) {
184+ let cid = ConstantId :: Promoted {
185+ def_id : self . fncx . frame ( ) . def_id ,
186+ substs : self . fncx . substs ( ) ,
187+ index : index,
188+ } ;
189+ if self . fncx . statics . contains_key ( & cid) {
197190 return ;
198191 }
199192 let mir = self . mir . promoted [ index] . clone ( ) ;
200193 let return_ty = mir. return_ty ;
201194 let return_ptr = self . fncx . alloc_ret_ptr ( return_ty) . expect ( "there's no such thing as an unreachable static" ) ;
202- self . fncx . frame_mut ( ) . promoted . insert ( index, return_ptr) ;
203195 let mir = CachedMir :: Owned ( Rc :: new ( mir) ) ;
204- self . fncx . frame_mut ( ) . constants . push ( ( ConstantId :: Promoted { index : index } , constant. span , return_ptr, mir) ) ;
196+ self . fncx . statics . insert ( cid. clone ( ) , return_ptr) ;
197+ self . fncx . frame_mut ( ) . constants . push ( ( cid, constant. span , return_ptr, mir) ) ;
205198 }
206199 }
207200 }
@@ -211,7 +204,7 @@ impl<'a, 'b, 'c, 'mir, 'tcx> Visitor<'tcx> for ConstantExtractor<'a, 'b, 'c, 'mi
211204 if let mir:: Lvalue :: Static ( def_id) = * lvalue {
212205 let substs = self . fncx . tcx . mk_substs ( subst:: Substs :: empty ( ) ) ;
213206 let span = self . span ;
214- self . constant ( def_id, substs, span) ;
207+ self . static_item ( def_id, substs, span) ;
215208 }
216209 }
217210}
0 commit comments