-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Implements RFC 1937: ?
in main
#46479
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @arielb1 (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
3942e38
to
c3ce50a
Compare
src/libstd/termination.rs
Outdated
} | ||
|
||
#[unstable(feature = "termination_trait", issue = "0")] | ||
impl Termination for () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider having only this impl in the first commit, since some of the others are more controversial in the details.
(Tests of the feature can add their own impls for their own types.)
src/librustc_trans/lib.rs
Outdated
@@ -17,7 +17,7 @@ | |||
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", | |||
html_favicon_url = "https://doc.rust-lang.org/favicon.ico", | |||
html_root_url = "https://doc.rust-lang.org/nightly/")] | |||
#![deny(warnings)] | |||
//#![deny(warnings)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reminder to undo this at some point.
c3ce50a
to
b79ba55
Compare
@@ -338,6 +338,8 @@ language_item_table! { | |||
U128ShloFnLangItem, "u128_shlo", u128_shlo_fn; | |||
I128ShroFnLangItem, "i128_shro", i128_shro_fn; | |||
U128ShroFnLangItem, "u128_shro", u128_shro_fn; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this line expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that is expected. There are multiple empty lines (scroll a little bit up in the file).
6181689
to
3f80837
Compare
src/librustc_trans/partitioning.rs
Outdated
|
||
// If we encounter the lang start item, we set the visibility to | ||
// default. | ||
if start_def_id == Ok(def_id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use self.tcx().lang_items().start_fn == Some(def_id)
to avoid spurious errors on small tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(To elaborate, I believe @arielb1's goal here is to avoid requiring the start lang item to be present if you are trying to write a tiny test targeting e.g. a #![no_std]
library, where the start lang item would not otherwise be needed. I agree this makes sense.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, already done that! :)
@@ -578,8 +591,8 @@ fn maybe_create_entry_wrapper(ccx: &CrateContext) { | |||
|
|||
let (start_fn, args) = if use_start_lang_item { | |||
let start_def_id = ccx.tcx().require_lang_item(StartFnLangItem); | |||
let start_instance = Instance::mono(ccx.tcx(), start_def_id); | |||
let start_fn = callee::get_fn(ccx, start_instance); | |||
let start_fn = callee::resolve_and_get_fn(ccx, start_def_id, ccx.tcx().mk_substs( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because user-defined start
is supposed to be non-generic, passing a substs to it could cause problems, so please don't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, but user-defined start
is handled in the else branch.
src/librustc_typeck/check/mod.rs
Outdated
if let Some((id, _)) = *fcx.tcx.sess.entry_fn.borrow() { | ||
if id == fn_id { | ||
match fcx.sess().entry_type.get() { | ||
Some(config::EntryMain) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll need to add a feature gate to avoid this being insta-stable for types other than ()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should also "fix" the compile-fail tests. Or you could just fix them for real and add #![feature(termination_trait)]
to them.
src/libstd/termination.rs
Outdated
/// The default implementations are returning `libc::EXIT_SUCCESS` to indicate | ||
/// a successful execution. In case of a failure, `libc::EXIT_FAILURE` is returned. | ||
#[cfg_attr(not(stage0), lang = "termination")] | ||
#[unstable(feature = "termination_trait", issue = "0")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want a
#[rustc_on_unimplemented("`main` can only return types that implement {Termination}, not `{Self}`")]
@@ -14,7 +14,10 @@ | |||
// that one cannot control the sizes of these types with the same sort |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you make this change? Seems like purely churn.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was done by @nikomatsakis to fix the tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In particular, the new definition of start
based around Termination
winds up pulling in a lot of code related to panics and unwinds, causing the output of -Zprint-type-sizes
to have a lot of unrelated gunk in it.
I would rather r? @nikomatsakis if I don't finish this. However, I think this is basically good to go, except:
|
☔ The latest upstream changes (presumably #45525) made this pull request unmergeable. Please resolve the merge conflicts. |
3f80837
to
d4f1f05
Compare
src/librustc_typeck/check/mod.rs
Outdated
_ => {}, | ||
// If the termination trait language item is activated, check that the main return type | ||
// implements the termination trait. | ||
if fcx.tcx.lang_items().termination().is_some() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: replace this with
if let Some(term_id) = fcx.tcx.lang_items().termination().is_some() {
And then you won't need to require
it within.
src/librustc_typeck/check/mod.rs
Outdated
@@ -1064,6 +1066,29 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>, | |||
} | |||
fcx.demand_suptype(span, ret_ty, actual_return_ty); | |||
|
|||
// If the termination trait language item is activated, check that the main return type | |||
// implements the termination trait. | |||
if fcx.tcx.lang_items().termination().is_some() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: use if let Some(term_id) = fcx.tcx.lang_items().termination()
, then you won't need to require
it later
This still needs a feature gate, also it would bee nice if you fix the nit. |
cd5ffc2
to
81e375d
Compare
src/libstd/rt.rs
Outdated
|
||
sys::init(); | ||
|
||
process::exit(unsafe { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From our discussion on gitter, this is the cause of the problem in wasm (usage of process::exit
which is an abort on wasm).
Let's change this to propagate the error code outwards I think?
This'll avoid exporting a symbol from binaries unnecessarily and should help the linker clean things up if it can.
@bors r+ |
📌 Commit 5a4298b has been approved by |
Implements RFC 1937: `?` in `main` This is the first part of the RFC 1937 that supports new `Termination` trait in the rust `main` function. Thanks @nikomatsakis, @arielb1 and all other people in the gitter channel for all your help! The support for doctest and `#[test]` is still missing, bu as @nikomatsakis said, smaller pull requests are better :)
This reverts commit 267800a.
Can someone approve? |
@bors r=arielb1 |
📌 Commit 09f94be has been approved by |
Implements RFC 1937: `?` in `main` This is the first part of the RFC 1937 that supports new `Termination` trait in the rust `main` function. Thanks @nikomatsakis, @arielb1 and all other people in the gitter channel for all your help! The support for doctest and `#[test]` is still missing, bu as @nikomatsakis said, smaller pull requests are better :)
☀️ Test successful - status-appveyor, status-travis |
Finally! :) |
Additional uses of this item were added to these files in rust-lang#45701 and rust-lang#46479
Additional uses of this item were added to these files in rust-lang#45701 and rust-lang#46479
Additional uses of this item were added to these files in rust-lang#45701 and rust-lang#46479
This is the first part of the RFC 1937 that supports new
Termination
trait in the rustmain
function.Thanks @nikomatsakis, @arielb1 and all other people in the gitter channel for all your help!
The support for doctest and
#[test]
is still missing, bu as @nikomatsakis said, smaller pull requests are better :)