Commit Graph

9711 Commits

Author SHA1 Message Date
bors
75a87c54d0 Auto merge of #37378 - petrochenkov:nopat, r=eddyb
Prohibit patterns in trait methods without bodies

They are not properly type checked
```rust
trait Tr {
    fn f(&a: u8); // <- This compiles
}
```
, mostly rejected by the parser already and generally don't make much sense.
This PR is kind of a missing part of https://github.com/rust-lang/rust/pull/35015.

Given the [statistics from crater](https://github.com/rust-lang/rust/pull/37378#issuecomment-256154994), the effect of this PR is mostly equivalent to improving `unused_mut` lint.

cc https://github.com/rust-lang/rust/issues/35078#issuecomment-255707355 https://github.com/rust-lang/rust/pull/35015 https://github.com/rust-lang/rfcs/pull/1685 https://github.com/rust-lang/rust/issues/35203
r? @eddyb
2016-10-29 05:41:05 -07:00
Vadim Petrochenkov
8a38928b44 Address comments + Fix rebase 2016-10-27 22:20:25 +03:00
Vadim Petrochenkov
a9f91b1b0e Preparations and cleanup
Diagnostics for struct path resolution errors in resolve and typeck are unified.
Self type is treated as a type alias in few places (not reachable yet).
Unsafe cell is seen in constants even through type aliases.
All checks for struct paths in typeck work on type level.
2016-10-27 22:14:41 +03:00
bors
a0e31a5bfc Auto merge of #36894 - petrochenkov:deny, r=nikomatsakis
Make sufficiently old or low-impact compatibility lints deny-by-default

Tracking issues are updated/created when necessary.
Needs crater run before proceeding.

r? @nikomatsakis
2016-10-27 04:06:31 -07:00
Vadim Petrochenkov
2a85211040 Make sufficiently old or low-impact compatibility lints deny-by-default 2016-10-27 12:06:03 +03:00
bors
46d39f3329 Auto merge of #37128 - nrc:depr-attr, r=@alexcrichton
Deprecate no_debug and custom_derive

r? @nikomatsakis
2016-10-27 00:51:58 -07:00
Eduard Burtescu
9908711e5e Implement field shorthands in struct literal expressions. 2016-10-27 03:15:13 +03:00
Nick Cameron
121e903f17 Add possibility of deprecating attributes 2016-10-27 11:44:42 +13:00
Vadim Petrochenkov
811a2b91de Prohibit patterns in trait methods without bodies 2016-10-26 20:55:16 +03:00
bors
a6b3b01b5f Auto merge of #37270 - Mark-Simulacrum:smallvec-optimized-arenas, r=eddyb
Add ArrayVec and AccumulateVec to reduce heap allocations during interning of slices

Updates `mk_tup`, `mk_type_list`, and `mk_substs` to allow interning directly from iterators. The previous PR, #37220, changed some of the calls to pass a borrowed slice from `Vec` instead of directly passing the iterator, and these changes further optimize that to avoid the allocation entirely.

This change yields 50% less malloc calls in [some cases](https://pastebin.mozilla.org/8921686). It also yields decent, though not amazing, performance improvements:
```
futures-rs-test  4.091s vs  4.021s --> 1.017x faster (variance: 1.004x, 1.004x)
helloworld       0.219s vs  0.220s --> 0.993x faster (variance: 1.010x, 1.018x)
html5ever-2016-  3.805s vs  3.736s --> 1.018x faster (variance: 1.003x, 1.009x)
hyper.0.5.0      4.609s vs  4.571s --> 1.008x faster (variance: 1.015x, 1.017x)
inflate-0.1.0    3.864s vs  3.883s --> 0.995x faster (variance: 1.232x, 1.005x)
issue-32062-equ  0.309s vs  0.299s --> 1.033x faster (variance: 1.014x, 1.003x)
issue-32278-big  1.614s vs  1.594s --> 1.013x faster (variance: 1.007x, 1.004x)
jld-day15-parse  1.390s vs  1.326s --> 1.049x faster (variance: 1.006x, 1.009x)
piston-image-0. 10.930s vs 10.675s --> 1.024x faster (variance: 1.006x, 1.010x)
reddit-stress    2.302s vs  2.261s --> 1.019x faster (variance: 1.010x, 1.026x)
regex.0.1.30     2.250s vs  2.240s --> 1.005x faster (variance: 1.087x, 1.011x)
rust-encoding-0  1.895s vs  1.887s --> 1.005x faster (variance: 1.005x, 1.018x)
syntex-0.42.2   29.045s vs 28.663s --> 1.013x faster (variance: 1.004x, 1.006x)
syntex-0.42.2-i 13.925s vs 13.868s --> 1.004x faster (variance: 1.022x, 1.007x)
```

We implement a small-size optimized vector, intended to be used primarily for collection of presumed to be short iterators. This vector cannot be "upsized/reallocated" into a heap-allocated vector, since that would require (slow) branching logic, but during the initial collection from an iterator heap-allocation is possible.

We make the new `AccumulateVec` and `ArrayVec` generic over implementors of the `Array` trait, of which there is currently one, `[T; 8]`. In the future, this is likely to expand to other values of N.

Huge thanks to @nnethercote for collecting the performance and other statistics mentioned above.
2016-10-26 03:47:55 -07:00
Mark-Simulacrum
982a48575b Utilize AccumulateVec to avoid heap allocations in mk_{substs, type_list, tup} calls. 2016-10-25 20:06:17 -06:00
bors
aef18be1bc Auto merge of #37111 - TimNN:sized-enums, r=nikomatsakis
Disallow Unsized Enums

Fixes #16812.

This PR is a potential fix for #16812, an issue which is reported [again](https://github.com/rust-lang/rust/issues/36801) and [again](https://github.com/rust-lang/rust/issues/36975), with over a dozen duplicates by now.

This PR is mainly meant to promoted discussion about the issue and the correct way to fix it.

This is a [breaking-change] since the error is now reported during wfchecking, so that even the definition of a (potentially) unsized enum will cause an error (whereas it would previously cause an ICE at trans time if the enum was used in an unsized manner).
2016-10-25 12:37:43 -07:00
bors
affc3b7552 Auto merge of #37292 - jseyfried:import_macros_in_resolve, r=nrc
Process `#[macro_use]` imports in `resolve` and clean up macro loading

Groundwork macro modularization (cc #35896).
r? @nrc
2016-10-24 23:15:59 -07:00
Jonathan Turner
691ab948ce Rollup merge of #37336 - michaelwoerister:debuginfo-type-ids, r=eddyb
debuginfo: Use TypeIdHasher for generating global debuginfo type IDs.

The only requirement for debuginfo type IDs is that they are globally unique. The `TypeIdHasher` (which is used for `std::intrinsic::type_id()` provides that, so we can get rid of some redundancy by re-using it for debuginfo. Values produced by the `TypeIdHasher` are also more stable than the current `UniqueTypeId` generation algorithm produces -- these incorporate the `NodeId`s, which is not good for incremental compilation.

@alexcrichton @eddyb : Could you take a look at the endianess adaptations that I made to the `TypeIdHasher`?

Also, are we sure that a 64 bit hash is wide enough for something that is supposed to be globally unique? For debuginfo I'm using 160 bits to make sure that we don't run into conflicts there.
2016-10-24 15:41:29 -07:00
Jonathan Turner
050499c407 Rollup merge of #37324 - GuillaumeGomez:trait_error_message, r=jonathandturner
Improve E0277 help message

Fixes #37319.

r? @jonathandturner
2016-10-24 15:41:29 -07:00
Tim Neumann
f1695238ca disallow unsized enums 2016-10-24 20:07:14 +02:00
Nicholas Nethercote
9270a9217a Use SmallVector in CombineFields::instantiate.
This avoids 4% of malloc calls when compiling
rustc-benchmarks/issue-32278-big-array-of-strings, and 1--2% for other
benchmarks. A small win, but an easy one.
2016-10-24 14:08:06 +11:00
Jeffrey Seyfried
5e8951d331 Clean up CrateLoader::process_item. 2016-10-24 00:51:11 +00:00
Jeffrey Seyfried
9c514a1cc1 Refactor away CrateLoader::load_macros. 2016-10-24 00:45:12 +00:00
Jeffrey Seyfried
53de24bbd1 Refactor away fields MacroDef::{use_locally, export}. 2016-10-24 00:43:19 +00:00
Jeffrey Seyfried
e4baeaa30d Import macros in resolve instead of in metadata::macro_import. 2016-10-24 00:43:12 +00:00
Johannes Muenzel
f9cb7dfc0c Fix typo that resulted in comparison-to-self 2016-10-22 13:51:31 -07:00
Michael Woerister
7ef418b37e Make ArchIndependentHasher publicly visible. 2016-10-21 19:28:01 -04:00
Michael Woerister
6f3edb034c type_id: Make result of std::intrinsics::type_id() endian-independent. 2016-10-21 17:53:49 -04:00
Niko Matsakis
567b11fc3a only remove keys that mention skolemized regions 2016-10-21 11:13:36 -04:00
Niko Matsakis
974817d493 when pop skol, also remove from proj cache 2016-10-21 11:13:34 -04:00
Guillaume Gomez
1fadd868cd Improve E0277 help message 2016-10-21 16:13:52 +02:00
bors
eb38d426c4 Auto merge of #36973 - nnethercote:dep_graph, r=nikomatsakis
Don't enqueue onto a disabled dep_graph.

This commit guards all calls to `DepGraphThreadData::enqueue` with a
check to make sure it is enabled. This avoids some useless allocation
and vector manipulations when it is disabled (i.e. when incremental
compilation is off) which improves speed by 1--2% on most of the
rustc-benchmarks.

This commit has an observable functional change: when the dep_graph is
disabled its `shadow_graph` will no longer receive messages. This should
be ok because these message are only used when debug assertions are
enabled.

r? @nikomatsakis
2016-10-19 22:05:13 -07:00
Guillaume Gomez
123a6ef25c Rollup merge of #37241 - zackmdavis:if_let_over_none_spaced_empty_block_arm, r=nikomatsakis
prefer `if let` to match with `None => { }` arm in some places

In #34268 (8531d581), we replaced matches of None to the unit value `()`
with `if let`s in places where it was deemed that this made the code
unambiguously clearer and more idiomatic. In #34638 (d37edef9), we did
the same for matches of None to the empty block `{}`.

A casual observer, upon seeing these commits fly by, might suppose that
the matter was then settled, that no further pull requests on this
utterly trivial point of style could or would be made. Unless ...

It turns out that sometimes people write the empty block with a space in
between the braces. Who knew?
2016-10-19 23:15:00 +02:00
Mark-Simulacrum
83b198249f Use TypedArena::alloc_slice in rustc. 2016-10-19 07:53:56 -06:00
Eduard-Mihai Burtescu
beaa4c5779 Rollup merge of #37224 - petrochenkov:nz, r=eddyb
Mark enums with non-zero discriminant as non-zero

cc https://github.com/rust-lang/rfcs/issues/1230
r? @eddyb
2016-10-19 08:00:02 +03:00
Eduard-Mihai Burtescu
a6788d0ba8 Rollup merge of #37198 - jseyfried:future_proof_macros_11, r=nrc
macros 1.1: future proofing and cleanup

This PR
 - uses the macro namespace for custom derives (instead of a dedicated custom derive namespace),
 - relaxes the shadowing rules for `#[macro_use]`-imported custom derives to match the shadowing rules for ordinary `#[macro_use]`-imported macros, and
 - treats custom derive `extern crate`s like empty modules so that we can eventually allow, for example, `extern crate serde_derive; use serde_derive::Serialize;` backwards compatibly.

r? @alexcrichton
2016-10-19 08:00:00 +03:00
Eduard-Mihai Burtescu
373fcd1bd3 Rollup merge of #37117 - pnkfelix:may-dangle-attr, r=nikomatsakis
`#[may_dangle]` attribute

`#[may_dangle]` attribute

Second step of #34761. Last big hurdle before we can work in earnest towards Allocator integration (#32838)

Note: I am not clear if this is *also* a syntax-breaking change that needs to be part of a breaking-batch.
2016-10-19 07:59:59 +03:00
Eduard-Mihai Burtescu
ab5dcff131 Format comment in a nicer way.
Just kidding I'm doing this only to unstuck @bors/homu/buildbot.
2016-10-19 07:37:20 +03:00
Nicholas Nethercote
1e4241ab31 Optimize Substs::super_fold_with.
This speeds up several rustc-benchmarks by 1--4%.
2016-10-18 20:55:23 +11:00
Nicholas Nethercote
cde42cd780 Don't enqueue onto a disabled dep_graph.
This commit guards all calls to `DepGraphThreadData::enqueue` with a
check to make sure it is enabled. This requires distinguishing between a
"fully enabled" and an "enqueue-enabled" graph.

This change avoids some useless allocation and vector manipulations when
the graph is disabled (i.e. when incremental compilation is off) which
improves speed by ~1% on some of the rustc-benchmarks.
2016-10-18 14:46:41 +11:00
Zack M. Davis
1e7cd5edcc prefer if let to match with None => { } arm in some places
In #34268 (8531d581), we replaced matches of None to the unit value `()`
with `if let`s in places where it was deemed that this made the code
unambiguously clearer and more idiomatic. In #34638 (d37edef9), we did
the same for matches of None to the empty block `{}`.

A casual observer, upon seeing these commits fly by, might suppose that
the matter was then settled, that no further pull requests on this
utterly trivial point of style could or would be made. Unless ...

It turns out that sometimes people write the empty block with a space in
between the braces. Who knew?
2016-10-17 19:00:20 -07:00
bors
e0111758eb Auto merge of #36915 - jfirebaugh:E0308-split, r=nikomatsakis
Use a distinct error code for "if may be missing an else clause"

Introduce the possibility of assigning distinct error codes to the various origin types of E0308. Start by assigning E0317 for the "IfExpressionWithNoElse" case, and write a long diagnostic specific to this case.

Fixes #36596
2016-10-17 14:06:46 -07:00
Felix S. Klock II
85d2e4d1d6 Review feedback: add linebreak and reindent to make braces match better. 2016-10-17 16:22:24 +02:00
Felix S. Klock II
0271a9a60a Fix Subst construction: use subst from adt_def rather than Drop impl's subst.
This addresses issue pointed out by niko that prior code would break
if the declaration order for generics does not match how they are fed
into the instantiation of the type itself. (Added some tests
exercising this scenario.)
2016-10-17 16:14:25 +02:00
bors
54c133d3ba Auto merge of #37082 - frewsxcv:session, r=jseyfried
'src/librustc/session/filesearch.rs' refactoring and cleanup.
2016-10-16 20:00:14 -07:00
Vadim Petrochenkov
49e6b466e9 Mark enums with non-zero discriminant as non-zero 2016-10-17 02:24:04 +03:00
bors
6572a46311 Auto merge of #37129 - arielb1:erased-normal, r=eddyb
normalize types every time HR regions are erased

Associated type normalization is inhibited by higher-ranked regions.
Therefore, every time we erase them, we must re-normalize.

I was meaning to introduce this change some time ago, but we used
to erase regions in generic context, which broke this terribly (because
you can't always normalize in a generic context). That seems to be gone
now.

Ensure this by having a `erase_late_bound_regions_and_normalize`
function.

Fixes #37109 (the missing call was in mir::block).

r? @eddyb
2016-10-16 04:22:21 -07:00
Jeffrey Seyfried
33e3da831c Use the macro namespace for custom derives. 2016-10-15 22:55:19 +00:00
bors
98a3502da1 Auto merge of #37152 - arielb1:drop-cache, r=pnkfelix
add a per-param-env cache to `impls_bound`

There used to be only a global cache, which led to uncached calls to
trait selection when there were type parameters.

This causes a 20% decrease in borrow-checking time and an overall 0.5% performance increase during bootstrapping (as borrow-checking tends to be a tiny part of compilation time).

Fixes #37106 (drop elaboration times are now ~half of borrow checking,
so might still be worthy of optimization, but not critical).

r? @pnkfelix
2016-10-15 15:38:52 -07:00
John Firebaugh
d07602b573 Remove FIXME 2016-10-15 08:49:16 -07:00
bors
8e05e7ee3c Auto merge of #37100 - dikaiosune:master, r=eddyb
Change Substs to type alias for Slice<Kind> for interning

This changes the definition of `librustc::ty::subst::Substs` to be a type alias to `Slice<Kind>`. `Substs` was already interned, but can now make use of the efficient `PartialEq` and `Hash` impls on `librustc::ty::Slice`.

I'm working on collecting some timing data for this, will update when it's done.

I chose to leave the impls on `Substs<'tcx>` even though it's now just a type alias to `Slice<Kind<'tcx>>` because it has the smallest footprint on other portions of the compiler which depend on its API. It turns out to be a pretty huge diff if you change where Substs's methods live 😄. That said, I'm not necessarily sure it's the *best* implementation but it's probably the easiest/smallest to review.

Many thanks to @eddyb for both suggesting this as a project for learning more about the compiler, and the tireless ~~handholding~~ mentorship he provided.
2016-10-15 06:08:55 -07:00
Ariel Ben-Yehuda
a61d85b2fe add a per-param-env cache to impls_bound
There used to be only a global cache, which led to uncached calls to
trait selection when there were type parameters.

I'm running a check that there are no adverse performance effects.

Fixes #37106 (drop elaboration times are now ~half of borrow checking,
so might still be worthy of optimization, but not critical).
2016-10-14 00:19:19 +03:00
Ariel Ben-Yehuda
ee338c31fe normalize types every time HR regions are erased
Associated type normalization is inhibited by higher-ranked regions.
Therefore, every time we erase them, we must re-normalize.

I was meaning to introduce this change some time ago, but we used
to erase regions in generic context, which broke this terribly (because
you can't always normalize in a generic context). That seems to be gone
now.

Ensure this by having a `erase_late_bound_regions_and_normalize`
function.

Fixes #37109 (the missing call was in mir::block).
2016-10-13 19:17:53 +03:00
Adam Perry
48b3dd11f5 Adding FIXME for noop Substs::params. 2016-10-13 07:54:06 -07:00