Skip to content

Rollup of 10 pull requests #76786

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

Merged
merged 28 commits into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8d96cc2
make llvm_asm options more intense
tesuji Sep 13, 2020
b7ce5b4
remove orphaned files
tshepang Sep 13, 2020
c9686cb
Introduce a PartitioningCx struct
wesleywiser Jul 26, 2020
0eac38b
fix syntax error in suggesting generic constraint in trait parameter
iximeow Sep 14, 2020
dd57275
shrink const infer error
lcnr Sep 14, 2020
035f879
improve const infer err
lcnr Sep 14, 2020
b881551
Simplify iter flatten struct doc
pickfire Sep 14, 2020
43709f7
:arrow_up: rust-analyzer
Sep 14, 2020
5112f87
Remove flatten doc intra-doc links
pickfire Sep 14, 2020
1f26a18
Use intra-doc links for `DelaySpanBugEmitted`
camelid Sep 14, 2020
15349ef
Minor improvements to `mir::Constant` docs
camelid Sep 14, 2020
5c1043a
Fix diagram for `DebruijnIndex`
camelid Sep 14, 2020
e1607c8
clean up comment text a bit
iximeow Sep 14, 2020
32efcfc
Include non-JSON output in error display for lint-doc failure.
ehuss Sep 14, 2020
9dad908
Fix generating rustc docs with non-default lib directory.
ehuss Sep 14, 2020
e82be71
document how to use memory addresses as operands
tesuji Sep 14, 2020
87666e5
Prefer asm! over llvm_asm! in core
tesuji Sep 16, 2020
4dc4e9f
Fix black_box bug detected by Amanieu
tesuji Sep 16, 2020
d1b0504
Rollup merge of #76669 - lzutao:core_asm, r=Amanieu
Dylan-DPC Sep 16, 2020
6194d7e
Rollup merge of #76675 - lzutao:asm_doc, r=Amanieu
Dylan-DPC Sep 16, 2020
c8bfbad
Rollup merge of #76681 - tshepang:unused, r=Mark-Simulacrum
Dylan-DPC Sep 16, 2020
2c2f1c2
Rollup merge of #76694 - wesleywiser:partitioning_cx_trait, r=davidtwco
Dylan-DPC Sep 16, 2020
54d7728
Rollup merge of #76695 - iximeow:trait-generic-bound-suggestion, r=es…
Dylan-DPC Sep 16, 2020
3f9e7fc
Rollup merge of #76699 - lcnr:const-infer-err, r=varkor
Dylan-DPC Sep 16, 2020
9524fff
Rollup merge of #76707 - pickfire:patch-4, r=jonas-schievink
Dylan-DPC Sep 16, 2020
7e202fc
Rollup merge of #76710 - rust-lang:rust-analyzer-2020-09-14, r=jonas-…
Dylan-DPC Sep 16, 2020
b25261f
Rollup merge of #76714 - camelid:patch-3, r=jonas-schievink
Dylan-DPC Sep 16, 2020
f631293
Rollup merge of #76717 - ehuss:fix-rustc-book-libdir, r=Mark-Simulacrum
Dylan-DPC Sep 16, 2020
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
27 changes: 20 additions & 7 deletions compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ use rustc_hir::def::{DefKind, Namespace};
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc_hir::{Body, Expr, ExprKind, FnRetTy, HirId, Local, Pat};
use rustc_middle::hir::map::Map;
use rustc_middle::infer::unify_key::ConstVariableOriginKind;
use rustc_middle::ty::print::Print;
use rustc_middle::ty::subst::{GenericArg, GenericArgKind};
use rustc_middle::ty::{self, DefIdTree, Ty};
use rustc_middle::ty::{self, DefIdTree, InferConst, Ty};
use rustc_span::source_map::DesugaringKind;
use rustc_span::symbol::kw;
use rustc_span::Span;
Expand Down Expand Up @@ -569,14 +570,26 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
local_visitor.visit_expr(expr);
}

let mut param_name = None;
let span = if let ty::ConstKind::Infer(InferConst::Var(vid)) = ct.val {
let origin = self.inner.borrow_mut().const_unification_table().probe_value(vid).origin;
if let ConstVariableOriginKind::ConstParameterDefinition(param) = origin.kind {
param_name = Some(param);
}
origin.span
} else {
local_visitor.target_span
};

let error_code = error_code.into();
let mut err = self.tcx.sess.struct_span_err_with_code(
local_visitor.target_span,
"type annotations needed",
error_code,
);
let mut err =
self.tcx.sess.struct_span_err_with_code(span, "type annotations needed", error_code);

err.note("unable to infer the value of a const parameter");
if let Some(param_name) = param_name {
err.note(&format!("cannot infer the value of the const parameter `{}`", param_name));
} else {
err.note("unable to infer the value of a const parameter");
}

err
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/infer/unify_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ pub struct ConstVariableOrigin {
pub enum ConstVariableOriginKind {
MiscVariable,
ConstInference,
// FIXME(const_generics): Consider storing the `DefId` of the param here.
ConstParameterDefinition(Symbol),
SubstitutionPlaceholder,
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2285,8 +2285,8 @@ impl<'tcx> Debug for Rvalue<'tcx> {
/// Constants
///
/// Two constants are equal if they are the same constant. Note that
/// this does not necessarily mean that they are "==" in Rust -- in
/// particular one must be wary of `NaN`!
/// this does not necessarily mean that they are `==` in Rust -- in
/// particular, one must be wary of `NaN`!

#[derive(Clone, Copy, PartialEq, TyEncodable, TyDecodable, HashStable)]
pub struct Constant<'tcx> {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ use std::mem;
use std::ops::{Bound, Deref};
use std::sync::Arc;

/// A type that is not publicly constructable. This prevents people from making `TyKind::Error`
/// except through `tcx.err*()`, which are in this module.
/// A type that is not publicly constructable. This prevents people from making [`TyKind::Error`]s
/// except through the error-reporting functions on a [`tcx`][TyCtxt].
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
#[derive(TyEncodable, TyDecodable, HashStable)]
pub struct DelaySpanBugEmitted(());
Expand Down
66 changes: 46 additions & 20 deletions compiler/rustc_middle/src/ty/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,33 +202,59 @@ pub fn suggest_constraining_type_param(
// Suggestion:
// fn foo<T>(t: T) where T: Foo, T: Bar {... }
// - insert: `, T: Zar`
//
// Additionally, there may be no `where` clause whatsoever in the case that this was
// reached because the generic parameter has a default:
//
// Message:
// trait Foo<T=()> {... }
// - help: consider further restricting this type parameter with `where T: Zar`
//
// Suggestion:
// trait Foo<T=()> where T: Zar {... }
// - insert: `where T: Zar`

let mut param_spans = Vec::new();
if matches!(param.kind, hir::GenericParamKind::Type { default: Some(_), .. })
&& generics.where_clause.predicates.len() == 0
{
// Suggest a bound, but there is no existing `where` clause *and* the type param has a
// default (`<T=Foo>`), so we suggest adding `where T: Bar`.
err.span_suggestion_verbose(
generics.where_clause.tail_span_for_suggestion(),
&msg_restrict_type_further,
format!(" where {}: {}", param_name, constraint),
Applicability::MachineApplicable,
);
} else {
let mut param_spans = Vec::new();

for predicate in generics.where_clause.predicates {
if let WherePredicate::BoundPredicate(WhereBoundPredicate {
span, bounded_ty, ..
}) = predicate
{
if let TyKind::Path(QPath::Resolved(_, path)) = &bounded_ty.kind {
if let Some(segment) = path.segments.first() {
if segment.ident.to_string() == param_name {
param_spans.push(span);
for predicate in generics.where_clause.predicates {
if let WherePredicate::BoundPredicate(WhereBoundPredicate {
span,
bounded_ty,
..
}) = predicate
{
if let TyKind::Path(QPath::Resolved(_, path)) = &bounded_ty.kind {
if let Some(segment) = path.segments.first() {
if segment.ident.to_string() == param_name {
param_spans.push(span);
}
}
}
}
}
}

match &param_spans[..] {
&[&param_span] => suggest_restrict(param_span.shrink_to_hi()),
_ => {
err.span_suggestion_verbose(
generics.where_clause.tail_span_for_suggestion(),
&msg_restrict_type_further,
format!(", {}: {}", param_name, constraint),
Applicability::MachineApplicable,
);
match &param_spans[..] {
&[&param_span] => suggest_restrict(param_span.shrink_to_hi()),
_ => {
err.span_suggestion_verbose(
generics.where_clause.tail_span_for_suggestion(),
&msg_restrict_type_further,
format!(", {}: {}", param_name, constraint),
Applicability::MachineApplicable,
);
}
}
}

Expand Down
14 changes: 7 additions & 7 deletions compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1233,13 +1233,13 @@ rustc_index::newtype_index! {
/// particular, imagine a type like this:
///
/// for<'a> fn(for<'b> fn(&'b isize, &'a isize), &'a char)
/// ^ ^ | | |
/// | | | | |
/// | +------------+ 0 | |
/// | | |
/// +--------------------------------+ 1 |
/// | |
/// +------------------------------------------+ 0
/// ^ ^ | | |
/// | | | | |
/// | +------------+ 0 | |
/// | | |
/// +----------------------------------+ 1 |
/// | |
/// +----------------------------------------------+ 0
///
/// In this type, there are two binders (the outer fn and the inner
/// fn). We need to be able to determine, for any given region, which
Expand Down
32 changes: 16 additions & 16 deletions compiler/rustc_mir/src/monomorphize/partitioning/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use rustc_middle::ty::print::characteristic_def_id_of_type;
use rustc_middle::ty::{self, DefIdTree, InstanceDef, TyCtxt};
use rustc_span::symbol::Symbol;

use super::PartitioningCx;
use crate::monomorphize::collector::InliningMap;
use crate::monomorphize::partitioning::merging;
use crate::monomorphize::partitioning::{
Expand All @@ -22,35 +23,36 @@ pub struct DefaultPartitioning;
impl<'tcx> Partitioner<'tcx> for DefaultPartitioning {
fn place_root_mono_items(
&mut self,
tcx: TyCtxt<'tcx>,
cx: &PartitioningCx<'_, 'tcx>,
mono_items: &mut dyn Iterator<Item = MonoItem<'tcx>>,
) -> PreInliningPartitioning<'tcx> {
let mut roots = FxHashSet::default();
let mut codegen_units = FxHashMap::default();
let is_incremental_build = tcx.sess.opts.incremental.is_some();
let is_incremental_build = cx.tcx.sess.opts.incremental.is_some();
let mut internalization_candidates = FxHashSet::default();

// Determine if monomorphizations instantiated in this crate will be made
// available to downstream crates. This depends on whether we are in
// share-generics mode and whether the current crate can even have
// downstream crates.
let export_generics = tcx.sess.opts.share_generics() && tcx.local_crate_exports_generics();
let export_generics =
cx.tcx.sess.opts.share_generics() && cx.tcx.local_crate_exports_generics();

let cgu_name_builder = &mut CodegenUnitNameBuilder::new(tcx);
let cgu_name_builder = &mut CodegenUnitNameBuilder::new(cx.tcx);
let cgu_name_cache = &mut FxHashMap::default();

for mono_item in mono_items {
match mono_item.instantiation_mode(tcx) {
match mono_item.instantiation_mode(cx.tcx) {
InstantiationMode::GloballyShared { .. } => {}
InstantiationMode::LocalCopy => continue,
}

let characteristic_def_id = characteristic_def_id_of_mono_item(tcx, mono_item);
let characteristic_def_id = characteristic_def_id_of_mono_item(cx.tcx, mono_item);
let is_volatile = is_incremental_build && mono_item.is_generic_fn();

let codegen_unit_name = match characteristic_def_id {
Some(def_id) => compute_codegen_unit_name(
tcx,
cx.tcx,
cgu_name_builder,
def_id,
is_volatile,
Expand All @@ -65,7 +67,7 @@ impl<'tcx> Partitioner<'tcx> for DefaultPartitioning {

let mut can_be_internalized = true;
let (linkage, visibility) = mono_item_linkage_and_visibility(
tcx,
cx.tcx,
&mono_item,
&mut can_be_internalized,
export_generics,
Expand Down Expand Up @@ -97,17 +99,16 @@ impl<'tcx> Partitioner<'tcx> for DefaultPartitioning {

fn merge_codegen_units(
&mut self,
tcx: TyCtxt<'tcx>,
cx: &PartitioningCx<'_, 'tcx>,
initial_partitioning: &mut PreInliningPartitioning<'tcx>,
target_cgu_count: usize,
) {
merging::merge_codegen_units(tcx, initial_partitioning, target_cgu_count);
merging::merge_codegen_units(cx, initial_partitioning);
}

fn place_inlined_mono_items(
&mut self,
cx: &PartitioningCx<'_, 'tcx>,
initial_partitioning: PreInliningPartitioning<'tcx>,
inlining_map: &InliningMap<'tcx>,
) -> PostInliningPartitioning<'tcx> {
let mut new_partitioning = Vec::new();
let mut mono_item_placements = FxHashMap::default();
Expand All @@ -124,7 +125,7 @@ impl<'tcx> Partitioner<'tcx> for DefaultPartitioning {
// Collect all items that need to be available in this codegen unit.
let mut reachable = FxHashSet::default();
for root in old_codegen_unit.items().keys() {
follow_inlining(*root, inlining_map, &mut reachable);
follow_inlining(*root, cx.inlining_map, &mut reachable);
}

let mut new_codegen_unit = CodegenUnit::new(old_codegen_unit.name());
Expand Down Expand Up @@ -198,9 +199,8 @@ impl<'tcx> Partitioner<'tcx> for DefaultPartitioning {

fn internalize_symbols(
&mut self,
_tcx: TyCtxt<'tcx>,
cx: &PartitioningCx<'_, 'tcx>,
partitioning: &mut PostInliningPartitioning<'tcx>,
inlining_map: &InliningMap<'tcx>,
) {
if partitioning.codegen_units.len() == 1 {
// Fast path for when there is only one codegen unit. In this case we
Expand All @@ -218,7 +218,7 @@ impl<'tcx> Partitioner<'tcx> for DefaultPartitioning {
// Build a map from every monomorphization to all the monomorphizations that
// reference it.
let mut accessor_map: FxHashMap<MonoItem<'tcx>, Vec<MonoItem<'tcx>>> = Default::default();
inlining_map.iter_accesses(|accessor, accessees| {
cx.inlining_map.iter_accesses(|accessor, accessees| {
for accessee in accessees {
accessor_map.entry(*accessee).or_default().push(accessor);
}
Expand Down
15 changes: 7 additions & 8 deletions compiler/rustc_mir/src/monomorphize/partitioning/merging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ use std::cmp;
use rustc_data_structures::fx::FxHashMap;
use rustc_hir::def_id::LOCAL_CRATE;
use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder};
use rustc_middle::ty::TyCtxt;
use rustc_span::symbol::{Symbol, SymbolStr};

use super::PartitioningCx;
use crate::monomorphize::partitioning::PreInliningPartitioning;

pub fn merge_codegen_units<'tcx>(
tcx: TyCtxt<'tcx>,
cx: &PartitioningCx<'_, 'tcx>,
initial_partitioning: &mut PreInliningPartitioning<'tcx>,
target_cgu_count: usize,
) {
assert!(target_cgu_count >= 1);
assert!(cx.target_cgu_count >= 1);
let codegen_units = &mut initial_partitioning.codegen_units;

// Note that at this point in time the `codegen_units` here may not be in a
Expand All @@ -32,7 +31,7 @@ pub fn merge_codegen_units<'tcx>(
codegen_units.iter().map(|cgu| (cgu.name(), vec![cgu.name().as_str()])).collect();

// Merge the two smallest codegen units until the target size is reached.
while codegen_units.len() > target_cgu_count {
while codegen_units.len() > cx.target_cgu_count {
// Sort small cgus to the back
codegen_units.sort_by_cached_key(|cgu| cmp::Reverse(cgu.size_estimate()));
let mut smallest = codegen_units.pop().unwrap();
Expand All @@ -56,9 +55,9 @@ pub fn merge_codegen_units<'tcx>(
);
}

let cgu_name_builder = &mut CodegenUnitNameBuilder::new(tcx);
let cgu_name_builder = &mut CodegenUnitNameBuilder::new(cx.tcx);

if tcx.sess.opts.incremental.is_some() {
if cx.tcx.sess.opts.incremental.is_some() {
// If we are doing incremental compilation, we want CGU names to
// reflect the path of the source level module they correspond to.
// For CGUs that contain the code of multiple modules because of the
Expand All @@ -84,7 +83,7 @@ pub fn merge_codegen_units<'tcx>(

for cgu in codegen_units.iter_mut() {
if let Some(new_cgu_name) = new_cgu_names.get(&cgu.name()) {
if tcx.sess.opts.debugging_opts.human_readable_cgu_names {
if cx.tcx.sess.opts.debugging_opts.human_readable_cgu_names {
cgu.set_name(Symbol::intern(&new_cgu_name));
} else {
// If we don't require CGU names to be human-readable, we
Expand Down
Loading