Skip to content

Commit

Permalink
Auto merge of rust-lang#137371 - matthiaskrgr:rollup-3qkdqar, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#128080 (Specify scope in `out_of_scope_macro_calls` lint)
 - rust-lang#135630 (add more `s390x` target features)
 - rust-lang#136089 (Reduce `Box::default` stack copies in debug mode)
 - rust-lang#137204 (Clarify MIR dialects and phases)
 - rust-lang#137299 (Simplify `Postorder` customization.)
 - rust-lang#137302 (Use a probe to avoid registering stray region obligations when re-checking drops in MIR typeck)
 - rust-lang#137305 (Tweaks in and around `rustc_middle`)
 - rust-lang#137313 (Some codegen_llvm cleanups)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Feb 21, 2025
2 parents 9f48ded + 636f4f1 commit 71e06b9
Show file tree
Hide file tree
Showing 44 changed files with 380 additions and 309 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/polonius/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ fn emit_polonius_mir<'tcx>(
regioncx,
closure_region_requirements,
borrow_set,
pass_where.clone(),
pass_where,
out,
)?;

Expand Down
22 changes: 14 additions & 8 deletions compiler/rustc_borrowck/src/type_check/liveness/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,9 +613,14 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
// types, so there's no guarantee that it succeeds. We also
// can't rely on the the `ErrorGuaranteed` from `fully_perform` here
// because it comes from delay_span_bug.
let ocx = ObligationCtxt::new_with_diagnostics(&typeck.infcx);
let errors =
match dropck_outlives::compute_dropck_outlives_with_errors(&ocx, op, span) {
//
// Do this inside of a probe because we don't particularly care (or want)
// any region side-effects of this operation in our infcx.
typeck.infcx.probe(|_| {
let ocx = ObligationCtxt::new_with_diagnostics(&typeck.infcx);
let errors = match dropck_outlives::compute_dropck_outlives_with_errors(
&ocx, op, span,
) {
Ok(_) => ocx.select_all_or_error(),
Err(e) => {
if e.is_empty() {
Expand All @@ -626,11 +631,12 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
}
};

if !errors.is_empty() {
typeck.infcx.err_ctxt().report_fulfillment_errors(errors);
} else {
span_bug!(span, "Rerunning drop data query produced no error.");
}
if !errors.is_empty() {
typeck.infcx.err_ctxt().report_fulfillment_errors(errors);
} else {
span_bug!(span, "Rerunning drop data query produced no error.");
}
});
DropData { dropck_result: Default::default(), region_constraint_data: None }
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,8 @@ fn fat_lto(
ptr as *const *const libc::c_char,
symbols_below_threshold.len() as libc::size_t,
);
save_temp_bitcode(cgcx, &module, "lto.after-restriction");
}
save_temp_bitcode(cgcx, &module, "lto.after-restriction");
}

Ok(LtoModuleCodegen::Fat(module))
Expand Down
106 changes: 50 additions & 56 deletions compiler/rustc_codegen_llvm/src/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ pub(crate) fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'t
// LLVM will prefix the name with `__imp_`. Ideally, we'd like the
// existing logic below to set the Storage Class, but it has an
// exemption for MinGW for backwards compatibility.
unsafe {
llvm::LLVMSetDLLStorageClass(llfn, llvm::DLLStorageClass::DllImport);
}
llvm::set_dllimport_storage_class(llfn);
llfn
} else {
cx.declare_fn(sym, fn_abi, Some(instance))
Expand Down Expand Up @@ -99,65 +97,61 @@ pub(crate) fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'t
// has been applied to the definition (wherever that definition may be).

llvm::set_linkage(llfn, llvm::Linkage::ExternalLinkage);
unsafe {
let is_generic = instance.args.non_erasable_generics().next().is_some();

let is_hidden = if is_generic {
// This is a monomorphization of a generic function.
if !(cx.tcx.sess.opts.share_generics()
|| tcx.codegen_fn_attrs(instance_def_id).inline
== rustc_attr_parsing::InlineAttr::Never)
{
// When not sharing generics, all instances are in the same
// crate and have hidden visibility.
true
} else {
if let Some(instance_def_id) = instance_def_id.as_local() {
// This is a monomorphization of a generic function
// defined in the current crate. It is hidden if:
// - the definition is unreachable for downstream
// crates, or
// - the current crate does not re-export generics
// (because the crate is a C library or executable)
cx.tcx.is_unreachable_local_definition(instance_def_id)
|| !cx.tcx.local_crate_exports_generics()
} else {
// This is a monomorphization of a generic function
// defined in an upstream crate. It is hidden if:
// - it is instantiated in this crate, and
// - the current crate does not re-export generics
instance.upstream_monomorphization(tcx).is_none()
&& !cx.tcx.local_crate_exports_generics()
}
}
} else {
// This is a non-generic function. It is hidden if:
// - it is instantiated in the local crate, and
// - it is defined an upstream crate (non-local), or
// - it is not reachable
cx.tcx.is_codegened_item(instance_def_id)
&& (!instance_def_id.is_local()
|| !cx.tcx.is_reachable_non_generic(instance_def_id))
};
if is_hidden {
llvm::set_visibility(llfn, llvm::Visibility::Hidden);
}
let is_generic = instance.args.non_erasable_generics().next().is_some();

// MinGW: For backward compatibility we rely on the linker to decide whether it
// should use dllimport for functions.
if cx.use_dll_storage_attrs
&& let Some(library) = tcx.native_library(instance_def_id)
&& library.kind.is_dllimport()
&& !matches!(tcx.sess.target.env.as_ref(), "gnu" | "uclibc")
let is_hidden = if is_generic {
// This is a monomorphization of a generic function.
if !(cx.tcx.sess.opts.share_generics()
|| tcx.codegen_fn_attrs(instance_def_id).inline
== rustc_attr_parsing::InlineAttr::Never)
{
llvm::LLVMSetDLLStorageClass(llfn, llvm::DLLStorageClass::DllImport);
// When not sharing generics, all instances are in the same
// crate and have hidden visibility.
true
} else {
if let Some(instance_def_id) = instance_def_id.as_local() {
// This is a monomorphization of a generic function
// defined in the current crate. It is hidden if:
// - the definition is unreachable for downstream
// crates, or
// - the current crate does not re-export generics
// (because the crate is a C library or executable)
cx.tcx.is_unreachable_local_definition(instance_def_id)
|| !cx.tcx.local_crate_exports_generics()
} else {
// This is a monomorphization of a generic function
// defined in an upstream crate. It is hidden if:
// - it is instantiated in this crate, and
// - the current crate does not re-export generics
instance.upstream_monomorphization(tcx).is_none()
&& !cx.tcx.local_crate_exports_generics()
}
}
} else {
// This is a non-generic function. It is hidden if:
// - it is instantiated in the local crate, and
// - it is defined an upstream crate (non-local), or
// - it is not reachable
cx.tcx.is_codegened_item(instance_def_id)
&& (!instance_def_id.is_local()
|| !cx.tcx.is_reachable_non_generic(instance_def_id))
};
if is_hidden {
llvm::set_visibility(llfn, llvm::Visibility::Hidden);
}

if cx.should_assume_dso_local(llfn, true) {
llvm::LLVMRustSetDSOLocal(llfn, true);
}
// MinGW: For backward compatibility we rely on the linker to decide whether it
// should use dllimport for functions.
if cx.use_dll_storage_attrs
&& let Some(library) = tcx.native_library(instance_def_id)
&& library.kind.is_dllimport()
&& !matches!(tcx.sess.target.env.as_ref(), "gnu" | "uclibc")
{
llvm::set_dllimport_storage_class(llfn);
}

cx.assume_dso_local(llfn, true);

llfn
};

Expand Down
19 changes: 4 additions & 15 deletions compiler/rustc_codegen_llvm/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,7 @@ impl<'ll> CodegenCx<'ll, '_> {
llvm::set_thread_local_mode(g, self.tls_model);
}

let dso_local = self.should_assume_dso_local(g, true);
if dso_local {
unsafe {
llvm::LLVMRustSetDSOLocal(g, true);
}
}
let dso_local = self.assume_dso_local(g, true);

if !def_id.is_local() {
let needs_dll_storage_attr = self.use_dll_storage_attrs
Expand Down Expand Up @@ -375,9 +370,7 @@ impl<'ll> CodegenCx<'ll, '_> {
// is actually present in the current crate. We can find out via the
// is_codegened_item query.
if !self.tcx.is_codegened_item(def_id) {
unsafe {
llvm::LLVMSetDLLStorageClass(g, llvm::DLLStorageClass::DllImport);
}
llvm::set_dllimport_storage_class(g);
}
}
}
Expand All @@ -387,9 +380,7 @@ impl<'ll> CodegenCx<'ll, '_> {
&& library.kind.is_dllimport()
{
// For foreign (native) libs we know the exact storage type to use.
unsafe {
llvm::LLVMSetDLLStorageClass(g, llvm::DLLStorageClass::DllImport);
}
llvm::set_dllimport_storage_class(g);
}

self.instances.borrow_mut().insert(instance, g);
Expand Down Expand Up @@ -460,9 +451,7 @@ impl<'ll> CodegenCx<'ll, '_> {
set_global_alignment(self, g, alloc.align);
llvm::set_initializer(g, v);

if self.should_assume_dso_local(g, true) {
llvm::LLVMRustSetDSOLocal(g, true);
}
self.assume_dso_local(g, true);

// Forward the allocation's mutability (picked by the const interner) to LLVM.
if alloc.mutability.is_not() {
Expand Down
12 changes: 12 additions & 0 deletions compiler/rustc_codegen_llvm/src/llvm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,3 +403,15 @@ pub(crate) fn add_module_flag_str(
);
}
}

pub(crate) fn set_dllimport_storage_class<'ll>(v: &'ll Value) {
unsafe {
LLVMSetDLLStorageClass(v, DLLStorageClass::DllImport);
}
}

pub(crate) fn set_dso_local<'ll>(v: &'ll Value) {
unsafe {
LLVMRustSetDSOLocal(v, true);
}
}
25 changes: 12 additions & 13 deletions compiler/rustc_codegen_llvm/src/mono_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ impl<'tcx> PreDefineCodegenMethods<'tcx> for CodegenCx<'_, 'tcx> {

llvm::set_linkage(g, base::linkage_to_llvm(linkage));
llvm::set_visibility(g, base::visibility_to_llvm(visibility));
unsafe {
if self.should_assume_dso_local(g, false) {
llvm::LLVMRustSetDSOLocal(g, true);
}
}
self.assume_dso_local(g, false);

self.instances.borrow_mut().insert(instance, g);
}
Expand Down Expand Up @@ -79,9 +75,7 @@ impl<'tcx> PreDefineCodegenMethods<'tcx> for CodegenCx<'_, 'tcx> {

debug!("predefine_fn: instance = {:?}", instance);

if self.should_assume_dso_local(lldecl, false) {
unsafe { llvm::LLVMRustSetDSOLocal(lldecl, true) };
}
self.assume_dso_local(lldecl, false);

self.instances.borrow_mut().insert(instance, lldecl);
}
Expand All @@ -90,11 +84,16 @@ impl<'tcx> PreDefineCodegenMethods<'tcx> for CodegenCx<'_, 'tcx> {
impl CodegenCx<'_, '_> {
/// Whether a definition or declaration can be assumed to be local to a group of
/// libraries that form a single DSO or executable.
pub(crate) fn should_assume_dso_local(
&self,
llval: &llvm::Value,
is_declaration: bool,
) -> bool {
/// Marks the local as DSO if so.
pub(crate) fn assume_dso_local(&self, llval: &llvm::Value, is_declaration: bool) -> bool {
let assume = self.should_assume_dso_local(llval, is_declaration);
if assume {
llvm::set_dso_local(llval);
}
assume
}

fn should_assume_dso_local(&self, llval: &llvm::Value, is_declaration: bool) -> bool {
let linkage = llvm::get_linkage(llval);
let visibility = llvm::get_visibility(llval);

Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use rustc_middle::bug;
use rustc_middle::infer::canonical::{CanonicalQueryInput, CanonicalVarValues};
use rustc_middle::mir::ConstraintCategory;
use rustc_middle::traits::select;
pub use rustc_middle::ty::IntVarValue;
use rustc_middle::ty::error::{ExpectedFound, TypeError};
use rustc_middle::ty::fold::{
BoundVarReplacerDelegate, TypeFoldable, TypeFolder, TypeSuperFoldable, fold_regions,
Expand Down Expand Up @@ -950,7 +949,7 @@ impl<'tcx> InferCtxt<'tcx> {
let inner = self.inner.borrow();
assert!(!UndoLogs::<UndoLog<'_>>::in_snapshot(&inner.undo_log));
let storage = inner.region_constraint_storage.as_ref().expect("regions already resolved");
assert!(storage.data.is_empty());
assert!(storage.data.is_empty(), "{:#?}", storage.data);
// We clone instead of taking because borrowck still wants to use the
// inference context after calling this for diagnostics and the new
// trait solver.
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,8 @@ lint_opaque_hidden_inferred_bound_sugg = add this bound
lint_or_patterns_back_compat = the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro
.suggestion = use pat_param to preserve semantics
lint_out_of_scope_macro_calls = cannot find macro `{$path}` in this scope
lint_out_of_scope_macro_calls = cannot find macro `{$path}` in the current scope when looking from {$location}
.label = not found from {$location}
.help = import `macro_rules` with `use` to make it callable above its definition
lint_overflowing_bin_hex = literal out of range for `{$ty}`
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_lint/src/early/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,8 @@ pub(super) fn decorate_lint(
lints::InnerAttributeUnstable::CustomInnerAttribute
}
.decorate_lint(diag),
BuiltinLintDiag::OutOfScopeMacroCalls { path } => {
lints::OutOfScopeMacroCalls { path }.decorate_lint(diag)
BuiltinLintDiag::OutOfScopeMacroCalls { span, path, location } => {
lints::OutOfScopeMacroCalls { span, path, location }.decorate_lint(diag)
}
BuiltinLintDiag::UnexpectedBuiltinCfg { cfg, cfg_name, controlled_by } => {
lints::UnexpectedBuiltinCfg { cfg, cfg_name, controlled_by }.decorate_lint(diag)
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3108,7 +3108,10 @@ pub(crate) struct UnsafeAttrOutsideUnsafeSuggestion {
#[diag(lint_out_of_scope_macro_calls)]
#[help]
pub(crate) struct OutOfScopeMacroCalls {
#[label]
pub span: Span,
pub path: String,
pub location: String,
}

#[derive(LintDiagnostic)]
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_lint_defs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,9 @@ pub enum BuiltinLintDiag {
is_macro: bool,
},
OutOfScopeMacroCalls {
span: Span,
path: String,
location: String,
},
UnexpectedBuiltinCfg {
cfg: String,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/basic_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl<'tcx> BasicBlocks<'tcx> {
#[inline]
pub fn reverse_postorder(&self) -> &[BasicBlock] {
self.cache.reverse_postorder.get_or_init(|| {
let mut rpo: Vec<_> = Postorder::new(&self.basic_blocks, START_BLOCK, ()).collect();
let mut rpo: Vec<_> = Postorder::new(&self.basic_blocks, START_BLOCK, None).collect();
rpo.reverse();
rpo
})
Expand Down
Loading

0 comments on commit 71e06b9

Please sign in to comment.