Commit graph

66 commits

Author SHA1 Message Date
Dylan DPC
cd6829382d
Rollup merge of #76245 - tmiasko:inline-generators, r=ecstatic-morse
inliner: Avoid query cycles when optimizing generators

The HIR Id trick is insufficient to prevent query cycles when optimizing
generators, since merely requesting a layout of a generator also
computes its `optimized_mir`.

Make no attempts to inline functions into generators within the same
crate to avoid query cycles.

Fixes #76181.
2020-09-03 02:22:14 +02:00
Dylan DPC
a4e30a6ae7
Rollup merge of #76167 - mati865:mingw-self-contained-heuristic, r=petrochenkov
Replace MinGW library hack with heuristic controlling link mode

Depends on https://github.com/rust-lang/rust/pull/76158
Closes https://github.com/rust-lang/rust/issues/68887
2020-09-03 02:22:06 +02:00
bors
51f79b618d Auto merge of #76233 - cuviper:unhasher, r=Mark-Simulacrum
Avoid rehashing Fingerprint as a map key

This introduces a no-op `Unhasher` for map keys that are already hash-
like, for example `Fingerprint` and its wrapper `DefPathHash`. For these
we can directly produce the `u64` hash for maps. The first use of this
is `def_path_hash_to_def_id: Option<UnhashMap<DefPathHash, DefId>>`.

cc #56308
r? @eddyb
2020-09-02 22:16:22 +00:00
bors
80fc9b0ecb Auto merge of #76160 - scileo:format-recovery, r=petrochenkov
Improve recovery on malformed format call

The token following a format expression should be a comma. However, when it is replaced with a similar token (such as a dot), then the corresponding error is emitted, but the token is treated as a comma, and the parsing step continues.

r? @petrochenkov
2020-09-02 19:29:27 +00:00
Sasha
3524c3ef43 Improve recovery on malformed format call
If a comma in a format call is replaced with a similar token, then we
emit an error and continue parsing, instead of stopping at this point.
2020-09-02 13:18:19 +02:00
bors
da897dfb6d Auto merge of #76216 - marmeladema:use-once-cell-from-std, r=matklad
compiler: use `OnceCell` from std

Fixes #76192

The only remaining direct use of `lazy_static` crate is in `src/bootstrap`  but I am not sure how I can remove that dependency for now.

r? @matklad
2020-09-02 06:46:21 +00:00
bors
b4acb11033 Auto merge of #76170 - matklad:notrivia, r=petrochenkov
Remove trivia tokens

r? @ghost
2020-09-02 03:19:38 +00:00
Josh Stone
469ca379d6 Avoid rehashing Fingerprint as a map key
This introduces a no-op `Unhasher` for map keys that are already hash-
like, for example `Fingerprint` and its wrapper `DefPathHash`. For these
we can directly produce the `u64` hash for maps. The first use of this
is `def_path_hash_to_def_id: Option<UnhashMap<DefPathHash, DefId>>`.
2020-09-01 18:27:02 -07:00
Tyler Mandry
56b5de2f29
Rollup merge of #76218 - petrochenkov:shebang3, r=matklad
lexer: Tiny improvement to shebang detection

Lexer now discerns between regular comments and doc comments, so use that.
The change only affects the choice of reported errors.
2020-09-01 18:24:46 -07:00
Tyler Mandry
4a6aa350c7
Rollup merge of #76158 - mati865:self-contained-option, r=petrochenkov
Stabilise link-self-contained option

MCP has been accepted: https://github.com/rust-lang/compiler-team/issues/343

I'll add improved heuristic in next PR.
2020-09-01 18:24:36 -07:00
Tyler Mandry
b01d0b1414
Rollup merge of #76143 - jyn514:duplicate-builtin-macros, r=petrochenkov
Give a better error message for duplicate built-in macros

Minor follow-up to https://github.com/rust-lang/rust/pull/75176 giving a better error message for duplicate builtin macros. This would have made it a little easier to debug.

r? @petrochenkov
2020-09-01 18:24:35 -07:00
Tyler Mandry
738b8eadfd
Rollup merge of #76132 - Aaron1011:mac-call-stmt, r=petrochenkov
Factor out StmtKind::MacCall fields into `MacCallStmt` struct

In PR #76130, I add a fourth field, which makes using a tuple variant
somewhat unwieldy.
2020-09-01 18:24:33 -07:00
Tyler Mandry
5f28831a40
Rollup merge of #76074 - richkadel:llvm-coverage-map-gen-6b.5.1, r=wesleywiser
Add new `-Z dump-mir-spanview` option

Similar to `-Z dump-mir-graphviz`, this adds the option to write
HTML+CSS files that allow users to analyze the spans associated with MIR
elements (by individual statement, just terminator, or overall basic
block).

This PR was split out from PR #76004, and exposes an API for spanview
HTML+CSS files that is also used to analyze code regions chosen for
coverage instrumentation (in a follow-on PR).

Rust compiler MCP rust-lang/compiler-team#278

Relevant issue: #34701 - Implement support for LLVMs code coverage
instrumentation

r? @tmandry
FYI @wesleywiser
2020-09-01 18:24:25 -07:00
Tomasz Miąsko
6c51ec96bb inliner: Avoid query cycles when optimizing generators
The HIR Id trick is insufficient to prevent query cycles when optimizing
generators, since merely requesting a layout of a generator also
computes its `optimized_mir`.

Make no attempts to inline functions into generators within the same
crate to avoid query cycles.
2020-09-02 00:00:00 +00:00
Vadim Petrochenkov
b1491eacfc lexer: Tiny improvement to shebang detection
Lexer now discerns between regular comments and doc comments, so use that.
The change only affects the choice of reported errors.
2020-09-02 00:40:19 +03:00
marmeladema
99c96c5bfe driver: replace lazy_static by SyncLazy from std 2020-09-01 22:06:47 +01:00
marmeladema
73a7204983 feature: replace lazy_static by SyncLazy from std 2020-09-01 22:06:47 +01:00
marmeladema
67b8f9491c hir: replace lazy_static by SyncLazy from std 2020-09-01 22:06:47 +01:00
marmeladema
1b650d0fea datastructures: replace lazy_static by SyncLazy from std 2020-09-01 22:06:47 +01:00
marmeladema
bd49eec3d7 interface: use OnceCell from standard library 2020-09-01 22:06:39 +01:00
bors
130359cb05 Auto merge of #76010 - Aaron1011:fix/cfg-generic-param, r=petrochenkov
Run cfg-stripping on generic parameters before invoking derive macros

Fixes #75930

This changes the tokens seen by a proc-macro. However, ising a `#[cfg]` attribute
on a generic paramter is unusual, and combining it with a proc-macro
derive is probably even more unusual. I don't expect this to cause any
breakage.
2020-09-01 20:03:55 +00:00
Mateusz Mikuła
770231e54d Replace MinGW library hack with heuristic controlling link mode 2020-09-01 19:52:39 +02:00
bors
397db054cb Auto merge of #75529 - bugadani:bounds-check, r=nagisa
Eliminate some other bound checks when index comes from an enum

#36962 introduced an assumption for the upper limit of the enum's value. This PR adds an assumption to the lower value as well.

I've modified the original codegen test to show that derived (in that case, adding 1) values also don't generate bounds checks.

However, this test is actually carefully crafted to not hit a bug: if the enum's variants are modified to 1 and 2 instead of 2 and 3, the test fails by adding a bounds check. I suppose this is an LLVM issue and #75525, while not exactly in this context should be tracking it.

I'm not at all confident if this patch can be accepted, or even if it _should_ be accepted in this state. But I'm curious about what others think :)

~Improves~ Should improve #13926 but does not close it because it's not exactly predictable, where bounds checks may pop up against the assumptions.
2020-09-01 13:36:52 +00:00
Joshua Nelson
be2947d0b7 Give a better error message for duplicate built-in macros
Previously, this would say no such macro existed, but this was
misleading, since the macro _did_ exist, it was just already seen.

- Say where the macro was previously defined
- Add long-form error message
2020-09-01 08:34:17 -04:00
Aleksey Kladov
fabd8a6834 Simplify TokenTreesReader
This `joint_to_prev` bit of state is no longer needed.
2020-09-01 11:46:49 +02:00
Aleksey Kladov
5326361fc0 Remove trivia tokens 2020-09-01 11:39:11 +02:00
Aleksey Kladov
8f24c2ec9d Don't emit trivia tokens 2020-09-01 11:39:11 +02:00
bors
6f1bbf5ee0 Auto merge of #76071 - khyperia:configurable_to_immediate, r=eddyb
Make to_immediate/from_immediate configurable by backends

`librustc_codegen_ssa` has the concept of an immediate vs. memory type, and `librustc_codegen_llvm` uses this distinction to implement `bool`s being `i8` in memory, and `i1` in immediate contexts. However, some of that implementation leaked into `codegen_ssa` when converting to/from immediate values. So, move those methods into builder traits, so that behavior can be configured by backends.

This is useful if a backend is able to keep bools as bools, or, needs to do more trickery than just bools to bytes.

(Note that there's already a large amount of things abstracted with "immediate types" - this is just bringing this particular thing in line to be abstracted as well)

---

Pinging @eddyb since that's who I was talking about this change with when they suggested I submit a PR.
2020-09-01 07:44:34 +00:00
Rich Kadel
6b5869a0ae Add new -Z dump-mir-spanview option
Similar to `-Z dump-mir-graphviz`, this adds the option to write
HTML+CSS files that allow users to analyze the spans associated with MIR
elements (by individual statement, just terminator, or overall basic
block).

This PR was split out from PR #76004, and exposes an API for spanview
HTML+CSS files that is also used to analyze code regions chosen for
coverage instrumentation (in a follow-on PR).

Rust compiler MCP rust-lang/compiler-team#278

Relevant issue: #34701 - Implement support for LLVMs code coverage
instrumentation
2020-08-31 22:57:55 -07:00
Tyler Mandry
8d328d785f
Rollup merge of #76178 - matklad:et, r=Mark-Simulacrum
Update expect-test to 1.0

The only change is that `expect_file` now uses path relative to the
current file (same as `include!`). Before, it used paths relative to
the workspace root, which makes no sense.
2020-08-31 19:18:31 -07:00
Tyler Mandry
90e4bfa952
Rollup merge of #76166 - matklad:privatereader, r=petrochenkov
Make `StringReader` private

r? @ghost

closes #75619
2020-08-31 19:18:28 -07:00
Tyler Mandry
9df193b6b2
Rollup merge of #76161 - pickfire:patch-3, r=pickfire
Remove notrust in rustc_middle

Fix #19599

This confuse people, no trust or not rust?
Or not rust no trust? Only trust rust ^^

Superseeds https://github.com/rust-lang/rust/pull/76063
r? @matklad
2020-08-31 19:18:24 -07:00
Tyler Mandry
4f276202f5
Rollup merge of #76103 - GuillaumeGomez:cleanup-e0769, r=Dylan-DPC
Clean up E0769

r? @pickfire

cc @Dylan-DPC
2020-08-31 19:18:19 -07:00
Tyler Mandry
5033203121
Rollup merge of #76059 - GuillaumeGomez:cleanup-e0764, r=Dylan-DPC,pickfire
Clean up E0764

r? @Dylan-DPC
2020-08-31 19:18:18 -07:00
Tyler Mandry
934127cca5
Rollup merge of #76003 - richkadel:llvm-coverage-map-gen-6b.4, r=wesleywiser
Adds two source span utility functions used in source-based coverage

`span.is_empty()` - returns true if `lo()` and `hi()` are equal. This is
not only a convenience, but makes it clear that a `Span` can be empty
(that is, retrieving the source for an empty `Span` will return an empty
string), and codifies the (otherwise undocumented--in the rustc_span
package, at least) fact that `Span` is a half-open interval (where
`hi()` is the open end).

`source_map.lookup_file_span()` - returns an enclosing `Span`
representing the start and end positions of the file enclosing the given
`BytePos`. This gives developers a clear way to quickly determine if any
any other `BytePos` or `Span` is also from the same file (for example,
by simply calling `file_span.contains(span)`).

This results in much simpler code and is much more runtime efficient
compared with the obvious alternative: calling `source_map.lookup_line()`
for any two `Span`'s byte positions, handle both arms of the `Result`
(both contain the file), and then compare files. It is also more
efficient than the non-public method `lookup_source_file_idx()` for each
`BytePos`, because, while comparing the internal source file indexes
would be efficient, looking up the source file index for every `BytePos`
or `Span` to be compared requires a binary search (worst case
performance being O(log n) for every lookup).

`source_map.lookup_file_span()` performs the binary search only once, to
get the `file_span` result that can be used to compare to any number of
other `BytePos` or `Span` values and those comparisons are always O(1).

This PR was split out from PR #75828 .

r? @tmandry
FYI: @wesleywiser
2020-08-31 19:18:16 -07:00
Tyler Mandry
6d834a4046
Rollup merge of #76002 - richkadel:llvm-coverage-map-gen-6b.3, r=tmandry
Fix `-Z instrument-coverage` on MSVC

Found that `-C link-dead-code` (which was enabled automatically
under `-Z instrument-coverage`) was causing the linking error that
resulted in segmentation faults in coverage instrumented binaries. Link
dead code is now disabled under MSVC, allowing `-Z instrument-coverage`
to be enabled under MSVC for the first time.

More details are included in Issue #76038 .

Note this PR makes it possible to support `Z instrument-coverage` but
does not enable instrument coverage for MSVC in existing tests. It will be
enabled in another PR to follow this one (both PRs coming from original
PR #75828).

r? @tmandry
FYI: @wesleywiser
2020-08-31 19:18:14 -07:00
Rich Kadel
7225f66887 Adds two source span utility functions used in source-based coverage
`span.is_empty()` - returns true if `lo()` and `hi()` are equal. This is
not only a convenience, but makes it clear that a `Span` can be empty
(that is, retrieving the source for an empty `Span` will return an empty
string), and codifies the (otherwise undocumented--in the rustc_span
package, at least) fact that `Span` is a half-open interval (where
`hi()` is the open end).

`source_map.lookup_file_span()` - returns an enclosing `Span`
representing the start and end positions of the file enclosing the given
`BytePos`. This gives developers a clear way to quickly determine if any
any other `BytePos` or `Span` is also from the same file (for example,
by simply calling `file_span.contains(span)`).

This results in much simpler code and is much more runtime efficient
compared with the obvious alternative: calling `source_map.lookup_line()`
for any two `Span`'s byte positions, handle both arms of the `Result`
(both contain the file), and then compare files. It is also more
efficient than the non-public method `lookup_source_file_idx()` for each
`BytePos`, because, while comparing the internal source file indexes
would be efficient, looking up the source file index for every `BytePos`
or `Span` to be compared requires a binary search (worst case
performance being O(log n) for every lookup).

`source_map.lookup_file_span()` performs the binary search only once, to
get the `file_span` result that can be used to compare to any number of
other `BytePos` or `Span` values and those comparisons are always O(1).
2020-08-31 18:41:57 -07:00
Rich Kadel
ddb054aee8 Fix -Z instrument-coverage on MSVC
Found that -C link-dead-code (which was enabled automatically
under -Z instrument-coverage) was causing the linking error that
resulted in segmentation faults in coverage instrumented binaries. Link
dead code is now disabled under MSVC, allowing `-Z instrument-coverage`
to be enabled under MSVC for the first time.

More details are included in Issue #76038.

(This PR was broken out from PR #75828)
2020-08-31 18:41:13 -07:00
bors
d824b23514 Auto merge of #75931 - estebank:suggest-if-let, r=petrochenkov
Suggest `if let x = y` when encountering `if x = y`

Detect potential cases where `if let` was meant but `let` was left out.

Fix #44990.
2020-09-01 00:26:01 +00:00
Aleksey Kladov
5716c3e18d Update expect-test to 1.0
The only change is that `expect_file` now uses path relative to the
current file (same as `include!`). Before, it used paths relative to
the workspace root, which makes no sense.
2020-08-31 21:04:09 +02:00
Guillaume Gomez
153f966d00 Clean up E0764 explanation 2020-08-31 20:14:37 +02:00
Guillaume Gomez
f3ae96ecd5 Clean up E0769 explanation 2020-08-31 20:10:57 +02:00
bors
1d22f75c9f Auto merge of #76030 - davidtwco:fewer-names-llvm-type-of, r=eddyb
cg_llvm: `fewer_names` in `uncached_llvm_type`

This PR changes `uncached_llvm_type` so that a named struct type (with an empty name) is always created when the `fewer_names` option is enabled. By skipping the generation of names, we can improve perf. Giving `LLVMStructCreateNamed` an empty name works because LLVM will perform random renames to avoid collisions. Needs a perf run!

cc @eddyb (whom I've discussed this with)
2020-08-31 18:04:29 +00:00
Aleksey Kladov
30ce15f1fa Make StringReader private
After the recent refactorings, we can actually completely hide this
type. It should help with #63689.
2020-08-31 18:01:01 +02:00
Ivan Tham
85a400d44e
Remove notrust in rustc_middle
Fix #19599

This confuse people, no trust or not rust?
Or not rust no trust? Only trust rust ^^
2020-08-31 22:10:09 +08:00
Aleksey Kladov
d8eb30127b
Rollup merge of #76115 - calebcartwright:parser-fn-visibility, r=matklad
Restore public visibility on some parsing functions for rustfmt

In #74826 the visibility of several parsing functions was reduced. However, rustfmt is an external consumer of some of these functions as well and needs the visibility to be public, similar to other elements in rustc_parse such as `parse_ident`

db534b3ac2/src/librustc_parse/parser/mod.rs (L433-L436)
2020-08-31 15:22:43 +02:00
Aleksey Kladov
67f16431aa
Rollup merge of #76075 - marmeladema:remove-once-cell-crate, r=matklad
datastructures: replace `once_cell` crate with an impl from std

Fixes #75700

r? @matklad

We might need a perf run for this change.
2020-08-31 15:22:42 +02:00
Aleksey Kladov
7d2460e5c4
Rollup merge of #76050 - matklad:pos, r=petrochenkov
Remove unused function
2020-08-31 15:22:40 +02:00
Mateusz Mikuła
23f0ccfe5d Stabilise link-self-contained option 2020-08-31 15:13:31 +02:00
David Wood
fa01ce802f
cg_llvm: fewer_names in uncached_llvm_type
This commit changes `uncached_llvm_type` so that a named struct type
(with an empty name) is always created when the `fewer_names` option
is enabled. By skipping the generation of names, we can improve perf.
Giving `LLVMStructCreateNamed` an empty name works because LLVM will
perform random renames to avoid collisions.

Signed-off-by: David Wood <david@davidtw.co>
2020-08-31 11:20:52 +01:00