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