@@ -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,21 @@ 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 executed 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 avoid optimization-dependent compile errors: the
396
+ /// collector recursively traverses all "mentioned" items and evaluates all their
397
+ /// `requiered_consts`.
398
+ ///
399
+ /// This is *not* soundness-critical and the contents of this list are *not* a stable guarantee.
400
+ /// See the documentation of `CollectionMode` in `compiler/rustc_monomorphize/src/collector.rs`
401
+ /// for more context.
402
+ pub mentioned_items : Vec < Spanned < MentionedItem < ' tcx > > > ,
403
+
380
404
/// Does this body use generic parameters. This is used for the `ConstEvaluatable` check.
381
405
///
382
406
/// Note that this does not actually mean that this body is not computable right now.
@@ -453,6 +477,7 @@ impl<'tcx> Body<'tcx> {
453
477
var_debug_info,
454
478
span,
455
479
required_consts : Vec :: new ( ) ,
480
+ mentioned_items : Vec :: new ( ) ,
456
481
is_polymorphic : false ,
457
482
injection_phase : None ,
458
483
tainted_by_errors,
@@ -482,6 +507,7 @@ impl<'tcx> Body<'tcx> {
482
507
spread_arg : None ,
483
508
span : DUMMY_SP ,
484
509
required_consts : Vec :: new ( ) ,
510
+ mentioned_items : Vec :: new ( ) ,
485
511
var_debug_info : Vec :: new ( ) ,
486
512
is_polymorphic : false ,
487
513
injection_phase : None ,
0 commit comments