Skip to content

remove support for the (unstable) #[start] attribute #134299

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

Merged
merged 1 commit into from
Jan 21, 2025
Merged
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
10 changes: 1 addition & 9 deletions compiler/rustc_ast/src/entry.rs
Original file line number Diff line number Diff line change
@@ -18,12 +18,6 @@ pub enum EntryPointType {
/// fn main() {}
/// ```
RustcMainAttr,
/// This is a function with the `#[start]` attribute.
/// ```ignore (clashes with test entrypoint)
/// #[start]
/// fn main() {}
/// ```
Start,
/// This function is **not** an entrypoint but simply named `main` (not at the root).
/// This is only used for diagnostics.
/// ```
@@ -40,9 +34,7 @@ pub fn entry_point_type(
at_root: bool,
name: Option<Symbol>,
) -> EntryPointType {
if attr::contains_name(attrs, sym::start) {
EntryPointType::Start
} else if attr::contains_name(attrs, sym::rustc_main) {
if attr::contains_name(attrs, sym::rustc_main) {
EntryPointType::RustcMainAttr
} else if let Some(name) = name
&& name == sym::main
12 changes: 0 additions & 12 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
@@ -230,18 +230,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
}
}

ast::ItemKind::Fn(..) => {
if attr::contains_name(&i.attrs, sym::start) {
gate!(
&self,
start,
i.span,
"`#[start]` functions are experimental and their signature may change \
over time"
);
}
}

ast::ItemKind::Struct(..) | ast::ItemKind::Enum(..) | ast::ItemKind::Union(..) => {
for attr in attr::filter_by_name(&i.attrs, sym::repr) {
for item in attr.meta_item_list().unwrap_or_else(ThinVec::new) {
7 changes: 3 additions & 4 deletions compiler/rustc_builtin_macros/src/test_harness.rs
Original file line number Diff line number Diff line change
@@ -204,11 +204,11 @@ impl<'a> MutVisitor for EntryPointCleaner<'a> {
ast::mut_visit::walk_item(self, item);
self.depth -= 1;

// Remove any #[rustc_main] or #[start] from the AST so it doesn't
// Remove any #[rustc_main] from the AST so it doesn't
// clash with the one we're going to add, but mark it as
// #[allow(dead_code)] to avoid printing warnings.
match entry_point_type(&item, self.depth == 0) {
EntryPointType::MainNamed | EntryPointType::RustcMainAttr | EntryPointType::Start => {
EntryPointType::MainNamed | EntryPointType::RustcMainAttr => {
let allow_dead_code = attr::mk_attr_nested_word(
&self.sess.psess.attr_id_generator,
ast::AttrStyle::Outer,
@@ -217,8 +217,7 @@ impl<'a> MutVisitor for EntryPointCleaner<'a> {
sym::dead_code,
self.def_site,
);
item.attrs
.retain(|attr| !attr.has_name(sym::rustc_main) && !attr.has_name(sym::start));
item.attrs.retain(|attr| !attr.has_name(sym::rustc_main));
item.attrs.push(allow_dead_code);
}
EntryPointType::None | EntryPointType::OtherMain => {}
21 changes: 8 additions & 13 deletions compiler/rustc_codegen_cranelift/src/main_shim.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext};
use rustc_hir::LangItem;
use rustc_middle::ty::{AssocKind, GenericArg};
use rustc_session::config::{EntryFnType, sigpipe};
use rustc_session::config::EntryFnType;
use rustc_span::{DUMMY_SP, Ident};

use crate::prelude::*;
@@ -14,10 +14,9 @@ pub(crate) fn maybe_create_entry_wrapper(
is_jit: bool,
is_primary_cgu: bool,
) {
let (main_def_id, (is_main_fn, sigpipe)) = match tcx.entry_fn(()) {
let (main_def_id, sigpipe) = match tcx.entry_fn(()) {
Some((def_id, entry_ty)) => (def_id, match entry_ty {
EntryFnType::Main { sigpipe } => (true, sigpipe),
EntryFnType::Start => (false, sigpipe::DEFAULT),
EntryFnType::Main { sigpipe } => sigpipe,
}),
None => return,
};
@@ -31,14 +30,13 @@ pub(crate) fn maybe_create_entry_wrapper(
return;
}

create_entry_fn(tcx, module, main_def_id, is_jit, is_main_fn, sigpipe);
create_entry_fn(tcx, module, main_def_id, is_jit, sigpipe);

fn create_entry_fn(
tcx: TyCtxt<'_>,
m: &mut dyn Module,
rust_main_def_id: DefId,
ignore_lang_start_wrapper: bool,
is_main_fn: bool,
sigpipe: u8,
) {
let main_ret_ty = tcx.fn_sig(rust_main_def_id).no_bound_vars().unwrap().output();
@@ -94,8 +92,8 @@ pub(crate) fn maybe_create_entry_wrapper(

let main_func_ref = m.declare_func_in_func(main_func_id, &mut bcx.func);

let result = if is_main_fn && ignore_lang_start_wrapper {
// regular main fn, but ignoring #[lang = "start"] as we are running in the jit
let result = if ignore_lang_start_wrapper {
// ignoring #[lang = "start"] as we are running in the jit
// FIXME set program arguments somehow
let call_inst = bcx.ins().call(main_func_ref, &[]);
let call_results = bcx.func.dfg.inst_results(call_inst).to_owned();
@@ -133,7 +131,8 @@ pub(crate) fn maybe_create_entry_wrapper(
types::I64 => bcx.ins().sextend(types::I64, res),
_ => unimplemented!("16bit systems are not yet supported"),
}
} else if is_main_fn {
} else {
// Regular main fn invoked via start lang item.
let start_def_id = tcx.require_lang_item(LangItem::Start, None);
let start_instance = Instance::expect_resolve(
tcx,
@@ -150,10 +149,6 @@ pub(crate) fn maybe_create_entry_wrapper(
let call_inst =
bcx.ins().call(func_ref, &[main_val, arg_argc, arg_argv, arg_sigpipe]);
bcx.inst_results(call_inst)[0]
} else {
// using user-defined start fn
let call_inst = bcx.ins().call(main_func_ref, &[arg_argc, arg_argv]);
bcx.inst_results(call_inst)[0]
};

bcx.ins().return_(&[result]);
26 changes: 0 additions & 26 deletions compiler/rustc_codegen_gcc/build_system/src/test.rs
Original file line number Diff line number Diff line change
@@ -426,19 +426,6 @@ fn std_tests(env: &Env, args: &TestArg) -> Result<(), String> {
run_command_with_env(&command, None, Some(env))?;
maybe_run_command_in_vm(&[&cargo_target_dir.join("track-caller-attribute")], env, args)?;

// FIXME: create a function "display_if_not_quiet" or something along the line.
println!("[AOT] mod_bench");
let mut command = args.config_info.rustc_command_vec();
command.extend_from_slice(&[
&"example/mod_bench.rs",
&"--crate-type",
&"bin",
&"--target",
&args.config_info.target_triple,
]);
run_command_with_env(&command, None, Some(env))?;
// FIXME: the compiled binary is not run.

Ok(())
}

@@ -696,19 +683,6 @@ fn test_libcore(env: &Env, args: &TestArg) -> Result<(), String> {
Ok(())
}

// echo "[BENCH COMPILE] mod_bench"
//
// COMPILE_MOD_BENCH_INLINE="$RUSTC example/mod_bench.rs --crate-type bin -Zmir-opt-level=3 -O --crate-name mod_bench_inline"
// COMPILE_MOD_BENCH_LLVM_0="rustc example/mod_bench.rs --crate-type bin -Copt-level=0 -o $cargo_target_dir/mod_bench_llvm_0 -Cpanic=abort"
// COMPILE_MOD_BENCH_LLVM_1="rustc example/mod_bench.rs --crate-type bin -Copt-level=1 -o $cargo_target_dir/mod_bench_llvm_1 -Cpanic=abort"
// COMPILE_MOD_BENCH_LLVM_2="rustc example/mod_bench.rs --crate-type bin -Copt-level=2 -o $cargo_target_dir/mod_bench_llvm_2 -Cpanic=abort"
// COMPILE_MOD_BENCH_LLVM_3="rustc example/mod_bench.rs --crate-type bin -Copt-level=3 -o $cargo_target_dir/mod_bench_llvm_3 -Cpanic=abort"
//
// Use 100 runs, because a single compilations doesn't take more than ~150ms, so it isn't very slow
// hyperfine --runs ${COMPILE_RUNS:-100} "$COMPILE_MOD_BENCH_INLINE" "$COMPILE_MOD_BENCH_LLVM_0" "$COMPILE_MOD_BENCH_LLVM_1" "$COMPILE_MOD_BENCH_LLVM_2" "$COMPILE_MOD_BENCH_LLVM_3"
// echo "[BENCH RUN] mod_bench"
// hyperfine --runs ${RUN_RUNS:-10} $cargo_target_dir/mod_bench{,_inline} $cargo_target_dir/mod_bench_llvm_*

fn extended_rand_tests(env: &Env, args: &TestArg) -> Result<(), String> {
if !args.is_using_gcc_master_branch() {
println!("Not using GCC master branch. Skipping `extended_rand_tests`.");
7 changes: 4 additions & 3 deletions compiler/rustc_codegen_gcc/example/alloc_example.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![feature(start, core_intrinsics, alloc_error_handler, lang_items)]
#![feature(core_intrinsics, alloc_error_handler, lang_items)]
#![no_std]
#![no_main]
#![allow(internal_features)]

extern crate alloc;
@@ -37,8 +38,8 @@ unsafe extern "C" fn _Unwind_Resume() {
core::intrinsics::unreachable();
}

#[start]
fn main(_argc: isize, _argv: *const *const u8) -> isize {
#[no_mangle]
extern "C" fn main(_argc: core::ffi::c_int, _argv: *const *const u8) -> core::ffi::c_int {
let world: Box<&str> = Box::new("Hello World!\0");
unsafe {
puts(*world as *const str as *const u8);
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Adapted from https://github.com/sunfishcode/mir2cranelift/blob/master/rust-examples/nocore-hello-world.rs

#![feature(
no_core, unboxed_closures, start, lang_items, never_type, linkage,
no_core, unboxed_closures, lang_items, never_type, linkage,
extern_types, thread_local
)]
#![no_core]
36 changes: 0 additions & 36 deletions compiler/rustc_codegen_gcc/example/mod_bench.rs

This file was deleted.

1 change: 0 additions & 1 deletion compiler/rustc_codegen_gcc/src/context.rs
Original file line number Diff line number Diff line change
@@ -513,7 +513,6 @@ impl<'gcc, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
} else {
// If the symbol already exists, it is an error: for example, the user wrote
// #[no_mangle] extern "C" fn main(..) {..}
// instead of #[start]
None
}
}
7 changes: 4 additions & 3 deletions compiler/rustc_codegen_gcc/tests/run/abort1.rs
Original file line number Diff line number Diff line change
@@ -3,11 +3,12 @@
// Run-time:
// status: signal

#![feature(auto_traits, lang_items, no_core, start, intrinsics, rustc_attrs)]
#![feature(auto_traits, lang_items, no_core, intrinsics, rustc_attrs)]
#![allow(internal_features)]

#![no_std]
#![no_core]
#![no_main]

/*
* Core
@@ -49,7 +50,7 @@ fn test_fail() -> ! {
unsafe { intrinsics::abort() };
}

#[start]
fn main(mut argc: isize, _argv: *const *const u8) -> isize {
#[no_mangle]
extern "C" fn main(argc: i32, _argv: *const *const u8) -> i32 {
test_fail();
}
7 changes: 4 additions & 3 deletions compiler/rustc_codegen_gcc/tests/run/abort2.rs
Original file line number Diff line number Diff line change
@@ -3,11 +3,12 @@
// Run-time:
// status: signal

#![feature(auto_traits, lang_items, no_core, start, intrinsics, rustc_attrs)]
#![feature(auto_traits, lang_items, no_core, intrinsics, rustc_attrs)]
#![allow(internal_features)]

#![no_std]
#![no_core]
#![no_main]

/*
* Core
@@ -50,8 +51,8 @@ fn fail() -> i32 {
0
}

#[start]
fn main(mut argc: isize, _argv: *const *const u8) -> isize {
#[no_mangle]
extern "C" fn main(argc: i32, _argv: *const *const u8) -> i32 {
fail();
0
}
7 changes: 4 additions & 3 deletions compiler/rustc_codegen_gcc/tests/run/array.rs
Original file line number Diff line number Diff line change
@@ -7,10 +7,11 @@
// 5
// 10

#![feature(no_core, start)]
#![feature(no_core)]

#![no_std]
#![no_core]
#![no_main]

extern crate mini_core;

@@ -28,8 +29,8 @@ fn make_array() -> [u8; 3] {
[42, 10, 5]
}

#[start]
fn main(argc: isize, _argv: *const *const u8) -> isize {
#[no_mangle]
extern "C" fn main(argc: i32, _argv: *const *const u8) -> i32 {
let array = [42, 7, 5];
let array2 = make_array();
unsafe {
7 changes: 4 additions & 3 deletions compiler/rustc_codegen_gcc/tests/run/assign.rs
Original file line number Diff line number Diff line change
@@ -6,10 +6,11 @@
// 10

#![allow(internal_features, unused_attributes)]
#![feature(auto_traits, lang_items, no_core, start, intrinsics, rustc_attrs, track_caller)]
#![feature(auto_traits, lang_items, no_core, intrinsics, rustc_attrs, track_caller)]

#![no_std]
#![no_core]
#![no_main]

/*
* Core
@@ -142,8 +143,8 @@ fn inc(num: isize) -> isize {
}


#[start]
fn main(mut argc: isize, _argv: *const *const u8) -> isize {
#[no_mangle]
extern "C" fn main(argc: i32, _argv: *const *const u8) -> i32 {
argc = inc(argc);
unsafe {
libc::printf(b"%ld\n\0" as *const u8 as *const i8, argc);
7 changes: 4 additions & 3 deletions compiler/rustc_codegen_gcc/tests/run/closure.rs
Original file line number Diff line number Diff line change
@@ -8,10 +8,11 @@
// Int argument: 2
// Both args: 11

#![feature(no_core, start)]
#![feature(no_core)]

#![no_std]
#![no_core]
#![no_main]

extern crate mini_core;

@@ -22,8 +23,8 @@ mod libc {
}
}

#[start]
fn main(mut argc: isize, _argv: *const *const u8) -> isize {
#[no_mangle]
extern "C" fn main(argc: i32, _argv: *const *const u8) -> i32 {
let string = "Arg: %d\n\0";
let mut closure = || {
unsafe {
7 changes: 4 additions & 3 deletions compiler/rustc_codegen_gcc/tests/run/condition.rs
Original file line number Diff line number Diff line change
@@ -5,10 +5,11 @@
// stdout: true
// 1

#![feature(no_core, start)]
#![feature(no_core)]

#![no_std]
#![no_core]
#![no_main]

extern crate mini_core;

@@ -19,8 +20,8 @@ mod libc {
}
}

#[start]
fn main(argc: isize, _argv: *const *const u8) -> isize {
#[no_mangle]
extern "C" fn main(argc: i32, _argv: *const *const u8) -> i32 {
unsafe {
if argc == 1 {
libc::printf(b"true\n\0" as *const u8 as *const i8);
Loading