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

Rollup of 11 pull requests #40397

Closed
wants to merge 25 commits into from
Closed

Rollup of 11 pull requests #40397

wants to merge 25 commits into from

Conversation

nagisa and others added 25 commits March 3, 2017 19:38
In recent months there have been a few different people investigating how to make a plugin that
registers a MIR-pass – one that isn’t intended to be eventually merged into rustc proper.

The interface to register MIR passes was added primarily for miri (& later was
found to make prototyping of rustc-proper MIR passes a tiny bit faster). Since miri does not use
this interface anymore it seems like a good time to remove this "feature".

For prototyping purposes a similar interface can be added by developers themselves in their custom
rustc build.
similar to GCC's __attribute((used))__. This attribute prevents LLVM from
optimizing away a non-exported symbol, within a compilation unit (object file),
when there are no references to it.

This is better explained with an example:

```
#[used]
static LIVE: i32 = 0;

static REFERENCED: i32 = 0;

static DEAD: i32 = 0;

fn internal() {}

pub fn exported() -> &'static i32 {
    &REFERENCED
}
```

Without optimizations, LLVM pretty much preserves all the static variables and
functions within the compilation unit.

```
$ rustc --crate-type=lib --emit=obj symbols.rs && nm -C symbols.o
0000000000000000 t drop::h1be0f8f27a2ba94a
0000000000000000 r symbols::REFERENCED::hb3bdfd46050bc84c
0000000000000000 r symbols::DEAD::hc2ea8f9bd06f380b
0000000000000000 r symbols::LIVE::h0970cf9889edb56e
0000000000000000 T symbols::exported::h6f096c2b1fc292b2
0000000000000000 t symbols::internal::h0ac1aadbc1e3a494
```

With optimizations, LLVM will drop dead code. Here `internal` is dropped because
it's not a exported function/symbol (i.e. not `pub`lic). `DEAD` is dropped for
the same reason. `REFERENCED` is preserved, even though it's not exported,
because it's referenced by the `exported` function. Finally, `LIVE` survives
because of the `#[used]` attribute even though it's not exported or referenced.

```
$ rustc --crate-type=lib -C opt-level=3 --emit=obj symbols.rs && nm -C symbols.o
0000000000000000 r symbols::REFERENCED::hb3bdfd46050bc84c
0000000000000000 r symbols::LIVE::h0970cf9889edb56e
0000000000000000 T symbols::exported::h6f096c2b1fc292b2
```

Note that the linker knows nothing about `#[used]` and will drop `LIVE`
because no other object references to it.

```
$ echo 'fn main() {}' >> symbols.rs
$ rustc symbols.rs && nm -C symbols | grep LIVE
```

At this time, `#[used]` only works on `static` variables.
When declaring nested unsafe blocks (`unsafe {unsafe {}}`) that trigger
the "unnecessary `unsafe` block" error, point out the enclosing `unsafe
block` or `unsafe fn` that makes it unnecessary.
This causes problems when first cloning and bootstrapping the repository
unfortunately, so let's ensure that Cargo sticks around in its own workspace.
Because Cargo is a submodule it's not available by default on the inital clone
of the rust-lang/rust repository. Normally it's the responsibility of the
rustbuild to take care of this, but unfortunately to build rustbuild itself we
need to resolve the workspace conflicts.

To deal with this we'll just have to ensure that all submodules are in their own
workspace, which sort of makes sense anyway as updates to dependencies as
bugfixes to Cargo should go to rust-lang/cargo instead of rust-lang/rust. In any
case this commit removes Cargo from the global workspace which should resolve
the issues that we've been seeing.

To actually perform this the `cargo` submodule has been moved to the top
directory to ensure it's outside the scope of `src/Cargo.toml` as a workspace.
This commit alters the compiler to exit quickly if the only output being emitted
is `dep-info`, which doesn't need a lot of other information to generate.

Closes rust-lang#40328
This allows limiting the number of linker jobs to avoid swapping when
linking LLVM with debug info.
Keeps MIR cleaner, `StorageLive(_: !)` makes no sense anyway.
…turner

Point to enclosing block/fn on nested unsafe

When declaring nested unsafe blocks (`unsafe {unsafe {}}`) that trigger
the "unnecessary `unsafe` block" error, point out the enclosing `unsafe
block` or `unsafe fn` that makes it unnecessary.

<img width="621" alt="" src="https://cloud.githubusercontent.com/assets/1606434/22139922/26ad468a-de9e-11e6-8884-2945be882ea8.png">

Fixes rust-lang#39144.
[RFC] #[used] attribute

(For an explanation of what this feature does, read the commit message)

I'd like to propose landing this as an experimental feature (experimental as in:
no clear stabilization path -- like `asm!`, `#[linkage]`) as it's low
maintenance (I think) and relevant to the "Usage in resource-constrained
environments" exploration area.

The main use case I see is running code before `main`. This could be used, for
instance, to cheaply initialize an allocator before `main` where the alternative
is to use `lazy_static` to initialize the allocator on its first use which it's
more expensive (atomics) and doesn't work on ARM Cortex-M0 microcontrollers (no
`AtomicUsize` on that platform)

Here's a `std` example of that:

``` rust

unsafe extern "C" fn before_main_1() {
    println!("Hello");
}

unsafe extern "C" fn before_main_2() {
    println!("World");
}

static INIT_ARRAY: [unsafe extern "C" fn(); 2] = [before_main_1, before_main_2];

fn main() {
    println!("Goodbye");
}
```

```
$ rustc -C lto -C opt-level=3 before_main.rs
$ ./before_main
Hello
World
Goodbye
```

In general, this pattern could be used to let *dependencies* run code before
`main` (which sounds like it could go very wrong in some cases). There are
probably other use cases; I hope that the people I have cc-ed can comment on
those.

Note that I'm personally unsure if the above pattern is something we want to
promote / allow and that's why I'm proposing this feature as experimental. If
this leads to more footguns than benefits then we can just axe the feature.

cc @nikomatsakis ^ I know you have some thoughts on having a process for
experimental features though I'm fine with writing an RFC before landing this.

- `dead_code` lint will have to be updated to special case `#[used]` symbols.

- Should we extend `#[used]` to work on non-generic functions?

cc rust-lang/rfcs#1002
cc rust-lang/rfcs#1459
cc @dpc @JinShil
… r=alexcrichton

Restore creating the channel-rust-$channel-date.txt files

I have **not** run this (because I don't know how to 😇), but it *does* compile.

r? @alexcrichton
…akis

Remove ability for plugins to register a MIR pass

In recent months there have been a few different people investigating how to make a plugin that
registers a MIR-pass – one that isn’t intended to be eventually merged into rustc proper.

The interface to register MIR passes was added primarily for miri (& later was
found to make prototyping of rustc-proper MIR passes a tiny bit faster). Since miri does not use
this interface anymore it seems like a good time to remove this "feature".

For prototyping purposes a similar interface can be added by developers themselves in their custom
rustc build.

cc @nikomatsakis
…richton

Fix emscripten test detection

Without this change `rustbuild` will attempt to run `.js.map` files (if they exist) resulting in lots of sadness.

r? @alexcrichton
…alexcrichton

rustbuild: expose LLVM_PARALLEL_LINK_JOBS

This allows limiting the number of linker jobs to avoid swapping when linking LLVM with debug info.
Don't put Cargo into the rustc workspace

This causes problems when first cloning and bootstrapping the repository
unfortunately, so let's ensure that Cargo sticks around in its own workspace.
Because Cargo is a submodule it's not available by default on the inital clone
of the rust-lang/rust repository. Normally it's the responsibility of the
rustbuild to take care of this, but unfortunately to build rustbuild itself we
need to resolve the workspace conflicts.

To deal with this we'll just have to ensure that all submodules are in their own
workspace, which sort of makes sense anyway as updates to dependencies as
bugfixes to Cargo should go to rust-lang/cargo instead of rust-lang/rust. In any
case this commit removes Cargo from the global workspace which should resolve
the issues that we've been seeing.

To actually perform this the `cargo` submodule has been moved to a new `vendor`
directory to ensure it's outside the scope of `src/Cargo.toml` as a workspace.

Closes rust-lang#40284
rustc: Exit quickly on only `--emit dep-info`

This commit alters the compiler to exit quickly if the only output being emitted
is `dep-info`, which doesn't need a lot of other information to generate.

Closes rust-lang#40328
Do not bother creating StorageLive for TyNever

Keeps MIR cleaner, `StorageLive(_: !)` makes no sense anyway.

r? @eddyb
@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 @pnkfelix (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.

@frewsxcv
Copy link
Member Author

frewsxcv commented Mar 9, 2017

@bors r+ p=10

@bors
Copy link
Contributor

bors commented Mar 9, 2017

📌 Commit 29a90c4 has been approved by frewsxcv

@bors
Copy link
Contributor

bors commented Mar 9, 2017

🔒 Merge conflict

@alexcrichton
Copy link
Member

@bors: retry

wut

@bors
Copy link
Contributor

bors commented Mar 9, 2017

🔒 Merge conflict

@arielb1 arielb1 closed this Mar 9, 2017
@frewsxcv frewsxcv deleted the rollup branch March 9, 2017 23:10
@Centril Centril added the rollup A PR which is a rollup label Oct 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rollup A PR which is a rollup
Projects
None yet
Development

Successfully merging this pull request may close these issues.