Commit Graph

652 Commits

Author SHA1 Message Date
Jeffrey Seyfried
872943c317 Improve macro reexports. 2016-11-10 10:04:24 +00:00
Jeffrey Seyfried
85f74c0eea Add variants Def::Macro and Namespace::MacroNS. 2016-11-10 09:21:44 +00:00
Jeffrey Seyfried
dd0781ea25 Register and stability check #[no_link] crates. 2016-11-10 09:21:29 +00:00
Jeffrey Seyfried
624a9b7311 Avoid building multiple reduced graphs for a crate
that is referenced by multiple `extern crate` items.
2016-11-10 09:20:55 +00:00
Jeffrey Seyfried
b0e13dc5ba Treat extern crates more like imports (pure refactoring). 2016-11-10 06:04:40 +00:00
Eduard Burtescu
49772fbf5d syntax: don't fake a block around closures' bodies during parsing. 2016-11-10 01:44:45 +02:00
Eduard-Mihai Burtescu
bd9969fb11 Rollup merge of #37428 - estebank:generic-type-error-span, r=sanxiyn
Point to type argument span when used as trait

Given the following code:

``` rust
struct Foo<T: Clone>(T);

use std::ops::Add;

impl<T: Clone, Add> Add for Foo<T> {
  type Output = usize;

  fn add(self, rhs: Self) -> Self::Output {
    unimplemented!();
  }
}
```

present the following output:

``` nocode
error[E0404]: `Add` is not a trait
 --> file3.rs:5:21
  |
5 | impl<T: Clone, Add> Add for Okok<T> {
  |                ---  ^^^ expected trait, found type parameter
  |                |
  |                type parameter defined here
```

Fixes #35987.
2016-11-09 20:51:16 +02:00
Eduard-Mihai Burtescu
dc8ac2679a Rollup merge of #37229 - nnethercote:FxHasher, r=nikomatsakis
Replace FNV with a faster hash function.

Hash table lookups are very hot in rustc profiles and the time taken within `FnvHash` itself is a big part of that. Although FNV is a simple hash, it processes its input one byte at a time. In contrast, Firefox has a homespun hash function that is also simple but works on multiple bytes at a time. So I tried it out and the results are compelling:

```
futures-rs-test  4.326s vs  4.212s --> 1.027x faster (variance: 1.001x, 1.007x)
helloworld       0.233s vs  0.232s --> 1.004x faster (variance: 1.037x, 1.016x)
html5ever-2016-  5.397s vs  5.210s --> 1.036x faster (variance: 1.009x, 1.006x)
hyper.0.5.0      5.018s vs  4.905s --> 1.023x faster (variance: 1.007x, 1.006x)
inflate-0.1.0    4.889s vs  4.872s --> 1.004x faster (variance: 1.012x, 1.007x)
issue-32062-equ  0.347s vs  0.335s --> 1.035x faster (variance: 1.033x, 1.019x)
issue-32278-big  1.717s vs  1.622s --> 1.059x faster (variance: 1.027x, 1.028x)
jld-day15-parse  1.537s vs  1.459s --> 1.054x faster (variance: 1.005x, 1.003x)
piston-image-0. 11.863s vs 11.482s --> 1.033x faster (variance: 1.060x, 1.002x)
regex.0.1.30     2.517s vs  2.453s --> 1.026x faster (variance: 1.011x, 1.013x)
rust-encoding-0  2.080s vs  2.047s --> 1.016x faster (variance: 1.005x, 1.005x)
syntex-0.42.2   32.268s vs 31.275s --> 1.032x faster (variance: 1.014x, 1.022x)
syntex-0.42.2-i 17.629s vs 16.559s --> 1.065x faster (variance: 1.013x, 1.021x)
```

(That's a stage1 compiler doing debug builds. Results for a stage2 compiler are similar.)

The attached commit is not in a state suitable for landing because I changed the implementation of FnvHasher without changing its name (because that would have required touching many lines in the compiler). Nonetheless, it is a good place to start discussions.

Profiles show very clearly that this new hash function is a lot faster to compute than FNV. The quality of the new hash function is less clear -- it seems to do better in some cases and worse in others (judging by the number of instructions executed in `Hash{Map,Set}::get`).

CC @brson, @arthurprs
2016-11-09 20:51:15 +02:00
Esteban Küber
3edb4fc563 Point to type argument span when used as trait
Given the following code:

```rust
struct Foo<T: Clone>(T);

use std::ops::Add;

impl<T: Clone, Add> Add for Foo<T> {
    type Output = usize;

    fn add(self, rhs: Self) -> Self::Output {
      unimplemented!();
    }
}
```

present the following output:

```nocode
error[E0404]: `Add` is not a trait
 --> file3.rs:5:21
  |
5 | impl<T: Clone, Add> Add for Okok<T> {
  |                ---  ^^^ expected trait, found type parameter
  |                |
  |                type parameter defined here
```
2016-11-08 14:17:18 -08:00
bors
38a959a543 Auto merge of #36843 - petrochenkov:dotstab, r=nikomatsakis
Stabilize `..` in tuple (struct) patterns

I'd like to nominate `..` in tuple and tuple struct patterns for stabilization.
This feature is a relatively small extension to existing stable functionality and doesn't have known blockers.
The feature first appeared in Rust 1.10 6 months ago.
An example of use: https://github.com/rust-lang/rust/pull/36203

Closes https://github.com/rust-lang/rust/issues/33627
r? @nikomatsakis
2016-11-08 02:06:45 -08:00
Nicholas Nethercote
00e48affde Replace FnvHasher use with FxHasher.
This speeds up compilation by 3--6% across most of rustc-benchmarks.
2016-11-08 15:14:59 +11:00
Vadim Petrochenkov
74bb594563 Stabilize .. in tuple (struct) patterns 2016-11-03 01:38:15 +03:00
Jeffrey Seyfried
076c5d445b Fix shadowing checking. 2016-11-02 07:42:37 +00:00
Jeffrey Seyfried
6c4b551403 Cleanup Resolver::disallowed_shadowing. 2016-10-31 06:56:06 +00:00
Guillaume Gomez
f12e66e642 Rollup merge of #37430 - robinst:missing-crate-message-add-semicolon, r=eddyb
Add semicolon to "Maybe a missing `extern crate foo`" message

I had it a couple of times that I was missing the "extern crate" line
after I introduced a new dependency. So I copied the text from the
message and inserted it into the beginning of my code, only to find the
compiler complaining that I was missing the semicolon. (I forgot to add
it after the text that I had pasted.)

There's a similar message which does include the semicolon, namely
"help: you can import it into scope: `use foo::Bar;`". I think the two
messages should be consistent, so this change adds it for "extern
crate".
2016-10-28 17:05:47 +02: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
Robin Stocker
de5172ce5f Add semicolon to "Maybe a missing extern crate foo" message
I had it a couple of times that I was missing the "extern crate" line
after I introduced a new dependency. So I copied the text from the
message and inserted it into the beginning of my code, only to find the
compiler complaining that I was missing the semicolon. (I forgot to add
it after the text that I had pasted.)

There's a similar message which does include the semicolon, namely
"help: you can import it into scope: `use foo::Bar;`". I think the two
messages should be consistent, so this change adds it for "extern
crate".
2016-10-27 15:24:08 +11:00
Jeffrey Seyfried
04ca378b89 Support use $crate; with a future compatibility warning. 2016-10-25 20:26:00 +00:00
Jeffrey Seyfried
199ed20aa6 Fix $crate-related regressions. 2016-10-25 20:25:59 +00:00
Jeffrey Seyfried
dcdab2df67 Fix label scopes. 2016-10-22 23:37:54 +00:00
Jeffrey Seyfried
8b0c292a72 Improve $crate. 2016-10-19 10:03:06 +00:00
Jeffrey Seyfried
7b81106a85 Use Idents instead of Names in ImportDirective's paths. 2016-10-19 09:58:12 +00:00
Jeffrey Seyfried
6a6ef91ba7 nit: Import Ident in resolve. 2016-10-19 09:58:08 +00: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
Jeffrey Seyfried
33e3da831c Use the macro namespace for custom derives. 2016-10-15 22:55:19 +00:00
Jonathan Turner
cd0c70f430 Rollup merge of #36307 - faebser:E0408_new_error_format, r=GuillaumeGomez
Changed error message E0408 to new format

Followed your text and was able to change the ouput to the new format.
I did not encounter any broken test therefore this is a really small commit.

Thanks for letting me hack on the compiler :)

r? @jonathandturner
2016-10-14 12:07:07 -07:00
Fabian Frei
595b754a4b Changed error message E0408 to new format
r? @jonathandturner
2016-10-13 00:16:52 +02:00
Alex Crichton
20991829e2 Rollup merge of #37084 - jseyfried:cleanup_expanded_macro_use_scopes, r=nrc
macros: clean up scopes of expanded `#[macro_use]` imports

This PR changes the scope of macro-expanded `#[macro_use]` imports to match that of unexpanded `#[macro_use]` imports. For example, this would be allowed:
```rust
example!();
macro_rules! m { () => { #[macro_use(example)] extern crate example_crate; } }
m!();
```

This PR also enforces the full shadowing restrictions from RFC 1560 on `#[macro_use]` imports (currently, we only enforce the weakened restrictions from #36767).

This is a [breaking-change], but I believe it is highly unlikely to cause breakage in practice.
r? @nrc
2016-10-12 14:07:56 -07:00
Jeffrey Seyfried
111caef9a3 Clean up the scopes of expanded #[macro_use] imports. 2016-10-11 05:14:08 +00:00
Jeffrey Seyfried
6808b0a2b7 Check for shadowing errors after all invocations have been expanded. 2016-10-11 03:28:54 +00:00
Jeffrey Seyfried
fbc96e18ad Persistent macro scopes. 2016-10-08 03:41:55 +00:00
Jeffrey Seyfried
a23bdd2769 Rename resolve::macros::{ExpansionData -> InvocationData}. 2016-10-07 21:54:37 +00:00
Jeffrey Seyfried
2cf964967c Immutable ExpansionData. 2016-10-07 21:54:05 +00:00
Vadim Petrochenkov
b3cb8f68cc Turn compatibility lint match_of_unit_variant_via_paren_dotdot into a hard error 2016-10-05 12:22:26 +03:00
Vadim Petrochenkov
bd291ce21a Turn some impossible definitions into ICEs 2016-10-04 22:25:25 +03:00
Vadim Petrochenkov
c95b280d72 Move pattern resolution checks from typeck to resolve
Make error messages more precise
2016-10-04 22:20:38 +03:00
Vadim Petrochenkov
e8ea38e42a Further cleanup in resolve
`try_define` is not used in build_reduced_graph anymore
Collection of field names for error reporting is optimized
Some comments added
2016-10-04 22:20:37 +03:00
Vadim Petrochenkov
da7b1c984c Separate Def::StructCtor/Def::VariantCtor from Def::Struct/Def::Variant 2016-10-04 22:20:37 +03:00
bors
f3745653e1 Auto merge of #36767 - jseyfried:enforce_rfc_1560_shadowing, r=nrc
Enforce the shadowing restrictions from RFC 1560 for today's macros

This PR enforces a weakened version of the shadowing restrictions from RFC 1560. More specifically,
 - If a macro expansion contains a `macro_rules!` macro definition that is used outside of the expansion, the defined macro may not shadow an existing macro.
 - If a macro expansion contains a `#[macro_use] extern crate` macro import that is used outside of the expansion, the imported macro may not shadow an existing macro.

This is a [breaking-change]. For example,
```rust
macro_rules! m { () => {} }
macro_rules! n { () => {
    macro_rules! m { () => {} } //< This shadows an existing macro.
    m!(); //< This is inside the expansion that generated `m`'s definition, so it is OK.
} }
n!();
m!(); //< This use of `m` is outside the expansion, so it causes the shadowing to be an error.
```

r? @nrc
2016-10-03 01:30:32 -07:00
Jeffrey Seyfried
ed1e00268b Enforce the weakened shadowing restriction. 2016-10-02 08:25:27 +00:00
Jeffrey Seyfried
797eb57aa8 Refactor field expansion_data of Resolver to use a Mark instead of a u32. 2016-10-02 04:25:31 +00:00
Jeffrey Seyfried
5c2d76d23e Add struct macros::NameBinding. 2016-10-02 04:25:27 +00:00
Jeffrey Seyfried
91e1f24f12 Fix module_to_string. 2016-10-01 07:41:53 +00:00
bors
a059cb2f33 Auto merge of #36601 - jseyfried:build_reduced_graph_in_expansion, r=nrc
Assign def ids and build the module graph during expansion

r? @nrc
2016-09-27 14:11:07 -07:00
Jeffrey Seyfried
634ecf038d Merge ModuleData and ModuleS. 2016-09-27 06:43:43 +00:00
Jeffrey Seyfried
b3a81ee844 Build the reduced graph during expansion. 2016-09-27 06:42:10 +00:00
Jeffrey Seyfried
ebaaafcd5d Peform def id assignment during expansion. 2016-09-27 06:42:09 +00:00
Jonathan Turner
2fa91b23c5 Update E0425, E0446, E0449 2016-09-26 16:05:46 -07:00
Jeffrey Seyfried
b4906a93a0 Load macros from #[macro_use] extern crates in resolve. 2016-09-24 20:22:25 +00:00
Jeffrey Seyfried
7b5c59ea65 Load extern crates in resolve. 2016-09-23 06:35:33 +00:00