1use std::cell::Cell;
4use std::fmt::Write;
5use std::fs::File;
6use std::io;
7
8use rustc_ast as ast;
9use rustc_ast_pretty::pprust as pprust_ast;
10use rustc_hir::intravisit;
11use rustc_hir_pretty as pprust_hir;
12use rustc_hir_pretty::PpAnn;
13use rustc_middle::mir::{write_mir_graphviz, write_mir_pretty};
14use rustc_middle::ty::{self, TyCtxt};
15use rustc_mir_build::thir::print::{thir_flat, thir_tree};
16use rustc_public::rustc_internal::pretty::write_smir_pretty;
17use rustc_session::Session;
18use rustc_session::config::{OutFileName, OutputType, PpHirMode, PpMode, PpSourceMode};
19use rustc_span::{FileName, Ident, bug};
20use tracing::debug;
21
22pub use self::PpMode::*;
23pub use self::PpSourceMode::*;
24
25struct AstNoAnn;
26
27impl pprust_ast::PpAnn for AstNoAnn {}
28
29struct AstIdentifiedAnn;
30
31impl pprust_ast::PpAnn for AstIdentifiedAnn {
32 fn pre(&self, s: &mut pprust_ast::State<'_>, node: pprust_ast::AnnNode<'_>) {
33 if let pprust_ast::AnnNode::Expr(_) = node {
34 s.popen();
35 }
36 }
37
38 fn post(&self, s: &mut pprust_ast::State<'_>, node: pprust_ast::AnnNode<'_>) {
39 match node {
40 pprust_ast::AnnNode::Crate(_)
41 | pprust_ast::AnnNode::Ident(_)
42 | pprust_ast::AnnNode::Name(_) => {}
43
44 pprust_ast::AnnNode::Item(item) => {
45 s.s.space();
46 s.synth_comment(item.id.to_string())
47 }
48 pprust_ast::AnnNode::SubItem(id) => {
49 s.s.space();
50 s.synth_comment(id.to_string())
51 }
52 pprust_ast::AnnNode::Block(blk) => {
53 s.s.space();
54 s.synth_comment(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("block {0}", blk.id))
})format!("block {}", blk.id))
55 }
56 pprust_ast::AnnNode::Expr(expr) => {
57 s.s.space();
58 s.synth_comment(expr.id.to_string());
59 s.pclose()
60 }
61 pprust_ast::AnnNode::Pat(pat) => {
62 s.s.space();
63 s.synth_comment(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("pat {0}", pat.id))
})format!("pat {}", pat.id));
64 }
65 }
66 }
67}
68
69struct HirIdentifiedAnn<'tcx> {
70 tcx: TyCtxt<'tcx>,
71}
72
73impl<'tcx> pprust_hir::PpAnn for HirIdentifiedAnn<'tcx> {
74 fn nested(&self, state: &mut pprust_hir::State<'_>, nested: pprust_hir::Nested) {
75 let this = &self.tcx as &dyn intravisit::HirTyCtxt<'_>;
76 this.nested(state, nested)
77 }
78
79 fn pre(&self, s: &mut pprust_hir::State<'_>, node: pprust_hir::AnnNode<'_>) {
80 if let pprust_hir::AnnNode::Expr(_) = node {
81 s.popen();
82 }
83 }
84
85 fn post(&self, s: &mut pprust_hir::State<'_>, node: pprust_hir::AnnNode<'_>) {
86 match node {
87 pprust_hir::AnnNode::Name(_) => {}
88 pprust_hir::AnnNode::Item(item) => {
89 s.s.space();
90 s.synth_comment(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("hir_id: {0}", item.hir_id()))
})format!("hir_id: {}", item.hir_id()));
91 }
92 pprust_hir::AnnNode::SubItem(id) => {
93 s.s.space();
94 s.synth_comment(id.to_string());
95 }
96 pprust_hir::AnnNode::Block(blk) => {
97 s.s.space();
98 s.synth_comment(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("block hir_id: {0}", blk.hir_id))
})format!("block hir_id: {}", blk.hir_id));
99 }
100 pprust_hir::AnnNode::Expr(expr) => {
101 s.s.space();
102 s.synth_comment(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("expr hir_id: {0}", expr.hir_id))
})format!("expr hir_id: {}", expr.hir_id));
103 s.pclose();
104 }
105 pprust_hir::AnnNode::Pat(pat) => {
106 s.s.space();
107 s.synth_comment(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("pat hir_id: {0}", pat.hir_id))
})format!("pat hir_id: {}", pat.hir_id));
108 }
109 pprust_hir::AnnNode::TyPat(pat) => {
110 s.s.space();
111 s.synth_comment(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("ty pat hir_id: {0}", pat.hir_id))
})format!("ty pat hir_id: {}", pat.hir_id));
112 }
113 pprust_hir::AnnNode::Arm(arm) => {
114 s.s.space();
115 s.synth_comment(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("arm hir_id: {0}", arm.hir_id))
})format!("arm hir_id: {}", arm.hir_id));
116 }
117 }
118 }
119}
120
121struct AstHygieneAnn<'a> {
122 sess: &'a Session,
123}
124
125impl<'a> pprust_ast::PpAnn for AstHygieneAnn<'a> {
126 fn post(&self, s: &mut pprust_ast::State<'_>, node: pprust_ast::AnnNode<'_>) {
127 match node {
128 pprust_ast::AnnNode::Ident(&Ident { name, span }) => {
129 s.s.space();
130 s.synth_comment(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0}{1:?}", name.as_u32(),
span.ctxt()))
})format!("{}{:?}", name.as_u32(), span.ctxt()))
131 }
132 pprust_ast::AnnNode::Name(&name) => {
133 s.s.space();
134 s.synth_comment(name.as_u32().to_string())
135 }
136 pprust_ast::AnnNode::Crate(_) => {
137 s.s.hardbreak();
138 let verbose = self.sess.verbose_internals();
139 s.synth_comment(rustc_span::hygiene::debug_hygiene_data(verbose));
140 s.s.hardbreak_if_not_bol();
141 }
142 _ => {}
143 }
144 }
145}
146
147struct HirTypedAnn<'tcx> {
148 tcx: TyCtxt<'tcx>,
149 maybe_typeck_results: Cell<Option<&'tcx ty::TypeckResults<'tcx>>>,
150}
151
152impl<'tcx> pprust_hir::PpAnn for HirTypedAnn<'tcx> {
153 fn nested(&self, state: &mut pprust_hir::State<'_>, nested: pprust_hir::Nested) {
154 let this = &self.tcx as &dyn intravisit::HirTyCtxt<'_>;
155 let old_maybe_typeck_results = self.maybe_typeck_results.get();
156 if let pprust_hir::Nested::Body(id) = nested {
157 self.maybe_typeck_results.set(Some(self.tcx.typeck_body(id)));
158 }
159 this.nested(state, nested);
160 self.maybe_typeck_results.set(old_maybe_typeck_results);
161 }
162
163 fn pre(&self, s: &mut pprust_hir::State<'_>, node: pprust_hir::AnnNode<'_>) {
164 if let pprust_hir::AnnNode::Expr(_) = node {
165 s.popen();
166 }
167 }
168
169 fn post(&self, s: &mut pprust_hir::State<'_>, node: pprust_hir::AnnNode<'_>) {
170 if let pprust_hir::AnnNode::Expr(expr) = node {
171 let typeck_results = self.maybe_typeck_results.get().or_else(|| {
172 self.tcx
173 .hir_maybe_body_owned_by(expr.hir_id.owner.def_id)
174 .map(|body_id| self.tcx.typeck_body(body_id.id()))
175 });
176
177 if let Some(typeck_results) = typeck_results {
178 s.s.space();
179 s.s.word("as");
180 s.s.space();
181 s.s.word(typeck_results.expr_ty(expr).to_string());
182 }
183
184 s.pclose();
185 }
186 }
187}
188
189fn get_source(sess: &Session) -> (String, FileName) {
190 let src_name = sess.io.input.file_name(&sess);
191 let src = String::clone(
192 sess.source_map()
193 .get_source_file(&src_name)
194 .expect("get_source_file")
195 .src
196 .as_ref()
197 .expect("src"),
198 );
199 (src, src_name)
200}
201
202fn write_or_print(out: &str, sess: &Session) {
203 sess.io.output_file.as_ref().unwrap_or(&OutFileName::Stdout).overwrite(out, sess);
204}
205
206pub enum PrintExtra<'tcx> {
209 AfterParsing { krate: &'tcx ast::Crate },
210 NeedsAstMap { tcx: TyCtxt<'tcx> },
211}
212
213impl<'tcx> PrintExtra<'tcx> {
214 fn with_krate<F, R>(&self, f: F) -> R
215 where
216 F: FnOnce(&ast::Crate) -> R,
217 {
218 match self {
219 PrintExtra::AfterParsing { krate, .. } => f(krate),
220 PrintExtra::NeedsAstMap { tcx } => f(&tcx.resolver_for_lowering().1.borrow()),
221 }
222 }
223
224 fn tcx(&self) -> TyCtxt<'tcx> {
225 match self {
226 PrintExtra::AfterParsing { .. } => bug_impl(None, format_args!("PrintExtra::tcx"), Location::caller())bug!("PrintExtra::tcx"),
227 PrintExtra::NeedsAstMap { tcx } => *tcx,
228 }
229 }
230}
231
232pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
233 if ppm.needs_analysis() {
234 ex.tcx().ensure_ok().analysis(());
235 }
236
237 let (src, src_name) = get_source(sess);
238
239 let out = match ppm {
240 Source(s) => {
241 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_driver_impl/src/pretty.rs:241",
"rustc_driver_impl::pretty", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_driver_impl/src/pretty.rs"),
::tracing_core::__macro_support::Option::Some(241u32),
::tracing_core::__macro_support::Option::Some("rustc_driver_impl::pretty"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("pretty printing source code {0:?}",
s) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("pretty printing source code {:?}", s);
242 let annotation: Box<dyn pprust_ast::PpAnn> = match s {
243 Normal => Box::new(AstNoAnn),
244 Expanded => Box::new(AstNoAnn),
245 ExpandedIdentified => Box::new(AstIdentifiedAnn),
246 ExpandedHygiene => Box::new(AstHygieneAnn { sess }),
247 };
248 let psess = &sess.psess;
249 let is_expanded = ppm.needs_ast_map();
250 ex.with_krate(|krate| {
251 pprust_ast::print_crate(
252 sess.source_map(),
253 krate,
254 src_name,
255 src,
256 &*annotation,
257 is_expanded,
258 psess.edition,
259 &sess.psess.attr_id_generator,
260 )
261 })
262 }
263 AstTree => {
264 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_driver_impl/src/pretty.rs:264",
"rustc_driver_impl::pretty", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_driver_impl/src/pretty.rs"),
::tracing_core::__macro_support::Option::Some(264u32),
::tracing_core::__macro_support::Option::Some("rustc_driver_impl::pretty"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("pretty printing AST tree")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("pretty printing AST tree");
265 ex.with_krate(|krate| ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0:#?}", krate))
})format!("{krate:#?}"))
266 }
267 AstTreeExpanded => {
268 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_driver_impl/src/pretty.rs:268",
"rustc_driver_impl::pretty", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_driver_impl/src/pretty.rs"),
::tracing_core::__macro_support::Option::Some(268u32),
::tracing_core::__macro_support::Option::Some("rustc_driver_impl::pretty"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("pretty-printing expanded AST")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("pretty-printing expanded AST");
269 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0:#?}",
ex.tcx().resolver_for_lowering().1.borrow()))
})format!("{:#?}", ex.tcx().resolver_for_lowering().1.borrow())
270 }
271 Hir(s) => {
272 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_driver_impl/src/pretty.rs:272",
"rustc_driver_impl::pretty", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_driver_impl/src/pretty.rs"),
::tracing_core::__macro_support::Option::Some(272u32),
::tracing_core::__macro_support::Option::Some("rustc_driver_impl::pretty"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("pretty printing HIR {0:?}",
s) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("pretty printing HIR {:?}", s);
273 let tcx = ex.tcx();
274 let f = |annotation: &dyn pprust_hir::PpAnn| {
275 let sm = sess.source_map();
276 let attrs = |id| tcx.hir_attrs(id);
277 pprust_hir::print_crate(
278 sm,
279 tcx.hir_root_module(),
280 src_name,
281 src,
282 &attrs,
283 annotation,
284 )
285 };
286 match s {
287 PpHirMode::Normal => f(&(&tcx as &dyn intravisit::HirTyCtxt<'_>) as &dyn PpAnn),
288 PpHirMode::Identified => {
289 let annotation = HirIdentifiedAnn { tcx };
290 f(&annotation)
291 }
292 PpHirMode::Typed => {
293 let annotation = HirTypedAnn { tcx, maybe_typeck_results: Cell::new(None) };
294 tcx.dep_graph.with_ignore(|| f(&annotation))
295 }
296 }
297 }
298 HirTree => {
299 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_driver_impl/src/pretty.rs:299",
"rustc_driver_impl::pretty", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_driver_impl/src/pretty.rs"),
::tracing_core::__macro_support::Option::Some(299u32),
::tracing_core::__macro_support::Option::Some("rustc_driver_impl::pretty"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("pretty printing HIR tree")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("pretty printing HIR tree");
300 ex.tcx()
301 .hir_crate_items(())
302 .owners()
303 .map(|owner| ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0:#?} => {1:#?}\n", owner,
ex.tcx().hir_owner_nodes(owner)))
})format!("{:#?} => {:#?}\n", owner, ex.tcx().hir_owner_nodes(owner)))
304 .collect()
305 }
306 Mir => {
307 let mut out = Vec::new();
308 write_mir_pretty(ex.tcx(), &mut out).unwrap();
309 String::from_utf8(out).unwrap()
310 }
311 MirCFG => {
312 let mut out = Vec::new();
313 write_mir_graphviz(ex.tcx(), &mut out).unwrap();
314 String::from_utf8(out).unwrap()
315 }
316 StableMir => {
317 let mut out = Vec::new();
318 write_smir_pretty(ex.tcx(), &mut out).unwrap();
319 String::from_utf8(out).unwrap()
320 }
321 ThirTree => {
322 let tcx = ex.tcx();
323 let mut out = String::new();
324 rustc_hir_analysis::check_crate(tcx);
325 tcx.dcx().abort_if_errors();
326 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_driver_impl/src/pretty.rs:326",
"rustc_driver_impl::pretty", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_driver_impl/src/pretty.rs"),
::tracing_core::__macro_support::Option::Some(326u32),
::tracing_core::__macro_support::Option::Some("rustc_driver_impl::pretty"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("pretty printing THIR tree")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("pretty printing THIR tree");
327 for did in tcx.hir_body_owners() {
328 let _ = out.write_fmt(format_args!("{0:?}:\n{1}\n\n", did, thir_tree(tcx, did)))writeln!(out, "{:?}:\n{}\n", did, thir_tree(tcx, did));
329 }
330 out
331 }
332 ThirFlat => {
333 let tcx = ex.tcx();
334 let mut out = String::new();
335 rustc_hir_analysis::check_crate(tcx);
336 tcx.dcx().abort_if_errors();
337 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_driver_impl/src/pretty.rs:337",
"rustc_driver_impl::pretty", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_driver_impl/src/pretty.rs"),
::tracing_core::__macro_support::Option::Some(337u32),
::tracing_core::__macro_support::Option::Some("rustc_driver_impl::pretty"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("pretty printing THIR flat")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("pretty printing THIR flat");
338 for did in tcx.hir_body_owners() {
339 let _ = out.write_fmt(format_args!("{0:?}:\n{1}\n\n", did, thir_flat(tcx, did)))writeln!(out, "{:?}:\n{}\n", did, thir_flat(tcx, did));
340 }
341 out
342 }
343 };
344
345 write_or_print(&out, sess);
346}
347
348pub fn emit_mir(tcx: TyCtxt<'_>) -> io::Result<()> {
350 match tcx.output_filenames(()).path(OutputType::Mir) {
351 OutFileName::Stdout => {
352 let mut f = io::stdout();
353 write_mir_pretty(tcx, &mut f)?;
354 }
355 OutFileName::Real(path) => {
356 let mut f = File::create_buffered(&path)?;
357 write_mir_pretty(tcx, &mut f)?;
358 if tcx.sess.opts.json_artifact_notifications {
359 tcx.dcx().emit_artifact_notification(&path, "mir");
360 }
361 }
362 }
363 Ok(())
364}