@@ -18,14 +18,14 @@ use syntax::attr;
18
18
use syntax:: codemap:: { self , DUMMY_SP , Span } ;
19
19
20
20
use error:: { EvalError , EvalResult } ;
21
- use memory:: { Memory , Pointer } ;
21
+ use memory:: { Memory , Pointer , FunctionDefinition } ;
22
22
use primval:: { self , PrimVal } ;
23
23
24
24
use std:: collections:: HashMap ;
25
25
26
26
mod stepper;
27
27
28
- pub fn step < ' ecx , ' a : ' ecx , ' tcx : ' a > ( ecx : & ' ecx mut EvalContext < ' a , ' tcx > ) -> EvalResult < bool > {
28
+ pub fn step < ' ecx , ' a : ' ecx , ' tcx : ' a > ( ecx : & ' ecx mut EvalContext < ' a , ' tcx > ) -> EvalResult < ' tcx , bool > {
29
29
stepper:: Stepper :: new ( ecx) . step ( )
30
30
}
31
31
@@ -163,7 +163,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
163
163
}
164
164
165
165
// TODO(solson): Try making const_to_primval instead.
166
- fn const_to_ptr ( & mut self , const_val : & const_val:: ConstVal ) -> EvalResult < Pointer > {
166
+ fn const_to_ptr ( & mut self , const_val : & const_val:: ConstVal ) -> EvalResult < ' tcx , Pointer > {
167
167
use rustc:: middle:: const_val:: ConstVal :: * ;
168
168
match * const_val {
169
169
Float ( _f) => unimplemented ! ( ) ,
@@ -372,7 +372,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
372
372
}
373
373
374
374
fn eval_terminator ( & mut self , terminator : & mir:: Terminator < ' tcx > )
375
- -> EvalResult < ( ) > {
375
+ -> EvalResult < ' tcx , ( ) > {
376
376
use rustc:: mir:: repr:: TerminatorKind :: * ;
377
377
match terminator. kind {
378
378
Return => self . pop_stack_frame ( ) ,
@@ -438,7 +438,10 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
438
438
let ptr = self . eval_operand ( func) ?;
439
439
assert_eq ! ( ptr. offset, 0 ) ;
440
440
let fn_ptr = self . memory . read_ptr ( ptr) ?;
441
- let ( def_id, substs) = self . memory . get_fn ( fn_ptr. alloc_id ) ?;
441
+ let FunctionDefinition { def_id, substs, fn_ty } = self . memory . get_fn ( fn_ptr. alloc_id ) ?;
442
+ if fn_ty != bare_fn_ty {
443
+ return Err ( EvalError :: FunctionPointerTyMismatch ( fn_ty, bare_fn_ty) ) ;
444
+ }
442
445
self . eval_fn_call ( def_id, substs, bare_fn_ty, return_ptr, args,
443
446
terminator. source_info . span ) ?
444
447
} ,
@@ -484,7 +487,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
484
487
return_ptr : Option < Pointer > ,
485
488
args : & [ mir:: Operand < ' tcx > ] ,
486
489
span : Span ,
487
- ) -> EvalResult < ( ) > {
490
+ ) -> EvalResult < ' tcx , ( ) > {
488
491
use syntax:: abi:: Abi ;
489
492
match fn_ty. abi {
490
493
Abi :: RustIntrinsic => {
@@ -563,7 +566,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
563
566
}
564
567
}
565
568
566
- fn drop ( & mut self , ptr : Pointer , ty : Ty < ' tcx > ) -> EvalResult < ( ) > {
569
+ fn drop ( & mut self , ptr : Pointer , ty : Ty < ' tcx > ) -> EvalResult < ' tcx , ( ) > {
567
570
if !self . type_needs_drop ( ty) {
568
571
debug ! ( "no need to drop {:?}" , ty) ;
569
572
return Ok ( ( ) ) ;
@@ -605,7 +608,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
605
608
Ok ( ( ) )
606
609
}
607
610
608
- fn read_discriminant_value ( & self , adt_ptr : Pointer , adt_ty : Ty < ' tcx > ) -> EvalResult < u64 > {
611
+ fn read_discriminant_value ( & self , adt_ptr : Pointer , adt_ty : Ty < ' tcx > ) -> EvalResult < ' tcx , u64 > {
609
612
use rustc:: ty:: layout:: Layout :: * ;
610
613
let adt_layout = self . type_layout ( adt_ty) ;
611
614
@@ -633,7 +636,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
633
636
Ok ( discr_val)
634
637
}
635
638
636
- fn read_nonnull_discriminant_value ( & self , ptr : Pointer , nndiscr : u64 ) -> EvalResult < u64 > {
639
+ fn read_nonnull_discriminant_value ( & self , ptr : Pointer , nndiscr : u64 ) -> EvalResult < ' tcx , u64 > {
637
640
let not_null = match self . memory . read_usize ( ptr) {
638
641
Ok ( 0 ) => false ,
639
642
Ok ( _) | Err ( EvalError :: ReadPointerAsBytes ) => true ,
@@ -650,7 +653,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
650
653
args : & [ mir:: Operand < ' tcx > ] ,
651
654
dest : Pointer ,
652
655
dest_size : usize
653
- ) -> EvalResult < ( ) > {
656
+ ) -> EvalResult < ' tcx , ( ) > {
654
657
let args_res: EvalResult < Vec < Pointer > > = args. iter ( )
655
658
. map ( |arg| self . eval_operand ( arg) )
656
659
. collect ( ) ;
@@ -796,7 +799,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
796
799
args : & [ mir:: Operand < ' tcx > ] ,
797
800
dest : Pointer ,
798
801
dest_size : usize ,
799
- ) -> EvalResult < ( ) > {
802
+ ) -> EvalResult < ' tcx , ( ) > {
800
803
let name = self . tcx . item_name ( def_id) ;
801
804
let attrs = self . tcx . get_attrs ( def_id) ;
802
805
let link_name = match attr:: first_attr_value_str_by_name ( & attrs, "link_name" ) {
@@ -859,7 +862,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
859
862
dest : Pointer ,
860
863
offsets : I ,
861
864
operands : & [ mir:: Operand < ' tcx > ] ,
862
- ) -> EvalResult < ( ) > {
865
+ ) -> EvalResult < ' tcx , ( ) > {
863
866
for ( offset, operand) in offsets. into_iter ( ) . zip ( operands) {
864
867
let src = self . eval_operand ( operand) ?;
865
868
let src_ty = self . operand_ty ( operand) ;
@@ -870,7 +873,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
870
873
}
871
874
872
875
fn eval_assignment ( & mut self , lvalue : & mir:: Lvalue < ' tcx > , rvalue : & mir:: Rvalue < ' tcx > )
873
- -> EvalResult < ( ) >
876
+ -> EvalResult < ' tcx , ( ) >
874
877
{
875
878
let dest = self . eval_lvalue ( lvalue) ?. to_ptr ( ) ;
876
879
let dest_ty = self . lvalue_ty ( lvalue) ;
@@ -1099,8 +1102,8 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1099
1102
}
1100
1103
1101
1104
ReifyFnPointer => match self . operand_ty ( operand) . sty {
1102
- ty:: TyFnDef ( def_id, substs, _ ) => {
1103
- let fn_ptr = self . memory . create_fn_ptr ( def_id, substs) ;
1105
+ ty:: TyFnDef ( def_id, substs, fn_ty ) => {
1106
+ let fn_ptr = self . memory . create_fn_ptr ( def_id, substs, fn_ty ) ;
1104
1107
self . memory . write_ptr ( dest, fn_ptr) ?;
1105
1108
} ,
1106
1109
ref other => panic ! ( "reify fn pointer on {:?}" , other) ,
@@ -1116,7 +1119,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1116
1119
Ok ( ( ) )
1117
1120
}
1118
1121
1119
- fn nonnull_offset ( & self , ty : Ty < ' tcx > , nndiscr : u64 , discrfield : & [ u32 ] ) -> EvalResult < Size > {
1122
+ fn nonnull_offset ( & self , ty : Ty < ' tcx > , nndiscr : u64 , discrfield : & [ u32 ] ) -> EvalResult < ' tcx , Size > {
1120
1123
// Skip the constant 0 at the start meant for LLVM GEP.
1121
1124
let mut path = discrfield. iter ( ) . skip ( 1 ) . map ( |& i| i as usize ) ;
1122
1125
@@ -1137,7 +1140,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1137
1140
self . field_path_offset ( inner_ty, path)
1138
1141
}
1139
1142
1140
- fn field_path_offset < I : Iterator < Item = usize > > ( & self , mut ty : Ty < ' tcx > , path : I ) -> EvalResult < Size > {
1143
+ fn field_path_offset < I : Iterator < Item = usize > > ( & self , mut ty : Ty < ' tcx > , path : I ) -> EvalResult < ' tcx , Size > {
1141
1144
let mut offset = Size :: from_bytes ( 0 ) ;
1142
1145
1143
1146
// Skip the initial 0 intended for LLVM GEP.
@@ -1150,7 +1153,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1150
1153
Ok ( offset)
1151
1154
}
1152
1155
1153
- fn get_field_ty ( & self , ty : Ty < ' tcx > , field_index : usize ) -> EvalResult < Ty < ' tcx > > {
1156
+ fn get_field_ty ( & self , ty : Ty < ' tcx > , field_index : usize ) -> EvalResult < ' tcx , Ty < ' tcx > > {
1154
1157
match ty. sty {
1155
1158
ty:: TyStruct ( adt_def, substs) => {
1156
1159
Ok ( adt_def. struct_variant ( ) . fields [ field_index] . ty ( self . tcx , substs) )
@@ -1166,7 +1169,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1166
1169
}
1167
1170
}
1168
1171
1169
- fn get_field_offset ( & self , ty : Ty < ' tcx > , field_index : usize ) -> EvalResult < Size > {
1172
+ fn get_field_offset ( & self , ty : Ty < ' tcx > , field_index : usize ) -> EvalResult < ' tcx , Size > {
1170
1173
let layout = self . type_layout ( ty) ;
1171
1174
1172
1175
use rustc:: ty:: layout:: Layout :: * ;
@@ -1183,7 +1186,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1183
1186
}
1184
1187
}
1185
1188
1186
- fn eval_operand ( & mut self , op : & mir:: Operand < ' tcx > ) -> EvalResult < Pointer > {
1189
+ fn eval_operand ( & mut self , op : & mir:: Operand < ' tcx > ) -> EvalResult < ' tcx , Pointer > {
1187
1190
use rustc:: mir:: repr:: Operand :: * ;
1188
1191
match * op {
1189
1192
Consume ( ref lvalue) => Ok ( self . eval_lvalue ( lvalue) ?. to_ptr ( ) ) ,
@@ -1217,7 +1220,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1217
1220
}
1218
1221
}
1219
1222
1220
- fn eval_lvalue ( & mut self , lvalue : & mir:: Lvalue < ' tcx > ) -> EvalResult < Lvalue > {
1223
+ fn eval_lvalue ( & mut self , lvalue : & mir:: Lvalue < ' tcx > ) -> EvalResult < ' tcx , Lvalue > {
1221
1224
use rustc:: mir:: repr:: Lvalue :: * ;
1222
1225
let ptr = match * lvalue {
1223
1226
ReturnPointer => self . frame ( ) . return_ptr
@@ -1325,7 +1328,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1325
1328
self . monomorphize ( self . mir ( ) . operand_ty ( self . tcx , operand) , self . substs ( ) )
1326
1329
}
1327
1330
1328
- fn move_ ( & mut self , src : Pointer , dest : Pointer , ty : Ty < ' tcx > ) -> EvalResult < ( ) > {
1331
+ fn move_ ( & mut self , src : Pointer , dest : Pointer , ty : Ty < ' tcx > ) -> EvalResult < ' tcx , ( ) > {
1329
1332
let size = self . type_size ( ty) ;
1330
1333
self . memory . copy ( src, dest, size) ?;
1331
1334
if self . type_needs_drop ( ty) {
@@ -1334,7 +1337,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1334
1337
Ok ( ( ) )
1335
1338
}
1336
1339
1337
- pub fn read_primval ( & mut self , ptr : Pointer , ty : Ty < ' tcx > ) -> EvalResult < PrimVal > {
1340
+ pub fn read_primval ( & mut self , ptr : Pointer , ty : Ty < ' tcx > ) -> EvalResult < ' tcx , PrimVal > {
1338
1341
use syntax:: ast:: { IntTy , UintTy } ;
1339
1342
let val = match ( self . memory . pointer_size , & ty. sty ) {
1340
1343
( _, & ty:: TyBool ) => PrimVal :: Bool ( self . memory . read_bool ( ptr) ?) ,
0 commit comments