@@ -20,6 +20,7 @@ use rustc_hir::def_id::{DefId, CRATE_DEF_ID};
2020use rustc_hir:: { self , CoroutineDesugaring , CoroutineKind , ImplicitSelfKind } ;
2121use rustc_hir:: { self as hir, HirId } ;
2222use rustc_session:: Session ;
23+ use rustc_span:: source_map:: Spanned ;
2324use rustc_target:: abi:: { FieldIdx , VariantIdx } ;
2425
2526use polonius_engine:: Atom ;
@@ -312,6 +313,16 @@ impl<'tcx> CoroutineInfo<'tcx> {
312313 }
313314}
314315
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+
315326/// The lowered representation of a single function.
316327#[ derive( Clone , TyEncodable , TyDecodable , Debug , HashStable , TypeFoldable , TypeVisitable ) ]
317328pub struct Body < ' tcx > {
@@ -375,8 +386,24 @@ pub struct Body<'tcx> {
375386
376387 /// Constants that are required to evaluate successfully for this MIR to be well-formed.
377388 /// 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.
378392 pub required_consts : Vec < ConstOperand < ' tcx > > ,
379393
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+ /// `required_consts`.
398+ ///
399+ /// This is *not* soundness-critical and the contents of this list are *not* a stable guarantee.
400+ /// All that's relevant is that this set is optimization-level-independent, and that it includes
401+ /// everything that the collector would consider "used". (For example, we currently compute this
402+ /// set after drop elaboration, so some drop calls that can never be reached are not considered
403+ /// "mentioned".) See the documentation of `CollectionMode` in
404+ /// `compiler/rustc_monomorphize/src/collector.rs` for more context.
405+ pub mentioned_items : Vec < Spanned < MentionedItem < ' tcx > > > ,
406+
380407 /// Does this body use generic parameters. This is used for the `ConstEvaluatable` check.
381408 ///
382409 /// Note that this does not actually mean that this body is not computable right now.
@@ -453,6 +480,7 @@ impl<'tcx> Body<'tcx> {
453480 var_debug_info,
454481 span,
455482 required_consts : Vec :: new ( ) ,
483+ mentioned_items : Vec :: new ( ) ,
456484 is_polymorphic : false ,
457485 injection_phase : None ,
458486 tainted_by_errors,
@@ -482,6 +510,7 @@ impl<'tcx> Body<'tcx> {
482510 spread_arg : None ,
483511 span : DUMMY_SP ,
484512 required_consts : Vec :: new ( ) ,
513+ mentioned_items : Vec :: new ( ) ,
485514 var_debug_info : Vec :: new ( ) ,
486515 is_polymorphic : false ,
487516 injection_phase : None ,
0 commit comments