Skip to content

Commit cfba499

Browse files
committed
Auto merge of rust-lang#81810 - m-ou-se:rollup-q3nborp, r=m-ou-se
Rollup of 7 pull requests Successful merges: - rust-lang#80011 (Stabilize `peekable_next_if`) - rust-lang#81580 (Document how `MaybeUninit<Struct>` can be initialized.) - rust-lang#81610 (BTreeMap: make Ord bound explicit, compile-test its absence) - rust-lang#81664 (Avoid a hir access inside get_static) - rust-lang#81675 (Make rustdoc respect `--error-format short` in doctests) - rust-lang#81753 (Never MIR inline functions with a different instruction set) - rust-lang#81795 (Small refactor with Iterator::reduce) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 16b8057 + 51c6803 commit cfba499

File tree

18 files changed

+440
-126
lines changed

18 files changed

+440
-126
lines changed

compiler/rustc_attr/src/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub enum InlineAttr {
7474
Never,
7575
}
7676

77-
#[derive(Clone, Encodable, Decodable, Debug)]
77+
#[derive(Clone, Encodable, Decodable, Debug, PartialEq, Eq)]
7878
pub enum InstructionSetAttr {
7979
ArmA32,
8080
ArmT32,

compiler/rustc_codegen_llvm/src/consts.rs

+24-56
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,14 @@ use crate::value::Value;
88
use libc::c_uint;
99
use rustc_codegen_ssa::traits::*;
1010
use rustc_data_structures::const_cstr;
11-
use rustc_hir as hir;
1211
use rustc_hir::def_id::DefId;
13-
use rustc_hir::Node;
1412
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
1513
use rustc_middle::mir::interpret::{
1614
read_target_uint, Allocation, ErrorHandled, GlobalAlloc, Pointer,
1715
};
1816
use rustc_middle::mir::mono::MonoItem;
1917
use rustc_middle::ty::{self, Instance, Ty};
2018
use rustc_middle::{bug, span_bug};
21-
use rustc_span::symbol::sym;
2219
use rustc_target::abi::{AddressSpace, Align, HasDataLayout, LayoutOf, Primitive, Scalar, Size};
2320
use tracing::debug;
2421

@@ -209,70 +206,42 @@ impl CodegenCx<'ll, 'tcx> {
209206

210207
let ty = instance.ty(self.tcx, ty::ParamEnv::reveal_all());
211208
let sym = self.tcx.symbol_name(instance).name;
209+
let fn_attrs = self.tcx.codegen_fn_attrs(def_id);
212210

213-
debug!("get_static: sym={} instance={:?}", sym, instance);
211+
debug!("get_static: sym={} instance={:?} fn_attrs={:?}", sym, instance, fn_attrs);
214212

215-
let g = if let Some(local_def_id) = def_id.as_local() {
216-
let id = self.tcx.hir().local_def_id_to_hir_id(local_def_id);
213+
let g = if def_id.is_local() && !self.tcx.is_foreign_item(def_id) {
217214
let llty = self.layout_of(ty).llvm_type(self);
218-
// FIXME: refactor this to work without accessing the HIR
219-
let (g, attrs) = match self.tcx.hir().get(id) {
220-
Node::Item(&hir::Item { attrs, kind: hir::ItemKind::Static(..), .. }) => {
221-
if let Some(g) = self.get_declared_value(sym) {
222-
if self.val_ty(g) != self.type_ptr_to(llty) {
223-
span_bug!(self.tcx.def_span(def_id), "Conflicting types for static");
224-
}
225-
}
226-
227-
let g = self.declare_global(sym, llty);
228-
229-
if !self.tcx.is_reachable_non_generic(local_def_id) {
230-
unsafe {
231-
llvm::LLVMRustSetVisibility(g, llvm::Visibility::Hidden);
232-
}
233-
}
234-
235-
(g, attrs)
215+
if let Some(g) = self.get_declared_value(sym) {
216+
if self.val_ty(g) != self.type_ptr_to(llty) {
217+
span_bug!(self.tcx.def_span(def_id), "Conflicting types for static");
236218
}
219+
}
237220

238-
Node::ForeignItem(&hir::ForeignItem {
239-
ref attrs,
240-
kind: hir::ForeignItemKind::Static(..),
241-
..
242-
}) => {
243-
let fn_attrs = self.tcx.codegen_fn_attrs(local_def_id);
244-
(check_and_apply_linkage(&self, &fn_attrs, ty, sym, def_id), &**attrs)
245-
}
246-
247-
item => bug!("get_static: expected static, found {:?}", item),
248-
};
249-
250-
debug!("get_static: sym={} attrs={:?}", sym, attrs);
221+
let g = self.declare_global(sym, llty);
251222

252-
for attr in attrs {
253-
if self.tcx.sess.check_name(attr, sym::thread_local) {
254-
llvm::set_thread_local_mode(g, self.tls_model);
223+
if !self.tcx.is_reachable_non_generic(def_id) {
224+
unsafe {
225+
llvm::LLVMRustSetVisibility(g, llvm::Visibility::Hidden);
255226
}
256227
}
257228

258229
g
259230
} else {
260-
// FIXME(nagisa): perhaps the map of externs could be offloaded to llvm somehow?
261-
debug!("get_static: sym={} item_attr={:?}", sym, self.tcx.item_attrs(def_id));
231+
check_and_apply_linkage(&self, &fn_attrs, ty, sym, def_id)
232+
};
262233

263-
let attrs = self.tcx.codegen_fn_attrs(def_id);
264-
let g = check_and_apply_linkage(&self, &attrs, ty, sym, def_id);
265-
266-
// Thread-local statics in some other crate need to *always* be linked
267-
// against in a thread-local fashion, so we need to be sure to apply the
268-
// thread-local attribute locally if it was present remotely. If we
269-
// don't do this then linker errors can be generated where the linker
270-
// complains that one object files has a thread local version of the
271-
// symbol and another one doesn't.
272-
if attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL) {
273-
llvm::set_thread_local_mode(g, self.tls_model);
274-
}
234+
// Thread-local statics in some other crate need to *always* be linked
235+
// against in a thread-local fashion, so we need to be sure to apply the
236+
// thread-local attribute locally if it was present remotely. If we
237+
// don't do this then linker errors can be generated where the linker
238+
// complains that one object files has a thread local version of the
239+
// symbol and another one doesn't.
240+
if fn_attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL) {
241+
llvm::set_thread_local_mode(g, self.tls_model);
242+
}
275243

244+
if !def_id.is_local() {
276245
let needs_dll_storage_attr = self.use_dll_storage_attrs && !self.tcx.is_foreign_item(def_id) &&
277246
// ThinLTO can't handle this workaround in all cases, so we don't
278247
// emit the attrs. Instead we make them unnecessary by disallowing
@@ -304,8 +273,7 @@ impl CodegenCx<'ll, 'tcx> {
304273
}
305274
}
306275
}
307-
g
308-
};
276+
}
309277

310278
if self.use_dll_storage_attrs && self.tcx.is_dllimport_foreign_item(def_id) {
311279
// For foreign (native) libs we know the exact storage type to use.

compiler/rustc_mir/src/transform/inline.rs

+5
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,11 @@ impl Inliner<'tcx> {
281281
return false;
282282
}
283283

284+
if self.codegen_fn_attrs.instruction_set != codegen_fn_attrs.instruction_set {
285+
debug!("`callee has incompatible instruction set - not inlining");
286+
return false;
287+
}
288+
284289
let hinted = match codegen_fn_attrs.inline {
285290
// Just treat inline(always) as a hint for now,
286291
// there are cases that prevent inlining that we

compiler/rustc_resolve/src/diagnostics.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1111,10 +1111,9 @@ impl<'a> Resolver<'a> {
11111111
_,
11121112
) = binding.kind
11131113
{
1114-
let def_id = (&*self).parent(ctor_def_id).expect("no parent for a constructor");
1114+
let def_id = self.parent(ctor_def_id).expect("no parent for a constructor");
11151115
let fields = self.field_names.get(&def_id)?;
1116-
let first_field = fields.first()?; // Handle `struct Foo()`
1117-
return Some(fields.iter().fold(first_field.span, |acc, field| acc.to(field.span)));
1116+
return fields.iter().map(|name| name.span).reduce(Span::to); // None for `struct Foo()`
11181117
}
11191118
None
11201119
}

0 commit comments

Comments
 (0)