@@ -25,9 +25,9 @@ use crate::type_desc::Ownership;
25
25
use crate :: util;
26
26
use crate :: util:: Callee ;
27
27
use crate :: util:: TestAttr ;
28
- use :: log:: warn;
29
28
use c2rust_pdg:: graph:: Graphs ;
30
29
use c2rust_pdg:: info:: NodeInfo ;
30
+ use log:: { debug, info, warn} ;
31
31
use rustc_hir:: def:: DefKind ;
32
32
use rustc_hir:: def_id:: CrateNum ;
33
33
use rustc_hir:: def_id:: DefId ;
@@ -244,15 +244,15 @@ fn update_pointer_info<'tcx>(acx: &mut AnalysisCtxt<'_, 'tcx>, mir: &Body<'tcx>)
244
244
_ => continue ,
245
245
} ;
246
246
247
- eprintln ! (
247
+ debug ! (
248
248
"update_pointer_info: visit assignment: {:?}[{}]: {:?}" ,
249
249
bb, i, stmt
250
250
) ;
251
251
252
252
if !pl. is_indirect ( ) {
253
253
// This is a write directly to `pl.local`.
254
254
* write_count. entry ( pl. local ) . or_insert ( 0 ) += 1 ;
255
- eprintln ! ( " record write to LHS {:?}" , pl) ;
255
+ debug ! ( " record write to LHS {:?}" , pl) ;
256
256
}
257
257
258
258
let ref_pl = match * rv {
@@ -264,7 +264,7 @@ fn update_pointer_info<'tcx>(acx: &mut AnalysisCtxt<'_, 'tcx>, mir: &Body<'tcx>)
264
264
// For simplicity, we consider taking the address of a local to be a write. We
265
265
// expect this not to happen for the sorts of temporary refs we're looking for.
266
266
if !ref_pl. is_indirect ( ) {
267
- eprintln ! ( " record write to ref target {:?}" , ref_pl) ;
267
+ debug ! ( " record write to ref target {:?}" , ref_pl) ;
268
268
* write_count. entry ( ref_pl. local ) . or_insert ( 0 ) += 1 ;
269
269
}
270
270
@@ -385,7 +385,7 @@ fn mark_foreign_fixed<'tcx>(
385
385
let fields = adt_def. all_fields ( ) ;
386
386
for field in fields {
387
387
let field_lty = gacx. field_ltys [ & field. did ] ;
388
- eprintln ! (
388
+ debug ! (
389
389
"adding FIXED permission for {adt_did:?} field {:?}" ,
390
390
field. did
391
391
) ;
@@ -573,9 +573,9 @@ struct FuncInfo<'tcx> {
573
573
}
574
574
575
575
fn run ( tcx : TyCtxt ) {
576
- eprintln ! ( "all defs:" ) ;
576
+ debug ! ( "all defs:" ) ;
577
577
for ldid in tcx. hir_crate_items ( ( ) ) . definitions ( ) {
578
- eprintln ! ( "{:?}" , ldid) ;
578
+ debug ! ( "{:?}" , ldid) ;
579
579
}
580
580
581
581
// Load the list of fixed defs early, so any errors are reported immediately.
@@ -591,9 +591,9 @@ fn run(tcx: TyCtxt) {
591
591
// Follow a postorder traversal, so that callers are visited after their callees. This means
592
592
// callee signatures will usually be up to date when we visit the call site.
593
593
let all_fn_ldids = fn_body_owners_postorder ( tcx) ;
594
- eprintln ! ( "callgraph traversal order:" ) ;
594
+ debug ! ( "callgraph traversal order:" ) ;
595
595
for & ldid in & all_fn_ldids {
596
- eprintln ! ( " {:?}" , ldid) ;
596
+ debug ! ( " {:?}" , ldid) ;
597
597
}
598
598
599
599
populate_field_users ( & mut gacx, & all_fn_ldids) ;
@@ -629,9 +629,9 @@ fn run(tcx: TyCtxt) {
629
629
630
630
// Collect all `static` items.
631
631
let all_static_dids = all_static_items ( tcx) ;
632
- eprintln ! ( "statics:" ) ;
632
+ debug ! ( "statics:" ) ;
633
633
for & did in & all_static_dids {
634
- eprintln ! ( " {:?}" , did) ;
634
+ debug ! ( " {:?}" , did) ;
635
635
}
636
636
637
637
// Assign global `PointerId`s for types of `static` items.
@@ -834,7 +834,7 @@ fn run(tcx: TyCtxt) {
834
834
// Remap pointers based on equivalence classes, so all members of an equivalence class now use
835
835
// the same `PointerId`.
836
836
let ( global_counter, global_equiv_map) = global_equiv. renumber ( ) ;
837
- eprintln ! ( "global_equiv_map = {global_equiv_map:?}" ) ;
837
+ debug ! ( "global_equiv_map = {global_equiv_map:?}" ) ;
838
838
pointee_type:: remap_pointers_global (
839
839
& mut global_pointee_types,
840
840
& global_equiv_map,
@@ -849,7 +849,7 @@ fn run(tcx: TyCtxt) {
849
849
850
850
let info = func_info. get_mut ( & ldid) . unwrap ( ) ;
851
851
let ( local_counter, local_equiv_map) = info. local_equiv . renumber ( & global_equiv_map) ;
852
- eprintln ! ( "local_equiv_map = {local_equiv_map:?}" ) ;
852
+ debug ! ( "local_equiv_map = {local_equiv_map:?}" ) ;
853
853
pointee_type:: remap_pointers_local (
854
854
& mut global_pointee_types,
855
855
& mut info. local_pointee_types ,
@@ -1043,8 +1043,8 @@ fn run(tcx: TyCtxt) {
1043
1043
& mut g_updates_forbidden,
1044
1044
) ;
1045
1045
1046
- eprintln ! ( "=== ADT Metadata ===" ) ;
1047
- eprintln ! ( "{:?}" , gacx. adt_metadata) ;
1046
+ debug ! ( "=== ADT Metadata ===" ) ;
1047
+ debug ! ( "{:?}" , gacx. adt_metadata) ;
1048
1048
1049
1049
let mut loop_count = 0 ;
1050
1050
loop {
@@ -1110,14 +1110,14 @@ fn run(tcx: TyCtxt) {
1110
1110
let added = new & !old;
1111
1111
let removed = old & !new;
1112
1112
let kept = old & new;
1113
- eprintln ! (
1113
+ debug ! (
1114
1114
"changed {:?}: added {:?}, removed {:?}, kept {:?}" ,
1115
1115
ptr, added, removed, kept
1116
1116
) ;
1117
1117
num_changed += 1 ;
1118
1118
}
1119
1119
}
1120
- eprintln ! (
1120
+ debug ! (
1121
1121
"iteration {}: {} global pointers changed" ,
1122
1122
loop_count, num_changed
1123
1123
) ;
@@ -1126,7 +1126,7 @@ fn run(tcx: TyCtxt) {
1126
1126
break ;
1127
1127
}
1128
1128
}
1129
- eprintln ! ( "reached fixpoint in {} iterations" , loop_count) ;
1129
+ info ! ( "reached fixpoint in {} iterations" , loop_count) ;
1130
1130
1131
1131
// Do final processing on each function.
1132
1132
for & ldid in & all_fn_ldids {
@@ -1404,7 +1404,7 @@ fn run2<'tcx>(
1404
1404
assert ! ( i < 100 ) ;
1405
1405
func_reports. clear ( ) ;
1406
1406
all_rewrites. clear ( ) ;
1407
- eprintln ! ( "\n --- start rewriting ---" ) ;
1407
+ info ! ( "--- start rewriting ---" ) ;
1408
1408
1409
1409
// Update non-rewritten items first. This has two purposes. First, it clears the
1410
1410
// `new_keys()` lists, which we check at the end of the loop to see whether we've reached a
@@ -1536,7 +1536,7 @@ fn run2<'tcx>(
1536
1536
let mut adt_reports = HashMap :: < DefId , String > :: new ( ) ;
1537
1537
for & def_id in gacx. adt_metadata . table . keys ( ) {
1538
1538
if gacx. foreign_mentioned_tys . contains ( & def_id) {
1539
- eprintln ! ( "Avoiding rewrite for foreign-mentioned type: {def_id:?}" ) ;
1539
+ debug ! ( "Avoiding rewrite for foreign-mentioned type: {def_id:?}" ) ;
1540
1540
continue ;
1541
1541
}
1542
1542
if fixed_defs. contains ( & def_id) {
@@ -1587,7 +1587,7 @@ fn run2<'tcx>(
1587
1587
1588
1588
// Print labeling and rewrites for the current function.
1589
1589
1590
- eprintln ! ( "\n final labeling for {:?}:" , name) ;
1590
+ debug ! ( "\n final labeling for {:?}:" , name) ;
1591
1591
let lcx1 = crate :: labeled_ty:: LabeledTyCtxt :: new ( tcx) ;
1592
1592
let lcx2 = crate :: labeled_ty:: LabeledTyCtxt :: new ( tcx) ;
1593
1593
for ( local, decl) in mir. local_decls . iter_enumerated ( ) {
@@ -1602,12 +1602,11 @@ fn run2<'tcx>(
1602
1602
) ;
1603
1603
}
1604
1604
1605
- eprintln ! ( "\n type assignment for {:?}:" , name) ;
1605
+ debug ! ( "\n type assignment for {:?}:" , name) ;
1606
1606
rewrite:: dump_rewritten_local_tys ( & acx, & asn, pointee_types, & mir, describe_local) ;
1607
1607
1608
- eprintln ! ( ) ;
1609
1608
if let Some ( report) = func_reports. remove ( & ldid) {
1610
- eprintln ! ( "{}" , report) ;
1609
+ debug ! ( "{}" , report) ;
1611
1610
}
1612
1611
1613
1612
info. acx_data . set ( acx. into_data ( ) ) ;
@@ -1673,7 +1672,7 @@ fn run2<'tcx>(
1673
1672
}
1674
1673
1675
1674
// Print results for `static` items.
1676
- eprintln ! ( "\n final labeling for static items:" ) ;
1675
+ debug ! ( "\n final labeling for static items:" ) ;
1677
1676
let lcx1 = crate :: labeled_ty:: LabeledTyCtxt :: new ( tcx) ;
1678
1677
let lcx2 = crate :: labeled_ty:: LabeledTyCtxt :: new ( tcx) ;
1679
1678
let mut static_dids = gacx. static_tys . keys ( ) . cloned ( ) . collect :: < Vec < _ > > ( ) ;
@@ -1691,10 +1690,10 @@ fn run2<'tcx>(
1691
1690
& gasn. flags ,
1692
1691
) ;
1693
1692
}
1694
- eprintln ! ( "\n {statics_report}" ) ;
1693
+ debug ! ( "\n {statics_report}" ) ;
1695
1694
1696
1695
// Print results for ADTs and fields
1697
- eprintln ! ( "\n final labeling for fields:" ) ;
1696
+ debug ! ( "\n final labeling for fields:" ) ;
1698
1697
let mut field_dids = gacx. field_ltys . keys ( ) . cloned ( ) . collect :: < Vec < _ > > ( ) ;
1699
1698
field_dids. sort ( ) ;
1700
1699
for did in field_dids {
@@ -1704,7 +1703,7 @@ fn run2<'tcx>(
1704
1703
if pid != PointerId :: NONE {
1705
1704
let ty_perms = gasn. perms [ pid] ;
1706
1705
let ty_flags = gasn. flags [ pid] ;
1707
- eprintln ! ( "{name:}: ({pid}) perms = {ty_perms:?}, flags = {ty_flags:?}" ) ;
1706
+ debug ! ( "{name:}: ({pid}) perms = {ty_perms:?}, flags = {ty_flags:?}" ) ;
1708
1707
}
1709
1708
1710
1709
// Emit annotations for fields
@@ -1739,7 +1738,7 @@ fn run2<'tcx>(
1739
1738
adt_dids. sort ( ) ;
1740
1739
for did in adt_dids {
1741
1740
if let Some ( report) = adt_reports. remove ( & did) {
1742
- eprintln ! ( "\n {}" , report) ;
1741
+ debug ! ( "\n {}" , report) ;
1743
1742
}
1744
1743
}
1745
1744
@@ -1778,17 +1777,17 @@ fn run2<'tcx>(
1778
1777
// ----------------------------------
1779
1778
1780
1779
// Report errors that were caught previously
1781
- eprintln ! ( "\n error details:" ) ;
1780
+ debug ! ( "\n error details:" ) ;
1782
1781
for ldid in tcx. hir ( ) . body_owners ( ) {
1783
1782
if let Some ( detail) = gacx. fns_failed . get ( & ldid. to_def_id ( ) ) {
1784
1783
if !detail. has_backtrace ( ) {
1785
1784
continue ;
1786
1785
}
1787
- eprintln ! ( "\n error in {:?}:\n {}" , ldid, detail. to_string_full( ) ) ;
1786
+ debug ! ( "\n error in {:?}:{}" , ldid, detail. to_string_full( ) ) ;
1788
1787
}
1789
1788
}
1790
1789
1791
- eprintln ! ( "\n error summary:" ) ;
1790
+ debug ! ( "\n error summary:" ) ;
1792
1791
fn sorted_def_ids ( it : impl IntoIterator < Item = DefId > ) -> Vec < DefId > {
1793
1792
let mut v = it. into_iter ( ) . collect :: < Vec < _ > > ( ) ;
1794
1793
v. sort ( ) ;
@@ -1802,27 +1801,27 @@ fn run2<'tcx>(
1802
1801
Some ( detail) => detail. to_string_short ( ) ,
1803
1802
None => "(no panic)" . into ( ) ,
1804
1803
} ;
1805
- eprintln ! ( "analysis of {def_id:?} failed: {flags:?}, {detail_str}" ) ;
1804
+ debug ! ( "analysis of {def_id:?} failed: {flags:?}, {detail_str}" ) ;
1806
1805
}
1807
1806
1808
1807
for def_id in sorted_def_ids ( gacx. dont_rewrite_statics . keys ( ) ) {
1809
1808
let flags = gacx. dont_rewrite_statics . get ( def_id) ;
1810
- eprintln ! ( "analysis of {def_id:?} failed: {flags:?}" ) ;
1809
+ debug ! ( "analysis of {def_id:?} failed: {flags:?}" ) ;
1811
1810
}
1812
1811
1813
1812
for def_id in sorted_def_ids ( gacx. dont_rewrite_fields . keys ( ) ) {
1814
1813
let flags = gacx. dont_rewrite_fields . get ( def_id) ;
1815
- eprintln ! ( "analysis of {def_id:?} failed: {flags:?}" ) ;
1814
+ debug ! ( "analysis of {def_id:?} failed: {flags:?}" ) ;
1816
1815
}
1817
1816
1818
- eprintln ! (
1817
+ info ! (
1819
1818
"\n saw errors in {} / {} functions" ,
1820
1819
gacx. fns_failed. len( ) ,
1821
1820
all_fn_ldids. len( )
1822
1821
) ;
1823
1822
1824
1823
if !known_perm_error_fns. is_empty ( ) {
1825
- eprintln ! (
1824
+ info ! (
1826
1825
"saw permission errors in {} known fns" ,
1827
1826
known_perm_error_fns. len( )
1828
1827
) ;
@@ -2184,7 +2183,7 @@ fn print_labeling_for_var<'tcx>(
2184
2183
perms[ lty. label ]
2185
2184
}
2186
2185
} ) ;
2187
- eprintln ! ( "{}: addr_of = {:?}, type = {:?}" , desc, addr_of1, ty1) ;
2186
+ debug ! ( "{}: addr_of = {:?}, type = {:?}" , desc, addr_of1, ty1) ;
2188
2187
2189
2188
let addr_of2 = flags[ addr_of_ptr] ;
2190
2189
let ty2 = lcx2. relabel ( lty, & mut |lty| {
@@ -2194,14 +2193,14 @@ fn print_labeling_for_var<'tcx>(
2194
2193
flags[ lty. label ]
2195
2194
}
2196
2195
} ) ;
2197
- eprintln ! (
2196
+ debug ! (
2198
2197
"{}: addr_of flags = {:?}, type flags = {:?}" ,
2199
2198
desc, addr_of2, ty2
2200
2199
) ;
2201
2200
2202
2201
let addr_of3 = addr_of_ptr;
2203
2202
let ty3 = lty;
2204
- eprintln ! ( "{}: addr_of = {:?}, type = {:?}" , desc, addr_of3, ty3) ;
2203
+ debug ! ( "{}: addr_of = {:?}, type = {:?}" , desc, addr_of3, ty3) ;
2205
2204
}
2206
2205
2207
2206
fn print_function_pointee_types < ' tcx > (
@@ -2210,9 +2209,9 @@ fn print_function_pointee_types<'tcx>(
2210
2209
mir : & Body < ' tcx > ,
2211
2210
pointee_types : PointerTable < PointeeTypes < ' tcx > > ,
2212
2211
) {
2213
- eprintln ! ( "\n pointee types for {}" , name) ;
2212
+ debug ! ( "\n pointee types for {}" , name) ;
2214
2213
for ( local, decl) in mir. local_decls . iter_enumerated ( ) {
2215
- eprintln ! (
2214
+ debug ! (
2216
2215
"{:?} ({}): addr_of = {:?}, type = {:?}" ,
2217
2216
local,
2218
2217
describe_local( acx. tcx( ) , decl) ,
@@ -2235,7 +2234,7 @@ fn print_function_pointee_types<'tcx>(
2235
2234
if tys. ltys . is_empty ( ) && !tys. incomplete {
2236
2235
continue ;
2237
2236
}
2238
- eprintln ! (
2237
+ debug ! (
2239
2238
" pointer {:?}: {:?}{}" ,
2240
2239
ptr,
2241
2240
tys. ltys,
0 commit comments