@@ -20,6 +20,7 @@ use rustc_hir::def_id::{DefId, CRATE_DEF_ID};
20
20
use rustc_hir:: { self , CoroutineDesugaring , CoroutineKind , ImplicitSelfKind } ;
21
21
use rustc_hir:: { self as hir, HirId } ;
22
22
use rustc_session:: Session ;
23
+ use rustc_span:: source_map:: Spanned ;
23
24
use rustc_target:: abi:: { FieldIdx , VariantIdx } ;
24
25
25
26
use polonius_engine:: Atom ;
@@ -312,6 +313,16 @@ impl<'tcx> CoroutineInfo<'tcx> {
312
313
}
313
314
}
314
315
316
+ /// Some item that needs to monomorphize successfully for a MIR body to be considered well-formed.
317
+ #[ derive( Copy , Clone , PartialEq , Debug , HashStable , TyEncodable , TyDecodable ) ]
318
+ #[ derive( TypeFoldable , TypeVisitable ) ]
319
+ pub enum MentionedItem < ' tcx > {
320
+ Fn ( DefId , GenericArgsRef < ' tcx > ) ,
321
+ Drop ( Ty < ' tcx > ) ,
322
+ // FIXME: add Vtable { source_ty: Ty<'tcx>, target_ty: Ty<'tcx> },
323
+ // FIXME: do we have to add closures?
324
+ }
325
+
315
326
/// The lowered representation of a single function.
316
327
#[ derive( Clone , TyEncodable , TyDecodable , Debug , HashStable , TypeFoldable , TypeVisitable ) ]
317
328
pub struct Body < ' tcx > {
@@ -375,8 +386,18 @@ pub struct Body<'tcx> {
375
386
376
387
/// Constants that are required to evaluate successfully for this MIR to be well-formed.
377
388
/// We hold in this field all the constants we are not able to evaluate yet.
389
+ ///
390
+ /// This is soundness-critical, we make a guarantee that all consts syntactically mentioned in a
391
+ /// function have successfully evaluated if the function ever gets xecuted at runtime.
378
392
pub required_consts : Vec < ConstOperand < ' tcx > > ,
379
393
394
+ /// Further items that were mentioned in this function and hence *may* become monomorphized,
395
+ /// depending on optimizations. We use this to ensure their consts evaluate successfully even if
396
+ /// they do not get monomorphized, to avoid optimization-dependent compile errors.
397
+ ///
398
+ /// This is *not* soundness-critical and the contents of this list are *not* a stable guarantee.
399
+ pub mentioned_items : Vec < Spanned < MentionedItem < ' tcx > > > ,
400
+
380
401
/// Does this body use generic parameters. This is used for the `ConstEvaluatable` check.
381
402
///
382
403
/// Note that this does not actually mean that this body is not computable right now.
@@ -453,6 +474,7 @@ impl<'tcx> Body<'tcx> {
453
474
var_debug_info,
454
475
span,
455
476
required_consts : Vec :: new ( ) ,
477
+ mentioned_items : Vec :: new ( ) ,
456
478
is_polymorphic : false ,
457
479
injection_phase : None ,
458
480
tainted_by_errors,
@@ -482,6 +504,7 @@ impl<'tcx> Body<'tcx> {
482
504
spread_arg : None ,
483
505
span : DUMMY_SP ,
484
506
required_consts : Vec :: new ( ) ,
507
+ mentioned_items : Vec :: new ( ) ,
485
508
var_debug_info : Vec :: new ( ) ,
486
509
is_polymorphic : false ,
487
510
injection_phase : None ,
0 commit comments