Commit Graph

9623 Commits

Author SHA1 Message Date
Mateusz Mikuła
770231e54d Replace MinGW library hack with heuristic controlling link mode 2020-09-01 19:52:39 +02:00
Kornel
7ec1de062a Clarify message about unresolved use 2020-09-01 18:38:14 +01:00
Mark Rousskov
e023158145 Permit uninhabited enums to cast into ints
This essentially reverts part of #6204.
2020-09-01 10:01:28 -04: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
jumbatm
5956254172 Fix typos in E0224 2020-09-01 23:05:56 +10:00
jumbatm
57edf88b40 Replace some trivial struct_span_err!s in typeck. 2020-09-01 23:05:56 +10: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
jumbatm
93eaf15646 Add SessionDiagnostic derive macro.
Co-authored-by: Oliver Scherer <github35764891676564198441@oli-obk.de>
2020-09-01 22:02:45 +10: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
Mateusz Mikuła
0ad3da0684 Enable ASLR for windows-gnu 2020-08-31 10:36:50 +02:00
Ralf Jung
97974e3cab only emit error for ManuallyDrop derefs 2020-08-31 10:14:31 +02:00
Ralf Jung
44defaea3a also detect DerefMut in nested union fields 2020-08-31 10:14:30 +02:00
Ralf Jung
ec0924f964 do not apply DerefMut on union field 2020-08-31 10:14:29 +02:00
Dániel Buga
c88b167f15 Additional assumption to elide bounds check 2020-08-31 08:19:15 +02:00
bors
8ed5cb56b5 Auto merge of #76027 - davidtwco:issue-61139-remove-obsolete-pretty-printer, r=eddyb
ty: remove obsolete pretty printer

Fixes #61139.

This PR removes the obsolete printer and replaces all uses of it with `FmtPrinter`. Of the replaced uses, all but one use was in `debug!` logging, two cases were notable:

- `MonoItem::to_string` is used in `-Z print-mono-items` and therefore affects the output of all codegen-units tests (which have been updated).
- `DefPathBasedNames` was used in `librustc_codegen_llvm/type_of.rs` with `LLVMStructCreateNamed` and that'll now get different values, but nothing will break as a result of this.

cc @eddyb (whom I've discussed this with)
2020-08-31 05:32:54 +00:00
bors
e98f0632bb Auto merge of #75082 - Aaron1011:feature/proc-macro-backtrace, r=petrochenkov
Add `-Z proc-macro-backtrace` to allow showing proc-macro panics

Fixes #75050

Previously, we would unconditionally suppress the panic hook during
proc-macro execution. This commit adds a new flag
`-Z proc-macro-backtrace`, which allows running the panic hook for
easier debugging.
2020-08-31 03:19:05 +00:00
Aaron Hill
d9208665b5
Add -Z proc-macro-backtrace to allow showing proc-macro panics
Fixes #75050

Previously, we would unconditionally suppress the panic hook during
proc-macro execution. This commit adds a new flag
-Z proc-macro-backtrace, which allows running the panic hook for
easier debugging.
2020-08-30 22:17:24 -04:00
bors
022e1fe235 Auto merge of #74668 - petrochenkov:noname, r=mark-i-m
cleanup: Remove duplicate library names from `Cargo.toml`s
2020-08-30 23:14:05 +00:00
Aaron Hill
090b16717a
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-08-30 18:38:53 -04:00
Esteban Küber
07112ca62d 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-08-30 15:01:06 -07:00
Dylan MacKenzie
b015109ba9 Add documentation to the Analysis traits 2020-08-30 14:26:04 -07:00
Dylan MacKenzie
e178a87036 Expand documentation for the lattice module 2020-08-30 13:27:07 -07:00
Sasha
f6d18db402 Use string literal directly when available in format
Previous implementation used the `Parser::parse_expr` function in order
to extract the format expression. If the first comma following the
format expression was mistakenly replaced with a dot, then the next
format expression was eaten by the function, because it looked as a
syntactically valid expression, which resulted in incorrectly spanned
error messages.

The way the format expression is exctracted is changed: we first look at
the first available token in the first argument supplied to the
`format!` macro call. If it is a string literal, then it is promoted as
a format expression immediatly, otherwise we fall back to the original
`parse_expr`-related method.

This allows us to ensure that the parser won't consume too much tokens
when a typo is made.

A test has been created so that it is ensured that the issue is properly
fixed.
2020-08-30 22:09:58 +02:00
Vadim Petrochenkov
7dfbf59f10 cleanup: Remove duplicate library names from Cargo.tomls 2020-08-30 22:57:54 +03:00
Wim Looman
fc8a3ad66c Update for moved function from #74932 2020-08-30 21:51:30 +02:00
kadmin
8894b366fd Remove error message in specific case
In the case that a trait is not implemented for an ADT with type errors, cancel the error.
2020-08-30 19:39:51 +00:00
marmeladema
68500ffacb datastructures: replace once_cell crate with an impl from std 2020-08-30 20:06:14 +01:00
Erik Desjardins
24e0913e37 handle vector layout 2020-08-30 14:58:03 -04:00
Erik Desjardins
68217c9e0f ignore zst offsets instead 2020-08-30 14:58:03 -04:00
Erik Desjardins
e5d85f917b allow reordering of the last field of a MaybeUnsized struct if it's a ZST 2020-08-30 14:58:03 -04:00
Wim Looman
7636de33cf Point to no_mangle/export_name attribute when linting 2020-08-30 20:16:23 +02:00
Wim Looman
9ed3661427 Add note about why no_mangle and export_name are unsafe 2020-08-30 20:16:23 +02:00
Wim Looman
79b0ab5195 Scope no_mangle and export_name warnings to the declarations name 2020-08-30 20:16:23 +02:00
Wim Looman
66b2f9acfc Add checking for export_name to unsafe_code lint 2020-08-30 20:16:22 +02:00
Wim Looman
06a0269c11 Add checking for no_mangle to unsafe_code lint 2020-08-30 20:16:22 +02:00
Dylan MacKenzie
c03eba2d08 Add FIXME for faster cached block transfer functions
I've tried a few ways of implementing this, but each fell short.

Adding an auxiliary `_Idx` associated type to `Analysis` that defaults
to `!` but is overridden in the blanket impl of `Analysis` for `A:
GenKillAnalysis` to `A::Idx` seems promising, but the trait solver is
unable to prove equivalence between `A::Idx` and `A::_Idx` within the
overridden version of `into_engine`. Without full-featured
specialization, removing `into_engine` or splitting it into a different
trait would have a significant ergonomic penalty.

Alternatively, we could erase the index type and store a
`GenKillSet<u32>` as well as a function pointer for transmuting between
`&mut A::Domain` and `&mut BitSet<u32>` in the hopes that LLVM can
devirtualize a simple function pointer better than the boxed closure.
However, this is brittle, requires `unsafe` code, and doesn't work for
index types that aren't the same size as a `u32` (e.g. `usize`) since
`GenKillSet` stores a `HybridBitSet`, which may be a `Vec<I>`. Perhaps
safe transmute could help here?
2020-08-30 11:15:25 -07:00
Dylan MacKenzie
b19b8ea611 Update dataflow analyses to use new interface 2020-08-30 11:15:25 -07:00
Dylan MacKenzie
3233fb18a8 Extend dataflow framework to support arbitrary lattices 2020-08-30 11:15:24 -07:00
Dylan MacKenzie
9e45e90596 Allow access to the underlying Results from a ResultsCursor 2020-08-30 11:15:24 -07:00
Dylan MacKenzie
a88dc37c54 Add regex dependency to librustc_mir 2020-08-30 11:15:21 -07:00
Dylan MacKenzie
149307efb7 Improve BitSet APIs
A few small cleanups to `BitSet` and friends:

- Overload `clone_from` for `BitSet`.
- Improve `Debug` represenation of `HybridBitSet`.
- Make `HybridBitSet::domain_size` public.
- Don't require `T: Idx` at the type level. The `Idx` bound is still on
  most `BitSet` methods, but like `HashMap`, it doesn't need to be
  satisfied for the type to exist.
2020-08-30 11:13:18 -07:00
Caleb Cartwright
883b1e7592 parser: restore some fn visibility for rustfmt 2020-08-30 13:04:36 -05:00
David Wood
6ff471b1cf
ty: remove obsolete printer
This commit removes the obsolete printer and replaces all uses of it
with `FmtPrinter`. Of the replaced uses, all but one use was in `debug!`
logging, two cases were notable:

- `MonoItem::to_string` is used in `-Z print-mono-items` and therefore
  affects the output of all codegen-units tests.
- `DefPathBasedNames` was used in `librustc_codegen_llvm/type_of.rs`
  with `LLVMStructCreateNamed` and that'll now get different values, but
  this should result in no functional change.

Signed-off-by: David Wood <david@davidtw.co>
2020-08-30 18:59:07 +01:00
David Wood
0f2bd56b29
lint/ty: move fns to avoid abstraction violation
This commit moves `transparent_newtype_field` and `is_zst` to
`LateContext` where they are used, rather than being on the `VariantDef`
and `TyS` types.

Signed-off-by: David Wood <david@davidtw.co>
2020-08-30 18:57:46 +01:00
Aleksey Kladov
518cac9190 Remove unused function 2020-08-30 19:54:45 +02:00
Aleksey Kladov
ccffea5b6b Move lexer unit tests to rustc_lexer
StringReader is an intornal abstraction which at the moment changes a
lot, so these unit tests cause quite a bit of friction.

Moving them to rustc_lexer and more ingerated-testing style should
make them much less annoying, hopefully without decreasing their
usefulness much.

Note that coloncolon tests are removed (it's unclear what those are
testing).

\r\n tests are removed as well, as we normalize line endings even
before lexing.
2020-08-30 19:53:36 +02:00
Aaron Hill
a97dcfa375
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-08-30 13:46:19 -04:00
mark
9e5f7d5631 mv compiler to compiler/ 2020-08-30 18:45:07 +03:00