Skip to content
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

Merged
merged 25 commits into from
Dec 27, 2017
Merged

Implements RFC 1937: ? in main #46479

merged 25 commits into from
Dec 27, 2017

Conversation

bkchr
Copy link
Contributor

@bkchr bkchr commented Dec 3, 2017

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 :)

@rust-highfive
Copy link
Collaborator

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.

}

#[unstable(feature = "termination_trait", issue = "0")]
impl Termination for () {
Copy link
Member

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.)

@@ -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)]
Copy link
Member

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.

@kennytm kennytm added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 4, 2017
@@ -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;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this line expected?

Copy link
Contributor Author

@bkchr bkchr Dec 4, 2017

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).

@shepmaster
Copy link
Member

Feels unlikely that @arielb1 will have much time to review this before the end of the year, so let's reassign to...

r? @estebank

@rust-highfive rust-highfive assigned estebank and unassigned arielb1 Dec 9, 2017

// If we encounter the lang start item, we set the visibility to
// default.
if start_def_id == Ok(def_id) {
Copy link
Contributor

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.

Copy link
Contributor

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.)

Copy link
Contributor Author

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(
Copy link
Contributor

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.

Copy link
Contributor Author

@bkchr bkchr Dec 21, 2017

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.

if let Some((id, _)) = *fcx.tcx.sess.entry_fn.borrow() {
if id == fn_id {
match fcx.sess().entry_type.get() {
Some(config::EntryMain) => {
Copy link
Contributor

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 ().

Copy link
Contributor

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.

/// 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")]
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@arielb1
Copy link
Contributor

arielb1 commented Dec 9, 2017

@shepmaster

I would rather r? @nikomatsakis if I don't finish this.

However, I think this is basically good to go, except:

  1. this needs a feature-gate to avoid being insta-stable
  2. I would like a run-fail (or run-make) test to see that if you return an integer other than 0 from main, this actually causes a failure.

@shepmaster
Copy link
Member

@arielb1 sounds good; just didn't want to put too much on your plate! ❤️

r? @arielb1

@rust-highfive rust-highfive assigned arielb1 and unassigned estebank Dec 9, 2017
@arielb1 arielb1 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 13, 2017
@bkchr bkchr mentioned this pull request Dec 17, 2017
12 tasks
@bors
Copy link
Contributor

bors commented Dec 19, 2017

☔ The latest upstream changes (presumably #45525) made this pull request unmergeable. Please resolve the merge conflicts.

_ => {},
// 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() {
Copy link
Contributor

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.

@@ -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() {
Copy link
Contributor

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

@arielb1
Copy link
Contributor

arielb1 commented Dec 21, 2017

@bkchr

This still needs a feature gate, also it would bee nice if you fix the nit.

src/libstd/rt.rs Outdated

sys::init();

process::exit(unsafe {
Copy link
Member

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?

alexcrichton and others added 2 commits December 26, 2017 14:26
This'll avoid exporting a symbol from binaries unnecessarily and should help the
linker clean things up if it can.
@arielb1
Copy link
Contributor

arielb1 commented Dec 26, 2017

@bors r+

@bors
Copy link
Contributor

bors commented Dec 26, 2017

📌 Commit 5a4298b has been approved by arielb1

@bors
Copy link
Contributor

bors commented Dec 26, 2017

⌛ Testing commit 5a4298b with merge 60fb575...

bors added a commit that referenced this pull request Dec 26, 2017
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 :)
@bkchr
Copy link
Contributor Author

bkchr commented Dec 27, 2017

Can someone approve?

@killercup
Copy link
Member

@bors r=arielb1

@bors
Copy link
Contributor

bors commented Dec 27, 2017

📌 Commit 09f94be has been approved by arielb1

@kennytm kennytm added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 27, 2017
@bors
Copy link
Contributor

bors commented Dec 27, 2017

⌛ Testing commit 09f94be with merge bfbb1f5...

bors added a commit that referenced this pull request Dec 27, 2017
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 :)
@bors
Copy link
Contributor

bors commented Dec 27, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: arielb1
Pushing bfbb1f5 to master...

@bors bors merged commit 09f94be into rust-lang:master Dec 27, 2017
@bkchr
Copy link
Contributor Author

bkchr commented Dec 27, 2017

Finally! :)

sgrif added a commit to sgrif/rust that referenced this pull request Jan 31, 2018
Additional uses of this item were added to these files in rust-lang#45701 and rust-lang#46479
sgrif added a commit to sgrif/rust that referenced this pull request Feb 6, 2018
Additional uses of this item were added to these files in rust-lang#45701 and rust-lang#46479
sgrif added a commit to sgrif/rust that referenced this pull request Mar 1, 2018
Additional uses of this item were added to these files in rust-lang#45701 and rust-lang#46479
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.