Skip to content

Commit 03cad56

Browse files
committed
Auto merge of #159697 - jhpratt:rollup-4WBEz7c, r=jhpratt
Rollup of 13 pull requests Successful merges: - #159582 (Sync from portable simd 2026 07 20) - #158890 (Fix splat v0 mangling) - #159614 (debuginfo generation for unsafe binders) - #159647 (Remove `early_exit` closures) - #159656 (define a `Simd` type in `minicore`) - #156474 (Add paths for linked associated items) - #159211 (Fix debuginfo argument when invoking LLBC linker) - #159527 (Bring runtime symbols statics on par with foreign functions) - #159625 (Refactor is_opsem_inhabited) - #159629 (Add more splat rust-call regression tests) - #159652 (Remove `cfg(not(no_global_oom_handling))` from the `Drop` impl of `UniqueArcUninit`) - #159657 (Remove the blanket `#![cfg_attr(test, allow(unused))]` from bootstrap ) - #159663 (Add layout cycle hang regression test)
2 parents b9ee8d8 + b3e5402 commit 03cad56

106 files changed

Lines changed: 1744 additions & 1184 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1635,7 +1635,7 @@ fn build_unsafe_binder_type_di_node<'ll, 'tcx>(
16351635
binder_type
16361636
)
16371637
};
1638-
let inner_type = inner.skip_binder();
1638+
let inner_type = cx.tcx.instantiate_bound_regions_with_erased((*inner).into());
16391639
let inner_type_di_node = type_di_node(cx, inner_type);
16401640

16411641
let type_name = compute_debuginfo_type_name(cx.tcx, binder_type, true);

compiler/rustc_codegen_ssa/src/back/linker.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,8 +1944,13 @@ impl<'a> Linker for LlbcLinker<'a> {
19441944
self.link_or_cc_arg(path);
19451945
}
19461946

1947-
fn debuginfo(&mut self, _strip: Strip, _: &[PathBuf]) {
1948-
self.link_arg("--debug");
1947+
fn debuginfo(&mut self, strip: Strip, _: &[PathBuf]) {
1948+
match strip {
1949+
Strip::None => {
1950+
self.link_arg("--debug");
1951+
}
1952+
Strip::Debuginfo | Strip::Symbols => {}
1953+
}
19491954
}
19501955

19511956
fn optimize(&mut self) {

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -231,28 +231,21 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))
231231
let sess = &compiler.sess;
232232
let codegen_backend = &*compiler.codegen_backend;
233233

234-
// This is used for early exits unrelated to errors. E.g. when just
235-
// printing some information without compiling, or exiting immediately
236-
// after parsing, etc.
237-
let early_exit = || {
238-
sess.dcx().abort_if_errors();
239-
};
240-
241234
// This implements `-Whelp`. It should be handled very early, like
242235
// `--help`/`-Zhelp`/`-Chelp`. This is the earliest it can run, because
243236
// it must happen after lints are registered, during session creation.
244237
if sess.opts.describe_lints {
245238
describe_lints(sess, registered_lints);
246-
return early_exit();
239+
return;
247240
}
248241

249242
// We have now handled all help options, exit
250243
if help_only {
251-
return early_exit();
244+
return;
252245
}
253246

254247
if print_crate_info(codegen_backend, sess, has_input) == Compilation::Stop {
255-
return early_exit();
248+
return;
256249
}
257250

258251
if !has_input {
@@ -261,12 +254,12 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))
261254

262255
if !sess.opts.unstable_opts.ls.is_empty() {
263256
list_metadata(sess, &*codegen_backend.metadata_loader());
264-
return early_exit();
257+
return;
265258
}
266259

267260
if sess.opts.unstable_opts.link_only {
268261
process_rlink(sess, compiler);
269-
return early_exit();
262+
return;
270263
}
271264

272265
// Parse the crate root source code (doesn't parse submodules yet)
@@ -285,28 +278,23 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))
285278
pretty::print(sess, pp_mode, pretty::PrintExtra::AfterParsing { krate: &krate });
286279
}
287280
trace!("finished pretty-printing");
288-
return early_exit();
281+
return;
289282
}
290283

291284
if callbacks.after_crate_root_parsing(compiler, &mut krate) == Compilation::Stop {
292-
return early_exit();
285+
return;
293286
}
294287

295288
if sess.opts.unstable_opts.parse_crate_root_only {
296-
return early_exit();
289+
return;
297290
}
298291

299292
let linker = create_and_enter_global_ctxt(compiler, krate, |tcx| {
300-
let early_exit = || {
301-
sess.dcx().abort_if_errors();
302-
None
303-
};
304-
305293
// Make sure name resolution and macro expansion is run.
306294
let _ = tcx.resolver_for_lowering();
307295

308296
if callbacks.after_expansion(compiler, tcx) == Compilation::Stop {
309-
return early_exit();
297+
return None;
310298
}
311299

312300
passes::write_dep_info(tcx);
@@ -316,11 +304,11 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))
316304
if sess.opts.output_types.contains_key(&OutputType::DepInfo)
317305
&& sess.opts.output_types.len() == 1
318306
{
319-
return early_exit();
307+
return None;
320308
}
321309

322310
if sess.opts.unstable_opts.no_analysis {
323-
return early_exit();
311+
return None;
324312
}
325313

326314
tcx.ensure_ok().analysis(());
@@ -330,16 +318,16 @@ pub fn run_compiler(at_args: &[String], callbacks: &mut (dyn Callbacks + Send))
330318
}
331319

332320
if callbacks.after_analysis(compiler, tcx) == Compilation::Stop {
333-
return early_exit();
321+
return None;
334322
}
335323

336-
if tcx.sess.opts.output_types.contains_key(&OutputType::Mir) {
324+
if sess.opts.output_types.contains_key(&OutputType::Mir) {
337325
if let Err(error) = pretty::emit_mir(tcx) {
338326
tcx.dcx().emit_fatal(CantEmitMIR { error });
339327
}
340328
}
341329

342-
let linker = Linker::codegen_and_build_linker(tcx, &*compiler.codegen_backend);
330+
let linker = Linker::codegen_and_build_linker(tcx, codegen_backend);
343331

344332
tcx.report_unused_features();
345333

compiler/rustc_lint/src/lints.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ pub(crate) enum RedefiningRuntimeSymbolsDiag<'tcx> {
846846
#[help(
847847
"either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = \"{$symbol_name}\")]`, or `#[link_name = \"{$symbol_name}\"]`"
848848
)]
849-
FnDefInvalid { symbol_name: String, expected_fn_sig: Ty<'tcx>, found_fn_sig: Ty<'tcx> },
849+
Invalid { symbol_name: String, expected_fn_sig: Ty<'tcx>, found_fn_sig: Ty<'tcx> },
850850
#[diag(
851851
"suspicious definition of the runtime `{$symbol_name}` symbol used by the standard library"
852852
)]
@@ -858,18 +858,7 @@ pub(crate) enum RedefiningRuntimeSymbolsDiag<'tcx> {
858858
"either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = \"{$symbol_name}\")]`, or `#[link_name = \"{$symbol_name}\"]`"
859859
)]
860860
#[help("allow this lint if the signature is compatible")]
861-
FnDefSuspicious { symbol_name: String, expected_fn_sig: Ty<'tcx>, found_fn_sig: Ty<'tcx> },
862-
#[diag(
863-
"invalid definition of the runtime `{$symbol_name}` symbol used by the standard library"
864-
)]
865-
#[note(
866-
"expected `{$expected_fn_sig}`
867-
found `static {$symbol_name}: {$static_ty}`"
868-
)]
869-
#[help(
870-
"either fix the signature or remove any attributes `#[unsafe(no_mangle)]` or `#[unsafe(export_name = \"{$symbol_name}\")]`"
871-
)]
872-
Static { symbol_name: String, static_ty: Ty<'tcx>, expected_fn_sig: Ty<'tcx> },
861+
Suspicious { symbol_name: String, expected_fn_sig: Ty<'tcx>, found_fn_sig: Ty<'tcx> },
873862
}
874863

875864
// drop_forget_useless.rs

compiler/rustc_lint/src/runtime_symbols.rs

Lines changed: 70 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_hir::def_id::LocalDefId;
22
use rustc_hir::{self as hir, CanonicalSymbol, FnSig, ForeignItemKind};
33
use rustc_infer::infer::DefineOpaqueTypes;
4-
use rustc_middle::ty::{self, Instance, Ty};
4+
use rustc_middle::ty::{self, Instance, PolyFnSig, Ty};
55
use rustc_session::{declare_lint, declare_lint_pass};
66
use rustc_span::{Span, Symbol};
77
use rustc_trait_selection::infer::TyCtxtInferExt;
@@ -125,7 +125,10 @@ impl<'tcx> LateLintPass<'tcx> for RuntimeSymbols {
125125
check_fn(cx, &symbol_name.name, fn_sig, did);
126126
}
127127
ForeignItemKind::Static(..) => {
128-
check_static(cx, &symbol_name.name, did, item.span);
128+
// We only check static with #[linkage = "..."] attribute (see std weak! macro)
129+
if cx.tcx.codegen_fn_attrs(did).import_linkage.is_some() {
130+
check_static(cx, &symbol_name.name, did, item.span);
131+
}
129132
}
130133
ForeignItemKind::Type => return,
131134
}
@@ -154,13 +157,72 @@ fn check_fn(cx: &LateContext<'_>, symbol_name: &str, sig: FnSig<'_>, did: LocalD
154157
.tcx
155158
.normalize_erasing_regions(cx.typing_env(), cx.tcx.fn_sig(did).instantiate_identity());
156159

160+
check(cx, symbol_name, did, sig.span, lang_sig, user_sig);
161+
}
162+
163+
fn check_static<'tcx>(cx: &LateContext<'tcx>, symbol_name: &str, did: LocalDefId, sp: Span) {
164+
let s = Symbol::intern(symbol_name);
165+
let Some(CanonicalSymbol { symbol: _, def_id: expected_def_id }) =
166+
cx.tcx.all_canonical_symbols(()).iter().find(|cs| cs.symbol == s)
167+
else {
168+
// The symbol name does not correspond to a runtime symbols, bail out
169+
return;
170+
};
171+
172+
// Get the expected symbol function signature
173+
let lang_sig = cx.tcx.normalize_erasing_regions(
174+
cx.typing_env(),
175+
cx.tcx.fn_sig(expected_def_id).instantiate_identity(),
176+
);
177+
178+
// Get the static type
179+
let outer_user_sig = cx.tcx.type_of(did).instantiate_identity().skip_norm_wip();
180+
181+
// Peel Option<...> and get the inner type (see std weak! macro with #[linkage = "extern_weak"])
182+
let user_sig: Ty<'_> = match outer_user_sig.kind() {
183+
ty::Adt(def, args) if Some(def.did()) == cx.tcx.lang_items().option_type() => {
184+
args.type_at(0)
185+
}
186+
_ => outer_user_sig,
187+
};
188+
189+
let user_sig = if let ty::FnPtr(sig_tys, hdr) = user_sig.kind() {
190+
sig_tys.with(*hdr)
191+
} else {
192+
// not a function pointer, report an error
193+
194+
let lang_sig = Ty::new_fn_ptr(cx.tcx, lang_sig);
195+
cx.emit_span_lint(
196+
INVALID_RUNTIME_SYMBOL_DEFINITIONS,
197+
sp,
198+
RedefiningRuntimeSymbolsDiag::Invalid {
199+
symbol_name: symbol_name.to_string(),
200+
found_fn_sig: user_sig,
201+
expected_fn_sig: lang_sig,
202+
},
203+
);
204+
return;
205+
};
206+
207+
// Compare the signatures and report a warning/error depending on the mismatch
208+
check(cx, symbol_name, did, sp, lang_sig, user_sig);
209+
}
210+
211+
fn check<'tcx>(
212+
cx: &LateContext<'tcx>,
213+
symbol_name: &str,
214+
did: LocalDefId,
215+
sp: Span,
216+
lang_sig: PolyFnSig<'tcx>,
217+
user_sig: PolyFnSig<'tcx>,
218+
) {
157219
// Compare the two signatures with an inference context
158220
let infcx = cx.tcx.infer_ctxt().build(cx.typing_mode());
159-
let cause = rustc_middle::traits::ObligationCause::misc(sig.span, did);
221+
let cause = rustc_middle::traits::ObligationCause::misc(sp, did);
160222
let result = infcx.at(&cause, cx.param_env).eq(DefineOpaqueTypes::No, lang_sig, user_sig);
161223

162224
// If they don't match, emit our own mismatch signatures
163-
if let Err(_terr) = result {
225+
if result.is_err() {
164226
// Create fn pointers for diagnostics purpose
165227
let expected = Ty::new_fn_ptr(cx.tcx, lang_sig);
166228
let actual = Ty::new_fn_ptr(cx.tcx, user_sig);
@@ -173,8 +235,8 @@ fn check_fn(cx: &LateContext<'_>, symbol_name: &str, sig: FnSig<'_>, did: LocalD
173235
{
174236
cx.emit_span_lint(
175237
INVALID_RUNTIME_SYMBOL_DEFINITIONS,
176-
sig.span,
177-
RedefiningRuntimeSymbolsDiag::FnDefInvalid {
238+
sp,
239+
RedefiningRuntimeSymbolsDiag::Invalid {
178240
symbol_name: symbol_name.to_string(),
179241
found_fn_sig: actual,
180242
expected_fn_sig: expected,
@@ -183,8 +245,8 @@ fn check_fn(cx: &LateContext<'_>, symbol_name: &str, sig: FnSig<'_>, did: LocalD
183245
} else {
184246
cx.emit_span_lint(
185247
SUSPICIOUS_RUNTIME_SYMBOL_DEFINITIONS,
186-
sig.span,
187-
RedefiningRuntimeSymbolsDiag::FnDefSuspicious {
248+
sp,
249+
RedefiningRuntimeSymbolsDiag::Suspicious {
188250
symbol_name: symbol_name.to_string(),
189251
found_fn_sig: actual,
190252
expected_fn_sig: expected,
@@ -193,45 +255,3 @@ fn check_fn(cx: &LateContext<'_>, symbol_name: &str, sig: FnSig<'_>, did: LocalD
193255
};
194256
}
195257
}
196-
197-
fn check_static<'tcx>(cx: &LateContext<'tcx>, symbol_name: &str, did: LocalDefId, sp: Span) {
198-
let s = Symbol::intern(symbol_name);
199-
let Some(CanonicalSymbol { symbol: _, def_id: expected_def_id }) =
200-
cx.tcx.all_canonical_symbols(()).iter().find(|cs| cs.symbol == s)
201-
else {
202-
// The symbol name does not correspond to a runtime symbols, bail out
203-
return;
204-
};
205-
206-
// Get the static type
207-
let static_ty = cx.tcx.type_of(did).instantiate_identity().skip_norm_wip();
208-
209-
// Peel Option<...> and get the inner type (see std weak! macro with #[linkage = "extern_weak"])
210-
let inner_static_ty: Ty<'_> = match static_ty.kind() {
211-
ty::Adt(def, args) if Some(def.did()) == cx.tcx.lang_items().option_type() => {
212-
args.type_at(0)
213-
}
214-
_ => static_ty,
215-
};
216-
217-
// Get the expected symbol function signature
218-
let lang_sig = cx.tcx.normalize_erasing_regions(
219-
cx.typing_env(),
220-
cx.tcx.fn_sig(expected_def_id).instantiate_identity(),
221-
);
222-
223-
let expected = Ty::new_fn_ptr(cx.tcx, lang_sig);
224-
225-
// Compare the expected function signature with the static type, report an error if they don't match
226-
if expected != inner_static_ty {
227-
cx.emit_span_lint(
228-
INVALID_RUNTIME_SYMBOL_DEFINITIONS,
229-
sp,
230-
RedefiningRuntimeSymbolsDiag::Static {
231-
static_ty,
232-
symbol_name: symbol_name.to_string(),
233-
expected_fn_sig: expected,
234-
},
235-
);
236-
}
237-
}

0 commit comments

Comments
 (0)