Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 6 pull requests #87108

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
07f1e61
Add natvis for NonZero and Wrapping types
wesleywiser Jun 28, 2021
9740dcc
Add natvis for Atomic types
wesleywiser Jun 29, 2021
cad42e0
Add natvis for cell types
wesleywiser Jun 29, 2021
8f1eec3
Fixup natvis for NonNull and Unique types
wesleywiser Jun 29, 2021
f2aba34
Add natvis for Range types
wesleywiser Jun 29, 2021
691ee05
Add natvis for Duration, ManuallyDrop and Pin types
wesleywiser Jun 30, 2021
a6a82c6
Add/improve visualizations for liballoc types
wesleywiser Jun 30, 2021
8500274
Add visualizer for OsString and fixup other string visualizers
wesleywiser Jul 1, 2021
d1852e1
Respond to review feedback
wesleywiser Jul 9, 2021
14fdf8a
Add test for `Unique<T>`, weak ref counts and ref counts for `Weak<T>`
wesleywiser Jul 12, 2021
10b65c8
Make BTreeSet::split_off name elements like other set methods do
ssomers Nov 18, 2020
28a50b3
Unignore some pretty printing tests
JohnTitor Jul 13, 2021
b09084c
Fix search result description text color for ayu theme
GuillaumeGomez Jul 12, 2021
f0169e9
Add test for search results colors
GuillaumeGomez Jul 12, 2021
168b4d4
Fix color for keyword/primitive search result
GuillaumeGomez Jul 12, 2021
b8264a8
Add test for keyword/primitive text color
GuillaumeGomez Jul 12, 2021
106d5a6
Fix display for non-rust code blocks
GuillaumeGomez Jul 11, 2021
09270ed
Add test for codeblocks overflow
GuillaumeGomez Jul 11, 2021
da56618
Handle non-integer const generic parameters in debuginfo type names.
michaelwoerister Jul 12, 2021
13ee7ea
Rollup merge of #86983 - wesleywiser:natvis_std_types, r=michaelwoeri…
GuillaumeGomez Jul 13, 2021
a3f3f91
Rollup merge of #87056 - GuillaumeGomez:fix-codeblocks-overflow, r=no…
GuillaumeGomez Jul 13, 2021
65c536a
Rollup merge of #87082 - michaelwoerister:const-in-debuginfo-type-nam…
GuillaumeGomez Jul 13, 2021
1d8d084
Rollup merge of #87085 - GuillaumeGomez:search-result-colors, r=notri…
GuillaumeGomez Jul 13, 2021
02382b2
Rollup merge of #87090 - ssomers:btree_comments, r=the8472
GuillaumeGomez Jul 13, 2021
5338b79
Rollup merge of #87098 - JohnTitor:unignore-some-tests, r=petrochenkov
GuillaumeGomez Jul 13, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 63 additions & 18 deletions compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
// * `"` is treated as the start of a string.

use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_hir::definitions::{DefPathData, DefPathDataName, DisambiguatedDefPathData};
use rustc_middle::ich::NodeIdHashingMode;
use rustc_middle::ty::layout::IntegerExt;
use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
use rustc_middle::ty::{self, AdtDef, Ty, TyCtxt};
use rustc_target::abi::{TagEncoding, Variants};
use rustc_target::abi::{Integer, TagEncoding, Variants};

use std::fmt::Write;

Expand Down Expand Up @@ -47,7 +50,7 @@ pub fn push_debuginfo_type_name<'tcx>(
) {
// When targeting MSVC, emit C++ style type names for compatibility with
// .natvis visualizers (and perhaps other existing native debuggers?)
let cpp_like_names = tcx.sess.target.is_like_msvc;
let cpp_like_names = cpp_like_names(tcx);

match *t.kind() {
ty::Bool => output.push_str("bool"),
Expand Down Expand Up @@ -424,16 +427,14 @@ fn push_unqualified_item_name(
disambiguated_data: DisambiguatedDefPathData,
output: &mut String,
) {
let cpp_like_names = tcx.sess.target.is_like_msvc;

match disambiguated_data.data {
DefPathData::CrateRoot => {
output.push_str(&tcx.crate_name(def_id.krate).as_str());
}
DefPathData::ClosureExpr if tcx.generator_kind(def_id).is_some() => {
// Generators look like closures, but we want to treat them differently
// in the debug info.
if cpp_like_names {
if cpp_like_names(tcx) {
write!(output, "generator${}", disambiguated_data.disambiguator).unwrap();
} else {
write!(output, "{{generator#{}}}", disambiguated_data.disambiguator).unwrap();
Expand All @@ -444,7 +445,7 @@ fn push_unqualified_item_name(
output.push_str(&name.as_str());
}
DefPathDataName::Anon { namespace } => {
if cpp_like_names {
if cpp_like_names(tcx) {
write!(output, "{}${}", namespace, disambiguated_data.disambiguator).unwrap();
} else {
write!(output, "{{{}#{}}}", namespace, disambiguated_data.disambiguator)
Expand Down Expand Up @@ -478,19 +479,14 @@ fn push_generic_params_internal<'tcx>(
match type_parameter {
GenericArgKind::Type(type_parameter) => {
push_debuginfo_type_name(tcx, type_parameter, true, output, visited);
output.push_str(", ");
}
GenericArgKind::Const(const_parameter) => match const_parameter.val {
ty::ConstKind::Param(param) => write!(output, "{}, ", param.name).unwrap(),
_ => write!(
output,
"0x{:x}, ",
const_parameter.eval_bits(tcx, ty::ParamEnv::reveal_all(), const_parameter.ty)
)
.unwrap(),
},
}
GenericArgKind::Const(ct) => {
push_const_param(tcx, ct, output);
}
other => bug!("Unexpected non-erasable generic: {:?}", other),
}

output.push_str(", ");
}

output.pop();
Expand All @@ -499,6 +495,51 @@ fn push_generic_params_internal<'tcx>(
push_close_angle_bracket(tcx, output);
}

fn push_const_param<'tcx>(tcx: TyCtxt<'tcx>, ct: &'tcx ty::Const<'tcx>, output: &mut String) {
match ct.val {
ty::ConstKind::Param(param) => {
write!(output, "{}", param.name)
}
_ => match ct.ty.kind() {
ty::Int(ity) => {
let bits = ct.eval_bits(tcx, ty::ParamEnv::reveal_all(), ct.ty);
let val = Integer::from_int_ty(&tcx, *ity).size().sign_extend(bits) as i128;
write!(output, "{}", val)
}
ty::Uint(_) => {
let val = ct.eval_bits(tcx, ty::ParamEnv::reveal_all(), ct.ty);
write!(output, "{}", val)
}
ty::Bool => {
let val = ct.try_eval_bool(tcx, ty::ParamEnv::reveal_all()).unwrap();
write!(output, "{}", val)
}
_ => {
// If we cannot evaluate the constant to a known type, we fall back
// to emitting a stable hash value of the constant. This isn't very pretty
// but we get a deterministic, virtually unique value for the constant.
let hcx = &mut tcx.create_stable_hashing_context();
let mut hasher = StableHasher::new();
hcx.while_hashing_spans(false, |hcx| {
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
ct.val.hash_stable(hcx, &mut hasher);
});
});
// Let's only emit 64 bits of the hash value. That should be plenty for
// avoiding collisions and will make the emitted type names shorter.
let hash: u64 = hasher.finish();

if cpp_like_names(tcx) {
write!(output, "CONST${:x}", hash)
} else {
write!(output, "{{CONST#{:x}}}", hash)
}
}
},
}
.unwrap();
}

pub fn push_generic_params<'tcx>(tcx: TyCtxt<'tcx>, substs: SubstsRef<'tcx>, output: &mut String) {
let mut visited = FxHashSet::default();
push_generic_params_internal(tcx, substs, output, &mut visited);
Expand All @@ -507,9 +548,13 @@ pub fn push_generic_params<'tcx>(tcx: TyCtxt<'tcx>, substs: SubstsRef<'tcx>, out
fn push_close_angle_bracket<'tcx>(tcx: TyCtxt<'tcx>, output: &mut String) {
// MSVC debugger always treats `>>` as a shift, even when parsing templates,
// so add a space to avoid confusion.
if tcx.sess.target.is_like_msvc && output.ends_with('>') {
if cpp_like_names(tcx) && output.ends_with('>') {
output.push(' ')
};

output.push('>');
}

fn cpp_like_names(tcx: TyCtxt<'_>) -> bool {
tcx.sess.target.is_like_msvc
}
8 changes: 4 additions & 4 deletions library/alloc/src/collections/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -903,8 +903,8 @@ impl<T> BTreeSet<T> {
self.map.append(&mut other.map);
}

/// Splits the collection into two at the given key. Returns everything after the given key,
/// including the key.
/// Splits the collection into two at the given value. Returns everything after the given value,
/// including the value.
///
/// # Examples
///
Expand Down Expand Up @@ -933,11 +933,11 @@ impl<T> BTreeSet<T> {
/// assert!(b.contains(&41));
/// ```
#[stable(feature = "btree_split_off", since = "1.11.0")]
pub fn split_off<Q: ?Sized + Ord>(&mut self, key: &Q) -> Self
pub fn split_off<Q: ?Sized + Ord>(&mut self, value: &Q) -> Self
where
T: Borrow<Q> + Ord,
{
BTreeSet { map: self.map.split_off(key) }
BTreeSet { map: self.map.split_off(value) }
}

/// Creates an iterator that visits all values in ascending order and uses a closure
Expand Down
4 changes: 2 additions & 2 deletions src/etc/natvis/intrinsic.natvis
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<Type Name="str">
<DisplayString>{data_ptr,[length]s8}</DisplayString>
<StringView>data_ptr,[length]s8</StringView>
<DisplayString>{(char*)data_ptr,[length]s8}</DisplayString>
<StringView>(char*)data_ptr,[length]s8</StringView>
<Expand>
<Item Name="[len]" ExcludeView="simple">length</Item>
<Synthetic Name="[chars]">
Expand Down
17 changes: 17 additions & 0 deletions src/etc/natvis/liballoc.natvis
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<Item Name="[len]" ExcludeView="simple">vec.len</Item>
<Item Name="[capacity]" ExcludeView="simple">vec.buf.cap</Item>
<Synthetic Name="[chars]">
<DisplayString>{(char*)vec.buf.ptr.pointer,[vec.len]s8}</DisplayString>
<Expand>
<ArrayItems>
<Size>vec.len</Size>
Expand All @@ -57,22 +58,38 @@
</Synthetic>
</Expand>
</Type>

<Type Name="alloc::rc::Rc&lt;*&gt;">
<DisplayString>{ptr.pointer->value}</DisplayString>
<Expand>
<ExpandedItem>ptr.pointer->value</ExpandedItem>
<Item Name="[Reference count]">ptr.pointer->strong</Item>
<Item Name="[Weak reference count]">ptr.pointer->weak</Item>
</Expand>
</Type>
<Type Name="alloc::rc::Weak&lt;*&gt;">
<DisplayString>{ptr.pointer->value}</DisplayString>
<Expand>
<ExpandedItem>ptr.pointer->value</ExpandedItem>
<Item Name="[Reference count]">ptr.pointer->strong</Item>
<Item Name="[Weak reference count]">ptr.pointer->weak</Item>
</Expand>
</Type>

<Type Name="alloc::sync::Arc&lt;*&gt;">
<DisplayString>{ptr.pointer->data}</DisplayString>
<Expand>
<ExpandedItem>ptr.pointer->data</ExpandedItem>
<Item Name="[Reference count]">ptr.pointer->strong</Item>
<Item Name="[Weak reference count]">ptr.pointer->weak</Item>
</Expand>
</Type>
<Type Name="alloc::sync::Weak&lt;*&gt;">
<DisplayString>{ptr.pointer->data}</DisplayString>
<Expand>
<ExpandedItem>ptr.pointer->data</ExpandedItem>
<Item Name="[Reference count]">ptr.pointer->strong</Item>
<Item Name="[Weak reference count]">ptr.pointer->weak</Item>
</Expand>
</Type>
<Type Name="alloc::borrow::Cow&lt;*&gt;">
Expand Down
Loading