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