@@ -383,23 +383,25 @@ pub struct Body<'tcx> {
383
383
384
384
/// Constants that are required to evaluate successfully for this MIR to be well-formed.
385
385
/// We hold in this field all the constants we are not able to evaluate yet.
386
+ /// `None` indicates that the list has not been computed yet.
386
387
///
387
388
/// This is soundness-critical, we make a guarantee that all consts syntactically mentioned in a
388
389
/// function have successfully evaluated if the function ever gets executed at runtime.
389
- pub required_consts : Vec < ConstOperand < ' tcx > > ,
390
+ pub required_consts : Option < Vec < ConstOperand < ' tcx > > > ,
390
391
391
392
/// Further items that were mentioned in this function and hence *may* become monomorphized,
392
393
/// depending on optimizations. We use this to avoid optimization-dependent compile errors: the
393
394
/// collector recursively traverses all "mentioned" items and evaluates all their
394
395
/// `required_consts`.
396
+ /// `None` indicates that the list has not been computed yet.
395
397
///
396
398
/// This is *not* soundness-critical and the contents of this list are *not* a stable guarantee.
397
399
/// All that's relevant is that this set is optimization-level-independent, and that it includes
398
400
/// everything that the collector would consider "used". (For example, we currently compute this
399
401
/// set after drop elaboration, so some drop calls that can never be reached are not considered
400
402
/// "mentioned".) See the documentation of `CollectionMode` in
401
403
/// `compiler/rustc_monomorphize/src/collector.rs` for more context.
402
- pub mentioned_items : Vec < Spanned < MentionedItem < ' tcx > > > ,
404
+ pub mentioned_items : Option < Vec < Spanned < MentionedItem < ' tcx > > > > ,
403
405
404
406
/// Does this body use generic parameters. This is used for the `ConstEvaluatable` check.
405
407
///
@@ -477,8 +479,8 @@ impl<'tcx> Body<'tcx> {
477
479
spread_arg : None ,
478
480
var_debug_info,
479
481
span,
480
- required_consts : Vec :: new ( ) ,
481
- mentioned_items : Vec :: new ( ) ,
482
+ required_consts : None ,
483
+ mentioned_items : None ,
482
484
is_polymorphic : false ,
483
485
injection_phase : None ,
484
486
tainted_by_errors,
@@ -507,8 +509,8 @@ impl<'tcx> Body<'tcx> {
507
509
arg_count : 0 ,
508
510
spread_arg : None ,
509
511
span : DUMMY_SP ,
510
- required_consts : Vec :: new ( ) ,
511
- mentioned_items : Vec :: new ( ) ,
512
+ required_consts : None ,
513
+ mentioned_items : None ,
512
514
var_debug_info : Vec :: new ( ) ,
513
515
is_polymorphic : false ,
514
516
injection_phase : None ,
@@ -785,6 +787,40 @@ impl<'tcx> Body<'tcx> {
785
787
// No inlined `SourceScope`s, or all of them were `#[track_caller]`.
786
788
caller_location. unwrap_or_else ( || from_span ( source_info. span ) )
787
789
}
790
+
791
+ #[ track_caller]
792
+ pub fn set_required_consts ( & mut self , required_consts : Vec < ConstOperand < ' tcx > > ) {
793
+ assert ! (
794
+ self . required_consts. is_none( ) ,
795
+ "required_consts for {:?} have already been set" ,
796
+ self . source. def_id( )
797
+ ) ;
798
+ self . required_consts = Some ( required_consts) ;
799
+ }
800
+ #[ track_caller]
801
+ pub fn required_consts ( & self ) -> & [ ConstOperand < ' tcx > ] {
802
+ match & self . required_consts {
803
+ Some ( l) => l,
804
+ None => panic ! ( "required_consts for {:?} have not yet been set" , self . source. def_id( ) ) ,
805
+ }
806
+ }
807
+
808
+ #[ track_caller]
809
+ pub fn set_mentioned_items ( & mut self , mentioned_items : Vec < Spanned < MentionedItem < ' tcx > > > ) {
810
+ assert ! (
811
+ self . mentioned_items. is_none( ) ,
812
+ "mentioned_items for {:?} have already been set" ,
813
+ self . source. def_id( )
814
+ ) ;
815
+ self . mentioned_items = Some ( mentioned_items) ;
816
+ }
817
+ #[ track_caller]
818
+ pub fn mentioned_items ( & self ) -> & [ Spanned < MentionedItem < ' tcx > > ] {
819
+ match & self . mentioned_items {
820
+ Some ( l) => l,
821
+ None => panic ! ( "mentioned_items for {:?} have not yet been set" , self . source. def_id( ) ) ,
822
+ }
823
+ }
788
824
}
789
825
790
826
impl < ' tcx > Index < BasicBlock > for Body < ' tcx > {
0 commit comments