Skip to content

Commit 5524ab1

Browse files
committed
Replace -Zon-broken-pipe=... with Externally Implementable Item #[std::io::on_broken_pipe]
1 parent 89b5153 commit 5524ab1

75 files changed

Lines changed: 387 additions & 426 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/src/main.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
#![feature(rustc_private)]
33
// Several crates are depended upon but unused so that they are present in the sysroot
44
#![expect(unused_crate_dependencies)]
5+
#![cfg_attr(not(bootstrap), feature(on_broken_pipe))]
6+
7+
#[cfg_attr(not(bootstrap), std::io::on_broken_pipe)]
8+
#[cfg(not(bootstrap))]
9+
fn on_broken_pipe() -> std::io::OnBrokenPipe {
10+
// FIXME(#131436): Ideally there would be no use of e.g. `println!()` in the compiler.
11+
std::io::OnBrokenPipe::Kill
12+
}
513

614
// A note about jemalloc: rustc uses jemalloc when built for CI and
715
// distribution. The obvious way to do this is with the `#[global_allocator]`

compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,7 @@ enum Ordering {
9898
}
9999

100100
#[lang = "start"]
101-
fn start<T: Termination + 'static>(
102-
main: fn() -> T,
103-
argc: isize,
104-
argv: *const *const u8,
105-
_sigpipe: u8,
106-
) -> isize {
101+
fn start<T: Termination + 'static>(main: fn() -> T, argc: isize, argv: *const *const u8) -> isize {
107102
if argc == 3 {
108103
unsafe {
109104
puts(*argv as *const i8);

compiler/rustc_codegen_cranelift/src/main_shim.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,8 @@ pub(crate) fn maybe_create_entry_wrapper(
1414
is_jit: bool,
1515
is_primary_cgu: bool,
1616
) {
17-
let (main_def_id, sigpipe) = match tcx.entry_fn(()) {
18-
Some((def_id, entry_ty)) => (
19-
def_id,
20-
match entry_ty {
21-
EntryFnType::Main { sigpipe } => sigpipe,
22-
},
23-
),
17+
let main_def_id = match tcx.entry_fn(()) {
18+
Some((def_id, EntryFnType::Main)) => def_id,
2419
None => return,
2520
};
2621

@@ -33,14 +28,13 @@ pub(crate) fn maybe_create_entry_wrapper(
3328
return;
3429
}
3530

36-
create_entry_fn(tcx, module, main_def_id, is_jit, sigpipe);
31+
create_entry_fn(tcx, module, main_def_id, is_jit);
3732

3833
fn create_entry_fn(
3934
tcx: TyCtxt<'_>,
4035
m: &mut dyn Module,
4136
rust_main_def_id: DefId,
4237
ignore_lang_start_wrapper: bool,
43-
sigpipe: u8,
4438
) {
4539
let main_ret_ty = tcx.fn_sig(rust_main_def_id).no_bound_vars().unwrap().output();
4640
// Given that `main()` has no arguments,
@@ -91,7 +85,6 @@ pub(crate) fn maybe_create_entry_wrapper(
9185
bcx.switch_to_block(block);
9286
let arg_argc = bcx.append_block_param(block, m.target_config().pointer_type());
9387
let arg_argv = bcx.append_block_param(block, m.target_config().pointer_type());
94-
let arg_sigpipe = bcx.ins().iconst(types::I8, sigpipe as i64);
9588

9689
let main_func_ref = m.declare_func_in_func(main_func_id, bcx.func);
9790

@@ -149,8 +142,7 @@ pub(crate) fn maybe_create_entry_wrapper(
149142
let main_val = bcx.ins().func_addr(m.target_config().pointer_type(), main_func_ref);
150143

151144
let func_ref = m.declare_func_in_func(start_func_id, bcx.func);
152-
let call_inst =
153-
bcx.ins().call(func_ref, &[main_val, arg_argc, arg_argv, arg_sigpipe]);
145+
let call_inst = bcx.ins().call(func_ref, &[main_val, arg_argc, arg_argv]);
154146
bcx.inst_results(call_inst)[0]
155147
};
156148

compiler/rustc_codegen_gcc/example/mini_core_hello_world.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ fn start<T: Termination + 'static>(
8686
main: fn() -> T,
8787
argc: isize,
8888
argv: *const *const u8,
89-
_sigpipe: u8,
9089
) -> isize {
9190
if argc == 3 {
9291
unsafe { puts(*argv); }

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
535535
let ptr_ty = cx.type_ptr();
536536
let (arg_argc, arg_argv) = get_argc_argv(&mut bx);
537537

538-
let EntryFnType::Main { sigpipe } = entry_type;
538+
let EntryFnType::Main = entry_type;
539539
let (start_fn, start_ty, args, instance) = {
540540
let start_def_id = cx.tcx().require_lang_item(LangItem::Start, DUMMY_SP);
541541
let start_instance = ty::Instance::expect_resolve(
@@ -547,16 +547,8 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
547547
);
548548
let start_fn = cx.get_fn_addr(start_instance);
549549

550-
let i8_ty = cx.type_i8();
551-
let arg_sigpipe = bx.const_u8(sigpipe);
552-
553-
let start_ty = cx.type_func(&[cx.val_ty(rust_main), isize_ty, ptr_ty, i8_ty], isize_ty);
554-
(
555-
start_fn,
556-
start_ty,
557-
vec![rust_main, arg_argc, arg_argv, arg_sigpipe],
558-
Some(start_instance),
559-
)
550+
let start_ty = cx.type_func(&[cx.val_ty(rust_main), isize_ty, ptr_ty], isize_ty);
551+
(start_fn, start_ty, vec![rust_main, arg_argc, arg_argv], Some(start_instance))
560552
};
561553

562554
let result = bx.call(start_ty, None, None, start_fn, &args, None, instance);

compiler/rustc_hir_analysis/src/check/entry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::errors;
1818

1919
pub(crate) fn check_for_entry_fn(tcx: TyCtxt<'_>) {
2020
match tcx.entry_fn(()) {
21-
Some((def_id, EntryFnType::Main { .. })) => check_main_fn_ty(tcx, def_id),
21+
Some((def_id, EntryFnType::Main)) => check_main_fn_ty(tcx, def_id),
2222
_ => {}
2323
}
2424
}

compiler/rustc_hir_typeck/src/check.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ fn check_panic_info_fn(tcx: TyCtxt<'_>, fn_id: LocalDefId, fn_sig: ty::FnSig<'_>
217217
}
218218

219219
fn check_lang_start_fn<'tcx>(tcx: TyCtxt<'tcx>, fn_sig: ty::FnSig<'tcx>, def_id: LocalDefId) {
220-
// build type `fn(main: fn() -> T, argc: isize, argv: *const *const u8, sigpipe: u8)`
220+
// build type `fn(main: fn() -> T, argc: isize, argv: *const *const u8)`
221221

222222
// make a Ty for the generic on the fn for diagnostics
223223
// FIXME: make the lang item generic checks check for the right generic *kind*
@@ -231,12 +231,7 @@ fn check_lang_start_fn<'tcx>(tcx: TyCtxt<'tcx>, fn_sig: ty::FnSig<'tcx>, def_id:
231231
);
232232

233233
let expected_sig = ty::Binder::dummy(tcx.mk_fn_sig(
234-
[
235-
main_fn_ty,
236-
tcx.types.isize,
237-
Ty::new_imm_ptr(tcx, Ty::new_imm_ptr(tcx, tcx.types.u8)),
238-
tcx.types.u8,
239-
],
234+
[main_fn_ty, tcx.types.isize, Ty::new_imm_ptr(tcx, Ty::new_imm_ptr(tcx, tcx.types.u8))],
240235
tcx.types.isize,
241236
false,
242237
fn_sig.safety,

compiler/rustc_interface/src/tests.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ use rustc_span::edition::{DEFAULT_EDITION, Edition};
2727
use rustc_span::source_map::{RealFileLoader, SourceMapInputs};
2828
use rustc_span::{FileName, SourceFileHashAlgorithm, sym};
2929
use rustc_target::spec::{
30-
CodeModel, FramePointer, LinkerFlavorCli, MergeFunctions, OnBrokenPipe, PanicStrategy,
31-
RelocModel, RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TlsModel,
30+
CodeModel, FramePointer, LinkerFlavorCli, MergeFunctions, PanicStrategy, RelocModel,
31+
RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TlsModel,
3232
};
3333

3434
use crate::interface::{initialize_checked_jobserver, parse_cfg};
@@ -839,7 +839,6 @@ fn test_unstable_options_tracking_hash() {
839839
tracked!(no_trait_vptr, true);
840840
tracked!(no_unique_section_names, true);
841841
tracked!(offload, vec![Offload::Device]);
842-
tracked!(on_broken_pipe, OnBrokenPipe::Kill);
843842
tracked!(osx_rpath_install_name, true);
844843
tracked!(packed_bundled_libs, true);
845844
tracked!(panic_abort_tests, true);

compiler/rustc_monomorphize/src/collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1684,7 +1684,7 @@ impl<'v> RootCollector<'_, 'v> {
16841684
/// the return type of `main`. This is not needed when
16851685
/// the user writes their own `start` manually.
16861686
fn push_extra_entry_roots(&mut self) {
1687-
let Some((main_def_id, EntryFnType::Main { .. })) = self.entry_fn else {
1687+
let Some((main_def_id, EntryFnType::Main)) = self.entry_fn else {
16881688
return;
16891689
};
16901690

compiler/rustc_passes/src/entry.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LOCAL_CRATE, LocalDefId};
55
use rustc_hir::{CRATE_HIR_ID, ItemId, Node, find_attr};
66
use rustc_middle::query::Providers;
77
use rustc_middle::ty::TyCtxt;
8-
use rustc_session::config::{CrateType, EntryFnType, sigpipe};
8+
use rustc_session::config::{CrateType, EntryFnType};
99
use rustc_span::{RemapPathScopeComponents, Span};
1010

1111
use crate::errors::{ExternMain, MultipleRustcMain, NoMainErr};
@@ -75,7 +75,7 @@ fn check_and_search_item(id: ItemId, ctxt: &mut EntryContext<'_>) {
7575
fn configure_main(tcx: TyCtxt<'_>, visitor: &EntryContext<'_>) -> Option<(DefId, EntryFnType)> {
7676
if let Some((local_def_id, _)) = visitor.rustc_main_fn {
7777
let def_id = local_def_id.to_def_id();
78-
Some((def_id, EntryFnType::Main { sigpipe: sigpipe(tcx) }))
78+
Some((def_id, EntryFnType::Main))
7979
} else {
8080
// The actual resolution of main happens in the resolver, this here
8181
if let Some(main_def) = tcx.resolutions(()).main_def
@@ -89,22 +89,13 @@ fn configure_main(tcx: TyCtxt<'_>, visitor: &EntryContext<'_>) -> Option<(DefId,
8989
return None;
9090
}
9191

92-
return Some((def_id, EntryFnType::Main { sigpipe: sigpipe(tcx) }));
92+
return Some((def_id, EntryFnType::Main));
9393
}
9494
no_main_err(tcx, visitor);
9595
None
9696
}
9797
}
9898

99-
fn sigpipe(tcx: TyCtxt<'_>) -> u8 {
100-
match tcx.sess.opts.unstable_opts.on_broken_pipe {
101-
rustc_target::spec::OnBrokenPipe::Default => sigpipe::DEFAULT,
102-
rustc_target::spec::OnBrokenPipe::Kill => sigpipe::SIG_DFL,
103-
rustc_target::spec::OnBrokenPipe::Error => sigpipe::SIG_IGN,
104-
rustc_target::spec::OnBrokenPipe::Inherit => sigpipe::INHERIT,
105-
}
106-
}
107-
10899
fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_>) {
109100
let sp = tcx.def_span(CRATE_DEF_ID);
110101

0 commit comments

Comments
 (0)