1
1
use rustc_abi:: { BackendRepr , VariantIdx } ;
2
2
use rustc_data_structures:: stack:: ensure_sufficient_stack;
3
- use rustc_middle:: mir:: interpret:: { EvalToValTreeResult , GlobalId , ReportedErrorInfo } ;
3
+ use rustc_middle:: mir:: interpret:: { EvalToValTreeResult , GlobalId , ValTreeCreationError } ;
4
4
use rustc_middle:: ty:: layout:: { LayoutCx , LayoutOf , TyAndLayout } ;
5
5
use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
6
6
use rustc_middle:: { bug, mir} ;
7
7
use rustc_span:: DUMMY_SP ;
8
8
use tracing:: { debug, instrument, trace} ;
9
9
10
+ use super :: VALTREE_MAX_NODES ;
10
11
use super :: eval_queries:: { mk_eval_cx_to_read_const_val, op_to_const} ;
11
12
use super :: machine:: CompileTimeInterpCx ;
12
- use super :: { VALTREE_MAX_NODES , ValTreeCreationError , ValTreeCreationResult } ;
13
13
use crate :: const_eval:: CanAccessMutGlobal ;
14
- use crate :: errors:: MaxNumNodesInConstErr ;
15
14
use crate :: interpret:: {
16
15
ImmTy , Immediate , InternKind , MPlaceTy , MemPlaceMeta , MemoryKind , PlaceTy , Projectable , Scalar ,
17
16
intern_const_alloc_recursive,
@@ -24,7 +23,7 @@ fn branches<'tcx>(
24
23
field_count : usize ,
25
24
variant : Option < VariantIdx > ,
26
25
num_nodes : & mut usize ,
27
- ) -> ValTreeCreationResult < ' tcx > {
26
+ ) -> EvalToValTreeResult < ' tcx > {
28
27
let place = match variant {
29
28
Some ( variant) => ecx. project_downcast ( place, variant) . unwrap ( ) ,
30
29
None => place. clone ( ) ,
@@ -58,7 +57,7 @@ fn slice_branches<'tcx>(
58
57
ecx : & CompileTimeInterpCx < ' tcx > ,
59
58
place : & MPlaceTy < ' tcx > ,
60
59
num_nodes : & mut usize ,
61
- ) -> ValTreeCreationResult < ' tcx > {
60
+ ) -> EvalToValTreeResult < ' tcx > {
62
61
let n = place. len ( ecx) . unwrap_or_else ( |_| panic ! ( "expected to use len of place {place:?}" ) ) ;
63
62
64
63
let mut elems = Vec :: with_capacity ( n as usize ) ;
@@ -76,7 +75,7 @@ fn const_to_valtree_inner<'tcx>(
76
75
ecx : & CompileTimeInterpCx < ' tcx > ,
77
76
place : & MPlaceTy < ' tcx > ,
78
77
num_nodes : & mut usize ,
79
- ) -> ValTreeCreationResult < ' tcx > {
78
+ ) -> EvalToValTreeResult < ' tcx > {
80
79
let tcx = * ecx. tcx ;
81
80
let ty = place. layout . ty ;
82
81
debug ! ( "ty kind: {:?}" , ty. kind( ) ) ;
@@ -91,7 +90,7 @@ fn const_to_valtree_inner<'tcx>(
91
90
Ok ( ty:: ValTree :: zst ( tcx) )
92
91
}
93
92
ty:: Bool | ty:: Int ( _) | ty:: Uint ( _) | ty:: Float ( _) | ty:: Char => {
94
- let val = ecx. read_immediate ( place) . unwrap ( ) ;
93
+ let val = ecx. read_immediate ( place) . report_err ( ) ? ;
95
94
let val = val. to_scalar_int ( ) . unwrap ( ) ;
96
95
* num_nodes += 1 ;
97
96
@@ -113,7 +112,7 @@ fn const_to_valtree_inner<'tcx>(
113
112
// equality at compile-time (see `ptr_guaranteed_cmp`).
114
113
// However we allow those that are just integers in disguise.
115
114
// First, get the pointer. Remember it might be wide!
116
- let val = ecx. read_immediate ( place) . unwrap ( ) ;
115
+ let val = ecx. read_immediate ( place) . report_err ( ) ? ;
117
116
// We could allow wide raw pointers where both sides are integers in the future,
118
117
// but for now we reject them.
119
118
if matches ! ( val. layout. backend_repr, BackendRepr :: ScalarPair ( ..) ) {
@@ -134,7 +133,7 @@ fn const_to_valtree_inner<'tcx>(
134
133
ty:: FnPtr ( ..) => Err ( ValTreeCreationError :: NonSupportedType ( ty) ) ,
135
134
136
135
ty:: Ref ( _, _, _) => {
137
- let derefd_place = ecx. deref_pointer ( place) . unwrap ( ) ;
136
+ let derefd_place = ecx. deref_pointer ( place) . report_err ( ) ? ;
138
137
const_to_valtree_inner ( ecx, & derefd_place, num_nodes)
139
138
}
140
139
@@ -158,7 +157,7 @@ fn const_to_valtree_inner<'tcx>(
158
157
bug ! ( "uninhabited types should have errored and never gotten converted to valtree" )
159
158
}
160
159
161
- let variant = ecx. read_discriminant ( place) . unwrap ( ) ;
160
+ let variant = ecx. read_discriminant ( place) . report_err ( ) ? ;
162
161
branches ( ecx, place, def. variant ( variant) . fields . len ( ) , def. is_enum ( ) . then_some ( variant) , num_nodes)
163
162
}
164
163
@@ -249,24 +248,7 @@ pub(crate) fn eval_to_valtree<'tcx>(
249
248
debug ! ( ?place) ;
250
249
251
250
let mut num_nodes = 0 ;
252
- let valtree_result = const_to_valtree_inner ( & ecx, & place, & mut num_nodes) ;
253
-
254
- match valtree_result {
255
- Ok ( valtree) => Ok ( Ok ( valtree) ) ,
256
- Err ( err) => {
257
- let did = cid. instance . def_id ( ) ;
258
- let global_const_id = cid. display ( tcx) ;
259
- let span = tcx. hir_span_if_local ( did) ;
260
- match err {
261
- ValTreeCreationError :: NodesOverflow => {
262
- let handled =
263
- tcx. dcx ( ) . emit_err ( MaxNumNodesInConstErr { span, global_const_id } ) ;
264
- Err ( ReportedErrorInfo :: allowed_in_infallible ( handled) . into ( ) )
265
- }
266
- ValTreeCreationError :: NonSupportedType ( ty) => Ok ( Err ( ty) ) ,
267
- }
268
- }
269
- }
251
+ const_to_valtree_inner ( & ecx, & place, & mut num_nodes)
270
252
}
271
253
272
254
/// Converts a `ValTree` to a `ConstValue`, which is needed after mir
0 commit comments