@@ -8,16 +8,13 @@ use rustc_borrowck as mir_borrowck;
8
8
use rustc_codegen_ssa:: traits:: CodegenBackend ;
9
9
use rustc_data_structures:: parallel;
10
10
use rustc_data_structures:: sync:: { Lrc , OnceCell , WorkerLocal } ;
11
- use rustc_data_structures:: temp_dir:: MaybeTempDir ;
12
11
use rustc_errors:: { Applicability , ErrorGuaranteed , MultiSpan , PResult } ;
13
12
use rustc_expand:: base:: { ExtCtxt , LintStoreExpand , ResolverExpand } ;
14
- use rustc_hir:: def_id:: { StableCrateId , LOCAL_CRATE } ;
13
+ use rustc_hir:: def_id:: StableCrateId ;
15
14
use rustc_hir:: definitions:: Definitions ;
16
15
use rustc_hir:: Crate ;
17
16
use rustc_lint:: { EarlyCheckNode , LintStore } ;
18
17
use rustc_metadata:: creader:: CStore ;
19
- use rustc_metadata:: fs:: emit_metadata;
20
- use rustc_metadata:: { encode_metadata, EncodedMetadata } ;
21
18
use rustc_middle:: arena:: Arena ;
22
19
use rustc_middle:: dep_graph:: DepGraph ;
23
20
use rustc_middle:: ty:: query:: { ExternProviders , Providers } ;
@@ -30,14 +27,13 @@ use rustc_query_impl::{OnDiskCache, Queries as TcxQueries};
30
27
use rustc_resolve:: { Resolver , ResolverArenas } ;
31
28
use rustc_session:: config:: { CrateType , Input , OutputFilenames , OutputType } ;
32
29
use rustc_session:: cstore:: { CrateStoreDyn , MetadataLoader , MetadataLoaderDyn } ;
33
- use rustc_session:: output:: { filename_for_input, filename_for_metadata } ;
30
+ use rustc_session:: output:: filename_for_input;
34
31
use rustc_session:: search_paths:: PathKind ;
35
32
use rustc_session:: { Limit , Session } ;
36
33
use rustc_span:: symbol:: { sym, Symbol } ;
37
34
use rustc_span:: FileName ;
38
35
use rustc_trait_selection:: traits;
39
36
use rustc_typeck as typeck;
40
- use tempfile:: Builder as TempFileBuilder ;
41
37
use tracing:: { info, warn} ;
42
38
43
39
use std:: any:: Any ;
@@ -1030,69 +1026,6 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
1030
1026
Ok ( ( ) )
1031
1027
}
1032
1028
1033
- fn encode_and_write_metadata (
1034
- tcx : TyCtxt < ' _ > ,
1035
- outputs : & OutputFilenames ,
1036
- ) -> ( EncodedMetadata , bool ) {
1037
- #[ derive( PartialEq , Eq , PartialOrd , Ord ) ]
1038
- enum MetadataKind {
1039
- None ,
1040
- Uncompressed ,
1041
- Compressed ,
1042
- }
1043
-
1044
- let metadata_kind = tcx
1045
- . sess
1046
- . crate_types ( )
1047
- . iter ( )
1048
- . map ( |ty| match * ty {
1049
- CrateType :: Executable | CrateType :: Staticlib | CrateType :: Cdylib => MetadataKind :: None ,
1050
-
1051
- CrateType :: Rlib => MetadataKind :: Uncompressed ,
1052
-
1053
- CrateType :: Dylib | CrateType :: ProcMacro => MetadataKind :: Compressed ,
1054
- } )
1055
- . max ( )
1056
- . unwrap_or ( MetadataKind :: None ) ;
1057
-
1058
- let metadata = match metadata_kind {
1059
- MetadataKind :: None => EncodedMetadata :: new ( ) ,
1060
- MetadataKind :: Uncompressed | MetadataKind :: Compressed => encode_metadata ( tcx) ,
1061
- } ;
1062
-
1063
- let _prof_timer = tcx. sess . prof . generic_activity ( "write_crate_metadata" ) ;
1064
-
1065
- let need_metadata_file = tcx. sess . opts . output_types . contains_key ( & OutputType :: Metadata ) ;
1066
- if need_metadata_file {
1067
- let crate_name = tcx. crate_name ( LOCAL_CRATE ) ;
1068
- let out_filename = filename_for_metadata ( tcx. sess , crate_name. as_str ( ) , outputs) ;
1069
- // To avoid races with another rustc process scanning the output directory,
1070
- // we need to write the file somewhere else and atomically move it to its
1071
- // final destination, with an `fs::rename` call. In order for the rename to
1072
- // always succeed, the temporary file needs to be on the same filesystem,
1073
- // which is why we create it inside the output directory specifically.
1074
- let metadata_tmpdir = TempFileBuilder :: new ( )
1075
- . prefix ( "rmeta" )
1076
- . tempdir_in ( out_filename. parent ( ) . unwrap ( ) )
1077
- . unwrap_or_else ( |err| tcx. sess . fatal ( & format ! ( "couldn't create a temp dir: {}" , err) ) ) ;
1078
- let metadata_tmpdir = MaybeTempDir :: new ( metadata_tmpdir, tcx. sess . opts . cg . save_temps ) ;
1079
- let metadata_filename = emit_metadata ( tcx. sess , metadata. raw_data ( ) , & metadata_tmpdir) ;
1080
- if let Err ( e) = util:: non_durable_rename ( & metadata_filename, & out_filename) {
1081
- tcx. sess . fatal ( & format ! ( "failed to write {}: {}" , out_filename. display( ) , e) ) ;
1082
- }
1083
- if tcx. sess . opts . json_artifact_notifications {
1084
- tcx. sess
1085
- . parse_sess
1086
- . span_diagnostic
1087
- . emit_artifact_notification ( & out_filename, "metadata" ) ;
1088
- }
1089
- }
1090
-
1091
- let need_metadata_module = metadata_kind == MetadataKind :: Compressed ;
1092
-
1093
- ( metadata, need_metadata_module)
1094
- }
1095
-
1096
1029
/// Runs the codegen backend, after which the AST and analysis can
1097
1030
/// be discarded.
1098
1031
pub fn start_codegen < ' tcx > (
@@ -1102,7 +1035,8 @@ pub fn start_codegen<'tcx>(
1102
1035
) -> Box < dyn Any > {
1103
1036
info ! ( "Pre-codegen\n {:?}" , tcx. debug_stats( ) ) ;
1104
1037
1105
- let ( metadata, need_metadata_module) = encode_and_write_metadata ( tcx, outputs) ;
1038
+ let ( metadata, need_metadata_module) =
1039
+ rustc_metadata:: fs:: encode_and_write_metadata ( tcx, outputs) ;
1106
1040
1107
1041
let codegen = tcx. sess . time ( "codegen_crate" , move || {
1108
1042
codegen_backend. codegen_crate ( tcx, metadata, need_metadata_module)
0 commit comments