@@ -138,55 +138,77 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
138
138
. unwrap_or_else ( || panic ! ( "failed to find required Rust item: {path:?}" ) )
139
139
}
140
140
141
- /// Evaluates the scalar at the specified path. Returns Some(val)
142
- /// if the path could be resolved, and None otherwise
143
- fn eval_path_scalar ( & self , path : & [ & str ] ) -> InterpResult < ' tcx , Scalar < Provenance > > {
141
+ /// Evaluates the scalar at the specified path.
142
+ fn eval_path_scalar ( & self , path : & [ & str ] ) -> Scalar < Provenance > {
144
143
let this = self . eval_context_ref ( ) ;
145
144
let instance = this. resolve_path ( path, Namespace :: ValueNS ) ;
146
145
let cid = GlobalId { instance, promoted : None } ;
147
146
// We don't give a span -- this isn't actually used directly by the program anyway.
148
- let const_val = this. eval_global ( cid, None ) ?;
147
+ let const_val = this
148
+ . eval_global ( cid, None )
149
+ . unwrap_or_else ( |err| panic ! ( "failed to evaluate required Rust item: {path:?}\n {err}" ) ) ;
149
150
this. read_scalar ( & const_val. into ( ) )
151
+ . unwrap_or_else ( |err| panic ! ( "failed to read required Rust item: {path:?}\n {err}" ) )
150
152
}
151
153
152
154
/// Helper function to get a `libc` constant as a `Scalar`.
153
- fn eval_libc ( & self , name : & str ) -> InterpResult < ' tcx , Scalar < Provenance > > {
155
+ fn eval_libc ( & self , name : & str ) -> Scalar < Provenance > {
154
156
self . eval_path_scalar ( & [ "libc" , name] )
155
157
}
156
158
157
159
/// Helper function to get a `libc` constant as an `i32`.
158
- fn eval_libc_i32 ( & self , name : & str ) -> InterpResult < ' tcx , i32 > {
160
+ fn eval_libc_i32 ( & self , name : & str ) -> i32 {
159
161
// TODO: Cache the result.
160
- self . eval_libc ( name) ?. to_i32 ( )
162
+ self . eval_libc ( name) . to_i32 ( ) . unwrap_or_else ( |_err| {
163
+ panic ! ( "required libc item has unexpected type (not `i32`): {name}" )
164
+ } )
165
+ }
166
+
167
+ /// Helper function to get a `libc` constant as an `u32`.
168
+ fn eval_libc_u32 ( & self , name : & str ) -> u32 {
169
+ // TODO: Cache the result.
170
+ self . eval_libc ( name) . to_u32 ( ) . unwrap_or_else ( |_err| {
171
+ panic ! ( "required libc item has unexpected type (not `u32`): {name}" )
172
+ } )
161
173
}
162
174
163
175
/// Helper function to get a `windows` constant as a `Scalar`.
164
- fn eval_windows ( & self , module : & str , name : & str ) -> InterpResult < ' tcx , Scalar < Provenance > > {
176
+ fn eval_windows ( & self , module : & str , name : & str ) -> Scalar < Provenance > {
165
177
self . eval_context_ref ( ) . eval_path_scalar ( & [ "std" , "sys" , "windows" , module, name] )
166
178
}
167
179
180
+ /// Helper function to get a `windows` constant as a `u32`.
181
+ fn eval_windows_u32 ( & self , module : & str , name : & str ) -> u32 {
182
+ // TODO: Cache the result.
183
+ self . eval_windows ( module, name) . to_u32 ( ) . unwrap_or_else ( |_err| {
184
+ panic ! ( "required Windows item has unexpected type (not `u32`): {module}::{name}" )
185
+ } )
186
+ }
187
+
168
188
/// Helper function to get a `windows` constant as a `u64`.
169
- fn eval_windows_u64 ( & self , module : & str , name : & str ) -> InterpResult < ' tcx , u64 > {
189
+ fn eval_windows_u64 ( & self , module : & str , name : & str ) -> u64 {
170
190
// TODO: Cache the result.
171
- self . eval_windows ( module, name) ?. to_u64 ( )
191
+ self . eval_windows ( module, name) . to_u64 ( ) . unwrap_or_else ( |_err| {
192
+ panic ! ( "required Windows item has unexpected type (not `u64`): {module}::{name}" )
193
+ } )
172
194
}
173
195
174
196
/// Helper function to get the `TyAndLayout` of a `libc` type
175
- fn libc_ty_layout ( & self , name : & str ) -> InterpResult < ' tcx , TyAndLayout < ' tcx > > {
197
+ fn libc_ty_layout ( & self , name : & str ) -> TyAndLayout < ' tcx > {
176
198
let this = self . eval_context_ref ( ) ;
177
199
let ty = this
178
200
. resolve_path ( & [ "libc" , name] , Namespace :: TypeNS )
179
201
. ty ( * this. tcx , ty:: ParamEnv :: reveal_all ( ) ) ;
180
- this. layout_of ( ty)
202
+ this. layout_of ( ty) . unwrap ( )
181
203
}
182
204
183
205
/// Helper function to get the `TyAndLayout` of a `windows` type
184
- fn windows_ty_layout ( & self , name : & str ) -> InterpResult < ' tcx , TyAndLayout < ' tcx > > {
206
+ fn windows_ty_layout ( & self , name : & str ) -> TyAndLayout < ' tcx > {
185
207
let this = self . eval_context_ref ( ) ;
186
208
let ty = this
187
209
. resolve_path ( & [ "std" , "sys" , "windows" , "c" , name] , Namespace :: TypeNS )
188
210
. ty ( * this. tcx , ty:: ParamEnv :: reveal_all ( ) ) ;
189
- this. layout_of ( ty)
211
+ this. layout_of ( ty) . unwrap ( )
190
212
}
191
213
192
214
/// Project to the given *named* field of the mplace (which must be a struct or union type).
@@ -609,14 +631,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
609
631
if target. families . iter ( ) . any ( |f| f == "unix" ) {
610
632
for & ( name, kind) in UNIX_IO_ERROR_TABLE {
611
633
if err_kind == kind {
612
- return this. eval_libc ( name) ;
634
+ return Ok ( this. eval_libc ( name) ) ;
613
635
}
614
636
}
615
637
throw_unsup_format ! ( "io error {:?} cannot be translated into a raw os error" , err_kind)
616
638
} else if target. families . iter ( ) . any ( |f| f == "windows" ) {
617
639
// FIXME: we have to finish implementing the Windows equivalent of this.
618
640
use std:: io:: ErrorKind :: * ;
619
- this. eval_windows (
641
+ Ok ( this. eval_windows (
620
642
"c" ,
621
643
match err_kind {
622
644
NotFound => "ERROR_FILE_NOT_FOUND" ,
@@ -627,7 +649,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
627
649
err_kind
628
650
) ,
629
651
} ,
630
- )
652
+ ) )
631
653
} else {
632
654
throw_unsup_format ! (
633
655
"converting io::Error into errnum is unsupported for OS {}" ,
@@ -647,7 +669,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
647
669
if target. families . iter ( ) . any ( |f| f == "unix" ) {
648
670
let errnum = errnum. to_i32 ( ) ?;
649
671
for & ( name, kind) in UNIX_IO_ERROR_TABLE {
650
- if errnum == this. eval_libc_i32 ( name) ? {
672
+ if errnum == this. eval_libc_i32 ( name) {
651
673
return Ok ( Some ( kind) ) ;
652
674
}
653
675
}
0 commit comments