Skip to content

Commit

Permalink
Auto merge of rust-lang#102741 - matthiaskrgr:rollup-63no5tz, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#98496 (make `compare_const_impl` a query and use it in `instance.rs`)
 - rust-lang#102680 (Fix overconstrained Send impls in btree internals)
 - rust-lang#102718 (Fix `opaque_hidden_inferred_bound` lint ICE)
 - rust-lang#102725 (Remove `-Ztime`)
 - rust-lang#102736 (Migrate search input color to CSS variable)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Oct 6, 2022
2 parents 2d46584 + 48964bd commit 0ca3565
Show file tree
Hide file tree
Showing 35 changed files with 500 additions and 169 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ pub(crate) fn run_pass_manager(
module: &mut ModuleCodegen<ModuleLlvm>,
thin: bool,
) -> Result<(), FatalError> {
let _timer = cgcx.prof.extra_verbose_generic_activity("LLVM_lto_optimize", &*module.name);
let _timer = cgcx.prof.verbose_generic_activity_with_arg("LLVM_lto_optimize", &*module.name);
let config = cgcx.config(module.kind);

// Now we have one massive module inside of llmod. Time to run the
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1637,7 +1637,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
llvm_start_time: &mut Option<VerboseTimingGuard<'a>>,
) {
if config.time_module && llvm_start_time.is_none() {
*llvm_start_time = Some(prof.extra_verbose_generic_activity("LLVM_passes", "crate"));
*llvm_start_time = Some(prof.verbose_generic_activity("LLVM_passes"));
}
}
}
Expand Down
64 changes: 27 additions & 37 deletions compiler/rustc_data_structures/src/profiling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,30 +158,21 @@ pub struct SelfProfilerRef {
// actually enabled.
event_filter_mask: EventFilter,

// Print verbose generic activities to stdout
// Print verbose generic activities to stderr?
print_verbose_generic_activities: bool,

// Print extra verbose generic activities to stdout
print_extra_verbose_generic_activities: bool,
}

impl SelfProfilerRef {
pub fn new(
profiler: Option<Arc<SelfProfiler>>,
print_verbose_generic_activities: bool,
print_extra_verbose_generic_activities: bool,
) -> SelfProfilerRef {
// If there is no SelfProfiler then the filter mask is set to NONE,
// ensuring that nothing ever tries to actually access it.
let event_filter_mask =
profiler.as_ref().map_or(EventFilter::empty(), |p| p.event_filter_mask);

SelfProfilerRef {
profiler,
event_filter_mask,
print_verbose_generic_activities,
print_extra_verbose_generic_activities,
}
SelfProfilerRef { profiler, event_filter_mask, print_verbose_generic_activities }
}

/// This shim makes sure that calls only get executed if the filter mask
Expand Down Expand Up @@ -214,7 +205,7 @@ impl SelfProfilerRef {
/// Start profiling a verbose generic activity. Profiling continues until the
/// VerboseTimingGuard returned from this call is dropped. In addition to recording
/// a measureme event, "verbose" generic activities also print a timing entry to
/// stdout if the compiler is invoked with -Ztime or -Ztime-passes.
/// stderr if the compiler is invoked with -Ztime-passes.
pub fn verbose_generic_activity<'a>(
&'a self,
event_label: &'static str,
Expand All @@ -225,19 +216,16 @@ impl SelfProfilerRef {
VerboseTimingGuard::start(message, self.generic_activity(event_label))
}

/// Start profiling an extra verbose generic activity. Profiling continues until the
/// VerboseTimingGuard returned from this call is dropped. In addition to recording
/// a measureme event, "extra verbose" generic activities also print a timing entry to
/// stdout if the compiler is invoked with -Ztime-passes.
pub fn extra_verbose_generic_activity<'a, A>(
/// Like `verbose_generic_activity`, but with an extra arg.
pub fn verbose_generic_activity_with_arg<'a, A>(
&'a self,
event_label: &'static str,
event_arg: A,
) -> VerboseTimingGuard<'a>
where
A: Borrow<str> + Into<String>,
{
let message = if self.print_extra_verbose_generic_activities {
let message = if self.print_verbose_generic_activities {
Some(format!("{}({})", event_label, event_arg.borrow()))
} else {
None
Expand Down Expand Up @@ -745,27 +733,9 @@ impl Drop for VerboseTimingGuard<'_> {
if let Some((start_time, start_rss, ref message)) = self.start_and_message {
let end_rss = get_resident_set_size();
let dur = start_time.elapsed();

if should_print_passes(dur, start_rss, end_rss) {
print_time_passes_entry(&message, dur, start_rss, end_rss);
}
}
}
}

fn should_print_passes(dur: Duration, start_rss: Option<usize>, end_rss: Option<usize>) -> bool {
if dur.as_millis() > 5 {
return true;
}

if let (Some(start_rss), Some(end_rss)) = (start_rss, end_rss) {
let change_rss = end_rss.abs_diff(start_rss);
if change_rss > 0 {
return true;
print_time_passes_entry(&message, dur, start_rss, end_rss);
}
}

false
}

pub fn print_time_passes_entry(
Expand All @@ -774,6 +744,26 @@ pub fn print_time_passes_entry(
start_rss: Option<usize>,
end_rss: Option<usize>,
) {
// Print the pass if its duration is greater than 5 ms, or it changed the
// measured RSS.
let is_notable = || {
if dur.as_millis() > 5 {
return true;
}

if let (Some(start_rss), Some(end_rss)) = (start_rss, end_rss) {
let change_rss = end_rss.abs_diff(start_rss);
if change_rss > 0 {
return true;
}
}

false
};
if !is_notable() {
return;
}

let rss_to_mb = |rss| (rss as f64 / 1_000_000.0).round() as usize;
let rss_change_to_mb = |rss| (rss as f64 / 1_000_000.0).round() as i128;

Expand Down
9 changes: 6 additions & 3 deletions compiler/rustc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,13 @@ pub struct TimePassesCallbacks {
}

impl Callbacks for TimePassesCallbacks {
// JUSTIFICATION: the session doesn't exist at this point.
#[allow(rustc::bad_opt_access)]
fn config(&mut self, config: &mut interface::Config) {
// If a --prints=... option has been given, we don't print the "total"
// time because it will mess up the --prints output. See #64339.
self.time_passes = config.opts.prints.is_empty() && config.opts.time_passes();
// If a --print=... option has been given, we don't print the "total"
// time because it will mess up the --print output. See #64339.
//
self.time_passes = config.opts.prints.is_empty() && config.opts.unstable_opts.time_passes;
config.opts.trimmed_def_paths = TrimmedDefPaths::GoodPath;
}
}
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_error_messages/locales/en-US/lint.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -436,4 +436,5 @@ lint_check_name_deprecated = lint name `{$lint_name}` is deprecated and does not
lint_opaque_hidden_inferred_bound = opaque type `{$ty}` does not satisfy its associated type bounds
.specifically = this associated type bound is unsatisfied for `{$proj_ty}`
.suggestion = add this bound
lint_opaque_hidden_inferred_bound_sugg = add this bound
14 changes: 5 additions & 9 deletions compiler/rustc_hir_analysis/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::check::intrinsicck::InlineAsmCtxt;

use super::coercion::CoerceMany;
use super::compare_method::check_type_bounds;
use super::compare_method::{compare_const_impl, compare_impl_method, compare_ty_impl};
use super::compare_method::{compare_impl_method, compare_ty_impl};
use super::*;
use rustc_attr as attr;
use rustc_errors::{Applicability, ErrorGuaranteed, MultiSpan};
Expand Down Expand Up @@ -1048,14 +1048,10 @@ fn check_impl_items_against_trait<'tcx>(
let impl_item_full = tcx.hir().impl_item(impl_item.id);
match impl_item_full.kind {
hir::ImplItemKind::Const(..) => {
// Find associated const definition.
compare_const_impl(
tcx,
&ty_impl_item,
impl_item.span,
&ty_trait_item,
impl_trait_ref,
);
let _ = tcx.compare_assoc_const_impl_item_with_trait_item((
impl_item.id.def_id.def_id,
ty_impl_item.trait_item_def_id.unwrap(),
));
}
hir::ImplItemKind::Fn(..) => {
let opt_trait_span = tcx.hir().span_if_local(ty_trait_item.def_id);
Expand Down
58 changes: 30 additions & 28 deletions compiler/rustc_hir_analysis/src/check/compare_method.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::potentially_plural_count;
use crate::errors::LifetimesOrBoundsMismatchOnTrait;
use hir::def_id::DefId;
use hir::def_id::{DefId, LocalDefId};
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticId, ErrorGuaranteed};
use rustc_hir as hir;
Expand Down Expand Up @@ -1300,17 +1300,20 @@ fn compare_generic_param_kinds<'tcx>(
Ok(())
}

pub(crate) fn compare_const_impl<'tcx>(
/// Use `tcx.compare_assoc_const_impl_item_with_trait_item` instead
pub(crate) fn raw_compare_const_impl<'tcx>(
tcx: TyCtxt<'tcx>,
impl_c: &ty::AssocItem,
impl_c_span: Span,
trait_c: &ty::AssocItem,
impl_trait_ref: ty::TraitRef<'tcx>,
) {
(impl_const_item_def, trait_const_item_def): (LocalDefId, DefId),
) -> Result<(), ErrorGuaranteed> {
let impl_const_item = tcx.associated_item(impl_const_item_def);
let trait_const_item = tcx.associated_item(trait_const_item_def);
let impl_trait_ref = tcx.impl_trait_ref(impl_const_item.container_id(tcx)).unwrap();
debug!("compare_const_impl(impl_trait_ref={:?})", impl_trait_ref);

let impl_c_span = tcx.def_span(impl_const_item_def.to_def_id());

tcx.infer_ctxt().enter(|infcx| {
let param_env = tcx.param_env(impl_c.def_id);
let param_env = tcx.param_env(impl_const_item_def.to_def_id());
let ocx = ObligationCtxt::new(&infcx);

// The below is for the most part highly similar to the procedure
Expand All @@ -1322,18 +1325,18 @@ pub(crate) fn compare_const_impl<'tcx>(

// Create a parameter environment that represents the implementation's
// method.
let impl_c_hir_id = tcx.hir().local_def_id_to_hir_id(impl_c.def_id.expect_local());
let impl_c_hir_id = tcx.hir().local_def_id_to_hir_id(impl_const_item_def);

// Compute placeholder form of impl and trait const tys.
let impl_ty = tcx.type_of(impl_c.def_id);
let trait_ty = tcx.bound_type_of(trait_c.def_id).subst(tcx, trait_to_impl_substs);
let impl_ty = tcx.type_of(impl_const_item_def.to_def_id());
let trait_ty = tcx.bound_type_of(trait_const_item_def).subst(tcx, trait_to_impl_substs);
let mut cause = ObligationCause::new(
impl_c_span,
impl_c_hir_id,
ObligationCauseCode::CompareImplItemObligation {
impl_item_def_id: impl_c.def_id.expect_local(),
trait_item_def_id: trait_c.def_id,
kind: impl_c.kind,
impl_item_def_id: impl_const_item_def,
trait_item_def_id: trait_const_item_def,
kind: impl_const_item.kind,
},
);

Expand All @@ -1358,24 +1361,24 @@ pub(crate) fn compare_const_impl<'tcx>(
);

// Locate the Span containing just the type of the offending impl
match tcx.hir().expect_impl_item(impl_c.def_id.expect_local()).kind {
match tcx.hir().expect_impl_item(impl_const_item_def).kind {
ImplItemKind::Const(ref ty, _) => cause.span = ty.span,
_ => bug!("{:?} is not a impl const", impl_c),
_ => bug!("{:?} is not a impl const", impl_const_item),
}

let mut diag = struct_span_err!(
tcx.sess,
cause.span,
E0326,
"implemented const `{}` has an incompatible type for trait",
trait_c.name
trait_const_item.name
);

let trait_c_span = trait_c.def_id.as_local().map(|trait_c_def_id| {
let trait_c_span = trait_const_item_def.as_local().map(|trait_c_def_id| {
// Add a label to the Span containing just the type of the const
match tcx.hir().expect_trait_item(trait_c_def_id).kind {
TraitItemKind::Const(ref ty, _) => ty.span,
_ => bug!("{:?} is not a trait const", trait_c),
_ => bug!("{:?} is not a trait const", trait_const_item),
}
});

Expand All @@ -1391,23 +1394,22 @@ pub(crate) fn compare_const_impl<'tcx>(
false,
false,
);
diag.emit();
}
return Err(diag.emit());
};

// Check that all obligations are satisfied by the implementation's
// version.
let errors = ocx.select_all_or_error();
if !errors.is_empty() {
infcx.report_fulfillment_errors(&errors, None, false);
return;
return Err(infcx.report_fulfillment_errors(&errors, None, false));
}

// FIXME return `ErrorReported` if region obligations error?
let outlives_environment = OutlivesEnvironment::new(param_env);
infcx.check_region_obligations_and_report_errors(
impl_c.def_id.expect_local(),
&outlives_environment,
);
});
infcx
.check_region_obligations_and_report_errors(impl_const_item_def, &outlives_environment);
Ok(())
})
}

pub(crate) fn compare_ty_impl<'tcx>(
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir_analysis/src/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ pub fn provide(providers: &mut Providers) {
check_mod_item_types,
region_scope_tree,
collect_trait_impl_trait_tys,
compare_assoc_const_impl_item_with_trait_item: compare_method::raw_compare_const_impl,
..*providers
};
}
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,6 @@ fn test_unstable_options_tracking_hash() {
untracked!(span_free_formats, true);
untracked!(temps_dir, Some(String::from("abc")));
untracked!(threads, 99);
untracked!(time, true);
untracked!(time_llvm_passes, true);
untracked!(time_passes, true);
untracked!(trace_macros, true);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/early.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ pub fn check_ast_node<'a>(
if sess.opts.unstable_opts.no_interleave_lints {
for (i, pass) in passes.iter_mut().enumerate() {
buffered =
sess.prof.extra_verbose_generic_activity("run_lint", pass.name()).run(|| {
sess.prof.verbose_generic_activity_with_arg("run_lint", pass.name()).run(|| {
early_lint_node(
sess,
!pre_expansion && i == 0,
Expand Down
17 changes: 10 additions & 7 deletions compiler/rustc_lint/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,20 +425,23 @@ fn late_lint_crate<'tcx, T: LateLintPass<'tcx>>(tcx: TyCtxt<'tcx>, builtin_lints
late_lint_pass_crate(tcx, builtin_lints);
} else {
for pass in &mut passes {
tcx.sess.prof.extra_verbose_generic_activity("run_late_lint", pass.name()).run(|| {
late_lint_pass_crate(tcx, LateLintPassObjects { lints: slice::from_mut(pass) });
});
tcx.sess.prof.verbose_generic_activity_with_arg("run_late_lint", pass.name()).run(
|| {
late_lint_pass_crate(tcx, LateLintPassObjects { lints: slice::from_mut(pass) });
},
);
}

let mut passes: Vec<_> =
unerased_lint_store(tcx).late_module_passes.iter().map(|pass| (pass)(tcx)).collect();

for pass in &mut passes {
tcx.sess.prof.extra_verbose_generic_activity("run_late_module_lint", pass.name()).run(
|| {
tcx.sess
.prof
.verbose_generic_activity_with_arg("run_late_module_lint", pass.name())
.run(|| {
late_lint_pass_crate(tcx, LateLintPassObjects { lints: slice::from_mut(pass) });
},
);
});
}
}
}
Expand Down
Loading

0 comments on commit 0ca3565

Please sign in to comment.