@@ -29,7 +29,7 @@ use rustc_codegen_ssa::back::write::{CodegenContext, FatLtoInput};
29
29
use rustc_codegen_ssa:: traits:: * ;
30
30
use rustc_codegen_ssa:: { ModuleCodegen , ModuleKind , looks_like_rust_object_file} ;
31
31
use rustc_data_structures:: memmap:: Mmap ;
32
- use rustc_errors:: { DiagCtxtHandle , FatalError } ;
32
+ use rustc_errors:: DiagCtxtHandle ;
33
33
use rustc_middle:: bug;
34
34
use rustc_middle:: dep_graph:: WorkProduct ;
35
35
use rustc_session:: config:: Lto ;
@@ -51,12 +51,11 @@ fn prepare_lto(
51
51
cgcx : & CodegenContext < GccCodegenBackend > ,
52
52
each_linked_rlib_for_lto : & [ PathBuf ] ,
53
53
dcx : DiagCtxtHandle < ' _ > ,
54
- ) -> Result < LtoData , FatalError > {
54
+ ) -> LtoData {
55
55
let tmp_path = match tempdir ( ) {
56
56
Ok ( tmp_path) => tmp_path,
57
57
Err ( error) => {
58
- eprintln ! ( "Cannot create temporary directory: {}" , error) ;
59
- return Err ( FatalError ) ;
58
+ dcx. fatal ( format ! ( "Cannot create temporary directory: {}" , error) ) ;
60
59
}
61
60
} ;
62
61
@@ -91,15 +90,14 @@ fn prepare_lto(
91
90
upstream_modules. push ( ( module, CString :: new ( name) . unwrap ( ) ) ) ;
92
91
}
93
92
Err ( e) => {
94
- dcx. emit_err ( e) ;
95
- return Err ( FatalError ) ;
93
+ dcx. emit_fatal ( e) ;
96
94
}
97
95
}
98
96
}
99
97
}
100
98
}
101
99
102
- Ok ( LtoData { upstream_modules, tmp_path } )
100
+ LtoData { upstream_modules, tmp_path }
103
101
}
104
102
105
103
fn save_as_file ( obj : & [ u8 ] , path : & Path ) -> Result < ( ) , LtoBitcodeFromRlib > {
@@ -114,10 +112,10 @@ pub(crate) fn run_fat(
114
112
cgcx : & CodegenContext < GccCodegenBackend > ,
115
113
each_linked_rlib_for_lto : & [ PathBuf ] ,
116
114
modules : Vec < FatLtoInput < GccCodegenBackend > > ,
117
- ) -> Result < ModuleCodegen < GccContext > , FatalError > {
115
+ ) -> ModuleCodegen < GccContext > {
118
116
let dcx = cgcx. create_dcx ( ) ;
119
117
let dcx = dcx. handle ( ) ;
120
- let lto_data = prepare_lto ( cgcx, each_linked_rlib_for_lto, dcx) ? ;
118
+ let lto_data = prepare_lto ( cgcx, each_linked_rlib_for_lto, dcx) ;
121
119
/*let symbols_below_threshold =
122
120
lto_data.symbols_below_threshold.iter().map(|c| c.as_ptr()).collect::<Vec<_>>();*/
123
121
fat_lto (
@@ -137,7 +135,7 @@ fn fat_lto(
137
135
mut serialized_modules : Vec < ( SerializedModule < ModuleBuffer > , CString ) > ,
138
136
tmp_path : TempDir ,
139
137
//symbols_below_threshold: &[String],
140
- ) -> Result < ModuleCodegen < GccContext > , FatalError > {
138
+ ) -> ModuleCodegen < GccContext > {
141
139
let _timer = cgcx. prof . generic_activity ( "GCC_fat_lto_build_monolithic_module" ) ;
142
140
info ! ( "going for a fat lto" ) ;
143
141
@@ -206,7 +204,7 @@ fn fat_lto(
206
204
let path = tmp_path. path ( ) . to_path_buf ( ) . join ( & module. name ) ;
207
205
let path = path. to_str ( ) . expect ( "path" ) ;
208
206
let context = & module. module_llvm . context ;
209
- let config = cgcx. config ( module . kind ) ;
207
+ let config = & cgcx. module_config ;
210
208
// NOTE: we need to set the optimization level here in order for LTO to do its job.
211
209
context. set_optimization_level ( to_gcc_opt_level ( config. opt_level ) ) ;
212
210
context. add_command_line_option ( "-flto=auto" ) ;
@@ -261,7 +259,7 @@ fn fat_lto(
261
259
// of now.
262
260
module. module_llvm . temp_dir = Some ( tmp_path) ;
263
261
264
- Ok ( module)
262
+ module
265
263
}
266
264
267
265
pub struct ModuleBuffer ( PathBuf ) ;
@@ -286,10 +284,10 @@ pub(crate) fn run_thin(
286
284
each_linked_rlib_for_lto : & [ PathBuf ] ,
287
285
modules : Vec < ( String , ThinBuffer ) > ,
288
286
cached_modules : Vec < ( SerializedModule < ModuleBuffer > , WorkProduct ) > ,
289
- ) -> Result < ( Vec < ThinModule < GccCodegenBackend > > , Vec < WorkProduct > ) , FatalError > {
287
+ ) -> ( Vec < ThinModule < GccCodegenBackend > > , Vec < WorkProduct > ) {
290
288
let dcx = cgcx. create_dcx ( ) ;
291
289
let dcx = dcx. handle ( ) ;
292
- let lto_data = prepare_lto ( cgcx, each_linked_rlib_for_lto, dcx) ? ;
290
+ let lto_data = prepare_lto ( cgcx, each_linked_rlib_for_lto, dcx) ;
293
291
if cgcx. opts . cg . linker_plugin_lto . enabled ( ) {
294
292
unreachable ! (
295
293
"We should never reach this case if the LTO step \
@@ -307,12 +305,9 @@ pub(crate) fn run_thin(
307
305
)
308
306
}
309
307
310
- pub ( crate ) fn prepare_thin (
311
- module : ModuleCodegen < GccContext > ,
312
- _emit_summary : bool ,
313
- ) -> ( String , ThinBuffer ) {
308
+ pub ( crate ) fn prepare_thin ( module : ModuleCodegen < GccContext > ) -> ( String , ThinBuffer ) {
314
309
let name = module. name ;
315
- //let buffer = ThinBuffer::new(module.module_llvm.context, true, emit_summary );
310
+ //let buffer = ThinBuffer::new(module.module_llvm.context, true);
316
311
let buffer = ThinBuffer :: new ( & module. module_llvm . context ) ;
317
312
( name, buffer)
318
313
}
@@ -355,7 +350,7 @@ fn thin_lto(
355
350
tmp_path : TempDir ,
356
351
cached_modules : Vec < ( SerializedModule < ModuleBuffer > , WorkProduct ) > ,
357
352
//_symbols_below_threshold: &[String],
358
- ) -> Result < ( Vec < ThinModule < GccCodegenBackend > > , Vec < WorkProduct > ) , FatalError > {
353
+ ) -> ( Vec < ThinModule < GccCodegenBackend > > , Vec < WorkProduct > ) {
359
354
let _timer = cgcx. prof . generic_activity ( "LLVM_thin_lto_global_analysis" ) ;
360
355
info ! ( "going for that thin, thin LTO" ) ;
361
356
@@ -518,13 +513,13 @@ fn thin_lto(
518
513
// TODO: save the directory so that it gets deleted later.
519
514
std:: mem:: forget ( tmp_path) ;
520
515
521
- Ok ( ( opt_jobs, copy_jobs) )
516
+ ( opt_jobs, copy_jobs)
522
517
}
523
518
524
519
pub fn optimize_thin_module (
525
520
thin_module : ThinModule < GccCodegenBackend > ,
526
521
_cgcx : & CodegenContext < GccCodegenBackend > ,
527
- ) -> Result < ModuleCodegen < GccContext > , FatalError > {
522
+ ) -> ModuleCodegen < GccContext > {
528
523
//let dcx = cgcx.create_dcx();
529
524
530
525
//let module_name = &thin_module.shared.module_names[thin_module.idx];
@@ -634,7 +629,8 @@ pub fn optimize_thin_module(
634
629
save_temp_bitcode(cgcx, &module, "thin-lto-after-pm");
635
630
}
636
631
}*/
637
- Ok ( module)
632
+ #[ allow( clippy:: let_and_return) ]
633
+ module
638
634
}
639
635
640
636
pub struct ThinBuffer {
@@ -651,10 +647,6 @@ impl ThinBufferMethods for ThinBuffer {
651
647
fn data ( & self ) -> & [ u8 ] {
652
648
& [ ]
653
649
}
654
-
655
- fn thin_link_data ( & self ) -> & [ u8 ] {
656
- unimplemented ! ( ) ;
657
- }
658
650
}
659
651
660
652
pub struct ThinData ; //(Arc<TempDir>);
0 commit comments