@@ -2,7 +2,7 @@ use rustc::middle::const_val;
2
2
use rustc:: hir:: def_id:: DefId ;
3
3
use rustc:: mir:: mir_map:: MirMap ;
4
4
use rustc:: mir:: repr as mir;
5
- use rustc:: traits:: ProjectionMode ;
5
+ use rustc:: traits:: Reveal ;
6
6
use rustc:: ty:: layout:: { self , Layout , Size } ;
7
7
use rustc:: ty:: subst:: { self , Subst , Substs } ;
8
8
use rustc:: ty:: { self , Ty , TyCtxt } ;
@@ -12,7 +12,6 @@ use std::cell::RefCell;
12
12
use std:: ops:: Deref ;
13
13
use std:: rc:: Rc ;
14
14
use std:: iter;
15
- use syntax:: ast;
16
15
use syntax:: codemap:: { self , DUMMY_SP } ;
17
16
18
17
use error:: { EvalError , EvalResult } ;
@@ -148,15 +147,10 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
148
147
}
149
148
}
150
149
151
- pub fn alloc_ret_ptr ( & mut self , output_ty : ty:: FnOutput < ' tcx > , substs : & ' tcx Substs < ' tcx > ) -> EvalResult < ' tcx , Option < Pointer > > {
152
- match output_ty {
153
- ty:: FnConverging ( ty) => {
154
- let size = self . type_size_with_substs ( ty, substs) ;
155
- let align = self . type_align_with_substs ( ty, substs) ;
156
- self . memory . allocate ( size, align) . map ( Some )
157
- }
158
- ty:: FnDiverging => Ok ( None ) ,
159
- }
150
+ pub fn alloc_ret_ptr ( & mut self , ty : Ty < ' tcx > , substs : & ' tcx Substs < ' tcx > ) -> EvalResult < ' tcx , Pointer > {
151
+ let size = self . type_size_with_substs ( ty, substs) ;
152
+ let align = self . type_align_with_substs ( ty, substs) ;
153
+ self . memory . allocate ( size, align)
160
154
}
161
155
162
156
pub fn memory ( & self ) -> & Memory < ' a , ' tcx > {
@@ -251,22 +245,21 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
251
245
}
252
246
253
247
pub fn load_mir ( & self , def_id : DefId ) -> CachedMir < ' a , ' tcx > {
254
- match self . tcx . map . as_local_node_id ( def_id) {
255
- Some ( node_id) => CachedMir :: Ref ( self . mir_map . map . get ( & node_id) . unwrap ( ) ) ,
256
- None => {
257
- let mut mir_cache = self . mir_cache . borrow_mut ( ) ;
258
- if let Some ( mir) = mir_cache. get ( & def_id) {
259
- return CachedMir :: Owned ( mir. clone ( ) ) ;
260
- }
261
-
262
- let cs = & self . tcx . sess . cstore ;
263
- let mir = cs. maybe_get_item_mir ( self . tcx , def_id) . unwrap_or_else ( || {
264
- panic ! ( "no mir for `{}`" , self . tcx. item_path_str( def_id) ) ;
265
- } ) ;
266
- let cached = Rc :: new ( mir) ;
267
- mir_cache. insert ( def_id, cached. clone ( ) ) ;
268
- CachedMir :: Owned ( cached)
248
+ if def_id. is_local ( ) {
249
+ CachedMir :: Ref ( self . mir_map . map . get ( & def_id) . unwrap ( ) )
250
+ } else {
251
+ let mut mir_cache = self . mir_cache . borrow_mut ( ) ;
252
+ if let Some ( mir) = mir_cache. get ( & def_id) {
253
+ return CachedMir :: Owned ( mir. clone ( ) ) ;
269
254
}
255
+
256
+ let cs = & self . tcx . sess . cstore ;
257
+ let mir = cs. maybe_get_item_mir ( self . tcx , def_id) . unwrap_or_else ( || {
258
+ panic ! ( "no mir for `{}`" , self . tcx. item_path_str( def_id) ) ;
259
+ } ) ;
260
+ let cached = Rc :: new ( mir) ;
261
+ mir_cache. insert ( def_id, cached. clone ( ) ) ;
262
+ CachedMir :: Owned ( cached)
270
263
}
271
264
}
272
265
@@ -299,7 +292,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
299
292
// TODO(solson): Is this inefficient? Needs investigation.
300
293
let ty = self . monomorphize ( ty, substs) ;
301
294
302
- self . tcx . normalizing_infer_ctxt ( ProjectionMode :: Any ) . enter ( |infcx| {
295
+ self . tcx . normalizing_infer_ctxt ( Reveal :: All ) . enter ( |infcx| {
303
296
// TODO(solson): Report this error properly.
304
297
ty. layout ( & infcx) . unwrap ( )
305
298
} )
@@ -755,7 +748,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
755
748
Temp ( i) => self . frame ( ) . locals [ self . frame ( ) . temp_offset + i. index ( ) ] ,
756
749
757
750
Static ( def_id) => {
758
- let substs = self . tcx . mk_substs ( subst:: Substs :: empty ( ) ) ;
751
+ let substs = subst:: Substs :: empty ( self . tcx ) ;
759
752
let cid = ConstantId {
760
753
def_id : def_id,
761
754
substs : substs,
@@ -846,11 +839,11 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
846
839
}
847
840
848
841
fn lvalue_ty ( & self , lvalue : & mir:: Lvalue < ' tcx > ) -> Ty < ' tcx > {
849
- self . monomorphize ( self . mir ( ) . lvalue_ty ( self . tcx , lvalue ) . to_ty ( self . tcx ) , self . substs ( ) )
842
+ self . monomorphize ( lvalue . ty ( & self . mir ( ) , self . tcx ) . to_ty ( self . tcx ) , self . substs ( ) )
850
843
}
851
844
852
845
fn operand_ty ( & self , operand : & mir:: Operand < ' tcx > ) -> Ty < ' tcx > {
853
- self . monomorphize ( self . mir ( ) . operand_ty ( self . tcx , operand ) , self . substs ( ) )
846
+ self . monomorphize ( operand . ty ( & self . mir ( ) , self . tcx ) , self . substs ( ) )
854
847
}
855
848
856
849
fn move_ ( & mut self , src : Pointer , dest : Pointer , ty : Ty < ' tcx > ) -> EvalResult < ' tcx , ( ) > {
@@ -961,21 +954,19 @@ impl<'mir, 'tcx: 'mir> Deref for CachedMir<'mir, 'tcx> {
961
954
pub fn eval_main < ' a , ' tcx : ' a > (
962
955
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
963
956
mir_map : & ' a MirMap < ' tcx > ,
964
- node_id : ast :: NodeId ,
957
+ def_id : DefId ,
965
958
memory_size : usize ,
966
959
step_limit : u64 ,
967
960
stack_limit : usize ,
968
961
) {
969
- let mir = mir_map. map . get ( & node_id) . expect ( "no mir for main function" ) ;
970
- let def_id = tcx. map . local_def_id ( node_id) ;
962
+ let mir = mir_map. map . get ( & def_id) . expect ( "no mir for main function" ) ;
971
963
let mut ecx = EvalContext :: new ( tcx, mir_map, memory_size, stack_limit) ;
972
- let substs = tcx . mk_substs ( subst:: Substs :: empty ( ) ) ;
964
+ let substs = subst:: Substs :: empty ( tcx ) ;
973
965
let return_ptr = ecx. alloc_ret_ptr ( mir. return_ty , substs)
974
- . expect ( "should at least be able to allocate space for the main function's return value" )
975
- . expect ( "main function should not be diverging" ) ;
966
+ . expect ( "should at least be able to allocate space for the main function's return value" ) ;
976
967
977
968
ecx. push_stack_frame ( def_id, mir. span , CachedMir :: Ref ( mir) , substs, Some ( return_ptr) )
978
- . expect ( "could not allocate first stack frame" ) ;
969
+ . expect ( "could not allocate first stack frame" ) ;
979
970
980
971
if mir. arg_decls . len ( ) == 2 {
981
972
// start function
@@ -1018,8 +1009,7 @@ fn report(tcx: TyCtxt, ecx: &EvalContext, e: EvalError) {
1018
1009
struct Instance < ' tcx > ( DefId , & ' tcx subst:: Substs < ' tcx > ) ;
1019
1010
impl < ' tcx > fmt:: Display for Instance < ' tcx > {
1020
1011
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1021
- ppaux:: parameterized ( f, self . 1 , self . 0 , ppaux:: Ns :: Value , & [ ] ,
1022
- |tcx| Some ( tcx. lookup_item_type ( self . 0 ) . generics ) )
1012
+ ppaux:: parameterized ( f, self . 1 , self . 0 , ppaux:: Ns :: Value , & [ ] )
1023
1013
}
1024
1014
}
1025
1015
err. span_note ( span, & format ! ( "inside call to {}" , Instance ( def_id, substs) ) ) ;
0 commit comments