Skip to content

Commit c919f49

Browse files
committed
Auto merge of #79138 - m-ou-se:rollup-owel5ld, r=m-ou-se
Rollup of 8 pull requests Successful merges: - #74293 (Rustdoc test compiler output color) - #78702 ([self-profiling] Include the estimated size of each cgu in the profile) - #79069 (Get rid of `highlight::Class::None`) - #79072 (Fix exhaustiveness in case a byte string literal is used at slice type) - #79120 (update rustfmt to v1.4.27) - #79125 (Get rid of clean::{Method, TyMethod}) - #79126 (Remove duplicate `Trait::auto` field) - #79130 (extend macro braces test) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents e0ef0fc + f698505 commit c919f49

File tree

24 files changed

+325
-141
lines changed

24 files changed

+325
-141
lines changed

Cargo.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -4338,7 +4338,7 @@ dependencies = [
43384338

43394339
[[package]]
43404340
name = "rustfmt-nightly"
4341-
version = "1.4.26"
4341+
version = "1.4.27"
43424342
dependencies = [
43434343
"annotate-snippets 0.6.1",
43444344
"anyhow",

compiler/rustc_codegen_llvm/src/base.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -97,21 +97,23 @@ pub fn compile_codegen_unit(
9797
tcx: TyCtxt<'tcx>,
9898
cgu_name: Symbol,
9999
) -> (ModuleCodegen<ModuleLlvm>, u64) {
100-
let prof_timer = tcx.prof.generic_activity_with_arg("codegen_module", cgu_name.to_string());
101100
let start_time = Instant::now();
102101

103102
let dep_node = tcx.codegen_unit(cgu_name).codegen_dep_node(tcx);
104103
let (module, _) =
105104
tcx.dep_graph.with_task(dep_node, tcx, cgu_name, module_codegen, dep_graph::hash_result);
106105
let time_to_codegen = start_time.elapsed();
107-
drop(prof_timer);
108106

109107
// We assume that the cost to run LLVM on a CGU is proportional to
110108
// the time we needed for codegenning it.
111109
let cost = time_to_codegen.as_nanos() as u64;
112110

113111
fn module_codegen(tcx: TyCtxt<'_>, cgu_name: Symbol) -> ModuleCodegen<ModuleLlvm> {
114112
let cgu = tcx.codegen_unit(cgu_name);
113+
let _prof_timer = tcx.prof.generic_activity_with_args(
114+
"codegen_module",
115+
&[cgu_name.to_string(), cgu.size_estimate().to_string()],
116+
);
115117
// Instantiate monomorphizations without filling out definitions yet...
116118
let llvm_module = ModuleLlvm::new(tcx, &cgu_name.as_str());
117119
{

compiler/rustc_data_structures/src/profiling.rs

+22
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,28 @@ impl SelfProfilerRef {
272272
})
273273
}
274274

275+
#[inline(always)]
276+
pub fn generic_activity_with_args(
277+
&self,
278+
event_label: &'static str,
279+
event_args: &[String],
280+
) -> TimingGuard<'_> {
281+
self.exec(EventFilter::GENERIC_ACTIVITIES, |profiler| {
282+
let builder = EventIdBuilder::new(&profiler.profiler);
283+
let event_label = profiler.get_or_alloc_cached_string(event_label);
284+
let event_id = if profiler.event_filter_mask.contains(EventFilter::FUNCTION_ARGS) {
285+
let event_args: Vec<_> = event_args
286+
.iter()
287+
.map(|s| profiler.get_or_alloc_cached_string(&s[..]))
288+
.collect();
289+
builder.from_label_and_args(event_label, &event_args)
290+
} else {
291+
builder.from_label(event_label)
292+
};
293+
TimingGuard::start(profiler, profiler.generic_activity_event_kind, event_id)
294+
})
295+
}
296+
275297
/// Start profiling a query provider. Profiling continues until the
276298
/// TimingGuard returned from this call is dropped.
277299
#[inline(always)]

compiler/rustc_errors/src/emitter.rs

+17
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@ pub trait Emitter {
200200
true
201201
}
202202

203+
/// Checks if we can use colors in the current output stream.
204+
fn supports_color(&self) -> bool {
205+
false
206+
}
207+
203208
fn source_map(&self) -> Option<&Lrc<SourceMap>>;
204209

205210
/// Formats the substitutions of the primary_span
@@ -504,6 +509,10 @@ impl Emitter for EmitterWriter {
504509
fn should_show_explain(&self) -> bool {
505510
!self.short_message
506511
}
512+
513+
fn supports_color(&self) -> bool {
514+
self.dst.supports_color()
515+
}
507516
}
508517

509518
/// An emitter that does nothing when emitting a diagnostic.
@@ -2057,6 +2066,14 @@ impl Destination {
20572066
Destination::Raw(ref mut t, true) => WritableDst::ColoredRaw(Ansi::new(t)),
20582067
}
20592068
}
2069+
2070+
fn supports_color(&self) -> bool {
2071+
match *self {
2072+
Self::Terminal(ref stream) => stream.supports_color(),
2073+
Self::Buffered(ref buffer) => buffer.buffer().supports_color(),
2074+
Self::Raw(_, supports_color) => supports_color,
2075+
}
2076+
}
20602077
}
20612078

20622079
impl<'a> WritableDst<'a> {

compiler/rustc_middle/src/ty/context.rs

+9
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,12 @@ pub struct TypeckResults<'tcx> {
422422
/// Stores the type, expression, span and optional scope span of all types
423423
/// that are live across the yield of this generator (if a generator).
424424
pub generator_interior_types: Vec<GeneratorInteriorTypeCause<'tcx>>,
425+
426+
/// We sometimes treat byte string literals (which are of type `&[u8; N]`)
427+
/// as `&[u8]`, depending on the pattern in which they are used.
428+
/// This hashset records all instances where we behave
429+
/// like this to allow `const_to_pat` to reliably handle this situation.
430+
pub treat_byte_string_as_slice: ItemLocalSet,
425431
}
426432

427433
impl<'tcx> TypeckResults<'tcx> {
@@ -448,6 +454,7 @@ impl<'tcx> TypeckResults<'tcx> {
448454
closure_captures: Default::default(),
449455
closure_min_captures: Default::default(),
450456
generator_interior_types: Default::default(),
457+
treat_byte_string_as_slice: Default::default(),
451458
}
452459
}
453460

@@ -683,6 +690,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for TypeckResults<'tcx> {
683690
ref closure_captures,
684691
ref closure_min_captures,
685692
ref generator_interior_types,
693+
ref treat_byte_string_as_slice,
686694
} = *self;
687695

688696
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
@@ -717,6 +725,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for TypeckResults<'tcx> {
717725
closure_captures.hash_stable(hcx, hasher);
718726
closure_min_captures.hash_stable(hcx, hasher);
719727
generator_interior_types.hash_stable(hcx, hasher);
728+
treat_byte_string_as_slice.hash_stable(hcx, hasher);
720729
})
721730
}
722731
}

compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs

+36-8
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,20 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
1818
/// Converts an evaluated constant to a pattern (if possible).
1919
/// This means aggregate values (like structs and enums) are converted
2020
/// to a pattern that matches the value (as if you'd compared via structural equality).
21+
#[instrument(skip(self))]
2122
pub(super) fn const_to_pat(
2223
&self,
2324
cv: &'tcx ty::Const<'tcx>,
2425
id: hir::HirId,
2526
span: Span,
2627
mir_structural_match_violation: bool,
2728
) -> Pat<'tcx> {
28-
debug!("const_to_pat: cv={:#?} id={:?}", cv, id);
29-
debug!("const_to_pat: cv.ty={:?} span={:?}", cv.ty, span);
30-
3129
let pat = self.tcx.infer_ctxt().enter(|infcx| {
3230
let mut convert = ConstToPat::new(self, id, span, infcx);
3331
convert.to_pat(cv, mir_structural_match_violation)
3432
});
3533

36-
debug!("const_to_pat: pat={:?}", pat);
34+
debug!(?pat);
3735
pat
3836
}
3937
}
@@ -61,6 +59,8 @@ struct ConstToPat<'a, 'tcx> {
6159
infcx: InferCtxt<'a, 'tcx>,
6260

6361
include_lint_checks: bool,
62+
63+
treat_byte_string_as_slice: bool,
6464
}
6565

6666
mod fallback_to_const_ref {
@@ -88,6 +88,7 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
8888
span: Span,
8989
infcx: InferCtxt<'a, 'tcx>,
9090
) -> Self {
91+
trace!(?pat_ctxt.typeck_results.hir_owner);
9192
ConstToPat {
9293
id,
9394
span,
@@ -97,6 +98,10 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
9798
saw_const_match_error: Cell::new(false),
9899
saw_const_match_lint: Cell::new(false),
99100
behind_reference: Cell::new(false),
101+
treat_byte_string_as_slice: pat_ctxt
102+
.typeck_results
103+
.treat_byte_string_as_slice
104+
.contains(&id.local_id),
100105
}
101106
}
102107

@@ -153,6 +158,7 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
153158
cv: &'tcx ty::Const<'tcx>,
154159
mir_structural_match_violation: bool,
155160
) -> Pat<'tcx> {
161+
trace!(self.treat_byte_string_as_slice);
156162
// This method is just a wrapper handling a validity check; the heavy lifting is
157163
// performed by the recursive `recur` method, which is not meant to be
158164
// invoked except by this method.
@@ -384,7 +390,7 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
384390
}
385391
PatKind::Wild
386392
}
387-
// `&str` and `&[u8]` are represented as `ConstValue::Slice`, let's keep using this
393+
// `&str` is represented as `ConstValue::Slice`, let's keep using this
388394
// optimization for now.
389395
ty::Str => PatKind::Constant { value: cv },
390396
// `b"foo"` produces a `&[u8; 3]`, but you can't use constants of array type when
@@ -393,11 +399,33 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
393399
// as slices. This means we turn `&[T; N]` constants into slice patterns, which
394400
// has no negative effects on pattern matching, even if we're actually matching on
395401
// arrays.
396-
ty::Array(..) |
402+
ty::Array(..) if !self.treat_byte_string_as_slice => {
403+
let old = self.behind_reference.replace(true);
404+
let array = tcx.deref_const(self.param_env.and(cv));
405+
let val = PatKind::Deref {
406+
subpattern: Pat {
407+
kind: Box::new(PatKind::Array {
408+
prefix: tcx
409+
.destructure_const(param_env.and(array))
410+
.fields
411+
.iter()
412+
.map(|val| self.recur(val, false))
413+
.collect::<Result<_, _>>()?,
414+
slice: None,
415+
suffix: vec![],
416+
}),
417+
span,
418+
ty: pointee_ty,
419+
},
420+
};
421+
self.behind_reference.set(old);
422+
val
423+
}
424+
ty::Array(elem_ty, _) |
397425
// Cannot merge this with the catch all branch below, because the `const_deref`
398426
// changes the type from slice to array, we need to keep the original type in the
399427
// pattern.
400-
ty::Slice(..) => {
428+
ty::Slice(elem_ty) => {
401429
let old = self.behind_reference.replace(true);
402430
let array = tcx.deref_const(self.param_env.and(cv));
403431
let val = PatKind::Deref {
@@ -413,7 +441,7 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
413441
suffix: vec![],
414442
}),
415443
span,
416-
ty: pointee_ty,
444+
ty: tcx.mk_slice(elem_ty),
417445
},
418446
};
419447
self.behind_reference.set(old);

compiler/rustc_typeck/src/check/pat.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
149149
///
150150
/// Outside of this module, `check_pat_top` should always be used.
151151
/// Conversely, inside this module, `check_pat_top` should never be used.
152+
#[instrument(skip(self, ti))]
152153
fn check_pat(
153154
&self,
154155
pat: &'tcx Pat<'tcx>,
155156
expected: Ty<'tcx>,
156157
def_bm: BindingMode,
157158
ti: TopInfo<'tcx>,
158159
) {
159-
debug!("check_pat(pat={:?},expected={:?},def_bm={:?})", pat, expected, def_bm);
160-
161160
let path_res = match &pat.kind {
162161
PatKind::Path(qpath) => Some(self.resolve_ty_and_res_ufcs(qpath, pat.hir_id, pat.span)),
163162
_ => None,
@@ -398,6 +397,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
398397
if let ty::Ref(_, inner_ty, _) = expected.kind() {
399398
if matches!(inner_ty.kind(), ty::Slice(_)) {
400399
let tcx = self.tcx;
400+
trace!(?lt.hir_id.local_id, "polymorphic byte string lit");
401+
self.typeck_results
402+
.borrow_mut()
403+
.treat_byte_string_as_slice
404+
.insert(lt.hir_id.local_id);
401405
pat_ty = tcx.mk_imm_ref(tcx.lifetimes.re_static, tcx.mk_slice(tcx.types.u8));
402406
}
403407
}

compiler/rustc_typeck/src/check/writeback.rs

+3
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
7070
debug!("used_trait_imports({:?}) = {:?}", item_def_id, used_trait_imports);
7171
wbcx.typeck_results.used_trait_imports = used_trait_imports;
7272

73+
wbcx.typeck_results.treat_byte_string_as_slice =
74+
mem::take(&mut self.typeck_results.borrow_mut().treat_byte_string_as_slice);
75+
7376
wbcx.typeck_results.closure_captures =
7477
mem::take(&mut self.typeck_results.borrow_mut().closure_captures);
7578

src/librustdoc/clean/inline.rs

-2
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,13 @@ crate fn build_external_trait(cx: &DocContext<'_>, did: DefId) -> clean::Trait {
193193
let trait_items =
194194
cx.tcx.associated_items(did).in_definition_order().map(|item| item.clean(cx)).collect();
195195

196-
let auto_trait = cx.tcx.trait_def(did).has_auto_impl;
197196
let predicates = cx.tcx.predicates_of(did);
198197
let generics = (cx.tcx.generics_of(did), predicates).clean(cx);
199198
let generics = filter_non_trait_generics(did, generics);
200199
let (generics, supertrait_bounds) = separate_supertrait_bounds(generics);
201200
let is_spotlight = load_attrs(cx, did).clean(cx).has_doc_flag(sym::spotlight);
202201
let is_auto = cx.tcx.trait_is_auto(did);
203202
clean::Trait {
204-
auto: auto_trait,
205203
unsafety: cx.tcx.trait_def(did).unsafety,
206204
generics,
207205
items: trait_items,

0 commit comments

Comments
 (0)