@@ -241,6 +241,8 @@ pub fn run_compiler(
241
241
242
242
callbacks. config ( & mut config) ;
243
243
244
+ let pretty_info = parse_pretty ( & mut config. opts , & matches) ;
245
+
244
246
interface:: run_compiler ( config, |compiler| {
245
247
let sess = compiler. session ( ) ;
246
248
let should_stop = RustcDefaultCalls :: print_crate_info (
@@ -260,14 +262,9 @@ pub fn run_compiler(
260
262
return sess. compile_status ( ) ;
261
263
}
262
264
263
- let pretty_info = parse_pretty ( sess, & matches) ;
264
-
265
- compiler. parse ( ) ?;
266
-
267
265
if let Some ( ( ppm, opt_uii) ) = pretty_info {
268
266
if ppm. needs_ast_map ( & opt_uii) {
269
- pretty:: visit_crate ( sess, & mut compiler. parse ( ) ?. peek_mut ( ) , ppm) ;
270
- compiler. global_ctxt ( ) ?. peek_mut ( ) . enter ( |tcx| {
267
+ compiler. enter ( |tcx| {
271
268
let expansion_result = tcx. expand_macros ( ( ) ) ?;
272
269
pretty:: print_after_hir_lowering (
273
270
tcx,
@@ -281,19 +278,24 @@ pub fn run_compiler(
281
278
} ) ?;
282
279
return sess. compile_status ( ) ;
283
280
} else {
284
- let mut krate = compiler. parse ( ) ?. take ( ) ;
285
- pretty:: visit_crate ( sess, & mut krate, ppm) ;
286
- pretty:: print_after_parsing (
287
- sess,
288
- & compiler. input ( ) ,
289
- & krate,
290
- ppm,
291
- compiler. output_file ( ) . as_ref ( ) . map ( |p| & * * p) ,
292
- ) ;
281
+ compiler. enter ( |tcx| {
282
+ let krate = tcx. parse ( ( ) ) ?;
283
+ let krate = krate. borrow ( ) ;
284
+ pretty:: print_after_parsing (
285
+ sess,
286
+ & compiler. input ( ) ,
287
+ & krate,
288
+ ppm,
289
+ compiler. output_file ( ) . as_ref ( ) . map ( |p| & * * p) ,
290
+ ) ;
291
+ Ok ( ( ) )
292
+ } ) ?;
293
293
return sess. compile_status ( ) ;
294
294
}
295
295
}
296
296
297
+ compiler. enter ( |tcx| tcx. parse ( ( ) ) ) ?;
298
+
297
299
if !callbacks. after_parsing ( compiler) {
298
300
return sess. compile_status ( ) ;
299
301
}
@@ -304,15 +306,15 @@ pub fn run_compiler(
304
306
return sess. compile_status ( ) ;
305
307
}
306
308
307
- compiler. register_plugins ( ) ?;
309
+ compiler. enter ( |tcx| tcx . register_plugins ( ( ) ) ) ?;
308
310
309
311
// Lint plugins are registered; now we can process command line flags.
310
312
if sess. opts . describe_lints {
311
313
describe_lints ( & sess, & sess. lint_store . borrow ( ) , true ) ;
312
314
return sess. compile_status ( ) ;
313
315
}
314
316
315
- compiler. global_ctxt ( ) ? . peek_mut ( ) . enter ( |tcx| {
317
+ compiler. enter ( |tcx| {
316
318
tcx. prepare_outputs ( ( ) ) ?;
317
319
Ok ( ( ) )
318
320
} ) ?;
@@ -323,7 +325,7 @@ pub fn run_compiler(
323
325
return sess. compile_status ( ) ;
324
326
}
325
327
326
- compiler. global_ctxt ( ) ? . peek_mut ( ) . enter ( |tcx| {
328
+ compiler. enter ( |tcx| {
327
329
tcx. lower_ast_to_hir ( ( ) ) ?;
328
330
Ok ( ( ) )
329
331
} ) ?;
@@ -334,10 +336,10 @@ pub fn run_compiler(
334
336
}
335
337
336
338
if sess. opts . debugging_opts . save_analysis {
337
- compiler. global_ctxt ( ) ? . peek_mut ( ) . enter ( |tcx| {
339
+ compiler. enter ( |tcx| {
338
340
let expansion_result = tcx. expand_macros ( ( ) ) ?;
339
341
let result = tcx. analysis ( LOCAL_CRATE ) ;
340
- let crate_name = & tcx. crate_name . as_str ( ) ;
342
+ let crate_name = & tcx. crate_name ( LOCAL_CRATE ) . as_str ( ) ;
341
343
342
344
time ( sess, "save analysis" , || {
343
345
save:: process_crate (
@@ -355,20 +357,20 @@ pub fn run_compiler(
355
357
// (needed by the RLS)
356
358
} ) ?;
357
359
} else {
358
- compiler. global_ctxt ( ) ? . peek_mut ( ) . enter ( |tcx| {
360
+ compiler. enter ( |tcx| {
359
361
// Drop AST after lowering HIR to free memory
360
362
mem:: drop ( tcx. expand_macros ( ( ) ) . unwrap ( ) . ast_crate . steal ( ) ) ;
361
363
} ) ;
362
364
}
363
365
364
- compiler. global_ctxt ( ) ? . peek_mut ( ) . enter ( |tcx| tcx. analysis ( LOCAL_CRATE ) ) ?;
366
+ compiler. enter ( |tcx| tcx. analysis ( LOCAL_CRATE ) ) ?;
365
367
366
368
if !callbacks. after_analysis ( compiler) {
367
369
return sess. compile_status ( ) ;
368
370
}
369
371
370
372
if sess. opts . debugging_opts . save_analysis {
371
- compiler. global_ctxt ( ) ? . peek_mut ( ) . enter ( |tcx| {
373
+ compiler. enter ( |tcx| {
372
374
// Drop AST after lowering HIR to free memory
373
375
mem:: drop ( tcx. expand_macros ( ( ) ) . unwrap ( ) . ast_crate . steal ( ) ) ;
374
376
} ) ;
@@ -441,22 +443,22 @@ fn make_input(free_matches: &[String]) -> Option<(Input, Option<PathBuf>, Option
441
443
}
442
444
}
443
445
444
- fn parse_pretty ( sess : & Session ,
446
+ fn parse_pretty ( opts : & mut config :: Options ,
445
447
matches : & getopts:: Matches )
446
448
-> Option < ( PpMode , Option < UserIdentifiedItem > ) > {
447
- let pretty = if sess . opts . debugging_opts . unstable_options {
449
+ let pretty = if opts. debugging_opts . unstable_options {
448
450
matches. opt_default ( "pretty" , "normal" ) . map ( |a| {
449
451
// stable pretty-print variants only
450
- pretty:: parse_pretty ( sess , & a, false )
452
+ pretty:: parse_pretty ( opts , & a, false )
451
453
} )
452
454
} else {
453
455
None
454
456
} ;
455
457
456
458
if pretty. is_none ( ) {
457
- sess . opts . debugging_opts . unpretty . as_ref ( ) . map ( |a| {
459
+ opts. debugging_opts . unpretty . clone ( ) . map ( |a| {
458
460
// extended with unstable pretty-print variants
459
- pretty:: parse_pretty ( sess , & a, true )
461
+ pretty:: parse_pretty ( opts , & a, true )
460
462
} )
461
463
} else {
462
464
pretty
0 commit comments