Skip to content

Commit

Permalink
Auto merge of #84342 - Dylan-DPC:rollup-5b40142, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 7 pull requests

Successful merges:

 - #84123 (Introduce CompileMonoItem DepNode)
 - #84126 (Enable sanitizers for x86_64-unknown-linux-musl)
 - #84168 (Lower async fn in traits.)
 - #84256 (doc: use U+2212 for minus sign in floating-point -0.0 remarks)
 - #84291 (fix aliasing violations in thread_local_const_init)
 - #84313 (fix suggestion for unsized function parameters)
 - #84330 (Remove unused footer section)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Apr 19, 2021
2 parents 1a6c98e + a23fd16 commit 9d9c2c9
Show file tree
Hide file tree
Showing 37 changed files with 146 additions and 57 deletions.
14 changes: 11 additions & 3 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -836,9 +836,17 @@ impl<'hir> LoweringContext<'_, 'hir> {
(generics, hir::TraitItemKind::Fn(sig, hir::TraitFn::Required(names)))
}
AssocItemKind::Fn(box FnKind(_, ref sig, ref generics, Some(ref body))) => {
let body_id = self.lower_fn_body_block(i.span, &sig.decl, Some(body));
let (generics, sig) =
self.lower_method_sig(generics, sig, trait_item_def_id, false, None, i.id);
let asyncness = sig.header.asyncness;
let body_id =
self.lower_maybe_async_body(i.span, &sig.decl, asyncness, Some(&body));
let (generics, sig) = self.lower_method_sig(
generics,
sig,
trait_item_def_id,
false,
asyncness.opt_return_id(),
i.id,
);
(generics, hir::TraitItemKind::Fn(sig, hir::TraitFn::Provided(body_id)))
}
AssocItemKind::TyAlias(box TyAliasKind(_, ref generics, ref bounds, ref default)) => {
Expand Down
36 changes: 28 additions & 8 deletions compiler/rustc_middle/src/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
//! `DepNode` definition happens in the `define_dep_nodes!()` macro. This macro
//! defines the `DepKind` enum. Each `DepKind` has its own parameters that are
//! needed at runtime in order to construct a valid `DepNode` fingerprint.
//! However, only `CompileCodegenUnit` is constructed explicitly (with
//! `make_compile_codegen_unit`).
//! However, only `CompileCodegenUnit` and `CompileMonoItem` are constructed
//! explicitly (with `make_compile_codegen_unit` cq `make_compile_mono_item`).
//!
//! Because the macro sees what parameters a given `DepKind` requires, it can
//! "infer" some properties for each kind of `DepNode`:
Expand All @@ -46,15 +46,17 @@
//! `DefId` it was computed from. In other cases, too much information gets
//! lost during fingerprint computation.
//!
//! `make_compile_codegen_unit`, together with `DepNode::new()`, ensures that only
//! valid `DepNode` instances can be constructed. For example, the API does not
//! allow for constructing parameterless `DepNode`s with anything other
//! than a zeroed out fingerprint. More generally speaking, it relieves the
//! user of the `DepNode` API of having to know how to compute the expected
//! fingerprint for a given set of node parameters.
//! `make_compile_codegen_unit` and `make_compile_mono_items`, together with
//! `DepNode::new()`, ensures that only valid `DepNode` instances can be
//! constructed. For example, the API does not allow for constructing
//! parameterless `DepNode`s with anything other than a zeroed out fingerprint.
//! More generally speaking, it relieves the user of the `DepNode` API of
//! having to know how to compute the expected fingerprint for a given set of
//! node parameters.
//!
//! [dependency graph]: https://rustc-dev-guide.rust-lang.org/query.html

use crate::mir::mono::MonoItem;
use crate::ty::TyCtxt;

use rustc_data_structures::fingerprint::Fingerprint;
Expand Down Expand Up @@ -175,6 +177,14 @@ pub mod dep_kind {
can_reconstruct_query_key: || false,
};

pub const CompileMonoItem: DepKindStruct = DepKindStruct {
has_params: true,
is_anon: false,
is_eval_always: false,

can_reconstruct_query_key: || false,
};

macro_rules! define_query_dep_kinds {
($(
[$($attrs:tt)*]
Expand Down Expand Up @@ -251,6 +261,10 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>

// WARNING: if `Symbol` is changed, make sure you update `make_compile_codegen_unit` below.
[] CompileCodegenUnit(Symbol),

// WARNING: if `MonoItem` is changed, make sure you update `make_compile_mono_item` below.
// Only used by rustc_codegen_cranelift
[] CompileMonoItem(MonoItem),
]);

// WARNING: `construct` is generic and does not know that `CompileCodegenUnit` takes `Symbol`s as keys.
Expand All @@ -259,6 +273,12 @@ crate fn make_compile_codegen_unit(tcx: TyCtxt<'_>, name: Symbol) -> DepNode {
DepNode::construct(tcx, DepKind::CompileCodegenUnit, &name)
}

// WARNING: `construct` is generic and does not know that `CompileMonoItem` takes `MonoItem`s as keys.
// Be very careful changing this type signature!
crate fn make_compile_mono_item(tcx: TyCtxt<'tcx>, mono_item: &MonoItem<'tcx>) -> DepNode {
DepNode::construct(tcx, DepKind::CompileMonoItem, mono_item)
}

pub type DepNode = rustc_query_system::dep_graph::DepNode<DepKind>;

// We keep a lot of `DepNode`s in memory during compilation. It's not
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/dep_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ pub use rustc_query_system::dep_graph::{
SerializedDepNodeIndex, WorkProduct, WorkProductId,
};

crate use dep_node::make_compile_codegen_unit;
pub use dep_node::{label_strs, DepKind, DepNode, DepNodeExt};
crate use dep_node::{make_compile_codegen_unit, make_compile_mono_item};

pub type DepGraph = rustc_query_system::dep_graph::DepGraph<DepKind>;
pub type TaskDeps = rustc_query_system::dep_graph::TaskDeps<DepKind>;
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_middle/src/mir/mono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ impl<'tcx> MonoItem<'tcx> {
}
.map(|hir_id| tcx.hir().span(hir_id))
}

// Only used by rustc_codegen_cranelift
pub fn codegen_dep_node(&self, tcx: TyCtxt<'tcx>) -> DepNode {
crate::dep_graph::make_compile_mono_item(tcx, self)
}
}

impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for MonoItem<'tcx> {
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_query_impl/src/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,11 @@ macro_rules! define_queries {
try_load_from_on_disk_cache: |_, _| {},
};

pub const CompileMonoItem: QueryStruct = QueryStruct {
force_from_dep_node: |_, _| false,
try_load_from_on_disk_cache: |_, _| {},
};

$(pub const $name: QueryStruct = {
const is_anon: bool = is_anon!([$($modifiers)*]);

Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_target/src/spec/x86_64_unknown_linux_musl.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::spec::{LinkerFlavor, StackProbeType, Target};
use crate::spec::{LinkerFlavor, SanitizerSet, StackProbeType, Target};

pub fn target() -> Target {
let mut base = super::linux_musl_base::opts();
Expand All @@ -7,6 +7,8 @@ pub fn target() -> Target {
base.pre_link_args.entry(LinkerFlavor::Gcc).or_default().push("-m64".to_string());
base.stack_probes = StackProbeType::InlineOrCall { min_llvm_version_for_inline: (11, 0, 1) };
base.static_position_independent_executables = true;
base.supported_sanitizers =
SanitizerSet::ADDRESS | SanitizerSet::LEAK | SanitizerSet::MEMORY | SanitizerSet::THREAD;

Target {
llvm_target: "x86_64-unknown-linux-musl".to_string(),
Expand Down
13 changes: 6 additions & 7 deletions compiler/rustc_typeck/src/check/gather_locals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@ use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKi
use rustc_middle::ty::Ty;
use rustc_span::{sym, Span};
use rustc_trait_selection::traits;
use std::mem;

pub(super) struct GatherLocalsVisitor<'a, 'tcx> {
fcx: &'a FnCtxt<'a, 'tcx>,
parent_id: hir::HirId,
// parameters are special cases of patterns, but we want to handle them as
// *distinct* cases. so track when we are hitting a pattern *within* an fn
// parameter.
outermost_fn_param_pat: bool,
outermost_fn_param_pat: Option<Span>,
}

impl<'a, 'tcx> GatherLocalsVisitor<'a, 'tcx> {
pub(super) fn new(fcx: &'a FnCtxt<'a, 'tcx>, parent_id: hir::HirId) -> Self {
Self { fcx, parent_id, outermost_fn_param_pat: false }
Self { fcx, parent_id, outermost_fn_param_pat: None }
}

fn assign(&mut self, span: Span, nid: hir::HirId, ty_opt: Option<LocalTy<'tcx>>) -> Ty<'tcx> {
Expand Down Expand Up @@ -92,7 +91,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> {
}

fn visit_param(&mut self, param: &'tcx hir::Param<'tcx>) {
let old_outermost_fn_param_pat = mem::replace(&mut self.outermost_fn_param_pat, true);
let old_outermost_fn_param_pat = self.outermost_fn_param_pat.replace(param.ty_span);
intravisit::walk_param(self, param);
self.outermost_fn_param_pat = old_outermost_fn_param_pat;
}
Expand All @@ -102,12 +101,12 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> {
if let PatKind::Binding(_, _, ident, _) = p.kind {
let var_ty = self.assign(p.span, p.hir_id, None);

if self.outermost_fn_param_pat {
if let Some(ty_span) = self.outermost_fn_param_pat {
if !self.fcx.tcx.features().unsized_fn_params {
self.fcx.require_type_is_sized(
var_ty,
p.span,
traits::SizedArgumentType(Some(p.span)),
traits::SizedArgumentType(Some(ty_span)),
);
}
} else {
Expand All @@ -123,7 +122,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> {
var_ty
);
}
let old_outermost_fn_param_pat = mem::replace(&mut self.outermost_fn_param_pat, false);
let old_outermost_fn_param_pat = self.outermost_fn_param_pat.take();
intravisit::walk_pat(self, p);
self.outermost_fn_param_pat = old_outermost_fn_param_pat;
}
Expand Down
8 changes: 4 additions & 4 deletions library/std/src/primitive_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -807,10 +807,10 @@ mod prim_tuple {}
///
/// Additionally, `f32` can represent some special values:
///
/// - -0.0: IEEE 754 floating point numbers have a bit that indicates their sign, so -0.0 is a
/// possible value. For comparison `-0.0 == +0.0` is true but floating point operations can
/// carry the sign bit through arithmetic operations. This means `-1.0 * 0.0` produces -0.0 and
/// a negative number rounded to a value smaller than a float can represent also produces -0.0.
/// - 0.0: IEEE 754 floating point numbers have a bit that indicates their sign, so 0.0 is a
/// possible value. For comparison 0.0 = +0.0, but floating point operations can carry
/// the sign bit through arithmetic operations. This means −0.0 × +0.0 produces 0.0 and
/// a negative number rounded to a value smaller than a float can represent also produces 0.0.
/// - [∞](#associatedconstant.INFINITY) and
/// [−∞](#associatedconstant.NEG_INFINITY): these result from calculations
/// like `1.0 / 0.0`.
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/thread/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ macro_rules! __thread_local_inner {
// so now.
0 => {
$crate::thread::__FastLocalKeyInner::<$t>::register_dtor(
&VAL as *const _ as *mut u8,
$crate::ptr::addr_of_mut!(VAL) as *mut u8,
destroy,
);
STATE = 1;
Expand Down
3 changes: 3 additions & 0 deletions src/bootstrap/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,9 @@ fn supported_sanitizers(
"x86_64-unknown-linux-gnu" => {
common_libs("linux", "x86_64", &["asan", "lsan", "msan", "tsan"])
}
"x86_64-unknown-linux-musl" => {
common_libs("linux", "x86_64", &["asan", "lsan", "msan", "tsan"])
}
_ => Vec::new(),
}
}
Expand Down
1 change: 0 additions & 1 deletion src/librustdoc/html/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ crate fn render<T: Print, S: Print>(
</nav>\
<section id=\"main\" class=\"content\">{content}</section>\
<section id=\"search\" class=\"content hidden\"></section>\
<section class=\"footer\"></section>\
{after_content}\
<div id=\"rustdoc-vars\" data-root-path=\"{root_path}\" data-current-crate=\"{krate}\" \
data-search-index-js=\"{root_path}search-index{suffix}.js\" \
Expand Down
4 changes: 4 additions & 0 deletions src/test/ui/async-await/async-trait-fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
trait T {
async fn foo() {} //~ ERROR functions in traits cannot be declared `async`
async fn bar(&self) {} //~ ERROR functions in traits cannot be declared `async`
async fn baz() { //~ ERROR functions in traits cannot be declared `async`
// Nested item must not ICE.
fn a() {}
}
}

fn main() {}
18 changes: 17 additions & 1 deletion src/test/ui/async-await/async-trait-fn.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@ LL | async fn bar(&self) {}
= note: `async` trait functions are not currently supported
= note: consider using the `async-trait` crate: https://crates.io/crates/async-trait

error: aborting due to 2 previous errors
error[E0706]: functions in traits cannot be declared `async`
--> $DIR/async-trait-fn.rs:5:5
|
LL | async fn baz() {
| ^----
| |
| _____`async` because of this
| |
LL | | // Nested item must not ICE.
LL | | fn a() {}
LL | | }
| |_____^
|
= note: `async` trait functions are not currently supported
= note: consider using the `async-trait` crate: https://crates.io/crates/async-trait

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0706`.
4 changes: 2 additions & 2 deletions src/test/ui/error-codes/E0277.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ LL | fn f(p: Path) { }
= help: unsized fn params are gated as an unstable feature
help: function arguments must have a statically known size, borrowed types always have a known size
|
LL | fn f(&p: Path) { }
| ^
LL | fn f(p: &Path) { }
| ^

error[E0277]: the trait bound `i32: Foo` is not satisfied
--> $DIR/E0277.rs:15:15
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ LL | fn foo(x: dyn Foo) {
= help: unsized fn params are gated as an unstable feature
help: function arguments must have a statically known size, borrowed types always have a known size
|
LL | fn foo(&x: dyn Foo) {
| ^
LL | fn foo(x: &dyn Foo) {
| ^

error[E0277]: the size for values of type `(dyn Foo + 'static)` cannot be known at compilation time
--> $DIR/feature-gate-unsized_fn_params.rs:24:5
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/feature-gates/feature-gate-unsized_locals.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ LL | fn f(f: dyn FnOnce()) {}
= help: unsized fn params are gated as an unstable feature
help: function arguments must have a statically known size, borrowed types always have a known size
|
LL | fn f(&f: dyn FnOnce()) {}
| ^
LL | fn f(f: &dyn FnOnce()) {}
| ^

error: aborting due to previous error

Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/issues/issue-5883.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ struct Struct {
r: dyn A + 'static
}

fn new_struct(r: dyn A + 'static)
-> Struct { //~^ ERROR the size for values of type
//~^ ERROR the size for values of type
fn new_struct(
r: dyn A + 'static //~ ERROR the size for values of type
) -> Struct { //~ ERROR the size for values of type
Struct { r: r }
}

Expand Down
17 changes: 8 additions & 9 deletions src/test/ui/issues/issue-5883.stderr
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
error[E0277]: the size for values of type `(dyn A + 'static)` cannot be known at compilation time
--> $DIR/issue-5883.rs:7:15
--> $DIR/issue-5883.rs:8:5
|
LL | fn new_struct(r: dyn A + 'static)
| ^ doesn't have a size known at compile-time
LL | r: dyn A + 'static
| ^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `(dyn A + 'static)`
= help: unsized fn params are gated as an unstable feature
help: function arguments must have a statically known size, borrowed types always have a known size
|
LL | fn new_struct(&r: dyn A + 'static)
| ^
LL | r: &dyn A + 'static
| ^

error[E0277]: the size for values of type `(dyn A + 'static)` cannot be known at compilation time
--> $DIR/issue-5883.rs:8:8
--> $DIR/issue-5883.rs:9:6
|
LL | -> Struct {
| ^^^^^^ doesn't have a size known at compile-time
LL |
LL | ) -> Struct {
| ^^^^^^ doesn't have a size known at compile-time
LL | Struct { r: r }
| --------------- this returned value is of type `Struct`
|
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/resolve/issue-5035-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ LL | fn foo(_x: K) {}
= help: unsized fn params are gated as an unstable feature
help: function arguments must have a statically known size, borrowed types always have a known size
|
LL | fn foo(&_x: K) {}
| ^
LL | fn foo(_x: &K) {}
| ^

error: aborting due to previous error

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/suggestions/path-by-value.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ LL | fn f(p: Path) { }
= help: unsized fn params are gated as an unstable feature
help: function arguments must have a statically known size, borrowed types always have a known size
|
LL | fn f(&p: Path) { }
| ^
LL | fn f(p: &Path) { }
| ^

error: aborting due to previous error

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/traits/bound/not-on-bare-trait.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ LL | fn foo(_x: Foo + Send) {
= help: unsized fn params are gated as an unstable feature
help: function arguments must have a statically known size, borrowed types always have a known size
|
LL | fn foo(&_x: Foo + Send) {
| ^
LL | fn foo(_x: &Foo + Send) {
| ^

error: aborting due to previous error; 1 warning emitted

Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/unsized/unsized-fn-arg.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// run-rustfix
#![crate_type="lib"]
#![allow(unused)]

fn f<T: ?Sized>(t: &T) {}
//~^ ERROR the size for values of type `T` cannot be known at compilation time
Loading

0 comments on commit 9d9c2c9

Please sign in to comment.