| Age | Commit message (Collapse) | Author | Lines |
|
|
|
|
|
... and make the latter mandatory to implement.
|
|
They don't implement FnLikeNode anymore, instead are handled differently
further up in the call tree. Also, keep less information (just def ids
for the args).
|
|
|
|
This is quite hacky and I hope to refactor it a bit, but at least it
seems to work.
|
|
|
|
Support `?Sized` in where clauses
Implemented as described in https://github.com/rust-lang/rust/issues/20503#issuecomment-258677026 - `?Trait` bounds are moved on type parameter definitions when possible, reported as errors otherwise.
(It'd be nice to unify bounds and where clauses in HIR, but this is mostly blocked by rustdoc now - it needs to render bounds in pleasant way and the best way to do it so far is to mirror what was written in source code.)
Fixes https://github.com/rust-lang/rust/issues/20503
r? @nikomatsakis
|
|
|
|
|
|
|
|
|
|
Implement the `loop_break_value` feature.
This implements RFC 1624, tracking issue #37339.
- `FnCtxt` (in typeck) gets a stack of `LoopCtxt`s, which store the
currently deduced type of that loop, the desired type, and a list of
break expressions currently seen. `loop` loops get a fresh type
variable as their initial type (this logic is stolen from that for
arrays). `while` loops get `()`.
- `break {expr}` looks up the broken loop, and unifies the type of
`expr` with the type of the loop.
- `break` with no expr unifies the loop's type with `()`.
- When building MIR, loops no longer construct a `()` value at
termination of the loop; rather, the `break` expression assigns the
result of the loop.
- ~~I have also changed the loop scoping in MIR-building so that the test
of a while loop is not considered to be part of that loop. This makes
the rules consistent with #37360. The new loop scopes in typeck also
follow this rule. That means that `loop { while (break) {} }` now
terminates instead of looping forever. This is technically a breaking
change.~~
- ~~On that note, expressions like `while break {}` and `if break {}` no
longer parse because `{}` is interpreted as an expression argument to
`break`. But no code except compiler test cases should do that anyway
because it makes no sense.~~
- The RFC did not make it clear, but I chose to make `break ()` inside
of a `while` loop illegal, just in case we wanted to do anything with
that design space in the future.
This is my first time dealing with this part of rustc so I'm sure
there's plenty of problems to pick on here ^_^
|
|
This implements RFC 1624, tracking issue #37339.
- `FnCtxt` (in typeck) gets a stack of `LoopCtxt`s, which store the
currently deduced type of that loop, the desired type, and a list of
break expressions currently seen. `loop` loops get a fresh type
variable as their initial type (this logic is stolen from that for
arrays). `while` loops get `()`.
- `break {expr}` looks up the broken loop, and unifies the type of
`expr` with the type of the loop.
- `break` with no expr unifies the loop's type with `()`.
- When building MIR, `loop` loops no longer construct a `()` value at
termination of the loop; rather, the `break` expression assigns the
result of the loop. `while` loops are unchanged.
- `break` respects contexts in which expressions may not end with braced
blocks. That is, `while break { break-value } { while-body }` is
illegal; this preserves backwards compatibility.
- The RFC did not make it clear, but I chose to make `break ()` inside
of a `while` loop illegal, just in case we wanted to do anything with
that design space in the future.
This is my first time dealing with this part of rustc so I'm sure
there's plenty of problems to pick on here ^_^
|
|
|
|
|
|
|
|
|
|
This allows you to enable *all* nested visits in a future-compatible
sort of way. Moreover, if you choose to override the `visit_nested`
methods yourself, you can "future-proof" against omissions by overriding
`nested_visit_map` to panic.
|
|
Basically adding `visit_impl_item` in various places and so forth.
|
|
There are now three patterns (shallow, deep, and nested visit). These
are described in detail on the docs in `itemlikevisit::ItemLikeVisitor`.
|
|
[6/n] rustc: transition HIR function bodies from Block to Expr.
_This is part of a series ([prev](https://github.com/rust-lang/rust/pull/37408) | [next](https://github.com/rust-lang/rust/pull/37676)) of patches designed to rework rustc into an out-of-order on-demand pipeline model for both better feature support (e.g. [MIR-based](https://github.com/solson/miri) early constant evaluation) and incremental execution of compiler passes (e.g. type-checking), with beneficial consequences to IDE support as well.
If any motivation is unclear, please ask for additional PR description clarifications or code comments._
<hr>
The main change here is that functions and closures both use `Expr` instead of `Block` for their bodies.
For closures this actually allows a honest representation of brace-less closure bodies, e.g. `|x| x + 1` is now distinguishable from `|x| { x + 1 }`, therefore this PR is `[syntax-breaking]` (cc @Manishearth).
Using `Expr` allows more logic to be shared between constant bodies and function bodies, with some small such changes already part of this PR, and eventually easing #35078 and per-body type tables.
Incidentally, there used to be some corners cut here and there and as such I had to (re)write divergence tracking for type-checking so that it is capable of understanding basic structured control-flow:
``` rust
fn a(x: bool) -> i32 {
// match also works (as long as all arms diverge)
if x { panic!("true") } else { return 1; }
0 // "unreachable expression" after this PR
}
```
And since liveness' "not all control paths return a value" moved to type-checking we can have nice things:
``` rust
// before & after:
fn b() -> i32 { 0; } // help: consider removing this semicolon
// only after this PR
fn c() -> i32 { { 0; } } // help: consider removing this semicolon
fn d() { let x: i32 = { 0; }; } // help: consider removing this semicolon
fn e() { f({ 0; }); } // help: consider removing this semicolon
```
|
|
|
|
|
|
|
|
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
|
|
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
|
|
This speeds up compilation by 3--6% across most of rustc-benchmarks.
|
|
Add `-Z hir-stats` for collecting statistics on HIR and AST
The data collected will be printed to the commandline and looks like the following:
```
// stats for libcore
PRE EXPANSION AST STATS
Name Accumulated Size Count Item Size
----------------------------------------------------------------
TypeBinding 2_280 57 40
Mod 3_560 89 40
PathListItem 6_516 181 36
Variant 7_872 82 96
LifetimeDef 21_280 380 56
StructField 22_880 260 88
Lifetime 23_800 1_190 20
Local 30_192 629 48
ForeignItem 31_504 179 176
Arm 42_880 670 64
Mac 46_960 587 80
FnDecl 57_792 1_204 48
TraitItem 69_504 362 192
TyParamBound 98_280 945 104
Block 108_384 2_258 48
Stmt 144_720 3_618 40
ImplItem 230_272 1_028 224
Item 467_456 1_826 256
Pat 517_776 4_623 112
Attribute 745_680 15_535 48
Ty 1_114_848 9_954 112
PathSegment 1_218_528 16_924 72
Expr 3_082_408 20_279 152
----------------------------------------------------------------
Total 8_095_372
POST EXPANSION AST STATS
Name Accumulated Size Count Item Size
----------------------------------------------------------------
MacroDef 1_056 12 88
Mod 3_400 85 40
TypeBinding 4_280 107 40
PathListItem 6_516 181 36
Variant 7_872 82 96
StructField 24_904 283 88
ForeignItem 31_504 179 176
TraitItem 69_504 362 192
Local 85_008 1_771 48
Arm 100_288 1_567 64
Lifetime 123_980 6_199 20
LifetimeDef 126_728 2_263 56
TyParamBound 297_128 2_857 104
FnDecl 305_856 6_372 48
Block 481_104 10_023 48
Stmt 535_120 13_378 40
Item 1_469_952 5_742 256
Attribute 1_629_840 33_955 48
ImplItem 1_732_864 7_736 224
Pat 2_360_176 21_073 112
PathSegment 5_888_448 81_784 72
Ty 6_237_168 55_689 112
Expr 12_013_320 79_035 152
----------------------------------------------------------------
Total 33_536_016
HIR STATS
Name Accumulated Size Count Item Size
----------------------------------------------------------------
MacroDef 864 12 72
Mod 2_720 85 32
TypeBinding 3_424 107 32
PathListItem 5_068 181 28
Variant 6_560 82 80
StructField 20_376 283 72
ForeignItem 27_208 179 152
WherePredicate 43_776 684 64
TraitItem 52_128 362 144
Decl 68_992 2_156 32
Local 89_184 1_858 48
Arm 94_368 1_966 48
LifetimeDef 108_624 2_263 48
Lifetime 123_980 6_199 20
Stmt 168_000 4_200 40
TyParamBound 251_416 2_857 88
FnDecl 254_880 6_372 40
Block 583_968 12_166 48
Item 1_240_272 5_742 216
ImplItem 1_361_536 7_736 176
Attribute 1_620_480 33_760 48
Pat 2_073_120 21_595 96
Path 2_385_856 74_558 32
Ty 4_455_040 55_688 80
PathSegment 5_587_904 87_311 64
Expr 7_588_992 79_052 96
----------------------------------------------------------------
Total 28_218_736
```
|
|
|
|
|
|
|
|
|
|
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
|
|
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.
|
|
|
|
|
|
And for methods/functions as well, they are zero-sized now
|
|
|
|
|
|
Update E0425, E0446, E0449
This addresses https://github.com/rust-lang/rust/issues/35343, https://github.com/rust-lang/rust/issues/35923, and https://github.com/rust-lang/rust/issues/35924. Part of https://github.com/rust-lang/rust/issues/35233
Specifically, this adds labels to these error messages following the suggestions in the attached bugs.
r? @nrc
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
update E0265 to new format
Fixes #35309 as part of #35233.
I've describe partially bonus achieve in #35309
r? @jonathandturner
|