bors [Fri, 3 Mar 2017 05:16:10 +0000 (05:16 +0000)]
Auto merge of #40178 - arielb1:provide-destructors, r=eddyb
convert AdtDef::destructor to on-demand
This removes the `Cell` from `AdtDef`. Also, moving destructor validity
checking to on-demand (forced during item-type checking) ensures that
invalid destructors can't cause ICEs.
bors [Fri, 3 Mar 2017 03:15:52 +0000 (03:15 +0000)]
Auto merge of #40152 - eddyb:order-in-rustbuild, r=alexcrichton
rustbuild: use deterministic step ordering and respect path order on the command-line.
Restores similar behavior to `make` rules, where:
* the step order was always the same, e.g. the testsuite order in `make check`
* `make check-stage1-{cfail,rpass}` would *always* run `cfail` before `rpass`
* `./x.py test--stage 1 src/test/{compile-fail,run-pass}` is now equivalent
bors [Fri, 3 Mar 2017 00:14:10 +0000 (00:14 +0000)]
Auto merge of #39927 - nikomatsakis:incr-comp-skip-borrowck-2, r=eddyb
transition borrowck to visit all **bodies** and not item-likes
This is a better structure for incremental compilation and also more compatible with the eventual borrowck mir. It also fixes #38520 as a drive-by fix.
Corey Farwell [Thu, 2 Mar 2017 19:53:51 +0000 (14:53 -0500)]
Rollup merge of #40166 - aidanhs:aphs-index-coerce, r=nikomatsakis
Allow types passed to [] to coerce, like .index()
Fixes #40085
Basically steals the relevant part of [check_argument_types](https://github.com/rust-lang/rust/blob/1.15.1/src/librustc_typeck/check/mod.rs#L2653-L2672).
Adds the `#[proc_macro]` attribute, which expects bare functions of the kind `fn(TokenStream) -> TokenStream`, which can be invoked like `my_macro!()`.
Corey Farwell [Thu, 2 Mar 2017 19:53:41 +0000 (14:53 -0500)]
Rollup merge of #39832 - phil-opp:x86-interrupt-calling-convention, r=nagisa
Add support for the x86-interrupt calling convention
This calling convention can be used for definining interrupt handlers on 32-bit and 64-bit x86 targets. The compiler then uses `iret` instead of `ret` for returning and ensures that all registers are restored to their
original values.
for exceptions that push an error code (e.g., page faults or general protection faults). The programmer must ensure that the correct version is used for each interrupt.
For more details see the [LLVM PR][1] and the corresponding [proposal][2].
It is also possible to implement interrupt handlers on x86 through [naked functions](https://github.com/rust-lang/rfcs/blob/master/text/1201-naked-fns.md). In fact, almost all existing Rust OS projects for x86 use naked functions for this, including [Redox](https://github.com/redox-os/kernel/blob/b9793deb59c7650f0805dea96adb6b773ad99336/arch/x86_64/src/lib.rs#L109-L147), [IntermezzOS](https://github.com/intermezzOS/kernel/blob/f959cc18c78b1ba153f3ff7039d9ecc07f397628/interrupts/src/lib.rs#L28-L72), and [blog_os](https://github.com/phil-opp/blog_os/blob/844d739379ffdea6a7ede88365ec6e21a725bbf5/src/interrupts/mod.rs#L49-L64). So support for the `x86-interrupt` calling convention isn't absolutely needed.
However, it has a number of benefits to naked functions:
- **No inline assembly needed**: [Inline assembly](https://doc.rust-lang.org/book/inline-assembly.html) is highly unstable and dangerous. It's pretty easy to mess things up. Also, it uses an arcane syntax and requires that the programmer knows x86 assembly.
- **Higher performance**: A naked wrapper function always saves _all_ registers before calling the Rust function. This isn't needed for a compiler supported calling convention, since the compiler knows which registers are clobbered by the interrupt handler. Thus, only these registers need to be saved and restored.
- **Safer interfaces**: We can write a `set_handler` function that takes a `extern "x86-interrupt" fn(&ExceptionStackFrame)` and the compiler ensures that we always use the right function type for all handler functions. This isn't possible with the `#[naked]` attribute.
- **More convenient**: Instead of writing [tons of assembly boilerplate](https://github.com/redox-os/kernel/blob/b9793deb59c7650f0805dea96adb6b773ad99336/arch/x86_64/src/lib.rs#L109-L147) and desperately trying to improve things [through macros](https://github.com/phil-opp/blog_os/blob/844d739379ffdea6a7ede88365ec6e21a725bbf5/src/interrupts/mod.rs#L17-L92), we can just write [code like this](https://github.com/phil-opp/blog_os/blob/e6a61f9507a4c4fef6fb4e3474bc596391bc97d2/src/interrupts/mod.rs#L85-L89).
- **Naked functions are unreliable**: It is allowed to use Rust code inside a naked function, which sometimes works and sometimes not. For example, [calling a function](https://github.com/redox-os/kernel/blob/b9793deb59c7650f0805dea96adb6b773ad99336/arch/x86_64/src/lib.rs#L132) through Rust code seems to work fine without function prologue, but [code declaring a variable](https://is.gd/NQYXqE) silently adds a prologue even though the function is naked (look at the generated assembly, there is a `movl` instruction before the `nop`).
**Edit**: See the [tracking issue](https://github.com/rust-lang/rust/issues/40180) for an updated list of issues.
Unfortunately, the implementation of the `x86-interrupt` calling convention in LLVM has some issues that make it unsuitable for 64-bit kernels at the moment:
- LLVM always tries to backup the `xmm` registers on 64-bit platforms even if the target doesn't support SSE. This leads to invalid opcode exceptions whenever an interrupt handler is invoked. I submitted a fix to LLVM in [D29959](https://reviews.llvm.org/D29959). The fix is really small (<10 lines), so maybe we could backport it to [Rust's LLVM fork](https://github.com/rust-lang/llvm)?. **Edit**: The fix was merged to LLVM trunk in [rL295347](https://reviews.llvm.org/rL295347). Backported in https://github.com/rust-lang/llvm/pull/63.
- On targets with SSE support, LLVM uses the `movaps` instruction for saving the `xmm` registers, which requires an alignment of 16. For handlers with error codes, however, the stack alignment is only 8, so a alignment exception occurs. This issue is tracked in [bug 26413](https://bugs.llvm.org/show_bug.cgi?id=26413). ~~Unfortunately, I don't know enough about LLVM to fix this.~~ **Edit**: Fix submitted in [D30049](https://reviews.llvm.org/D30049).
This PR adds experimental support for this calling convention under the `abi_x86_interrupt` feature gate. The implementation is very similar to #38465 and was surprisingly simple :).
There is no accepted RFC for this change. In fact, the [RFC for interrupt calling convention](https://github.com/rust-lang/rfcs/pull/1275) from 2015 was closed in favor of naked functions. However, the reactions to the recent [PR](https://github.com/rust-lang/rust/pull/38465) for a MSP430 interrupt calling convention were [in favor of experimental interrupt ABIs](https://github.com/rust-lang/rust/pull/38465#issuecomment-270015470).
- [x] Add compile-fail tests for the feature gate.
- [x] Create tracking issue for the `abi_x86_interrupt` feature (and link it in code). **Edit**: Tracking issue: #40180
- [x] Backport [rL295347](https://reviews.llvm.org/rL295347) to Rust's LLVM fork. **Edit**: Done in https://github.com/rust-lang/llvm/pull/63
@tari @steveklabnik @jackpot51 @ticki @hawkw @thepowersgang, you might be interested in this.
This calling convention can be used for definining interrupt handlers on
32-bit and 64-bit x86 targets. The compiler then uses `iret` instead of
`ret` for returning and ensures that all registers are restored to their
original values.
for exceptions that push an error code (e.g., page faults or general
protection faults). The programmer must ensure that the correct version
is used for each interrupt.
For more details see the [LLVM PR][1] and the corresponding [proposal][2].
Guillaume Gomez [Thu, 2 Mar 2017 10:29:41 +0000 (11:29 +0100)]
Rollup merge of #40175 - d-e-s-o:fix-inconsistency-in-guessing-game-readme, r=steveklabnik
doc: fix inconsistency in error output in guessing-game.md
The line '.expect("failed to read line");' is partly started with a
lower case 'f' and partly with an uppercase one, adding additional
spurious changes to otherwise clean diffs if each sample is
copy-and-pasted over the previous.
This change starts the string with an uppercase everywhere which is in
line with the style of the other strings.
This removes the Cell from AdtDef. Also, moving destructor validity
checking to on-demand (forced during item-type checking) ensures that
invalid destructors can't cause ICEs.
deso [Wed, 1 Mar 2017 13:44:50 +0000 (05:44 -0800)]
doc: fix inconsistency in error output in guessing-game.md
The line '.expect("failed to read line");' is partly started with a
lower case 'f' and partly with an uppercase one, adding additional
spurious changes to otherwise clean diffs if each sample is
copy-and-pasted over the previous.
This change starts the string with an uppercase everywhere which is in
line with the style of the other strings.
bors [Wed, 1 Mar 2017 10:03:44 +0000 (10:03 +0000)]
Auto merge of #34198 - eddyb:you're-a-bad-transmute-and-you-should-feel-bad, r=nikomatsakis
Make transmuting from fn item types to pointer-sized types a hard error.
Closes #19925 by removing the future compatibility lint and the associated workarounds.
This is a `[breaking-change]` if you `transmute` from a function item without casting first.
For more information on how to fix your code, see https://github.com/rust-lang/rust/issues/19925.
bors [Wed, 1 Mar 2017 05:58:09 +0000 (05:58 +0000)]
Auto merge of #39419 - jseyfried:simplify_tokentree, r=nrc
Simplify `TokenTree` and fix `macro_rules!` bugs
This PR
- fixes #39390, fixes #39403, and fixes #39404 (each is a [breaking-change], see issues for examples),
- fixes #39889,
- simplifies and optimizes macro invocation parsing,
- cleans up `ext::tt::transcribe`,
- removes `tokenstream::TokenTree::Sequence` and `Token::MatchNt`,
- instead, adds a new type `ext::tt::quoted::TokenTree` for use by `macro_rules!` (`ext::tt`)
- removes `parser.quote_depth` and `parser.parsing_token_tree`, and
- removes `quote_matcher!`.
- Instead, use `quote_tokens!` and `ext::tt::quoted::parse` the result with `expect_matchers=true`.
- I found no outside uses of `quote_matcher!` when searching Rust code on Github.
Corey Farwell [Wed, 1 Mar 2017 03:55:26 +0000 (22:55 -0500)]
Rollup merge of #39419 - jseyfried:simplify_tokentree, r=nrc
Simplify `TokenTree` and fix `macro_rules!` bugs
This PR
- fixes #39390, fixes #39403, and fixes #39404 (each is a [breaking-change], see issues for examples),
- fixes #39889,
- simplifies and optimizes macro invocation parsing,
- cleans up `ext::tt::transcribe`,
- removes `tokenstream::TokenTree::Sequence` and `Token::MatchNt`,
- instead, adds a new type `ext::tt::quoted::TokenTree` for use by `macro_rules!` (`ext::tt`)
- removes `parser.quote_depth` and `parser.parsing_token_tree`, and
- removes `quote_matcher!`.
- Instead, use `quote_tokens!` and `ext::tt::quoted::parse` the result with `expect_matchers=true`.
- I found no outside uses of `quote_matcher!` when searching Rust code on Github.
Steve Klabnik [Tue, 28 Feb 2017 23:38:43 +0000 (15:38 -0800)]
Rollup merge of #40153 - steveklabnik:alphabetize-unstable-book, r=frewsxcv
sort unstable book alphabetically
I made these the same order as they were in the compiler, but for no good reason. Much easier to find out what you need when they're sorted alphabetically
Steve Klabnik [Tue, 28 Feb 2017 19:06:05 +0000 (14:06 -0500)]
sort unstable book alphabetically
I made these the same order as they were in the compiler, but for no good reason. Much easier to find out what you need when they're sorted alphabetically
Corey Farwell [Tue, 28 Feb 2017 13:33:10 +0000 (08:33 -0500)]
Rollup merge of #40131 - MajorBreakfast:patch-3, r=steveklabnik
Make lifetime elision docs clearer
Previously it said
"It's forbidden to allow reasoning about types based on the item signature alone."
I think that sentence is wrong. Rust **uses** the item signatures to perform type inference within the body. I think what's meant is the other way around: It does not infer types for item signatures.
Corey Farwell [Tue, 28 Feb 2017 13:33:07 +0000 (08:33 -0500)]
Rollup merge of #40122 - robinst:process-add-example-for-writing-to-stdin, r=alexcrichton
Example for how to provide stdin using std::process::Command
Spawning a child process and writing to its stdin is a bit tricky due to
`as_mut` and having to use a limited borrow. An example for this might
help newer users.
Corey Farwell [Tue, 28 Feb 2017 13:33:04 +0000 (08:33 -0500)]
Rollup merge of #40056 - keeperofdakeys:contributing, r=alexcrichton
Replace ./configure with config.toml in README.md and CONTRIBUTING.md
Replace ./configure with config.toml in README.md and CONTRIBUTING.md, so that new users aren't confused about which build system to use, and how to configure the build process.
Corey Farwell [Tue, 28 Feb 2017 13:33:00 +0000 (08:33 -0500)]
Rollup merge of #39977 - frewsxcv:error-reporting-cleanup, r=eddyb
librustc error_reporting.rs cleanup.
Read some code in librustc, mainly in error_reporting.rs, and cleaned up some things along the way. I recommend looking at each commit individually or looking at the [whitespace insensitive diff](https://github.com/rust-lang/rust/pull/39977/files?w=1).