@@ -5,6 +5,7 @@ use rustc::mir;
5
5
use rustc:: ty:: { self , TyCtxt , Ty , Instance } ;
6
6
use rustc:: ty:: layout:: { self , LayoutOf } ;
7
7
use rustc:: ty:: subst:: Subst ;
8
+ use rustc:: util:: nodemap:: FxHashSet ;
8
9
9
10
use syntax:: ast:: Mutability ;
10
11
use syntax:: codemap:: Span ;
@@ -504,7 +505,13 @@ pub fn const_eval_provider<'a, 'tcx>(
504
505
} ;
505
506
506
507
let ( res, ecx) = eval_body_and_ecx ( tcx, cid, None , key. param_env ) ;
507
- res. map ( |( miri_value, _, miri_ty) | {
508
+ res. map ( |( miri_value, ptr, miri_ty) | {
509
+ if tcx. is_static ( def_id) . is_some ( ) {
510
+ if let Ok ( ptr) = ptr. primval . to_ptr ( ) {
511
+ let mut seen = FxHashSet :: default ( ) ;
512
+ create_depgraph_edges ( tcx, ptr. alloc_id , & mut seen) ;
513
+ }
514
+ }
508
515
tcx. mk_const ( ty:: Const {
509
516
val : ConstVal :: Value ( miri_value) ,
510
517
ty : miri_ty,
@@ -521,3 +528,24 @@ pub fn const_eval_provider<'a, 'tcx>(
521
528
}
522
529
} )
523
530
}
531
+
532
+ fn create_depgraph_edges < ' a , ' tcx > (
533
+ tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
534
+ alloc_id : AllocId ,
535
+ seen : & mut FxHashSet < AllocId > ,
536
+ ) {
537
+ trace ! ( "create_depgraph_edges: {:?}, {:?}" , alloc_id, seen) ;
538
+ if seen. insert ( alloc_id) {
539
+ trace ! ( "seen: {:?}, {:?}" , alloc_id, seen) ;
540
+ if let Some ( alloc) = tcx. interpret_interner . get_alloc ( alloc_id) {
541
+ trace ! ( "get_alloc: {:?}, {:?}, {:?}" , alloc_id, seen, alloc) ;
542
+ for ( _, & reloc) in & alloc. relocations {
543
+ if let Some ( did) = tcx. interpret_interner . get_corresponding_static_def_id ( reloc) {
544
+ trace ! ( "get_corresponding: {:?}, {:?}, {:?}, {:?}, {:?}" , alloc_id, seen, alloc, did, reloc) ;
545
+ let _ = tcx. maybe_optimized_mir ( did) ;
546
+ }
547
+ create_depgraph_edges ( tcx, reloc, seen) ;
548
+ }
549
+ }
550
+ }
551
+ }
0 commit comments