Skip to content

Commit e10cbc3

Browse files
committed
Auto merge of rust-lang#84822 - Dylan-DPC:rollup-wego8d6, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - rust-lang#84358 (Update closure capture error logging for disjoint captures for disjoint captures) - rust-lang#84392 (Make AssertKind::fmt_assert_args public) - rust-lang#84752 (Fix debuginfo for generators) - rust-lang#84763 (shrink doctree::Module) - rust-lang#84821 (Fix nit in rustc_session::options) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 89ebad5 + 0bc9727 commit e10cbc3

File tree

68 files changed

+664
-249
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+664
-249
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+34-30
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ impl RecursiveTypeDescription<'ll, 'tcx> {
309309
unfinished_type,
310310
member_holding_stub,
311311
member_descriptions,
312+
None,
312313
);
313314
MetadataCreationResult::new(metadata_stub, true)
314315
}
@@ -1459,6 +1460,7 @@ struct EnumMemberDescriptionFactory<'ll, 'tcx> {
14591460
layout: TyAndLayout<'tcx>,
14601461
tag_type_metadata: Option<&'ll DIType>,
14611462
containing_scope: &'ll DIScope,
1463+
common_members: Vec<Option<&'ll DIType>>,
14621464
span: Span,
14631465
}
14641466

@@ -1493,10 +1495,6 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
14931495
} else {
14941496
type_metadata(cx, self.enum_type, self.span)
14951497
};
1496-
let flags = match self.enum_type.kind() {
1497-
ty::Generator(..) => DIFlags::FlagArtificial,
1498-
_ => DIFlags::FlagZero,
1499-
};
15001498

15011499
match self.layout.variants {
15021500
Variants::Single { index } => {
@@ -1523,14 +1521,15 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
15231521
self.enum_type,
15241522
variant_type_metadata,
15251523
member_descriptions,
1524+
Some(&self.common_members),
15261525
);
15271526
vec![MemberDescription {
15281527
name: if fallback { String::new() } else { variant_info.variant_name() },
15291528
type_metadata: variant_type_metadata,
15301529
offset: Size::ZERO,
15311530
size: self.layout.size,
15321531
align: self.layout.align.abi,
1533-
flags,
1532+
flags: DIFlags::FlagZero,
15341533
discriminant: None,
15351534
source_info: variant_info.source_info(cx),
15361535
}]
@@ -1572,6 +1571,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
15721571
self.enum_type,
15731572
variant_type_metadata,
15741573
member_descriptions,
1574+
Some(&self.common_members),
15751575
);
15761576

15771577
MemberDescription {
@@ -1584,7 +1584,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
15841584
offset: Size::ZERO,
15851585
size: self.layout.size,
15861586
align: self.layout.align.abi,
1587-
flags,
1587+
flags: DIFlags::FlagZero,
15881588
discriminant: Some(
15891589
self.layout.ty.discriminant_for_variant(cx.tcx, i).unwrap().val
15901590
as u64,
@@ -1621,6 +1621,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
16211621
self.enum_type,
16221622
variant_type_metadata,
16231623
variant_member_descriptions,
1624+
Some(&self.common_members),
16241625
);
16251626

16261627
// Encode the information about the null variant in the union
@@ -1667,7 +1668,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
16671668
offset: Size::ZERO,
16681669
size: variant.size,
16691670
align: variant.align.abi,
1670-
flags,
1671+
flags: DIFlags::FlagZero,
16711672
discriminant: None,
16721673
source_info: variant_info.source_info(cx),
16731674
}]
@@ -1695,6 +1696,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
16951696
self.enum_type,
16961697
variant_type_metadata,
16971698
member_descriptions,
1699+
Some(&self.common_members),
16981700
);
16991701

17001702
let niche_value = if i == dataful_variant {
@@ -1717,7 +1719,7 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
17171719
offset: Size::ZERO,
17181720
size: self.layout.size,
17191721
align: self.layout.align.abi,
1720-
flags,
1722+
flags: DIFlags::FlagZero,
17211723
discriminant: niche_value,
17221724
source_info: variant_info.source_info(cx),
17231725
}
@@ -1849,13 +1851,6 @@ impl<'tcx> VariantInfo<'_, 'tcx> {
18491851
}
18501852
None
18511853
}
1852-
1853-
fn is_artificial(&self) -> bool {
1854-
match self {
1855-
VariantInfo::Generator { .. } => true,
1856-
VariantInfo::Adt(..) => false,
1857-
}
1858-
}
18591854
}
18601855

18611856
/// Returns a tuple of (1) `type_metadata_stub` of the variant, (2) a
@@ -1881,8 +1876,7 @@ fn describe_enum_variant(
18811876
&variant_name,
18821877
unique_type_id,
18831878
Some(containing_scope),
1884-
// FIXME(tmandry): This doesn't seem to have any effect.
1885-
if variant.is_artificial() { DIFlags::FlagArtificial } else { DIFlags::FlagZero },
1879+
DIFlags::FlagZero,
18861880
)
18871881
});
18881882

@@ -1945,11 +1939,6 @@ fn prepare_enum_metadata(
19451939
) -> RecursiveTypeDescription<'ll, 'tcx> {
19461940
let tcx = cx.tcx;
19471941
let enum_name = compute_debuginfo_type_name(tcx, enum_type, false);
1948-
// FIXME(tmandry): This doesn't seem to have any effect.
1949-
let enum_flags = match enum_type.kind() {
1950-
ty::Generator(..) => DIFlags::FlagArtificial,
1951-
_ => DIFlags::FlagZero,
1952-
};
19531942

19541943
let containing_scope = get_namespace_for_item(cx, enum_def_id);
19551944
// FIXME: This should emit actual file metadata for the enum, but we
@@ -2082,7 +2071,7 @@ fn prepare_enum_metadata(
20822071
UNKNOWN_LINE_NUMBER,
20832072
layout.size.bits(),
20842073
layout.align.abi.bits() as u32,
2085-
enum_flags,
2074+
DIFlags::FlagZero,
20862075
None,
20872076
0, // RuntimeLang
20882077
unique_type_id_str.as_ptr().cast(),
@@ -2102,6 +2091,7 @@ fn prepare_enum_metadata(
21022091
layout,
21032092
tag_type_metadata: discriminant_type_metadata,
21042093
containing_scope,
2094+
common_members: vec![],
21052095
span,
21062096
}),
21072097
);
@@ -2171,7 +2161,7 @@ fn prepare_enum_metadata(
21712161
}
21722162
};
21732163

2174-
let mut outer_fields = match layout.variants {
2164+
let outer_fields = match layout.variants {
21752165
Variants::Single { .. } => vec![],
21762166
Variants::Multiple { .. } => {
21772167
let tuple_mdf = TupleMemberDescriptionFactory {
@@ -2203,18 +2193,21 @@ fn prepare_enum_metadata(
22032193
UNKNOWN_LINE_NUMBER,
22042194
layout.size.bits(),
22052195
layout.align.abi.bits() as u32,
2206-
enum_flags,
2196+
DIFlags::FlagZero,
22072197
discriminator_metadata,
22082198
empty_array,
22092199
variant_part_unique_type_id_str.as_ptr().cast(),
22102200
variant_part_unique_type_id_str.len(),
22112201
)
22122202
};
2213-
outer_fields.push(Some(variant_part));
22142203

22152204
let struct_wrapper = {
22162205
// The variant part must be wrapped in a struct according to DWARF.
2217-
let type_array = create_DIArray(DIB(cx), &outer_fields);
2206+
// All fields except the discriminant (including `outer_fields`)
2207+
// should be put into structures inside the variant part, which gives
2208+
// an equivalent layout but offers us much better integration with
2209+
// debuggers.
2210+
let type_array = create_DIArray(DIB(cx), &[Some(variant_part)]);
22182211

22192212
let type_map = debug_context(cx).type_map.borrow();
22202213
let unique_type_id_str = type_map.get_unique_type_id_as_string(unique_type_id);
@@ -2229,7 +2222,7 @@ fn prepare_enum_metadata(
22292222
UNKNOWN_LINE_NUMBER,
22302223
layout.size.bits(),
22312224
layout.align.abi.bits() as u32,
2232-
enum_flags,
2225+
DIFlags::FlagZero,
22332226
None,
22342227
type_array,
22352228
0,
@@ -2251,6 +2244,7 @@ fn prepare_enum_metadata(
22512244
layout,
22522245
tag_type_metadata: None,
22532246
containing_scope,
2247+
common_members: outer_fields,
22542248
span,
22552249
}),
22562250
)
@@ -2283,7 +2277,13 @@ fn composite_type_metadata(
22832277
DIFlags::FlagZero,
22842278
);
22852279
// ... and immediately create and add the member descriptions.
2286-
set_members_of_composite_type(cx, composite_type, composite_type_metadata, member_descriptions);
2280+
set_members_of_composite_type(
2281+
cx,
2282+
composite_type,
2283+
composite_type_metadata,
2284+
member_descriptions,
2285+
None,
2286+
);
22872287

22882288
composite_type_metadata
22892289
}
@@ -2293,6 +2293,7 @@ fn set_members_of_composite_type(
22932293
composite_type: Ty<'tcx>,
22942294
composite_type_metadata: &'ll DICompositeType,
22952295
member_descriptions: Vec<MemberDescription<'ll>>,
2296+
common_members: Option<&Vec<Option<&'ll DIType>>>,
22962297
) {
22972298
// In some rare cases LLVM metadata uniquing would lead to an existing type
22982299
// description being used instead of a new one created in
@@ -2311,10 +2312,13 @@ fn set_members_of_composite_type(
23112312
}
23122313
}
23132314

2314-
let member_metadata: Vec<_> = member_descriptions
2315+
let mut member_metadata: Vec<_> = member_descriptions
23152316
.into_iter()
23162317
.map(|desc| Some(desc.into_metadata(cx, composite_type_metadata)))
23172318
.collect();
2319+
if let Some(other_members) = common_members {
2320+
member_metadata.extend(other_members.iter());
2321+
}
23182322

23192323
let type_params = compute_type_parameters(cx, composite_type);
23202324
unsafe {

compiler/rustc_middle/src/mir/mod.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,15 @@ impl BorrowKind {
683683
BorrowKind::Mut { allow_two_phase_borrow } => allow_two_phase_borrow,
684684
}
685685
}
686+
687+
pub fn describe_mutability(&self) -> String {
688+
match *self {
689+
BorrowKind::Shared | BorrowKind::Shallow | BorrowKind::Unique => {
690+
"immutable".to_string()
691+
}
692+
BorrowKind::Mut { .. } => "mutable".to_string(),
693+
}
694+
}
686695
}
687696

688697
///////////////////////////////////////////////////////////////////////////
@@ -1340,7 +1349,7 @@ impl<O> AssertKind<O> {
13401349
}
13411350

13421351
/// Format the message arguments for the `assert(cond, msg..)` terminator in MIR printing.
1343-
fn fmt_assert_args<W: Write>(&self, f: &mut W) -> fmt::Result
1352+
pub fn fmt_assert_args<W: Write>(&self, f: &mut W) -> fmt::Result
13441353
where
13451354
O: Debug,
13461355
{
@@ -2369,6 +2378,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
23692378
};
23702379
let mut struct_fmt = fmt.debug_struct(&name);
23712380

2381+
// FIXME(project-rfc-2229#48): This should be a list of capture names/places
23722382
if let Some(upvars) = tcx.upvars_mentioned(def_id) {
23732383
for (&var_id, place) in iter::zip(upvars.keys(), places) {
23742384
let var_name = tcx.hir().name(var_id);
@@ -2388,6 +2398,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
23882398
let name = format!("[generator@{:?}]", tcx.hir().span(hir_id));
23892399
let mut struct_fmt = fmt.debug_struct(&name);
23902400

2401+
// FIXME(project-rfc-2229#48): This should be a list of capture names/places
23912402
if let Some(upvars) = tcx.upvars_mentioned(def_id) {
23922403
for (&var_id, place) in iter::zip(upvars.keys(), places) {
23932404
let var_name = tcx.hir().name(var_id);

compiler/rustc_middle/src/ty/closure.rs

+20
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ pub struct CapturedPlace<'tcx> {
151151
}
152152

153153
impl CapturedPlace<'tcx> {
154+
pub fn to_string(&self, tcx: TyCtxt<'tcx>) -> String {
155+
place_to_string_for_capture(tcx, &self.place)
156+
}
157+
154158
/// Returns the hir-id of the root variable for the captured place.
155159
/// e.g., if `a.b.c` was captured, would return the hir-id for `a`.
156160
pub fn get_root_variable(&self) -> hir::HirId {
@@ -168,6 +172,22 @@ impl CapturedPlace<'tcx> {
168172
}
169173
}
170174

175+
/// Return span pointing to use that resulted in selecting the captured path
176+
pub fn get_path_span(&self, tcx: TyCtxt<'tcx>) -> Span {
177+
if let Some(path_expr_id) = self.info.path_expr_id {
178+
tcx.hir().span(path_expr_id)
179+
} else if let Some(capture_kind_expr_id) = self.info.capture_kind_expr_id {
180+
tcx.hir().span(capture_kind_expr_id)
181+
} else {
182+
// Fallback on upvars mentioned if neither path or capture expr id is captured
183+
184+
// Safe to unwrap since we know this place is captured by the closure, therefore the closure must have upvars.
185+
tcx.upvars_mentioned(self.get_closure_local_def_id()).unwrap()
186+
[&self.get_root_variable()]
187+
.span
188+
}
189+
}
190+
171191
/// Return span pointing to use that resulted in selecting the current capture kind
172192
pub fn get_capture_kind_span(&self, tcx: TyCtxt<'tcx>) -> Span {
173193
if let Some(capture_kind_expr_id) = self.info.capture_kind_expr_id {

0 commit comments

Comments
 (0)