Skip to content

Commit

Permalink
Auto merge of #70672 - Dylan-DPC:rollup-cco9bbd, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 6 pull requests

Successful merges:

 - #70535 (Track the finalizing node in the specialization graph)
 - #70590 (Miri: make backtrace function names and spans match up)
 - #70616 (rustc_target::abi: rename FieldPlacement to FieldsShape.)
 - #70626 (cargotest: remove webrender)
 - #70649 (clean up E0468 explanation)
 - #70662 (compiletest: don't use `std::io::stdout()`, as it bypasses `set_print`.)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Apr 1, 2020
2 parents 235938d + 7d4d450 commit 76b1198
Show file tree
Hide file tree
Showing 36 changed files with 411 additions and 363 deletions.
12 changes: 6 additions & 6 deletions src/librustc_codegen_llvm/type_of.rs
Expand Up @@ -79,7 +79,7 @@ fn uncached_llvm_type<'a, 'tcx>(
};

match layout.fields {
layout::FieldPlacement::Union(_) => {
layout::FieldsShape::Union(_) => {
let fill = cx.type_padding_filler(layout.size, layout.align.abi);
let packed = false;
match name {
Expand All @@ -91,10 +91,10 @@ fn uncached_llvm_type<'a, 'tcx>(
}
}
}
layout::FieldPlacement::Array { count, .. } => {
layout::FieldsShape::Array { count, .. } => {
cx.type_array(layout.field(cx, 0).llvm_type(cx), count)
}
layout::FieldPlacement::Arbitrary { .. } => match name {
layout::FieldsShape::Arbitrary { .. } => match name {
None => {
let (llfields, packed) = struct_llfields(cx, layout);
cx.type_struct(&llfields, packed)
Expand Down Expand Up @@ -371,13 +371,13 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
_ => {}
}
match self.fields {
layout::FieldPlacement::Union(_) => {
layout::FieldsShape::Union(_) => {
bug!("TyAndLayout::llvm_field_index({:?}): not applicable", self)
}

layout::FieldPlacement::Array { .. } => index as u64,
layout::FieldsShape::Array { .. } => index as u64,

layout::FieldPlacement::Arbitrary { .. } => {
layout::FieldsShape::Arbitrary { .. } => {
1 + (self.fields.memory_index(index) as u64) * 2
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/mir/place.rs
Expand Up @@ -66,7 +66,7 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
}

pub fn len<Cx: ConstMethods<'tcx, Value = V>>(&self, cx: &Cx) -> V {
if let layout::FieldPlacement::Array { count, .. } = self.layout.fields {
if let layout::FieldsShape::Array { count, .. } = self.layout.fields {
if self.layout.is_unsized() {
assert_eq!(count, 0);
self.llextra.unwrap()
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_error_codes/error_codes/E0468.md
@@ -1,4 +1,4 @@
A non-root module attempts to import macros from another crate.
A non-root module tried to import macros from another crate.

Example of erroneous code:

Expand All @@ -17,7 +17,7 @@ Either move the macro import to crate root or do without the foreign macros.
This will work:

```
#[macro_use(debug_assert)]
#[macro_use(debug_assert)] // ok!
extern crate core;
mod foo {
Expand Down
22 changes: 9 additions & 13 deletions src/librustc_middle/mir/interpret/error.rs
Expand Up @@ -53,9 +53,8 @@ pub struct ConstEvalErr<'tcx> {

#[derive(Debug)]
pub struct FrameInfo<'tcx> {
/// This span is in the caller.
pub call_site: Span,
pub instance: ty::Instance<'tcx>,
pub span: Span,
pub lint_root: Option<hir::HirId>,
}

Expand All @@ -65,12 +64,12 @@ impl<'tcx> fmt::Display for FrameInfo<'tcx> {
if tcx.def_key(self.instance.def_id()).disambiguated_data.data
== DefPathData::ClosureExpr
{
write!(f, "inside call to closure")?;
write!(f, "inside closure")?;
} else {
write!(f, "inside call to `{}`", self.instance)?;
write!(f, "inside `{}`", self.instance)?;
}
if !self.call_site.is_dummy() {
let lo = tcx.sess.source_map().lookup_char_pos(self.call_site.lo());
if !self.span.is_dummy() {
let lo = tcx.sess.source_map().lookup_char_pos(self.span.lo());
write!(f, " at {}:{}:{}", lo.file.name, lo.line, lo.col.to_usize() + 1)?;
}
Ok(())
Expand Down Expand Up @@ -168,13 +167,10 @@ impl<'tcx> ConstEvalErr<'tcx> {
if let Some(span_msg) = span_msg {
err.span_label(self.span, span_msg);
}
// Add spans for the stacktrace.
// Skip the last, which is just the environment of the constant. The stacktrace
// is sometimes empty because we create "fake" eval contexts in CTFE to do work
// on constant values.
if !self.stacktrace.is_empty() {
for frame_info in &self.stacktrace[..self.stacktrace.len() - 1] {
err.span_label(frame_info.call_site, frame_info.to_string());
// Add spans for the stacktrace. Don't print a single-line backtrace though.
if self.stacktrace.len() > 1 {
for frame_info in &self.stacktrace {
err.span_label(frame_info.span, frame_info.to_string());
}
}
// Let the caller finish the job.
Expand Down
70 changes: 59 additions & 11 deletions src/librustc_middle/traits/specialization_graph.rs
Expand Up @@ -154,14 +154,44 @@ impl Iterator for Ancestors<'_> {
}
}

pub struct NodeItem<T> {
pub node: Node,
pub item: T,
/// Information about the most specialized definition of an associated item.
pub struct LeafDef {
/// The associated item described by this `LeafDef`.
pub item: ty::AssocItem,

/// The node in the specialization graph containing the definition of `item`.
pub defining_node: Node,

/// The "top-most" (ie. least specialized) specialization graph node that finalized the
/// definition of `item`.
///
/// Example:
///
/// ```
/// trait Tr {
/// fn assoc(&self);
/// }
///
/// impl<T> Tr for T {
/// default fn assoc(&self) {}
/// }
///
/// impl Tr for u8 {}
/// ```
///
/// If we start the leaf definition search at `impl Tr for u8`, that impl will be the
/// `finalizing_node`, while `defining_node` will be the generic impl.
///
/// If the leaf definition search is started at the generic impl, `finalizing_node` will be
/// `None`, since the most specialized impl we found still allows overriding the method
/// (doesn't finalize it).
pub finalizing_node: Option<Node>,
}

impl<T> NodeItem<T> {
pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> NodeItem<U> {
NodeItem { node: self.node, item: f(self.item) }
impl LeafDef {
/// Returns whether this definition is known to not be further specializable.
pub fn is_final(&self) -> bool {
self.finalizing_node.is_some()
}
}

Expand All @@ -173,18 +203,36 @@ impl<'tcx> Ancestors<'tcx> {
tcx: TyCtxt<'tcx>,
trait_item_name: Ident,
trait_item_kind: ty::AssocKind,
) -> Option<NodeItem<ty::AssocItem>> {
) -> Option<LeafDef> {
let trait_def_id = self.trait_def_id;
let mut finalizing_node = None;

self.find_map(|node| {
node.item(tcx, trait_item_name, trait_item_kind, trait_def_id)
.map(|item| NodeItem { node, item })
if let Some(item) = node.item(tcx, trait_item_name, trait_item_kind, trait_def_id) {
if finalizing_node.is_none() {
let is_specializable = item.defaultness.is_default()
|| tcx.impl_defaultness(node.def_id()).is_default();

if !is_specializable {
finalizing_node = Some(node);
}
}

Some(LeafDef { item, defining_node: node, finalizing_node })
} else {
// Item not mentioned. This "finalizes" any defaulted item provided by an ancestor.
finalizing_node = Some(node);
None
}
})
}
}

/// Walk up the specialization ancestors of a given impl, starting with that
/// impl itself. Returns `None` if an error was reported while building the
/// specialization graph.
/// impl itself.
///
/// Returns `Err` if an error was reported while building the specialization
/// graph.
pub fn ancestors(
tcx: TyCtxt<'tcx>,
trait_def_id: DefId,
Expand Down

0 comments on commit 76b1198

Please sign in to comment.