@@ -51,6 +51,7 @@ use rustc_interface::{Linker, Queries, interface, passes};
51
51
use rustc_lint:: unerased_lint_store;
52
52
use rustc_metadata:: creader:: MetadataLoader ;
53
53
use rustc_metadata:: locator;
54
+ use rustc_middle:: ty:: TyCtxt ;
54
55
use rustc_parse:: { new_parser_from_file, new_parser_from_source_str, unwrap_or_emit_fatal} ;
55
56
use rustc_session:: config:: {
56
57
CG_OPTIONS , ErrorOutputType , Input , OutFileName , OutputType , UnstableOptions , Z_OPTIONS ,
@@ -103,7 +104,7 @@ mod signal_handler {
103
104
104
105
use crate :: session_diagnostics:: {
105
106
RLinkEmptyVersionNumber , RLinkEncodingVersionMismatch , RLinkRustcVersionMismatch ,
106
- RLinkWrongFileType , RlinkCorruptFile , RlinkNotAFile , RlinkUnableToRead ,
107
+ RLinkWrongFileType , RlinkCorruptFile , RlinkNotAFile , RlinkUnableToRead , UnstableFeatureUsage ,
107
108
} ;
108
109
109
110
rustc_fluent_macro:: fluent_messages! { "../messages.ftl" }
@@ -431,6 +432,10 @@ fn run_compiler(
431
432
// Make sure name resolution and macro expansion is run.
432
433
queries. global_ctxt( ) ?. enter( |tcx| tcx. resolver_for_lowering( ) ) ;
433
434
435
+ if let Some ( metrics_dir) = & sess. opts. unstable_opts. metrics_dir {
436
+ queries. global_ctxt( ) ?. enter( |tcxt| dump_feature_usage_metrics( tcxt, metrics_dir) ) ;
437
+ }
438
+
434
439
if callbacks. after_expansion( compiler, queries) == Compilation :: Stop {
435
440
return early_exit( ) ;
436
441
}
@@ -475,6 +480,23 @@ fn run_compiler(
475
480
} )
476
481
}
477
482
483
+ fn dump_feature_usage_metrics( tcxt: TyCtxt <' _>, metrics_dir: & PathBuf ) {
484
+ let output_filenames = tcxt. output_filenames( ( ) ) ;
485
+ let mut metrics_file_name = std:: ffi:: OsString :: from( "unstable_feature_usage_metrics-" ) ;
486
+ let mut metrics_path = output_filenames. with_directory_and_extension( metrics_dir, "json" ) ;
487
+ let metrics_file_stem =
488
+ metrics_path. file_name( ) . expect( "there should be a valid default output filename" ) ;
489
+ metrics_file_name. push( metrics_file_stem) ;
490
+ metrics_path. pop( ) ;
491
+ metrics_path. push( metrics_file_name) ;
492
+ if let Err ( error) = tcxt. features( ) . dump_feature_usage_metrics( metrics_path) {
493
+ // FIXME(yaahc): once metrics can be enabled by default we will want "failure to emit
494
+ // default metrics" to only produce a warning when metrics are enabled by default and emit
495
+ // an error only when the user manually enables metrics
496
+ tcxt. dcx( ) . emit_err( UnstableFeatureUsage { error } ) ;
497
+ }
498
+ }
499
+
478
500
// Extract output directory and file from matches.
479
501
fn make_output( matches: & getopts:: Matches ) -> ( Option <PathBuf >, Option <OutFileName >) {
480
502
let odir = matches. opt_str( "out-dir" ) . map( |o| PathBuf :: from( & o) ) ;
0 commit comments