Skip to content

tests: Add RUST_BACKTRACE and -Cpanic revisions to panic-main.rs test #142304

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 1 addition & 4 deletions compiler/rustc_codegen_llvm/src/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,7 @@ pub(crate) fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'t

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_data_structures::InlineAttr::Never)
{
if !cx.tcx.sess.opts.share_generics() {
// When not sharing generics, all instances are in the same
// crate and have hidden visibility.
true
Expand Down
13 changes: 1 addition & 12 deletions compiler/rustc_codegen_ssa/src/back/symbol_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ fn exported_symbols_provider_local<'tcx>(
));
}

if tcx.local_crate_exports_generics() {
if tcx.sess.opts.share_generics() && tcx.local_crate_exports_generics() {
use rustc_middle::mir::mono::{Linkage, MonoItem, Visibility};
use rustc_middle::ty::InstanceKind;

Expand Down Expand Up @@ -368,17 +368,6 @@ fn exported_symbols_provider_local<'tcx>(
continue;
}

if !tcx.sess.opts.share_generics() {
if tcx.codegen_fn_attrs(mono_item.def_id()).inline
== rustc_attr_data_structures::InlineAttr::Never
{
// this is OK, we explicitly allow sharing inline(never) across crates even
// without share-generics.
} else {
continue;
}
}

match *mono_item {
MonoItem::Fn(Instance { def: InstanceKind::Item(def), args }) => {
let has_generics = args.non_erasable_generics().next().is_some();
Expand Down
15 changes: 0 additions & 15 deletions compiler/rustc_middle/src/mir/mono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::fmt;
use std::hash::Hash;

use rustc_ast::expand::autodiff_attrs::AutoDiffItem;
use rustc_attr_data_structures::InlineAttr;
use rustc_data_structures::base_n::{BaseNString, CASE_INSENSITIVE, ToBaseN};
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::FxIndexMap;
Expand Down Expand Up @@ -211,20 +210,6 @@ impl<'tcx> MonoItem<'tcx> {
return InstantiationMode::LocalCopy;
}

// #[inline(never)] functions in general are poor candidates for inlining and thus since
// LocalCopy generally increases code size for the benefit of optimizations from inlining,
// we want to give them GloballyShared codegen.
// The slight problem is that generic functions need to always support cross-crate
// compilation, so all previous stages of the compiler are obligated to treat generic
// functions the same as those that unconditionally get LocalCopy codegen. It's only when
// we get here that we can at least not codegen a #[inline(never)] generic function in all
// of our CGUs.
if let InlineAttr::Never = tcx.codegen_fn_attrs(instance.def_id()).inline
&& self.is_generic_fn()
{
return InstantiationMode::GloballyShared { may_conflict: true };
}

// The fallthrough case is to generate LocalCopy for all optimized builds, and
// GloballyShared with conflict prevention when optimizations are disabled.
match tcx.sess.opts.optimize {
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2151,6 +2151,8 @@ impl<'tcx> TyCtxt<'tcx> {

#[inline]
pub fn local_crate_exports_generics(self) -> bool {
debug_assert!(self.sess.opts.share_generics());

self.crate_types().iter().any(|crate_type| {
match crate_type {
CrateType::Executable
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_middle/src/ty/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,7 @@ impl<'tcx> Instance<'tcx> {
// If we are not in share generics mode, we don't link to upstream
// monomorphizations but always instantiate our own internal versions
// instead.
if !tcx.sess.opts.share_generics()
// However, if the def_id is marked inline(never), then it's fine to just reuse the
// upstream monomorphization.
&& tcx.codegen_fn_attrs(self.def_id()).inline != rustc_attr_data_structures::InlineAttr::Never
{
if !tcx.sess.opts.share_generics() {
return None;
}

Expand Down
32 changes: 8 additions & 24 deletions compiler/rustc_monomorphize/src/partitioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ use std::fs::{self, File};
use std::io::Write;
use std::path::{Path, PathBuf};

use rustc_attr_data_structures::InlineAttr;
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
use rustc_data_structures::sync;
use rustc_data_structures::unord::{UnordMap, UnordSet};
Expand Down Expand Up @@ -210,8 +209,8 @@ where
// available to downstream crates. This depends on whether we are in
// share-generics mode and whether the current crate can even have
// downstream crates.
let can_export_generics = cx.tcx.local_crate_exports_generics();
let always_export_generics = can_export_generics && cx.tcx.sess.opts.share_generics();
let export_generics =
cx.tcx.sess.opts.share_generics() && cx.tcx.local_crate_exports_generics();

let cgu_name_builder = &mut CodegenUnitNameBuilder::new(cx.tcx);
let cgu_name_cache = &mut UnordMap::default();
Expand Down Expand Up @@ -251,8 +250,7 @@ where
cx.tcx,
&mono_item,
&mut can_be_internalized,
can_export_generics,
always_export_generics,
export_generics,
);

// We can't differentiate a function that got inlined.
Expand Down Expand Up @@ -747,19 +745,12 @@ fn mono_item_linkage_and_visibility<'tcx>(
tcx: TyCtxt<'tcx>,
mono_item: &MonoItem<'tcx>,
can_be_internalized: &mut bool,
can_export_generics: bool,
always_export_generics: bool,
export_generics: bool,
) -> (Linkage, Visibility) {
if let Some(explicit_linkage) = mono_item.explicit_linkage(tcx) {
return (explicit_linkage, Visibility::Default);
}
let vis = mono_item_visibility(
tcx,
mono_item,
can_be_internalized,
can_export_generics,
always_export_generics,
);
let vis = mono_item_visibility(tcx, mono_item, can_be_internalized, export_generics);
(Linkage::External, vis)
}

Expand All @@ -782,8 +773,7 @@ fn mono_item_visibility<'tcx>(
tcx: TyCtxt<'tcx>,
mono_item: &MonoItem<'tcx>,
can_be_internalized: &mut bool,
can_export_generics: bool,
always_export_generics: bool,
export_generics: bool,
) -> Visibility {
let instance = match mono_item {
// This is pretty complicated; see below.
Expand Down Expand Up @@ -843,11 +833,7 @@ fn mono_item_visibility<'tcx>(

// Upstream `DefId` instances get different handling than local ones.
let Some(def_id) = def_id.as_local() else {
return if is_generic
&& (always_export_generics
|| (can_export_generics
&& tcx.codegen_fn_attrs(def_id).inline == InlineAttr::Never))
{
return if export_generics && is_generic {
// If it is an upstream monomorphization and we export generics, we must make
// it available to downstream crates.
*can_be_internalized = false;
Expand All @@ -858,9 +844,7 @@ fn mono_item_visibility<'tcx>(
};

if is_generic {
if always_export_generics
|| (can_export_generics && tcx.codegen_fn_attrs(def_id).inline == InlineAttr::Never)
{
if export_generics {
if tcx.is_unreachable_local_definition(def_id) {
// This instance cannot be used from another crate.
Visibility::Hidden
Expand Down
4 changes: 1 addition & 3 deletions library/alloc/src/raw_vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -760,9 +760,7 @@ impl<A: Allocator> RawVecInner<A> {
}
}

// not marked inline(never) since we want optimizers to be able to observe the specifics of this
// function, see tests/codegen/vec-reserve-extend.rs.
#[cold]
#[inline(never)]
fn finish_grow<A>(
new_layout: Layout,
current_memory: Option<(NonNull<u8>, Layout)>,
Expand Down
1 change: 0 additions & 1 deletion library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,6 @@
#![feature(sync_unsafe_cell)]
#![feature(temporary_niche_types)]
#![feature(ub_checks)]
#![feature(used_with_arg)]
// tidy-alphabetical-end
//
// Library features (alloc):
Expand Down
16 changes: 0 additions & 16 deletions library/std/src/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,6 @@ use crate::sys::backtrace;
use crate::sys::stdio::panic_output;
use crate::{fmt, intrinsics, process, thread};

// This forces codegen of the function called by panic!() inside the std crate, rather than in
// downstream crates. Primarily this is useful for rustc's codegen tests, which rely on noticing
// complete removal of panic from generated IR. Since begin_panic is inline(never), it's only
// codegen'd once per crate-graph so this pushes that to std rather than our codegen test crates.
//
// (See https://github.com/rust-lang/rust/pull/123244 for more info on why).
//
// If this is causing problems we can also modify those codegen tests to use a crate type like
// cdylib which doesn't export "Rust" symbols to downstream linkage units.
#[unstable(feature = "libstd_sys_internals", reason = "used by the panic! macro", issue = "none")]
#[doc(hidden)]
#[allow(dead_code)]
#[used(compiler)]
pub static EMPTY_PANIC: fn(&'static str) -> ! =
begin_panic::<&'static str> as fn(&'static str) -> !;

// Binary interface to the panic runtime that the standard library depends on.
//
// The standard library is tagged with `#![needs_panic_runtime]` (introduced in
Expand Down
3 changes: 1 addition & 2 deletions src/ci/docker/host-aarch64/aarch64-gnu/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ ENV RUST_CONFIGURE_ARGS \
--enable-profiler \
--enable-compiler-docs
# FIXME: Skipping cargo panic_abort_doc_tests due to https://github.com/rust-lang/rust/issues/123733
ENV SCRIPT python3 ../x.py --stage 2 test && \
python3 ../x.py --stage 2 test src/tools/cargo --test-args \"--skip panic_abort_doc_tests\"
ENV SCRIPT python3 ../x.py --stage 2 test tests/ui/panics
29 changes: 1 addition & 28 deletions src/ci/github-actions/jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,35 +122,8 @@ jobs:
# These jobs automatically inherit envs.pr, to avoid repeating
# it in each job definition.
pr:
- name: mingw-check-1
<<: *job-linux-4c
- name: mingw-check-2
<<: *job-linux-4c
- name: mingw-check-tidy
continue_on_error: true
free_disk: false
env:
# This submodule is expensive to checkout, and it should not be needed for
# tidy. This speeds up the PR CI job by ~1 minute.
SKIP_SUBMODULES: src/gcc
<<: *job-linux-4c
- name: x86_64-gnu-llvm-19
env:
ENABLE_GCC_CODEGEN: "1"
DOCKER_SCRIPT: x86_64-gnu-llvm.sh
<<: *job-linux-4c
- name: aarch64-gnu-llvm-19-1
env:
IMAGE: aarch64-gnu-llvm-19
DOCKER_SCRIPT: stage_2_test_set1.sh
<<: *job-aarch64-linux
- name: aarch64-gnu-llvm-19-2
env:
IMAGE: aarch64-gnu-llvm-19
DOCKER_SCRIPT: stage_2_test_set2.sh
- name: aarch64-gnu
<<: *job-aarch64-linux
- name: x86_64-gnu-tools
<<: *job-linux-36c-codebuild

# Jobs that run when you perform a try build (@bors try)
# These jobs automatically inherit envs.try, to avoid repeating
Expand Down
1 change: 0 additions & 1 deletion src/tools/tidy/src/issues.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3132,7 +3132,6 @@ ui/packed/issue-118537-field-offset.rs
ui/packed/issue-27060-2.rs
ui/packed/issue-27060.rs
ui/packed/issue-46152.rs
ui/panics/issue-47429-short-backtraces.rs
ui/parser/issue-116781.rs
ui/parser/issue-12187-1.rs
ui/parser/issue-12187-2.rs
Expand Down

This file was deleted.

37 changes: 0 additions & 37 deletions tests/codegen-units/partitioning/auxiliary/cgu_generic_function.rs

This file was deleted.

36 changes: 0 additions & 36 deletions tests/codegen-units/partitioning/extern-generic.rs

This file was deleted.

Loading
Loading