]> git.proxmox.com Git - rustc.git/blob - src/librustc_driver/driver.rs
New upstream version 1.23.0+dfsg1
[rustc.git] / src / librustc_driver / driver.rs
1 // Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 use rustc::dep_graph::DepGraph;
12 use rustc::hir::{self, map as hir_map};
13 use rustc::hir::lowering::lower_crate;
14 use rustc::ich::Fingerprint;
15 use rustc_data_structures::stable_hasher::StableHasher;
16 use rustc_mir as mir;
17 use rustc::session::{Session, CompileResult, CrateDisambiguator};
18 use rustc::session::CompileIncomplete;
19 use rustc::session::config::{self, Input, OutputFilenames, OutputType};
20 use rustc::session::search_paths::PathKind;
21 use rustc::lint;
22 use rustc::middle::{self, stability, reachable};
23 use rustc::middle::cstore::CrateStore;
24 use rustc::middle::privacy::AccessLevels;
25 use rustc::ty::{self, TyCtxt, Resolutions, GlobalArenas};
26 use rustc::traits;
27 use rustc::util::common::{ErrorReported, time};
28 use rustc_allocator as allocator;
29 use rustc_borrowck as borrowck;
30 use rustc_incremental;
31 use rustc_resolve::{MakeGlobMap, Resolver};
32 use rustc_metadata::creader::CrateLoader;
33 use rustc_metadata::cstore::{self, CStore};
34 use rustc_trans as trans;
35 use rustc_trans_utils::trans_crate::TransCrate;
36 use rustc_typeck as typeck;
37 use rustc_privacy;
38 use rustc_plugin::registry::Registry;
39 use rustc_plugin as plugin;
40 use rustc_passes::{self, ast_validation, no_asm, loops, consts, static_recursion, hir_stats};
41 use rustc_const_eval::{self, check_match};
42 use super::Compilation;
43 use ::DefaultTransCrate;
44
45 use serialize::json;
46
47 use std::any::Any;
48 use std::env;
49 use std::ffi::{OsString, OsStr};
50 use std::fs;
51 use std::io::{self, Write};
52 use std::iter;
53 use std::path::{Path, PathBuf};
54 use std::rc::Rc;
55 use std::sync::mpsc;
56 use syntax::{ast, diagnostics, visit};
57 use syntax::attr;
58 use syntax::ext::base::ExtCtxt;
59 use syntax::parse::{self, PResult};
60 use syntax::util::node_count::NodeCounter;
61 use syntax;
62 use syntax_ext;
63 use arena::DroplessArena;
64
65 use derive_registrar;
66
67 use profile;
68
69 pub fn compile_input(sess: &Session,
70 cstore: &CStore,
71 input: &Input,
72 outdir: &Option<PathBuf>,
73 output: &Option<PathBuf>,
74 addl_plugins: Option<Vec<String>>,
75 control: &CompileController) -> CompileResult {
76 use rustc::session::config::CrateType;
77
78 macro_rules! controller_entry_point {
79 ($point: ident, $tsess: expr, $make_state: expr, $phase_result: expr) => {{
80 let state = &mut $make_state;
81 let phase_result: &CompileResult = &$phase_result;
82 if phase_result.is_ok() || control.$point.run_callback_on_error {
83 (control.$point.callback)(state);
84 }
85
86 if control.$point.stop == Compilation::Stop {
87 // FIXME: shouldn't this return Err(CompileIncomplete::Stopped)
88 // if there are no errors?
89 return $tsess.compile_status();
90 }
91 }}
92 }
93
94 if cfg!(not(feature="llvm")) {
95 for cty in sess.opts.crate_types.iter() {
96 match *cty {
97 CrateType::CrateTypeRlib | CrateType::CrateTypeDylib |
98 CrateType::CrateTypeExecutable => {},
99 _ => {
100 sess.parse_sess.span_diagnostic.warn(
101 &format!("LLVM unsupported, so output type {} is not supported", cty)
102 );
103 },
104 }
105 }
106
107 sess.abort_if_errors();
108 }
109
110 if sess.profile_queries() {
111 profile::begin();
112 }
113
114 // We need nested scopes here, because the intermediate results can keep
115 // large chunks of memory alive and we want to free them as soon as
116 // possible to keep the peak memory usage low
117 let (outputs, trans, dep_graph) = {
118 let krate = match phase_1_parse_input(control, sess, input) {
119 Ok(krate) => krate,
120 Err(mut parse_error) => {
121 parse_error.emit();
122 return Err(CompileIncomplete::Errored(ErrorReported));
123 }
124 };
125
126 let (krate, registry) = {
127 let mut compile_state = CompileState::state_after_parse(input,
128 sess,
129 outdir,
130 output,
131 krate,
132 &cstore);
133 controller_entry_point!(after_parse,
134 sess,
135 compile_state,
136 Ok(()));
137
138 (compile_state.krate.unwrap(), compile_state.registry)
139 };
140
141 let outputs = build_output_filenames(input, outdir, output, &krate.attrs, sess);
142 let crate_name =
143 ::rustc_trans_utils::link::find_crate_name(Some(sess), &krate.attrs, input);
144 let ExpansionResult { expanded_crate, defs, analysis, resolutions, mut hir_forest } = {
145 phase_2_configure_and_expand(
146 sess,
147 &cstore,
148 krate,
149 registry,
150 &crate_name,
151 addl_plugins,
152 control.make_glob_map,
153 |expanded_crate| {
154 let mut state = CompileState::state_after_expand(
155 input, sess, outdir, output, &cstore, expanded_crate, &crate_name,
156 );
157 controller_entry_point!(after_expand, sess, state, Ok(()));
158 Ok(())
159 }
160 )?
161 };
162
163 write_out_deps(sess, &outputs, &crate_name);
164 if sess.opts.output_types.contains_key(&OutputType::DepInfo) &&
165 sess.opts.output_types.keys().count() == 1 {
166 return Ok(())
167 }
168
169 let arena = DroplessArena::new();
170 let arenas = GlobalArenas::new();
171
172 // Construct the HIR map
173 let hir_map = time(sess.time_passes(),
174 "indexing hir",
175 || hir_map::map_crate(sess, cstore, &mut hir_forest, &defs));
176
177 {
178 let _ignore = hir_map.dep_graph.in_ignore();
179 controller_entry_point!(after_hir_lowering,
180 sess,
181 CompileState::state_after_hir_lowering(input,
182 sess,
183 outdir,
184 output,
185 &arena,
186 &arenas,
187 &cstore,
188 &hir_map,
189 &analysis,
190 &resolutions,
191 &expanded_crate,
192 &hir_map.krate(),
193 &outputs,
194 &crate_name),
195 Ok(()));
196 }
197
198 time(sess.time_passes(), "attribute checking", || {
199 hir::check_attr::check_crate(sess, &expanded_crate);
200 });
201
202 let opt_crate = if control.keep_ast {
203 Some(&expanded_crate)
204 } else {
205 drop(expanded_crate);
206 None
207 };
208
209 phase_3_run_analysis_passes(control,
210 sess,
211 cstore,
212 hir_map,
213 analysis,
214 resolutions,
215 &arena,
216 &arenas,
217 &crate_name,
218 &outputs,
219 |tcx, analysis, rx, result| {
220 {
221 // Eventually, we will want to track plugins.
222 let _ignore = tcx.dep_graph.in_ignore();
223
224 let mut state = CompileState::state_after_analysis(input,
225 sess,
226 outdir,
227 output,
228 opt_crate,
229 tcx.hir.krate(),
230 &analysis,
231 tcx,
232 &crate_name);
233 (control.after_analysis.callback)(&mut state);
234
235 if control.after_analysis.stop == Compilation::Stop {
236 return result.and_then(|_| Err(CompileIncomplete::Stopped));
237 }
238 }
239
240 result?;
241
242 if log_enabled!(::log::LogLevel::Info) {
243 println!("Pre-trans");
244 tcx.print_debug_stats();
245 }
246
247 let trans = phase_4_translate_to_llvm::<DefaultTransCrate>(tcx, rx);
248
249 if log_enabled!(::log::LogLevel::Info) {
250 println!("Post-trans");
251 tcx.print_debug_stats();
252 }
253
254 if tcx.sess.opts.output_types.contains_key(&OutputType::Mir) {
255 if let Err(e) = mir::transform::dump_mir::emit_mir(tcx, &outputs) {
256 sess.err(&format!("could not emit MIR: {}", e));
257 sess.abort_if_errors();
258 }
259 }
260
261 Ok((outputs.clone(), trans, tcx.dep_graph.clone()))
262 })??
263 };
264
265 if sess.opts.debugging_opts.print_type_sizes {
266 sess.code_stats.borrow().print_type_sizes();
267 }
268
269 let (phase5_result, trans) =
270 phase_5_run_llvm_passes::<DefaultTransCrate>(sess, &dep_graph, trans);
271
272 controller_entry_point!(after_llvm,
273 sess,
274 CompileState::state_after_llvm(input, sess, outdir, output, &trans),
275 phase5_result);
276 phase5_result?;
277
278 // Run the linker on any artifacts that resulted from the LLVM run.
279 // This should produce either a finished executable or library.
280 time(sess.time_passes(), "linking", || {
281 DefaultTransCrate::link_binary(sess, &trans, &outputs)
282 });
283
284 // Now that we won't touch anything in the incremental compilation directory
285 // any more, we can finalize it (which involves renaming it)
286 #[cfg(feature="llvm")]
287 rustc_incremental::finalize_session_directory(sess, trans.link.crate_hash);
288
289 if sess.opts.debugging_opts.perf_stats {
290 sess.print_perf_stats();
291 }
292
293 controller_entry_point!(
294 compilation_done,
295 sess,
296 CompileState::state_when_compilation_done(input, sess, outdir, output),
297 Ok(())
298 );
299
300 Ok(())
301 }
302
303 fn keep_hygiene_data(sess: &Session) -> bool {
304 sess.opts.debugging_opts.keep_hygiene_data
305 }
306
307
308 /// The name used for source code that doesn't originate in a file
309 /// (e.g. source from stdin or a string)
310 pub fn anon_src() -> String {
311 "<anon>".to_string()
312 }
313
314 pub fn source_name(input: &Input) -> String {
315 match *input {
316 // FIXME (#9639): This needs to handle non-utf8 paths
317 Input::File(ref ifile) => ifile.to_str().unwrap().to_string(),
318 Input::Str { ref name, .. } => name.clone(),
319 }
320 }
321
322 /// CompileController is used to customize compilation, it allows compilation to
323 /// be stopped and/or to call arbitrary code at various points in compilation.
324 /// It also allows for various flags to be set to influence what information gets
325 /// collected during compilation.
326 ///
327 /// This is a somewhat higher level controller than a Session - the Session
328 /// controls what happens in each phase, whereas the CompileController controls
329 /// whether a phase is run at all and whether other code (from outside the
330 /// compiler) is run between phases.
331 ///
332 /// Note that if compilation is set to stop and a callback is provided for a
333 /// given entry point, the callback is called before compilation is stopped.
334 ///
335 /// Expect more entry points to be added in the future.
336 pub struct CompileController<'a> {
337 pub after_parse: PhaseController<'a>,
338 pub after_expand: PhaseController<'a>,
339 pub after_hir_lowering: PhaseController<'a>,
340 pub after_analysis: PhaseController<'a>,
341 pub after_llvm: PhaseController<'a>,
342 pub compilation_done: PhaseController<'a>,
343
344 // FIXME we probably want to group the below options together and offer a
345 // better API, rather than this ad-hoc approach.
346 pub make_glob_map: MakeGlobMap,
347 // Whether the compiler should keep the ast beyond parsing.
348 pub keep_ast: bool,
349 // -Zcontinue-parse-after-error
350 pub continue_parse_after_error: bool,
351
352 /// Allows overriding default rustc query providers,
353 /// after `default_provide` has installed them.
354 pub provide: Box<Fn(&mut ty::maps::Providers) + 'a>,
355 /// Same as `provide`, but only for non-local crates,
356 /// applied after `default_provide_extern`.
357 pub provide_extern: Box<Fn(&mut ty::maps::Providers) + 'a>,
358 }
359
360 impl<'a> CompileController<'a> {
361 pub fn basic() -> CompileController<'a> {
362 CompileController {
363 after_parse: PhaseController::basic(),
364 after_expand: PhaseController::basic(),
365 after_hir_lowering: PhaseController::basic(),
366 after_analysis: PhaseController::basic(),
367 after_llvm: PhaseController::basic(),
368 compilation_done: PhaseController::basic(),
369 make_glob_map: MakeGlobMap::No,
370 keep_ast: false,
371 continue_parse_after_error: false,
372 provide: box |_| {},
373 provide_extern: box |_| {},
374 }
375 }
376 }
377
378 pub struct PhaseController<'a> {
379 pub stop: Compilation,
380 // If true then the compiler will try to run the callback even if the phase
381 // ends with an error. Note that this is not always possible.
382 pub run_callback_on_error: bool,
383 pub callback: Box<Fn(&mut CompileState) + 'a>,
384 }
385
386 impl<'a> PhaseController<'a> {
387 pub fn basic() -> PhaseController<'a> {
388 PhaseController {
389 stop: Compilation::Continue,
390 run_callback_on_error: false,
391 callback: box |_| {},
392 }
393 }
394 }
395
396 /// State that is passed to a callback. What state is available depends on when
397 /// during compilation the callback is made. See the various constructor methods
398 /// (`state_*`) in the impl to see which data is provided for any given entry point.
399 pub struct CompileState<'a, 'tcx: 'a> {
400 pub input: &'a Input,
401 pub session: &'tcx Session,
402 pub krate: Option<ast::Crate>,
403 pub registry: Option<Registry<'a>>,
404 pub cstore: Option<&'tcx CStore>,
405 pub crate_name: Option<&'a str>,
406 pub output_filenames: Option<&'a OutputFilenames>,
407 pub out_dir: Option<&'a Path>,
408 pub out_file: Option<&'a Path>,
409 pub arena: Option<&'tcx DroplessArena>,
410 pub arenas: Option<&'tcx GlobalArenas<'tcx>>,
411 pub expanded_crate: Option<&'a ast::Crate>,
412 pub hir_crate: Option<&'a hir::Crate>,
413 pub hir_map: Option<&'a hir_map::Map<'tcx>>,
414 pub resolutions: Option<&'a Resolutions>,
415 pub analysis: Option<&'a ty::CrateAnalysis>,
416 pub tcx: Option<TyCtxt<'a, 'tcx, 'tcx>>,
417 pub trans: Option<&'a trans::CrateTranslation>,
418 }
419
420 impl<'a, 'tcx> CompileState<'a, 'tcx> {
421 fn empty(input: &'a Input,
422 session: &'tcx Session,
423 out_dir: &'a Option<PathBuf>)
424 -> Self {
425 CompileState {
426 input,
427 session,
428 out_dir: out_dir.as_ref().map(|s| &**s),
429 out_file: None,
430 arena: None,
431 arenas: None,
432 krate: None,
433 registry: None,
434 cstore: None,
435 crate_name: None,
436 output_filenames: None,
437 expanded_crate: None,
438 hir_crate: None,
439 hir_map: None,
440 resolutions: None,
441 analysis: None,
442 tcx: None,
443 trans: None,
444 }
445 }
446
447 fn state_after_parse(input: &'a Input,
448 session: &'tcx Session,
449 out_dir: &'a Option<PathBuf>,
450 out_file: &'a Option<PathBuf>,
451 krate: ast::Crate,
452 cstore: &'tcx CStore)
453 -> Self {
454 CompileState {
455 // Initialize the registry before moving `krate`
456 registry: Some(Registry::new(&session, krate.span)),
457 krate: Some(krate),
458 cstore: Some(cstore),
459 out_file: out_file.as_ref().map(|s| &**s),
460 ..CompileState::empty(input, session, out_dir)
461 }
462 }
463
464 fn state_after_expand(input: &'a Input,
465 session: &'tcx Session,
466 out_dir: &'a Option<PathBuf>,
467 out_file: &'a Option<PathBuf>,
468 cstore: &'tcx CStore,
469 expanded_crate: &'a ast::Crate,
470 crate_name: &'a str)
471 -> Self {
472 CompileState {
473 crate_name: Some(crate_name),
474 cstore: Some(cstore),
475 expanded_crate: Some(expanded_crate),
476 out_file: out_file.as_ref().map(|s| &**s),
477 ..CompileState::empty(input, session, out_dir)
478 }
479 }
480
481 fn state_after_hir_lowering(input: &'a Input,
482 session: &'tcx Session,
483 out_dir: &'a Option<PathBuf>,
484 out_file: &'a Option<PathBuf>,
485 arena: &'tcx DroplessArena,
486 arenas: &'tcx GlobalArenas<'tcx>,
487 cstore: &'tcx CStore,
488 hir_map: &'a hir_map::Map<'tcx>,
489 analysis: &'a ty::CrateAnalysis,
490 resolutions: &'a Resolutions,
491 krate: &'a ast::Crate,
492 hir_crate: &'a hir::Crate,
493 output_filenames: &'a OutputFilenames,
494 crate_name: &'a str)
495 -> Self {
496 CompileState {
497 crate_name: Some(crate_name),
498 arena: Some(arena),
499 arenas: Some(arenas),
500 cstore: Some(cstore),
501 hir_map: Some(hir_map),
502 analysis: Some(analysis),
503 resolutions: Some(resolutions),
504 expanded_crate: Some(krate),
505 hir_crate: Some(hir_crate),
506 output_filenames: Some(output_filenames),
507 out_file: out_file.as_ref().map(|s| &**s),
508 ..CompileState::empty(input, session, out_dir)
509 }
510 }
511
512 fn state_after_analysis(input: &'a Input,
513 session: &'tcx Session,
514 out_dir: &'a Option<PathBuf>,
515 out_file: &'a Option<PathBuf>,
516 krate: Option<&'a ast::Crate>,
517 hir_crate: &'a hir::Crate,
518 analysis: &'a ty::CrateAnalysis,
519 tcx: TyCtxt<'a, 'tcx, 'tcx>,
520 crate_name: &'a str)
521 -> Self {
522 CompileState {
523 analysis: Some(analysis),
524 tcx: Some(tcx),
525 expanded_crate: krate,
526 hir_crate: Some(hir_crate),
527 crate_name: Some(crate_name),
528 out_file: out_file.as_ref().map(|s| &**s),
529 ..CompileState::empty(input, session, out_dir)
530 }
531 }
532
533 fn state_after_llvm(input: &'a Input,
534 session: &'tcx Session,
535 out_dir: &'a Option<PathBuf>,
536 out_file: &'a Option<PathBuf>,
537 trans: &'a trans::CrateTranslation)
538 -> Self {
539 CompileState {
540 trans: Some(trans),
541 out_file: out_file.as_ref().map(|s| &**s),
542 ..CompileState::empty(input, session, out_dir)
543 }
544 }
545
546 fn state_when_compilation_done(input: &'a Input,
547 session: &'tcx Session,
548 out_dir: &'a Option<PathBuf>,
549 out_file: &'a Option<PathBuf>)
550 -> Self {
551 CompileState {
552 out_file: out_file.as_ref().map(|s| &**s),
553 ..CompileState::empty(input, session, out_dir)
554 }
555 }
556 }
557
558 pub fn phase_1_parse_input<'a>(control: &CompileController,
559 sess: &'a Session,
560 input: &Input)
561 -> PResult<'a, ast::Crate> {
562 sess.diagnostic().set_continue_after_error(control.continue_parse_after_error);
563
564 if sess.profile_queries() {
565 profile::begin();
566 }
567
568 let krate = time(sess.time_passes(), "parsing", || {
569 match *input {
570 Input::File(ref file) => {
571 parse::parse_crate_from_file(file, &sess.parse_sess)
572 }
573 Input::Str { ref input, ref name } => {
574 parse::parse_crate_from_source_str(name.clone(), input.clone(), &sess.parse_sess)
575 }
576 }
577 })?;
578
579 sess.diagnostic().set_continue_after_error(true);
580
581 if sess.opts.debugging_opts.ast_json_noexpand {
582 println!("{}", json::as_json(&krate));
583 }
584
585 if sess.opts.debugging_opts.input_stats {
586 println!("Lines of code: {}", sess.codemap().count_lines());
587 println!("Pre-expansion node count: {}", count_nodes(&krate));
588 }
589
590 if let Some(ref s) = sess.opts.debugging_opts.show_span {
591 syntax::show_span::run(sess.diagnostic(), s, &krate);
592 }
593
594 if sess.opts.debugging_opts.hir_stats {
595 hir_stats::print_ast_stats(&krate, "PRE EXPANSION AST STATS");
596 }
597
598 Ok(krate)
599 }
600
601 fn count_nodes(krate: &ast::Crate) -> usize {
602 let mut counter = NodeCounter::new();
603 visit::walk_crate(&mut counter, krate);
604 counter.count
605 }
606
607 // For continuing compilation after a parsed crate has been
608 // modified
609
610 pub struct ExpansionResult {
611 pub expanded_crate: ast::Crate,
612 pub defs: hir_map::Definitions,
613 pub analysis: ty::CrateAnalysis,
614 pub resolutions: Resolutions,
615 pub hir_forest: hir_map::Forest,
616 }
617
618 /// Run the "early phases" of the compiler: initial `cfg` processing,
619 /// loading compiler plugins (including those from `addl_plugins`),
620 /// syntax expansion, secondary `cfg` expansion, synthesis of a test
621 /// harness if one is to be provided, injection of a dependency on the
622 /// standard library and prelude, and name resolution.
623 ///
624 /// Returns `None` if we're aborting after handling -W help.
625 pub fn phase_2_configure_and_expand<F>(sess: &Session,
626 cstore: &CStore,
627 krate: ast::Crate,
628 registry: Option<Registry>,
629 crate_name: &str,
630 addl_plugins: Option<Vec<String>>,
631 make_glob_map: MakeGlobMap,
632 after_expand: F)
633 -> Result<ExpansionResult, CompileIncomplete>
634 where F: FnOnce(&ast::Crate) -> CompileResult,
635 {
636 let time_passes = sess.time_passes();
637
638 let (mut krate, features) = syntax::config::features(krate, &sess.parse_sess, sess.opts.test);
639 // these need to be set "early" so that expansion sees `quote` if enabled.
640 *sess.features.borrow_mut() = features;
641
642 *sess.crate_types.borrow_mut() = collect_crate_types(sess, &krate.attrs);
643
644 let disambiguator = compute_crate_disambiguator(sess);
645 *sess.crate_disambiguator.borrow_mut() = Some(disambiguator);
646 rustc_incremental::prepare_session_directory(
647 sess,
648 &crate_name,
649 disambiguator,
650 );
651
652 let dep_graph = if sess.opts.build_dep_graph() {
653 let prev_dep_graph = time(time_passes, "load prev dep-graph", || {
654 rustc_incremental::load_dep_graph(sess)
655 });
656
657 DepGraph::new(prev_dep_graph)
658 } else {
659 DepGraph::new_disabled()
660 };
661
662 time(time_passes, "recursion limit", || {
663 middle::recursion_limit::update_limits(sess, &krate);
664 });
665
666 krate = time(time_passes, "crate injection", || {
667 let alt_std_name = sess.opts.alt_std_name.clone();
668 syntax::std_inject::maybe_inject_crates_ref(krate, alt_std_name)
669 });
670
671 let mut addl_plugins = Some(addl_plugins);
672 let registrars = time(time_passes, "plugin loading", || {
673 plugin::load::load_plugins(sess,
674 &cstore,
675 &krate,
676 crate_name,
677 addl_plugins.take().unwrap())
678 });
679
680 let mut registry = registry.unwrap_or(Registry::new(sess, krate.span));
681
682 time(time_passes, "plugin registration", || {
683 if sess.features.borrow().rustc_diagnostic_macros {
684 registry.register_macro("__diagnostic_used",
685 diagnostics::plugin::expand_diagnostic_used);
686 registry.register_macro("__register_diagnostic",
687 diagnostics::plugin::expand_register_diagnostic);
688 registry.register_macro("__build_diagnostic_array",
689 diagnostics::plugin::expand_build_diagnostic_array);
690 }
691
692 for registrar in registrars {
693 registry.args_hidden = Some(registrar.args);
694 (registrar.fun)(&mut registry);
695 }
696 });
697
698 let whitelisted_legacy_custom_derives = registry.take_whitelisted_custom_derives();
699 let Registry { syntax_exts, early_lint_passes, late_lint_passes, lint_groups,
700 llvm_passes, attributes, .. } = registry;
701
702 sess.track_errors(|| {
703 let mut ls = sess.lint_store.borrow_mut();
704 for pass in early_lint_passes {
705 ls.register_early_pass(Some(sess), true, pass);
706 }
707 for pass in late_lint_passes {
708 ls.register_late_pass(Some(sess), true, pass);
709 }
710
711 for (name, to) in lint_groups {
712 ls.register_group(Some(sess), true, name, to);
713 }
714
715 *sess.plugin_llvm_passes.borrow_mut() = llvm_passes;
716 *sess.plugin_attributes.borrow_mut() = attributes.clone();
717 })?;
718
719 // Lint plugins are registered; now we can process command line flags.
720 if sess.opts.describe_lints {
721 super::describe_lints(&sess.lint_store.borrow(), true);
722 return Err(CompileIncomplete::Stopped);
723 }
724
725 // Currently, we ignore the name resolution data structures for the purposes of dependency
726 // tracking. Instead we will run name resolution and include its output in the hash of each
727 // item, much like we do for macro expansion. In other words, the hash reflects not just
728 // its contents but the results of name resolution on those contents. Hopefully we'll push
729 // this back at some point.
730 let mut crate_loader = CrateLoader::new(sess, &cstore, crate_name);
731 let resolver_arenas = Resolver::arenas();
732 let mut resolver = Resolver::new(sess,
733 cstore,
734 &krate,
735 crate_name,
736 make_glob_map,
737 &mut crate_loader,
738 &resolver_arenas);
739 resolver.whitelisted_legacy_custom_derives = whitelisted_legacy_custom_derives;
740 syntax_ext::register_builtins(&mut resolver, syntax_exts, sess.features.borrow().quote);
741
742 krate = time(time_passes, "expansion", || {
743 // Windows dlls do not have rpaths, so they don't know how to find their
744 // dependencies. It's up to us to tell the system where to find all the
745 // dependent dlls. Note that this uses cfg!(windows) as opposed to
746 // targ_cfg because syntax extensions are always loaded for the host
747 // compiler, not for the target.
748 //
749 // This is somewhat of an inherently racy operation, however, as
750 // multiple threads calling this function could possibly continue
751 // extending PATH far beyond what it should. To solve this for now we
752 // just don't add any new elements to PATH which are already there
753 // within PATH. This is basically a targeted fix at #17360 for rustdoc
754 // which runs rustc in parallel but has been seen (#33844) to cause
755 // problems with PATH becoming too long.
756 let mut old_path = OsString::new();
757 if cfg!(windows) {
758 old_path = env::var_os("PATH").unwrap_or(old_path);
759 let mut new_path = sess.host_filesearch(PathKind::All)
760 .get_dylib_search_paths();
761 for path in env::split_paths(&old_path) {
762 if !new_path.contains(&path) {
763 new_path.push(path);
764 }
765 }
766 env::set_var("PATH",
767 &env::join_paths(new_path.iter()
768 .filter(|p| env::join_paths(iter::once(p)).is_ok()))
769 .unwrap());
770 }
771 let features = sess.features.borrow();
772 let cfg = syntax::ext::expand::ExpansionConfig {
773 features: Some(&features),
774 recursion_limit: sess.recursion_limit.get(),
775 trace_mac: sess.opts.debugging_opts.trace_macros,
776 should_test: sess.opts.test,
777 ..syntax::ext::expand::ExpansionConfig::default(crate_name.to_string())
778 };
779
780 let mut ecx = ExtCtxt::new(&sess.parse_sess, cfg, &mut resolver);
781 let err_count = ecx.parse_sess.span_diagnostic.err_count();
782
783 let krate = ecx.monotonic_expander().expand_crate(krate);
784
785 ecx.check_unused_macros();
786
787 let mut missing_fragment_specifiers: Vec<_> =
788 ecx.parse_sess.missing_fragment_specifiers.borrow().iter().cloned().collect();
789 missing_fragment_specifiers.sort();
790 for span in missing_fragment_specifiers {
791 let lint = lint::builtin::MISSING_FRAGMENT_SPECIFIER;
792 let msg = "missing fragment specifier";
793 sess.buffer_lint(lint, ast::CRATE_NODE_ID, span, msg);
794 }
795 if ecx.parse_sess.span_diagnostic.err_count() - ecx.resolve_err_count > err_count {
796 ecx.parse_sess.span_diagnostic.abort_if_errors();
797 }
798 if cfg!(windows) {
799 env::set_var("PATH", &old_path);
800 }
801 krate
802 });
803
804 krate = time(time_passes, "maybe building test harness", || {
805 syntax::test::modify_for_testing(&sess.parse_sess,
806 &mut resolver,
807 sess.opts.test,
808 krate,
809 sess.diagnostic())
810 });
811
812 // If we're in rustdoc we're always compiling as an rlib, but that'll trip a
813 // bunch of checks in the `modify` function below. For now just skip this
814 // step entirely if we're rustdoc as it's not too useful anyway.
815 if !sess.opts.actually_rustdoc {
816 krate = time(time_passes, "maybe creating a macro crate", || {
817 let crate_types = sess.crate_types.borrow();
818 let num_crate_types = crate_types.len();
819 let is_proc_macro_crate = crate_types.contains(&config::CrateTypeProcMacro);
820 let is_test_crate = sess.opts.test;
821 syntax_ext::proc_macro_registrar::modify(&sess.parse_sess,
822 &mut resolver,
823 krate,
824 is_proc_macro_crate,
825 is_test_crate,
826 num_crate_types,
827 sess.diagnostic())
828 });
829 }
830
831 krate = time(time_passes, "creating allocators", || {
832 allocator::expand::modify(&sess.parse_sess,
833 &mut resolver,
834 krate,
835 sess.diagnostic())
836 });
837
838 after_expand(&krate)?;
839
840 if sess.opts.debugging_opts.input_stats {
841 println!("Post-expansion node count: {}", count_nodes(&krate));
842 }
843
844 if sess.opts.debugging_opts.hir_stats {
845 hir_stats::print_ast_stats(&krate, "POST EXPANSION AST STATS");
846 }
847
848 if sess.opts.debugging_opts.ast_json {
849 println!("{}", json::as_json(&krate));
850 }
851
852 time(time_passes,
853 "checking for inline asm in case the target doesn't support it",
854 || no_asm::check_crate(sess, &krate));
855
856 time(time_passes,
857 "AST validation",
858 || ast_validation::check_crate(sess, &krate));
859
860 time(time_passes, "name resolution", || -> CompileResult {
861 resolver.resolve_crate(&krate);
862 Ok(())
863 })?;
864
865 if resolver.found_unresolved_macro {
866 sess.parse_sess.span_diagnostic.abort_if_errors();
867 }
868
869 // Needs to go *after* expansion to be able to check the results of macro expansion.
870 time(time_passes, "complete gated feature checking", || {
871 sess.track_errors(|| {
872 syntax::feature_gate::check_crate(&krate,
873 &sess.parse_sess,
874 &sess.features.borrow(),
875 &attributes,
876 sess.opts.unstable_features);
877 })
878 })?;
879
880 // Lower ast -> hir.
881 let hir_forest = time(time_passes, "lowering ast -> hir", || {
882 let hir_crate = lower_crate(sess, cstore, &dep_graph, &krate, &mut resolver);
883
884 if sess.opts.debugging_opts.hir_stats {
885 hir_stats::print_hir_stats(&hir_crate);
886 }
887
888 hir_map::Forest::new(hir_crate, &dep_graph)
889 });
890
891 time(time_passes,
892 "early lint checks",
893 || lint::check_ast_crate(sess, &krate));
894
895 // Discard hygiene data, which isn't required after lowering to HIR.
896 if !keep_hygiene_data(sess) {
897 syntax::ext::hygiene::clear_markings();
898 }
899
900 Ok(ExpansionResult {
901 expanded_crate: krate,
902 defs: resolver.definitions,
903 analysis: ty::CrateAnalysis {
904 access_levels: Rc::new(AccessLevels::default()),
905 name: crate_name.to_string(),
906 glob_map: if resolver.make_glob_map { Some(resolver.glob_map) } else { None },
907 },
908 resolutions: Resolutions {
909 freevars: resolver.freevars,
910 export_map: resolver.export_map,
911 trait_map: resolver.trait_map,
912 maybe_unused_trait_imports: resolver.maybe_unused_trait_imports,
913 maybe_unused_extern_crates: resolver.maybe_unused_extern_crates,
914 },
915 hir_forest,
916 })
917 }
918
919 pub fn default_provide(providers: &mut ty::maps::Providers) {
920 borrowck::provide(providers);
921 mir::provide(providers);
922 reachable::provide(providers);
923 rustc_privacy::provide(providers);
924 DefaultTransCrate::provide(providers);
925 typeck::provide(providers);
926 ty::provide(providers);
927 traits::provide(providers);
928 reachable::provide(providers);
929 rustc_const_eval::provide(providers);
930 rustc_passes::provide(providers);
931 middle::region::provide(providers);
932 cstore::provide(providers);
933 lint::provide(providers);
934 }
935
936 pub fn default_provide_extern(providers: &mut ty::maps::Providers) {
937 cstore::provide_extern(providers);
938 DefaultTransCrate::provide_extern(providers);
939 }
940
941 /// Run the resolution, typechecking, region checking and other
942 /// miscellaneous analysis passes on the crate. Return various
943 /// structures carrying the results of the analysis.
944 pub fn phase_3_run_analysis_passes<'tcx, F, R>(control: &CompileController,
945 sess: &'tcx Session,
946 cstore: &'tcx CrateStore,
947 hir_map: hir_map::Map<'tcx>,
948 mut analysis: ty::CrateAnalysis,
949 resolutions: Resolutions,
950 arena: &'tcx DroplessArena,
951 arenas: &'tcx GlobalArenas<'tcx>,
952 name: &str,
953 output_filenames: &OutputFilenames,
954 f: F)
955 -> Result<R, CompileIncomplete>
956 where F: for<'a> FnOnce(TyCtxt<'a, 'tcx, 'tcx>,
957 ty::CrateAnalysis,
958 mpsc::Receiver<Box<Any + Send>>,
959 CompileResult) -> R
960 {
961 macro_rules! try_with_f {
962 ($e: expr, ($($t:tt)*)) => {
963 match $e {
964 Ok(x) => x,
965 Err(x) => {
966 f($($t)*, Err(x));
967 return Err(x);
968 }
969 }
970 }
971 }
972
973 let time_passes = sess.time_passes();
974
975 let query_result_on_disk_cache = time(time_passes,
976 "load query result cache",
977 || rustc_incremental::load_query_result_cache(sess));
978
979 let named_region_map = time(time_passes,
980 "lifetime resolution",
981 || middle::resolve_lifetime::krate(sess, cstore, &hir_map))?;
982
983 time(time_passes,
984 "looking for entry point",
985 || middle::entry::find_entry_point(sess, &hir_map));
986
987 sess.plugin_registrar_fn.set(time(time_passes, "looking for plugin registrar", || {
988 plugin::build::find_plugin_registrar(sess.diagnostic(), &hir_map)
989 }));
990 sess.derive_registrar_fn.set(derive_registrar::find(&hir_map));
991
992 time(time_passes,
993 "loop checking",
994 || loops::check_crate(sess, &hir_map));
995
996 time(time_passes,
997 "static item recursion checking",
998 || static_recursion::check_crate(sess, &hir_map))?;
999
1000 let mut local_providers = ty::maps::Providers::default();
1001 default_provide(&mut local_providers);
1002 (control.provide)(&mut local_providers);
1003
1004 let mut extern_providers = local_providers;
1005 default_provide_extern(&mut extern_providers);
1006 (control.provide_extern)(&mut extern_providers);
1007
1008 let (tx, rx) = mpsc::channel();
1009
1010 TyCtxt::create_and_enter(sess,
1011 cstore,
1012 local_providers,
1013 extern_providers,
1014 arenas,
1015 arena,
1016 resolutions,
1017 named_region_map,
1018 hir_map,
1019 query_result_on_disk_cache,
1020 name,
1021 tx,
1022 output_filenames,
1023 |tcx| {
1024 // Do some initialization of the DepGraph that can only be done with the
1025 // tcx available.
1026 rustc_incremental::dep_graph_tcx_init(tcx);
1027
1028 time(time_passes,
1029 "stability checking",
1030 || stability::check_unstable_api_usage(tcx));
1031
1032 // passes are timed inside typeck
1033 try_with_f!(typeck::check_crate(tcx), (tcx, analysis, rx));
1034
1035 time(time_passes,
1036 "const checking",
1037 || consts::check_crate(tcx));
1038
1039 analysis.access_levels =
1040 time(time_passes, "privacy checking", || rustc_privacy::check_crate(tcx));
1041
1042 time(time_passes,
1043 "intrinsic checking",
1044 || middle::intrinsicck::check_crate(tcx));
1045
1046 time(time_passes,
1047 "match checking",
1048 || check_match::check_crate(tcx));
1049
1050 // this must run before MIR dump, because
1051 // "not all control paths return a value" is reported here.
1052 //
1053 // maybe move the check to a MIR pass?
1054 time(time_passes,
1055 "liveness checking",
1056 || middle::liveness::check_crate(tcx));
1057
1058 time(time_passes,
1059 "borrow checking",
1060 || borrowck::check_crate(tcx));
1061
1062 time(time_passes,
1063 "MIR borrow checking",
1064 || for def_id in tcx.body_owners() { tcx.mir_borrowck(def_id) });
1065
1066 time(time_passes,
1067 "MIR effect checking",
1068 || for def_id in tcx.body_owners() {
1069 mir::transform::check_unsafety::check_unsafety(tcx, def_id)
1070 });
1071 // Avoid overwhelming user with errors if type checking failed.
1072 // I'm not sure how helpful this is, to be honest, but it avoids
1073 // a
1074 // lot of annoying errors in the compile-fail tests (basically,
1075 // lint warnings and so on -- kindck used to do this abort, but
1076 // kindck is gone now). -nmatsakis
1077 if sess.err_count() > 0 {
1078 return Ok(f(tcx, analysis, rx, sess.compile_status()));
1079 }
1080
1081 time(time_passes, "death checking", || middle::dead::check_crate(tcx));
1082
1083 time(time_passes, "unused lib feature checking", || {
1084 stability::check_unused_or_stable_features(tcx)
1085 });
1086
1087 time(time_passes, "lint checking", || lint::check_crate(tcx));
1088
1089 return Ok(f(tcx, analysis, rx, tcx.sess.compile_status()));
1090 })
1091 }
1092
1093 /// Run the translation phase to LLVM, after which the AST and analysis can
1094 /// be discarded.
1095 pub fn phase_4_translate_to_llvm<'a, 'tcx, Trans: TransCrate>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1096 rx: mpsc::Receiver<Box<Any + Send>>)
1097 -> <Trans as TransCrate>::OngoingCrateTranslation {
1098 let time_passes = tcx.sess.time_passes();
1099
1100 time(time_passes,
1101 "resolving dependency formats",
1102 || ::rustc::middle::dependency_format::calculate(tcx));
1103
1104 let translation =
1105 time(time_passes, "translation", move || {
1106 Trans::trans_crate(tcx, rx)
1107 });
1108 if tcx.sess.profile_queries() {
1109 profile::dump("profile_queries".to_string())
1110 }
1111
1112 translation
1113 }
1114
1115 /// Run LLVM itself, producing a bitcode file, assembly file or object file
1116 /// as a side effect.
1117 pub fn phase_5_run_llvm_passes<Trans: TransCrate>(sess: &Session,
1118 dep_graph: &DepGraph,
1119 trans: <Trans as TransCrate>::OngoingCrateTranslation)
1120 -> (CompileResult, <Trans as TransCrate>::TranslatedCrate) {
1121 let trans = Trans::join_trans(trans, sess, dep_graph);
1122
1123 if sess.opts.debugging_opts.incremental_info {
1124 Trans::dump_incremental_data(&trans);
1125 }
1126
1127 time(sess.time_passes(),
1128 "serialize work products",
1129 move || rustc_incremental::save_work_products(sess, dep_graph));
1130
1131 (sess.compile_status(), trans)
1132 }
1133
1134 fn escape_dep_filename(filename: &str) -> String {
1135 // Apparently clang and gcc *only* escape spaces:
1136 // http://llvm.org/klaus/clang/commit/9d50634cfc268ecc9a7250226dd5ca0e945240d4
1137 filename.replace(" ", "\\ ")
1138 }
1139
1140 fn write_out_deps(sess: &Session, outputs: &OutputFilenames, crate_name: &str) {
1141 let mut out_filenames = Vec::new();
1142 for output_type in sess.opts.output_types.keys() {
1143 let file = outputs.path(*output_type);
1144 match *output_type {
1145 OutputType::Exe => {
1146 for output in sess.crate_types.borrow().iter() {
1147 let p = ::rustc_trans_utils::link::filename_for_input(
1148 sess,
1149 *output,
1150 crate_name,
1151 outputs
1152 );
1153 out_filenames.push(p);
1154 }
1155 }
1156 _ => {
1157 out_filenames.push(file);
1158 }
1159 }
1160 }
1161
1162 // Write out dependency rules to the dep-info file if requested
1163 if !sess.opts.output_types.contains_key(&OutputType::DepInfo) {
1164 return;
1165 }
1166 let deps_filename = outputs.path(OutputType::DepInfo);
1167
1168 let result =
1169 (|| -> io::Result<()> {
1170 // Build a list of files used to compile the output and
1171 // write Makefile-compatible dependency rules
1172 let files: Vec<String> = sess.codemap()
1173 .files()
1174 .iter()
1175 .filter(|fmap| fmap.is_real_file())
1176 .filter(|fmap| !fmap.is_imported())
1177 .map(|fmap| escape_dep_filename(&fmap.name))
1178 .collect();
1179 let mut file = fs::File::create(&deps_filename)?;
1180 for path in &out_filenames {
1181 write!(file, "{}: {}\n\n", path.display(), files.join(" "))?;
1182 }
1183
1184 // Emit a fake target for each input file to the compilation. This
1185 // prevents `make` from spitting out an error if a file is later
1186 // deleted. For more info see #28735
1187 for path in files {
1188 writeln!(file, "{}:", path)?;
1189 }
1190 Ok(())
1191 })();
1192
1193 match result {
1194 Ok(()) => {}
1195 Err(e) => {
1196 sess.fatal(&format!("error writing dependencies to `{}`: {}",
1197 deps_filename.display(),
1198 e));
1199 }
1200 }
1201 }
1202
1203 pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec<config::CrateType> {
1204 // Unconditionally collect crate types from attributes to make them used
1205 let attr_types: Vec<config::CrateType> =
1206 attrs.iter()
1207 .filter_map(|a| {
1208 if a.check_name("crate_type") {
1209 match a.value_str() {
1210 Some(ref n) if *n == "rlib" => {
1211 Some(config::CrateTypeRlib)
1212 }
1213 Some(ref n) if *n == "dylib" => {
1214 Some(config::CrateTypeDylib)
1215 }
1216 Some(ref n) if *n == "cdylib" => {
1217 Some(config::CrateTypeCdylib)
1218 }
1219 Some(ref n) if *n == "lib" => {
1220 Some(config::default_lib_output())
1221 }
1222 Some(ref n) if *n == "staticlib" => {
1223 Some(config::CrateTypeStaticlib)
1224 }
1225 Some(ref n) if *n == "proc-macro" => {
1226 Some(config::CrateTypeProcMacro)
1227 }
1228 Some(ref n) if *n == "bin" => Some(config::CrateTypeExecutable),
1229 Some(_) => {
1230 session.buffer_lint(lint::builtin::UNKNOWN_CRATE_TYPES,
1231 ast::CRATE_NODE_ID,
1232 a.span,
1233 "invalid `crate_type` value");
1234 None
1235 }
1236 _ => {
1237 session.struct_span_err(a.span, "`crate_type` requires a value")
1238 .note("for example: `#![crate_type=\"lib\"]`")
1239 .emit();
1240 None
1241 }
1242 }
1243 } else {
1244 None
1245 }
1246 })
1247 .collect();
1248
1249 // If we're generating a test executable, then ignore all other output
1250 // styles at all other locations
1251 if session.opts.test {
1252 return vec![config::CrateTypeExecutable];
1253 }
1254
1255 // Only check command line flags if present. If no types are specified by
1256 // command line, then reuse the empty `base` Vec to hold the types that
1257 // will be found in crate attributes.
1258 let mut base = session.opts.crate_types.clone();
1259 if base.is_empty() {
1260 base.extend(attr_types);
1261 if base.is_empty() {
1262 base.push(::rustc_trans_utils::link::default_output_for_target(session));
1263 }
1264 base.sort();
1265 base.dedup();
1266 }
1267
1268 base.into_iter()
1269 .filter(|crate_type| {
1270 let res = !::rustc_trans_utils::link::invalid_output_for_target(session, *crate_type);
1271
1272 if !res {
1273 session.warn(&format!("dropping unsupported crate type `{}` for target `{}`",
1274 *crate_type,
1275 session.opts.target_triple));
1276 }
1277
1278 res
1279 })
1280 .collect()
1281 }
1282
1283 pub fn compute_crate_disambiguator(session: &Session) -> CrateDisambiguator {
1284 use std::hash::Hasher;
1285
1286 // The crate_disambiguator is a 128 bit hash. The disambiguator is fed
1287 // into various other hashes quite a bit (symbol hashes, incr. comp. hashes,
1288 // debuginfo type IDs, etc), so we don't want it to be too wide. 128 bits
1289 // should still be safe enough to avoid collisions in practice.
1290 let mut hasher = StableHasher::<Fingerprint>::new();
1291
1292 let mut metadata = session.opts.cg.metadata.clone();
1293 // We don't want the crate_disambiguator to dependent on the order
1294 // -C metadata arguments, so sort them:
1295 metadata.sort();
1296 // Every distinct -C metadata value is only incorporated once:
1297 metadata.dedup();
1298
1299 hasher.write(b"metadata");
1300 for s in &metadata {
1301 // Also incorporate the length of a metadata string, so that we generate
1302 // different values for `-Cmetadata=ab -Cmetadata=c` and
1303 // `-Cmetadata=a -Cmetadata=bc`
1304 hasher.write_usize(s.len());
1305 hasher.write(s.as_bytes());
1306 }
1307
1308 // Also incorporate crate type, so that we don't get symbol conflicts when
1309 // linking against a library of the same name, if this is an executable.
1310 let is_exe = session.crate_types.borrow().contains(&config::CrateTypeExecutable);
1311 hasher.write(if is_exe { b"exe" } else { b"lib" });
1312
1313 CrateDisambiguator::from(hasher.finish())
1314
1315 }
1316
1317 pub fn build_output_filenames(input: &Input,
1318 odir: &Option<PathBuf>,
1319 ofile: &Option<PathBuf>,
1320 attrs: &[ast::Attribute],
1321 sess: &Session)
1322 -> OutputFilenames {
1323 match *ofile {
1324 None => {
1325 // "-" as input file will cause the parser to read from stdin so we
1326 // have to make up a name
1327 // We want to toss everything after the final '.'
1328 let dirpath = match *odir {
1329 Some(ref d) => d.clone(),
1330 None => PathBuf::new(),
1331 };
1332
1333 // If a crate name is present, we use it as the link name
1334 let stem = sess.opts
1335 .crate_name
1336 .clone()
1337 .or_else(|| attr::find_crate_name(attrs).map(|n| n.to_string()))
1338 .unwrap_or(input.filestem());
1339
1340 OutputFilenames {
1341 out_directory: dirpath,
1342 out_filestem: stem,
1343 single_output_file: None,
1344 extra: sess.opts.cg.extra_filename.clone(),
1345 outputs: sess.opts.output_types.clone(),
1346 }
1347 }
1348
1349 Some(ref out_file) => {
1350 let unnamed_output_types = sess.opts
1351 .output_types
1352 .values()
1353 .filter(|a| a.is_none())
1354 .count();
1355 let ofile = if unnamed_output_types > 1 {
1356 sess.warn("due to multiple output types requested, the explicitly specified \
1357 output file name will be adapted for each output type");
1358 None
1359 } else {
1360 Some(out_file.clone())
1361 };
1362 if *odir != None {
1363 sess.warn("ignoring --out-dir flag due to -o flag.");
1364 }
1365
1366 let cur_dir = Path::new("");
1367
1368 OutputFilenames {
1369 out_directory: out_file.parent().unwrap_or(cur_dir).to_path_buf(),
1370 out_filestem: out_file.file_stem()
1371 .unwrap_or(OsStr::new(""))
1372 .to_str()
1373 .unwrap()
1374 .to_string(),
1375 single_output_file: ofile,
1376 extra: sess.opts.cg.extra_filename.clone(),
1377 outputs: sess.opts.output_types.clone(),
1378 }
1379 }
1380 }
1381 }