@@ -5,6 +5,7 @@ use rustc::mir;
55use rustc:: ty:: { self , TyCtxt , Ty , Instance } ;
66use rustc:: ty:: layout:: { self , LayoutOf } ;
77use rustc:: ty:: subst:: Subst ;
8+ use rustc:: util:: nodemap:: FxHashSet ;
89
910use syntax:: ast:: Mutability ;
1011use syntax:: codemap:: Span ;
@@ -504,7 +505,13 @@ pub fn const_eval_provider<'a, 'tcx>(
504505 } ;
505506
506507 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+ }
508515 tcx. mk_const ( ty:: Const {
509516 val : ConstVal :: Value ( miri_value) ,
510517 ty : miri_ty,
@@ -521,3 +528,24 @@ pub fn const_eval_provider<'a, 'tcx>(
521528 }
522529 } )
523530}
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