Skip to content

Commit c0d0ce9

Browse files
committed
safe transmute: tweak tracing
ref: #92268 (comment) ref: #92268 (comment) ref: #92268 (comment)
1 parent 0fa70c3 commit c0d0ce9

File tree

5 files changed

+16
-21
lines changed

5 files changed

+16
-21
lines changed

compiler/rustc_transmute/src/layout/dfa.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ where
103103
Self { transitions, start, accepting }
104104
}
105105

106-
#[tracing::instrument]
106+
#[instrument(level = "DEBUG")]
107107
#[cfg_attr(feature = "rustc", allow(rustc::potential_query_instability))]
108108
pub(crate) fn from_nfa(nfa: Nfa<R>) -> Self {
109109
let Nfa { transitions: nfa_transitions, start: nfa_start, accepting: nfa_accepting } = nfa;

compiler/rustc_transmute/src/layout/tree.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ where
7676
}
7777

7878
/// A `Tree` whose layout is entirely padding of the given width.
79-
#[tracing::instrument]
8079
pub(crate) fn padding(width_in_bytes: usize) -> Self {
8180
Self::Seq(vec![Self::uninit(); width_in_bytes])
8281
}
@@ -316,10 +315,7 @@ pub(crate) mod rustc {
316315
tcx,
317316
)?,
318317
AdtKind::Enum => {
319-
tracing::trace!(
320-
adt_def = ?adt_def,
321-
"treeifying enum"
322-
);
318+
tracing::trace!(?adt_def, "treeifying enum");
323319
let mut tree = Tree::uninhabited();
324320

325321
for (idx, discr) in adt_def.discriminants(tcx) {
@@ -398,13 +394,13 @@ pub(crate) mod rustc {
398394

399395
// The layout of the variant is prefixed by the discriminant, if any.
400396
if let Some(discr) = discr {
401-
tracing::trace!(discr = ?discr, "treeifying discriminant");
397+
tracing::trace!(?discr, "treeifying discriminant");
402398
let discr_layout = alloc::Layout::from_size_align(
403399
layout_summary.discriminant_size,
404400
clamp(layout_summary.discriminant_align),
405401
)
406402
.unwrap();
407-
tracing::trace!(discr_layout = ?discr_layout, "computed discriminant layout");
403+
tracing::trace!(?discr_layout, "computed discriminant layout");
408404
variant_layout = variant_layout.extend(discr_layout).unwrap().0;
409405
tree = tree.then(Self::from_disr(discr, tcx, layout_summary.discriminant_size));
410406
}
@@ -469,11 +465,7 @@ pub(crate) mod rustc {
469465
layout.align().abi.bytes().try_into().unwrap(),
470466
)
471467
.unwrap();
472-
tracing::trace!(
473-
ty = ?ty,
474-
layout = ?layout,
475-
"computed layout for type"
476-
);
468+
tracing::trace!(?ty, ?layout, "computed layout for type");
477469
Ok(layout)
478470
}
479471
}

compiler/rustc_transmute/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
)]
99
#![allow(dead_code, unused_variables)]
1010

11+
#[macro_use]
12+
extern crate tracing;
13+
1114
#[cfg(feature = "rustc")]
1215
pub(crate) use rustc_data_structures::fx::{FxHashMap as Map, FxHashSet as Set};
1316

compiler/rustc_transmute/src/maybe_transmutable/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ mod rustc {
6464
impl<'tcx> MaybeTransmutableQuery<Ty<'tcx>, TyCtxt<'tcx>> {
6565
/// This method begins by converting `src` and `dst` from `Ty`s to `Tree`s,
6666
/// then computes an answer using those trees.
67-
#[tracing::instrument(skip(self), fields(src = ?self.src, dst = ?self.dst))]
67+
#[instrument(level = "DEBUG", skip(self), fields(src = ?self.src, dst = ?self.dst))]
6868
pub fn answer(self) -> Answer<<TyCtxt<'tcx> as QueryContext>::Ref> {
6969
let query_or_answer = self.map_layouts(|src, dst, scope, &context| {
7070
// Convert `src` and `dst` from their rustc representations, to `Tree`-based
@@ -103,14 +103,14 @@ where
103103
/// This method begins by de-def'ing `src` and `dst`, and prunes private paths from `dst`,
104104
/// then converts `src` and `dst` to `Nfa`s, and computes an answer using those NFAs.
105105
#[inline(always)]
106-
#[tracing::instrument(skip(self), fields(src = ?self.src, dst = ?self.dst))]
106+
#[instrument(level = "DEBUG", skip(self), fields(src = ?self.src, dst = ?self.dst))]
107107
pub(crate) fn answer(self) -> Answer<<C as QueryContext>::Ref> {
108108
let assume_visibility = self.assume.visibility;
109109
let query_or_answer = self.map_layouts(|src, dst, scope, context| {
110110
// Remove all `Def` nodes from `src`, without checking their visibility.
111111
let src = src.prune(&|def| true);
112112

113-
tracing::trace!(src = ?src, "pruned src");
113+
tracing::trace!(?src, "pruned src");
114114

115115
// Remove all `Def` nodes from `dst`, additionally...
116116
let dst = if assume_visibility {
@@ -121,7 +121,7 @@ where
121121
dst.prune(&|def| context.is_accessible_from(def, scope))
122122
};
123123

124-
tracing::trace!(dst = ?dst, "pruned dst");
124+
tracing::trace!(?dst, "pruned dst");
125125

126126
// Convert `src` from a tree-based representation to an NFA-based representation.
127127
// If the conversion fails because `src` is uninhabited, conclude that the transmutation
@@ -152,7 +152,7 @@ where
152152
///
153153
/// This method converts `src` and `dst` to DFAs, then computes an answer using those DFAs.
154154
#[inline(always)]
155-
#[tracing::instrument(skip(self), fields(src = ?self.src, dst = ?self.dst))]
155+
#[instrument(level = "DEBUG", skip(self), fields(src = ?self.src, dst = ?self.dst))]
156156
pub(crate) fn answer(self) -> Answer<<C as QueryContext>::Ref> {
157157
let query_or_answer = self
158158
.map_layouts(|src, dst, scope, context| Ok((Dfa::from_nfa(src), Dfa::from_nfa(dst))));
@@ -192,7 +192,7 @@ where
192192
}
193193

194194
#[inline(always)]
195-
#[tracing::instrument(skip(self))]
195+
#[instrument(level = "DEBUG", skip(self))]
196196
fn answer_memo(
197197
&self,
198198
cache: &mut Map<(dfa::State, dfa::State), Answer<<C as QueryContext>::Ref>>,

compiler/rustc_transmute/src/maybe_transmutable/query_context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ mod rustc {
5252

5353
type Scope = Ty<'tcx>;
5454

55-
#[tracing::instrument(skip(self))]
55+
#[instrument(level = "DEBUG", skip(self))]
5656
fn is_accessible_from(&self, def: Self::Def, scope: Self::Scope) -> bool {
5757
use layout::rustc::Def;
5858
use rustc_middle::ty;
@@ -82,7 +82,7 @@ mod rustc {
8282
false
8383
};
8484

85-
tracing::trace!(ret = ?ret, "ret");
85+
tracing::trace!(?ret, "ret");
8686
ret
8787
}
8888

0 commit comments

Comments
 (0)