@@ -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
@@ -159,7 +159,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
159
159
}
160
160
161
161
// TODO(solson): Try making const_to_primval instead.
162
- fn const_to_ptr ( & mut self , const_val : & const_val:: ConstVal ) -> EvalResult < Pointer > {
162
+ fn const_to_ptr ( & mut self , const_val : & const_val:: ConstVal ) -> EvalResult < ' tcx , Pointer > {
163
163
use rustc:: middle:: const_val:: ConstVal :: * ;
164
164
match * const_val {
165
165
Float ( _f) => unimplemented ! ( ) ,
@@ -368,7 +368,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
368
368
}
369
369
370
370
fn eval_terminator ( & mut self , terminator : & mir:: Terminator < ' tcx > )
371
- -> EvalResult < ( ) > {
371
+ -> EvalResult < ' tcx , ( ) > {
372
372
use rustc:: mir:: repr:: TerminatorKind :: * ;
373
373
match terminator. kind {
374
374
Return => self . pop_stack_frame ( ) ,
@@ -434,7 +434,10 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
434
434
let ptr = self . eval_operand ( func) ?;
435
435
assert_eq ! ( ptr. offset, 0 ) ;
436
436
let fn_ptr = self . memory . read_ptr ( ptr) ?;
437
- let ( def_id, substs) = self . memory . get_fn ( fn_ptr. alloc_id ) ?;
437
+ let FunctionDefinition { def_id, substs, fn_ty } = self . memory . get_fn ( fn_ptr. alloc_id ) ?;
438
+ if fn_ty != bare_fn_ty {
439
+ return Err ( EvalError :: FunctionPointerTyMismatch ( fn_ty, bare_fn_ty) ) ;
440
+ }
438
441
self . eval_fn_call ( def_id, substs, bare_fn_ty, return_ptr, args,
439
442
terminator. source_info . span ) ?
440
443
} ,
@@ -480,7 +483,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
480
483
return_ptr : Option < Pointer > ,
481
484
args : & [ mir:: Operand < ' tcx > ] ,
482
485
span : Span ,
483
- ) -> EvalResult < ( ) > {
486
+ ) -> EvalResult < ' tcx , ( ) > {
484
487
use syntax:: abi:: Abi ;
485
488
match fn_ty. abi {
486
489
Abi :: RustIntrinsic => {
@@ -559,7 +562,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
559
562
}
560
563
}
561
564
562
- fn drop ( & mut self , ptr : Pointer , ty : Ty < ' tcx > ) -> EvalResult < ( ) > {
565
+ fn drop ( & mut self , ptr : Pointer , ty : Ty < ' tcx > ) -> EvalResult < ' tcx , ( ) > {
563
566
if !self . type_needs_drop ( ty) {
564
567
debug ! ( "no need to drop {:?}" , ty) ;
565
568
return Ok ( ( ) ) ;
@@ -601,7 +604,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
601
604
Ok ( ( ) )
602
605
}
603
606
604
- fn read_discriminant_value ( & self , adt_ptr : Pointer , adt_ty : Ty < ' tcx > ) -> EvalResult < u64 > {
607
+ fn read_discriminant_value ( & self , adt_ptr : Pointer , adt_ty : Ty < ' tcx > ) -> EvalResult < ' tcx , u64 > {
605
608
use rustc:: ty:: layout:: Layout :: * ;
606
609
let adt_layout = self . type_layout ( adt_ty) ;
607
610
@@ -629,7 +632,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
629
632
Ok ( discr_val)
630
633
}
631
634
632
- fn read_nonnull_discriminant_value ( & self , ptr : Pointer , nndiscr : u64 ) -> EvalResult < u64 > {
635
+ fn read_nonnull_discriminant_value ( & self , ptr : Pointer , nndiscr : u64 ) -> EvalResult < ' tcx , u64 > {
633
636
let not_null = match self . memory . read_usize ( ptr) {
634
637
Ok ( 0 ) => false ,
635
638
Ok ( _) | Err ( EvalError :: ReadPointerAsBytes ) => true ,
@@ -646,7 +649,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
646
649
args : & [ mir:: Operand < ' tcx > ] ,
647
650
dest : Pointer ,
648
651
dest_size : usize
649
- ) -> EvalResult < ( ) > {
652
+ ) -> EvalResult < ' tcx , ( ) > {
650
653
let args_res: EvalResult < Vec < Pointer > > = args. iter ( )
651
654
. map ( |arg| self . eval_operand ( arg) )
652
655
. collect ( ) ;
@@ -792,7 +795,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
792
795
args : & [ mir:: Operand < ' tcx > ] ,
793
796
dest : Pointer ,
794
797
dest_size : usize ,
795
- ) -> EvalResult < ( ) > {
798
+ ) -> EvalResult < ' tcx , ( ) > {
796
799
let name = self . tcx . item_name ( def_id) ;
797
800
let attrs = self . tcx . get_attrs ( def_id) ;
798
801
let link_name = match attr:: first_attr_value_str_by_name ( & attrs, "link_name" ) {
@@ -855,7 +858,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
855
858
dest : Pointer ,
856
859
offsets : I ,
857
860
operands : & [ mir:: Operand < ' tcx > ] ,
858
- ) -> EvalResult < ( ) > {
861
+ ) -> EvalResult < ' tcx , ( ) > {
859
862
for ( offset, operand) in offsets. into_iter ( ) . zip ( operands) {
860
863
let src = self . eval_operand ( operand) ?;
861
864
let src_ty = self . operand_ty ( operand) ;
@@ -866,7 +869,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
866
869
}
867
870
868
871
fn eval_assignment ( & mut self , lvalue : & mir:: Lvalue < ' tcx > , rvalue : & mir:: Rvalue < ' tcx > )
869
- -> EvalResult < ( ) >
872
+ -> EvalResult < ' tcx , ( ) >
870
873
{
871
874
let dest = self . eval_lvalue ( lvalue) ?. to_ptr ( ) ;
872
875
let dest_ty = self . lvalue_ty ( lvalue) ;
@@ -1095,8 +1098,8 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1095
1098
}
1096
1099
1097
1100
ReifyFnPointer => match self . operand_ty ( operand) . sty {
1098
- ty:: TyFnDef ( def_id, substs, _ ) => {
1099
- let fn_ptr = self . memory . create_fn_ptr ( def_id, substs) ;
1101
+ ty:: TyFnDef ( def_id, substs, fn_ty ) => {
1102
+ let fn_ptr = self . memory . create_fn_ptr ( def_id, substs, fn_ty ) ;
1100
1103
self . memory . write_ptr ( dest, fn_ptr) ?;
1101
1104
} ,
1102
1105
ref other => panic ! ( "reify fn pointer on {:?}" , other) ,
@@ -1112,7 +1115,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1112
1115
Ok ( ( ) )
1113
1116
}
1114
1117
1115
- fn nonnull_offset ( & self , ty : Ty < ' tcx > , nndiscr : u64 , discrfield : & [ u32 ] ) -> EvalResult < Size > {
1118
+ fn nonnull_offset ( & self , ty : Ty < ' tcx > , nndiscr : u64 , discrfield : & [ u32 ] ) -> EvalResult < ' tcx , Size > {
1116
1119
// Skip the constant 0 at the start meant for LLVM GEP.
1117
1120
let mut path = discrfield. iter ( ) . skip ( 1 ) . map ( |& i| i as usize ) ;
1118
1121
@@ -1133,7 +1136,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1133
1136
self . field_path_offset ( inner_ty, path)
1134
1137
}
1135
1138
1136
- fn field_path_offset < I : Iterator < Item = usize > > ( & self , mut ty : Ty < ' tcx > , path : I ) -> EvalResult < Size > {
1139
+ fn field_path_offset < I : Iterator < Item = usize > > ( & self , mut ty : Ty < ' tcx > , path : I ) -> EvalResult < ' tcx , Size > {
1137
1140
let mut offset = Size :: from_bytes ( 0 ) ;
1138
1141
1139
1142
// Skip the initial 0 intended for LLVM GEP.
@@ -1146,7 +1149,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1146
1149
Ok ( offset)
1147
1150
}
1148
1151
1149
- fn get_field_ty ( & self , ty : Ty < ' tcx > , field_index : usize ) -> EvalResult < Ty < ' tcx > > {
1152
+ fn get_field_ty ( & self , ty : Ty < ' tcx > , field_index : usize ) -> EvalResult < ' tcx , Ty < ' tcx > > {
1150
1153
match ty. sty {
1151
1154
ty:: TyStruct ( adt_def, substs) => {
1152
1155
Ok ( adt_def. struct_variant ( ) . fields [ field_index] . ty ( self . tcx , substs) )
@@ -1162,7 +1165,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1162
1165
}
1163
1166
}
1164
1167
1165
- fn get_field_offset ( & self , ty : Ty < ' tcx > , field_index : usize ) -> EvalResult < Size > {
1168
+ fn get_field_offset ( & self , ty : Ty < ' tcx > , field_index : usize ) -> EvalResult < ' tcx , Size > {
1166
1169
let layout = self . type_layout ( ty) ;
1167
1170
1168
1171
use rustc:: ty:: layout:: Layout :: * ;
@@ -1179,7 +1182,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1179
1182
}
1180
1183
}
1181
1184
1182
- fn eval_operand ( & mut self , op : & mir:: Operand < ' tcx > ) -> EvalResult < Pointer > {
1185
+ fn eval_operand ( & mut self , op : & mir:: Operand < ' tcx > ) -> EvalResult < ' tcx , Pointer > {
1183
1186
use rustc:: mir:: repr:: Operand :: * ;
1184
1187
match * op {
1185
1188
Consume ( ref lvalue) => Ok ( self . eval_lvalue ( lvalue) ?. to_ptr ( ) ) ,
@@ -1213,7 +1216,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1213
1216
}
1214
1217
}
1215
1218
1216
- fn eval_lvalue ( & mut self , lvalue : & mir:: Lvalue < ' tcx > ) -> EvalResult < Lvalue > {
1219
+ fn eval_lvalue ( & mut self , lvalue : & mir:: Lvalue < ' tcx > ) -> EvalResult < ' tcx , Lvalue > {
1217
1220
use rustc:: mir:: repr:: Lvalue :: * ;
1218
1221
let ptr = match * lvalue {
1219
1222
ReturnPointer => self . frame ( ) . return_ptr
@@ -1321,7 +1324,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1321
1324
self . monomorphize ( self . mir ( ) . operand_ty ( self . tcx , operand) , self . substs ( ) )
1322
1325
}
1323
1326
1324
- fn move_ ( & mut self , src : Pointer , dest : Pointer , ty : Ty < ' tcx > ) -> EvalResult < ( ) > {
1327
+ fn move_ ( & mut self , src : Pointer , dest : Pointer , ty : Ty < ' tcx > ) -> EvalResult < ' tcx , ( ) > {
1325
1328
let size = self . type_size ( ty) ;
1326
1329
self . memory . copy ( src, dest, size) ?;
1327
1330
if self . type_needs_drop ( ty) {
@@ -1330,7 +1333,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
1330
1333
Ok ( ( ) )
1331
1334
}
1332
1335
1333
- pub fn read_primval ( & mut self , ptr : Pointer , ty : Ty < ' tcx > ) -> EvalResult < PrimVal > {
1336
+ pub fn read_primval ( & mut self , ptr : Pointer , ty : Ty < ' tcx > ) -> EvalResult < ' tcx , PrimVal > {
1334
1337
use syntax:: ast:: { IntTy , UintTy } ;
1335
1338
let val = match ( self . memory . pointer_size , & ty. sty ) {
1336
1339
( _, & ty:: TyBool ) => PrimVal :: Bool ( self . memory . read_bool ( ptr) ?) ,
0 commit comments