Skip to content
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

Rollup of 8 pull requests #96083

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f427698
Parse inner attributes on inline const block
dtolnay Mar 16, 2022
9cfdb89
Only add codegen backend to dep info if -Zbinary-dep-depinfo is used
bjorn3 Feb 13, 2022
c681a88
Don't include invalid paths in the depinfo for builtin backends
bjorn3 Feb 13, 2022
147e5da
Add test
bjorn3 Mar 24, 2022
8035796
Stablize `const_extern_fn` for "Rust" and "C"
Aaron1011 Mar 26, 2022
8c2353b
remove find_use_placement
kckeiks Mar 18, 2022
98190b7
Revert "Work around invalid DWARF bugs for fat LTO"
cbiffle Apr 4, 2022
42af197
Improve debuginfo test coverage for simple statics.
cbiffle Apr 5, 2022
edeb826
Inline shallow_resolve_ty into ShallowResolver
compiler-errors Apr 10, 2022
7f945b2
add simd_arith_offset intrinsics
RalfJung Apr 12, 2022
e886dc5
portable-simd: use simd_arith_offset to avoid ptr-int transmutation
RalfJung Apr 12, 2022
eb905c0
add codegen smoke test
RalfJung Apr 13, 2022
7c2d57e
couple of clippy::complexity fixes
matthiaskrgr Apr 13, 2022
6718b41
Rollup merge of #93969 - bjorn3:codegen_backend_dep_info, r=pnkfelix
RalfJung Apr 15, 2022
0bf9ebb
Rollup merge of #94985 - dtolnay:constattr, r=pnkfelix
RalfJung Apr 15, 2022
0ee9aae
Rollup merge of #95194 - kckeiks:update-algo-in-find-use-placement, r…
RalfJung Apr 15, 2022
94351ec
Rollup merge of #95346 - Aaron1011:stablize-const-extern-fn, r=pnkfelix
RalfJung Apr 15, 2022
cc4267c
Rollup merge of #95685 - oxidecomputer:restore-static-dwarf, r=pnkfelix
RalfJung Apr 15, 2022
f7009d2
Rollup merge of #95908 - compiler-errors:shallow_resolve_ty-inline, r…
RalfJung Apr 15, 2022
3dcb068
Rollup merge of #95961 - RalfJung:gather-scatter, r=workingjubilee
RalfJung Apr 15, 2022
3f0504c
Rollup merge of #96026 - matthiaskrgr:clippy_compl_1304, r=Dylan-DPC
RalfJung Apr 15, 2022
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
4 changes: 3 additions & 1 deletion compiler/rustc_ast_lowering/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ pub(super) fn index_hir<'hir>(
};

match item {
OwnerNode::Crate(citem) => collector.visit_mod(&citem, citem.inner, hir::CRATE_HIR_ID),
OwnerNode::Crate(citem) => {
collector.visit_mod(&citem, citem.spans.inner_span, hir::CRATE_HIR_ID)
}
OwnerNode::Item(item) => collector.visit_item(item),
OwnerNode::TraitItem(item) => collector.visit_trait_item(item),
OwnerNode::ImplItem(item) => collector.visit_impl_item(item),
Expand Down
13 changes: 8 additions & 5 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
debug_assert_eq!(self.resolver.local_def_id(CRATE_NODE_ID), CRATE_DEF_ID);

self.with_lctx(CRATE_NODE_ID, |lctx| {
let module = lctx.lower_mod(&c.items, c.spans.inner_span);
let module = lctx.lower_mod(&c.items, &c.spans);
lctx.lower_attrs(hir::CRATE_HIR_ID, &c.attrs);
hir::OwnerNode::Crate(lctx.arena.alloc(module))
})
Expand Down Expand Up @@ -186,9 +186,12 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
}

impl<'hir> LoweringContext<'_, 'hir> {
pub(super) fn lower_mod(&mut self, items: &[P<Item>], inner: Span) -> hir::Mod<'hir> {
pub(super) fn lower_mod(&mut self, items: &[P<Item>], spans: &ModSpans) -> hir::Mod<'hir> {
hir::Mod {
inner: self.lower_span(inner),
spans: hir::ModSpans {
inner_span: self.lower_span(spans.inner_span),
inject_use_span: self.lower_span(spans.inject_use_span),
},
item_ids: self.arena.alloc_from_iter(items.iter().flat_map(|x| self.lower_item_ref(x))),
}
}
Expand Down Expand Up @@ -308,8 +311,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
})
}
ItemKind::Mod(_, ref mod_kind) => match mod_kind {
ModKind::Loaded(items, _, ModSpans { inner_span, inject_use_span: _ }) => {
hir::ItemKind::Mod(self.lower_mod(items, *inner_span))
ModKind::Loaded(items, _, spans) => {
hir::ItemKind::Mod(self.lower_mod(items, spans))
}
ModKind::Unloaded => panic!("`mod` items should have been loaded by now"),
},
Expand Down
37 changes: 20 additions & 17 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,22 @@ struct PostExpansionVisitor<'a> {
}

impl<'a> PostExpansionVisitor<'a> {
fn check_abi(&self, abi: ast::StrLit) {
fn check_abi(&self, abi: ast::StrLit, constness: ast::Const) {
let ast::StrLit { symbol_unescaped, span, .. } = abi;

if let ast::Const::Yes(_) = constness {
match symbol_unescaped.as_str() {
// Stable
"Rust" | "C" => {}
abi => gate_feature_post!(
&self,
const_extern_fn,
span,
&format!("`{}` as a `const fn` ABI is unstable", abi)
),
}
}

match symbol_unescaped.as_str() {
// Stable
"Rust" | "C" | "cdecl" | "stdcall" | "fastcall" | "aapcs" | "win64" | "sysv64"
Expand Down Expand Up @@ -261,9 +274,9 @@ impl<'a> PostExpansionVisitor<'a> {
}
}

fn check_extern(&self, ext: ast::Extern) {
fn check_extern(&self, ext: ast::Extern, constness: ast::Const) {
if let ast::Extern::Explicit(abi) = ext {
self.check_abi(abi);
self.check_abi(abi, constness);
}
}

Expand Down Expand Up @@ -437,7 +450,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
match i.kind {
ast::ItemKind::ForeignMod(ref foreign_module) => {
if let Some(abi) = foreign_module.abi {
self.check_abi(abi);
self.check_abi(abi, ast::Const::No);
}
}

Expand Down Expand Up @@ -560,7 +573,8 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
fn visit_ty(&mut self, ty: &'a ast::Ty) {
match ty.kind {
ast::TyKind::BareFn(ref bare_fn_ty) => {
self.check_extern(bare_fn_ty.ext);
// Function pointers cannot be `const`
self.check_extern(bare_fn_ty.ext, ast::Const::No);
}
ast::TyKind::Never => {
gate_feature_post!(&self, never_type, ty.span, "the `!` type is experimental");
Expand Down Expand Up @@ -660,18 +674,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
fn visit_fn(&mut self, fn_kind: FnKind<'a>, span: Span, _: NodeId) {
if let Some(header) = fn_kind.header() {
// Stability of const fn methods are covered in `visit_assoc_item` below.
self.check_extern(header.ext);

if let (ast::Const::Yes(_), ast::Extern::Implicit)
| (ast::Const::Yes(_), ast::Extern::Explicit(_)) = (header.constness, header.ext)
{
gate_feature_post!(
&self,
const_extern_fn,
span,
"`const extern fn` definitions are unstable"
);
}
self.check_extern(header.ext, header.constness);
}

if fn_kind.ctxt() != Some(FnCtxt::Foreign) && fn_kind.decl().c_variadic() {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ impl<'a> State<'a> {
self.word_space("=");
match term {
Term::Ty(ty) => self.print_type(ty),
Term::Const(c) => self.print_expr_anon_const(c),
Term::Const(c) => self.print_expr_anon_const(c, &[]),
}
}
ast::AssocConstraintKind::Bound { bounds } => self.print_type_bounds(":", &*bounds),
Expand Down
17 changes: 14 additions & 3 deletions compiler/rustc_ast_pretty/src/pprust/state/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,21 @@ impl<'a> State<'a> {
self.end();
}

pub(super) fn print_expr_anon_const(&mut self, expr: &ast::AnonConst) {
pub(super) fn print_expr_anon_const(
&mut self,
expr: &ast::AnonConst,
attrs: &[ast::Attribute],
) {
self.ibox(INDENT_UNIT);
self.word("const");
self.print_expr(&expr.value);
self.nbsp();
if let ast::ExprKind::Block(block, None) = &expr.value.kind {
self.cbox(0);
self.ibox(0);
self.print_block_with_attrs(block, attrs);
} else {
self.print_expr(&expr.value);
}
self.end();
}

Expand Down Expand Up @@ -275,7 +286,7 @@ impl<'a> State<'a> {
self.print_expr_vec(exprs);
}
ast::ExprKind::ConstBlock(ref anon_const) => {
self.print_expr_anon_const(anon_const);
self.print_expr_anon_const(anon_const, attrs);
}
ast::ExprKind::Repeat(ref element, ref count) => {
self.print_expr_repeat(element, count);
Expand Down
18 changes: 2 additions & 16 deletions compiler/rustc_codegen_llvm/src/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,20 +325,6 @@ fn fat_lto(
drop(linker);
save_temp_bitcode(cgcx, &module, "lto.input");

// Fat LTO also suffers from the invalid DWARF issue similar to Thin LTO.
// Here we rewrite all `DICompileUnit` pointers if there is only one `DICompileUnit`.
// This only works around the problem when codegen-units = 1.
// Refer to the comments in the `optimize_thin_module` function for more details.
let mut cu1 = ptr::null_mut();
let mut cu2 = ptr::null_mut();
unsafe { llvm::LLVMRustLTOGetDICompileUnit(llmod, &mut cu1, &mut cu2) };
if !cu2.is_null() {
let _timer =
cgcx.prof.generic_activity_with_arg("LLVM_fat_lto_patch_debuginfo", &*module.name);
unsafe { llvm::LLVMRustLTOPatchDICompileUnit(llmod, cu1) };
save_temp_bitcode(cgcx, &module, "fat-lto-after-patch");
}

// Internalize everything below threshold to help strip out more modules and such.
unsafe {
let ptr = symbols_below_threshold.as_ptr();
Expand Down Expand Up @@ -757,7 +743,7 @@ pub unsafe fn optimize_thin_module(
// an error.
let mut cu1 = ptr::null_mut();
let mut cu2 = ptr::null_mut();
llvm::LLVMRustLTOGetDICompileUnit(llmod, &mut cu1, &mut cu2);
llvm::LLVMRustThinLTOGetDICompileUnit(llmod, &mut cu1, &mut cu2);
if !cu2.is_null() {
let msg = "multiple source DICompileUnits found";
return Err(write::llvm_err(&diag_handler, msg));
Expand Down Expand Up @@ -846,7 +832,7 @@ pub unsafe fn optimize_thin_module(
let _timer = cgcx
.prof
.generic_activity_with_arg("LLVM_thin_lto_patch_debuginfo", thin_module.name());
llvm::LLVMRustLTOPatchDICompileUnit(llmod, cu1);
llvm::LLVMRustThinLTOPatchDICompileUnit(llmod, cu1);
save_temp_bitcode(cgcx, &module, "thin-lto-after-patch");
}

Expand Down
21 changes: 21 additions & 0 deletions compiler/rustc_codegen_llvm/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1839,6 +1839,27 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,
simd_neg: Int => neg, Float => fneg;
}

if name == sym::simd_arith_offset {
// This also checks that the first operand is a ptr type.
let pointee = in_elem.builtin_deref(true).unwrap_or_else(|| {
span_bug!(span, "must be called with a vector of pointer types as first argument")
});
let layout = bx.layout_of(pointee.ty);
let ptrs = args[0].immediate();
// The second argument must be a ptr-sized integer.
// (We don't care about the signedness, this is wrapping anyway.)
let (_offsets_len, offsets_elem) = arg_tys[1].simd_size_and_type(bx.tcx());
if !matches!(offsets_elem.kind(), ty::Int(ty::IntTy::Isize) | ty::Uint(ty::UintTy::Usize)) {
span_bug!(
span,
"must be called with a vector of pointer-sized integers as second argument"
);
}
let offsets = args[1].immediate();

return Ok(bx.gep(bx.backend_type(layout), ptrs, &[offsets]));
}

if name == sym::simd_saturating_add || name == sym::simd_saturating_sub {
let lhs = args[0].immediate();
let rhs = args[1].immediate();
Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2506,8 +2506,12 @@ extern "C" {
len: usize,
out_len: &mut usize,
) -> *const u8;
pub fn LLVMRustLTOGetDICompileUnit(M: &Module, CU1: &mut *mut c_void, CU2: &mut *mut c_void);
pub fn LLVMRustLTOPatchDICompileUnit(M: &Module, CU: *mut c_void);
pub fn LLVMRustThinLTOGetDICompileUnit(
M: &Module,
CU1: &mut *mut c_void,
CU2: &mut *mut c_void,
);
pub fn LLVMRustThinLTOPatchDICompileUnit(M: &Module, CU: *mut c_void);

pub fn LLVMRustLinkerNew(M: &Module) -> &mut Linker<'_>;
pub fn LLVMRustLinkerAdd(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ impl Diagnostic {
name: impl Into<Cow<'static, str>>,
arg: DiagnosticArgValue<'static>,
) -> &mut Self {
self.args.push((name.into(), arg.into()));
self.args.push((name.into(), arg));
self
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/mbe/macro_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ fn check_binders(
MISSING_FRAGMENT_SPECIFIER,
span,
node_id,
&format!("missing fragment specifier"),
"missing fragment specifier",
);
}
if !macros.is_empty() {
Expand Down
14 changes: 10 additions & 4 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2557,11 +2557,17 @@ impl FnRetTy<'_> {

#[derive(Encodable, Debug, HashStable_Generic)]
pub struct Mod<'hir> {
pub spans: ModSpans,
pub item_ids: &'hir [ItemId],
}

#[derive(Copy, Clone, Debug, HashStable_Generic, Encodable)]
pub struct ModSpans {
/// A span from the first token past `{` to the last token until `}`.
/// For `mod foo;`, the inner span ranges from the first token
/// to the last token in the external file.
pub inner: Span,
pub item_ids: &'hir [ItemId],
pub inner_span: Span,
pub inject_use_span: Span,
}

#[derive(Debug, HashStable_Generic)]
Expand Down Expand Up @@ -3059,8 +3065,8 @@ impl<'hir> OwnerNode<'hir> {
OwnerNode::Item(Item { span, .. })
| OwnerNode::ForeignItem(ForeignItem { span, .. })
| OwnerNode::ImplItem(ImplItem { span, .. })
| OwnerNode::TraitItem(TraitItem { span, .. })
| OwnerNode::Crate(Mod { inner: span, .. }) => *span,
| OwnerNode::TraitItem(TraitItem { span, .. }) => *span,
OwnerNode::Crate(Mod { spans: ModSpans { inner_span, .. }, .. }) => *inner_span,
}
}

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_infer/src/infer/at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
/// common state. Used in coherence.
pub fn fork(&self) -> Self {
Self {
tcx: self.tcx.clone(),
defining_use_anchor: self.defining_use_anchor.clone(),
in_progress_typeck_results: self.in_progress_typeck_results.clone(),
tcx: self.tcx,
defining_use_anchor: self.defining_use_anchor,
in_progress_typeck_results: self.in_progress_typeck_results,
inner: self.inner.clone(),
skip_leak_check: self.skip_leak_check.clone(),
lexical_region_resolutions: self.lexical_region_resolutions.clone(),
Expand Down
Loading