Commit graph

2130 commits

Author SHA1 Message Date
bors 98d66340d6 Auto merge of #78809 - vn-ki:fix-issue-76064, r=oli-obk
add error_occured field to ConstQualifs,

fix #76064

I wasn't sure what `in_return_place` actually did and not sure why it returns `ConstQualifs` while it's sibling functions return `bool`. So I tried to make as minimal changes to the structure as possible. Please point out whether I have to refactor it or not.

r? `@oli-obk`
cc `@RalfJung`
2020-11-14 18:03:17 +00:00
Fabian Zaiser 8cf3564310 Add underscore expressions for destructuring assignments
Co-authored-by: varkor <github@varkor.com>
2020-11-14 13:53:12 +00:00
bors 66c1309446 Auto merge of #78959 - petrochenkov:likeuefi, r=nagisa
rustc_target: Mark UEFI targets as `is_like_windows`/`is_like_msvc`

And document what `is_like_windows` and `is_like_msvc` actually mean in more detail.

Addresses FIXMEs left from https://github.com/rust-lang/rust/pull/71030.
r? `@nagisa`
2020-11-14 09:11:25 +00:00
bors 1a25580c6c Auto merge of #78951 - petrochenkov:unknown, r=ehuss
rustc_target: Change os and vendor values to "none" and "unknown" for some targets

Closes https://github.com/rust-lang/rust/issues/77730
r? `@ehuss`
2020-11-14 06:44:18 +00:00
bors 50d3c2a3cb Auto merge of #78736 - petrochenkov:lazyenum, r=Aaron1011
rustc_parse: Remove optimization for 0-length streams in `collect_tokens`

The optimization conflates empty token streams with unknown token stream, which is at least suspicious, and doesn't affect performance because 0-length token streams are very rare.

r? `@Aaron1011`
2020-11-14 04:21:56 +00:00
Camille GILLOT 41c44b498f Move Steal to rustc_data_structures. 2020-11-14 01:30:56 +01:00
Tomasz Miąsko 6903273339 Lower intrinsics calls: forget, size_of, unreachable, wrapping_*
This allows constant propagation to evaluate `size_of` and `wrapping_*`,
and unreachable propagation to propagate a call to `unreachable`.

The lowering is performed as a MIR optimization, rather than during MIR
building to preserve the special status of intrinsics with respect to
unsafety checks and promotion.
2020-11-14 00:00:00 +00:00
Vadim Petrochenkov ac4c1f58b9 rustc_resolve: Make macro_rules scope chain compression lazy 2020-11-14 00:35:56 +03:00
Aman Arora c50e57f946 Log closure as well 2020-11-13 16:10:12 -05:00
Camelid 7eb1a1afcf Validate that locals have a corresponding LocalDecl 2020-11-13 12:54:42 -08:00
Bastian Kauschke 06c9c599ed lessen restriction in check_kind_count 2020-11-13 19:12:49 +01:00
Bastian Kauschke 49c0b318df tbh what 2020-11-13 18:56:39 +01:00
Rich Kadel b4b0ef3e4b Addressed feedback 2020-11-13 09:07:39 -08:00
bors f2a11a2537 Auto merge of #79017 - GuillaumeGomez:rollup-5orhudd, r=GuillaumeGomez
Rollup of 6 pull requests

Successful merges:

 - #77151 (Add regression test for issue #76042)
 - #77996 (Doc change: Remove mention of `fnv` in HashMap)
 - #78463 (Add type to `ConstKind::Placeholder`)
 - #78984 (Rustdoc check option)
 - #78985 (add dropck test for const params)
 - #78996 (add explicit test for const param promotion)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2020-11-13 14:53:55 +00:00
Bastian Kauschke 894b1f7d3d extract closures into a separate trait 2020-11-13 15:49:17 +01:00
Guillaume Gomez 0b7a7930b4
Rollup merge of #78463 - varkor:placeholder-const, r=nikomatsakis
Add type to `ConstKind::Placeholder`

I simply threaded `<'tcx>` through everything that required it. I'm not sure whether this is the correct thing to do, but it seems to work.

r? `@nikomatsakis`
2020-11-13 15:26:14 +01:00
Dániel Buga f0d0d87a20 Push to result vector instead of allocating
Co-authored-by: lcnr <bastian_kauschke@hotmail.de>
2020-11-13 11:19:25 +01:00
Dániel Buga 45faeb43ae Reuse vector 2020-11-13 11:19:25 +01:00
Dániel Buga a7f2bb6343 Reserve space in advance 2020-11-13 11:19:25 +01:00
Dániel Buga 2ca0b85593 Allocate less in lower_block_noalloc 2020-11-13 11:19:25 +01:00
Dániel Buga 660d8a6550 Eliminate some temporary vectors & Remove unnecessary mark_attr_used 2020-11-13 11:19:23 +01:00
bors a38f8fb674 Auto merge of #78826 - petrochenkov:mrscopes2, r=eddyb
resolve: Collapse `macro_rules` scope chains on the fly

Otherwise they grow too long and you have to endlessly walk through them when resolving macros or imports.
Addresses https://rust-lang.zulipchat.com/#narrow/stream/247081-t-compiler.2Fperformance/topic/Slow.20Builtin.20Derives/near/215750815
2020-11-13 05:40:37 +00:00
J. Ryan Stinnett bd0fba207b Clean up outdated use_once_payload pretty printer comment
While reading some parts of the pretty printer code, I noticed this old comment
which seemed out of place. The `use_once_payload` this outdated comment mentions
was removed in 2017 in 40f03a1e0d, so this
completes the work by removing the comment.
2020-11-13 05:34:03 +00:00
Rich Kadel c131063988 Added a unit test for BcbCounters
Restructured the code a little, to allow getting both the mir::Body and
coverage graph.
2020-11-12 16:22:25 -08:00
Vadim Petrochenkov 8766c0452c cleanup: Remove ParseSess::injected_crate_name 2020-11-13 00:59:57 +03:00
Tomasz Miąsko 99be78d135 Always use param_env_reveal_all_normalized in validator 2020-11-12 20:57:43 +01:00
Tomasz Miąsko d486bfcbff Normalize function type during validation
During inlining, the callee body is normalized and has types revealed,
but some of locals corresponding to the arguments might come from the
caller body which is not. As a result the caller body does not pass
validation without additional normalization.
2020-11-12 20:57:43 +01:00
Vadim Petrochenkov 909c8945b1 stability: More precise location for deprecation lint on macros 2020-11-12 22:53:42 +03:00
Tomasz Miąsko 79d853ecce Never inline C variadic functions 2020-11-12 20:09:04 +01:00
Tomasz Miąsko 66cadec176 Fix generator inlining by checking for rust-call abi and spread arg 2020-11-12 20:09:04 +01:00
Vadim Petrochenkov 2879ab793e rustc_parse: Remove optimization for 0-length streams in collect_tokens
The optimization conflates empty token streams with unknown token stream, which is at least suspicious, and doesn't affect performance because 0-length token streams are very rare.
2020-11-12 22:00:48 +03:00
Tomasz Miąsko 9bb3d6b7d4 Remove check for impossible condition
The callee body is already transformed; the condition is always false.
2020-11-12 19:52:03 +01:00
Tomasz Miąsko ae4332643d Never inline cold functions
The information about cold attribute is lost during inlining,
Avoid the issue by never inlining cold functions.
2020-11-12 19:52:03 +01:00
Tomasz Miąsko 0b4af1614d Never inline when no_sanitize attributes differ
The inliner looks if a sanitizer is enabled before considering
`no_sanitize` attribute as possible source of incompatibility.

The MIR inlining could happen in a crate with sanitizer disabled, but
code generation in a crate with sanitizer enabled, thus the attribute
would be incorrectly ignored.

To avoid the issue never inline functions with different `no_sanitize`
attributes.
2020-11-12 19:52:03 +01:00
Mara Bos 76fa5f25ab
Rollup merge of #78950 - khyperia:spirv-asm, r=Amanieu
Add asm register information for SPIR-V

As discussed in [zulip](https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Defining.20asm!.20for.20new.20architecture), we at [rust-gpu](https://github.com/EmbarkStudios/rust-gpu) would like to support `asm!` for our SPIR-V backend. However, we cannot do so purely without frontend support: [this match](d4ea0b3e46/compiler/rustc_target/src/asm/mod.rs (L185)) fails and so `asm!` is not supported ([error reported here](d4ea0b3e46/compiler/rustc_ast_lowering/src/expr.rs (L1095))). To resolve this, we need to stub out register information for SPIR-V to support getting the `asm!` content all the way to [`AsmBuilderMethods::codegen_inline_asm`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_codegen_ssa/traits/trait.AsmBuilderMethods.html#tymethod.codegen_inline_asm), at which point the rust-gpu backend can do all the parsing and codegen that is needed.

This is a pretty weird PR - adding support for a backend that isn't in-tree feels pretty gross to me, but I don't see an easy way around this. ``@Amanieu`` said I should submit it anyway, so, here we are! Let me know if this needs to go through a more formal process (MCP?) and what I should do to help this along.

I based this off the [wasm asm PR](https://github.com/rust-lang/rust/pull/78684), which unfortunately this PR conflicts with that one quite a bit, sorry for any merge conflict pain :(

---

Some open questions:

- What do we call the register class? Some context, SPIR-V is an SSA-based IR, there are "instructions" that create IDs (referred to as `<id>` in the spec), which can be referenced by other instructions. So, `reg` isn't exactly accurate, they're SSA IDs, not re-assignable registers.
- What happens when a SPIR-V register gets to the LLVM backend? Right now it's a `bug!`, but should that be a `sess.fatal()`? I'm not sure if it's even possible to reach that point, maybe there's a check that prevents the `spirv` target from even reaching that codepath.
2020-11-12 19:46:14 +01:00
Mara Bos 755dd14e00
Rollup merge of #78836 - fanzier:struct-and-slice-destructuring, r=petrochenkov
Implement destructuring assignment for structs and slices

This is the second step towards implementing destructuring assignment (RFC: rust-lang/rfcs#2909, tracking issue: #71126). This PR is the second part of #71156, which was split up to allow for easier review.

Note that the first PR (#78748) is not merged yet, so it is included as the first commit in this one. I thought this would allow the review to start earlier because I have some time this weekend to respond to reviews. If ``@petrochenkov`` prefers to wait until the first PR is merged, I totally understand, of course.

This PR implements destructuring assignment for (tuple) structs and slices. In order to do this, the following *parser change* was necessary: struct expressions are not required to have a base expression, i.e. `Struct { a: 1, .. }` becomes legal (in order to act like a struct pattern).

Unfortunately, this PR slightly regresses the diagnostics implemented in #77283. However, it is only a missing help message in `src/test/ui/issues/issue-77218.rs`. Other instances of this diagnostic are not affected. Since I don't exactly understand how this help message works and how to fix it yet, I was hoping it's OK to regress this temporarily and fix it in a follow-up PR.

Thanks to ``@varkor`` who helped with the implementation, particularly around the struct rest changes.

r? ``@petrochenkov``
2020-11-12 19:46:09 +01:00
Mara Bos 4b0b42a280
Rollup merge of #76730 - ebkalderon:rustdoc-fix-mut-args-async-fn, r=tmandry
Fix rustdoc rendering of by-value mutable arguments in async fn

r? `@jyn514`

Fixes #76517.
2020-11-12 19:46:08 +01:00
Nadrieril b9da2b372f Factor out match usefulness computation in check_match
This make `_match` a lot more self-contained
2020-11-12 18:17:42 +00:00
Nadrieril d5a7ec0929 Unreachable subpatterns are rare
We may as well leave early when we know there's nothing to report.
2020-11-12 17:42:02 +00:00
Nadrieril b025813f03 Handle empty matches cleanly 2020-11-12 17:41:36 +00:00
Vadim Petrochenkov 04d41e1f40 rustc_target: Mark UEFI targets as is_like_windows/is_like_msvc
Document what `is_like_windows` and `is_like_msvc` mean in more detail.
2020-11-12 19:40:41 +03:00
Vadim Petrochenkov dd682cb48c rustc_target: Fix dash vs underscore mismatches in option names 2020-11-12 19:33:07 +03:00
Joshua Nelson 38127caf73 Handle and test wildcard arguments 2020-11-12 11:14:29 -05:00
Joshua Nelson 2baa0ceff4 Don't reuse bindings for ref mut
Reusing bindings causes errors later in lowering:

```
 error[E0596]: cannot borrow `vec` as mutable, as it is not declared as mutable
  --> /checkout/src/test/ui/async-await/argument-patterns.rs:12:20
   |
LL | async fn b(n: u32, ref mut vec: A) {
   |                    ^^^^^^^^^^^
   |                    |
   |                    cannot borrow as mutable
   |                    help: consider changing this to be mutable: `mut vec`
```
2020-11-12 11:13:05 -05:00
Eyal Kalderon 380b222f52 Consider mutable ident binding patterns to be simple
This should fix `rustdoc` rendering of by-value mutable arguments in
`async fn` contexts.
2020-11-12 11:13:05 -05:00
varkor e24a4b4690 Add type to ConstKind::Placeholder 2020-11-12 15:39:55 +00:00
Vishnunarayan K I 8119c4beee review comments 2020-11-12 21:08:18 +05:30
Vishnunarayan K I 5029a19313 check mir exists before validation; fix tests 2020-11-12 21:08:18 +05:30
Vishnunarayan K I 6781907444 fix tests and formatting 2020-11-12 21:08:18 +05:30
Vishnunarayan K I 8bce9af78c add error_occured field to ConstQualifs, fix #76064 2020-11-12 21:08:18 +05:30
bors 9722952f0b Auto merge of #76256 - tgnottingham:issue-74890, r=nikomatsakis
incr-comp: hash and serialize span end line/column

Hash both the length and the end location (line/column) of a span. If we
hash only the length, for example, then two otherwise equal spans with
different end locations will have the same hash. This can cause a
problem during incremental compilation wherein a previous result for a
query that depends on the end location of a span will be incorrectly
reused when the end location of the span it depends on has changed. A
similar analysis applies if some query depends specifically on the
length of the span, but we only hash the end location. So hash both.

Fix #46744, fix #59954, fix #63161, fix #73640, fix #73967, fix #74890, fix #75900

---

See #74890 for a more in-depth analysis.

I haven't thought about what other problems this root cause could be responsible for. Please let me know if anything springs to mind. I believe the issue has existed since the inception of incremental compilation.
2020-11-12 15:34:09 +00:00
DevJPM 86193ca91c fixed a re-format due to removed chain call 2020-11-12 14:40:41 +01:00
DevJPM 7e443c4282 Dropped Support for Bidirectional Custom Target Definition Emulation
as requested in the review and argued that this is only consistent with later LLVM upgrades
2020-11-12 14:39:47 +01:00
DevJPM 8236830209 Removed an unused function now that LLVM 9 is the minimal supported version
The function was only used in LLVM 8 compatibility code
and was found and flagged by dead code detection and now removed.
2020-11-12 14:39:47 +01:00
DevJPM b51bcc72d9 fully exploited the dropped support of LLVM 8
This commit grepped for LLVM_VERSION_GE, LLVM_VERSION_LT, get_major_version and
min-llvm-version and statically evaluated every expression possible
(and sensible) assuming that the LLVM version is >=9 now
2020-11-12 14:39:47 +01:00
thiolliere 775f1e5acd fix pretty print for qpath 2020-11-12 12:47:25 +01:00
Guillaume Gomez d3244df6b6
Rollup merge of #78933 - jyn514:tracing-output, r=oli-obk
Don't print thread ids and names in `tracing` logs

Before:

```
2:rustc INFO rustc_interface::passes Pre-codegen
2:rustcTy interner             total           ty lt ct all
2:rustc    Adt               :   1078 81.3%,  0.0%   0.0%  0.0%  0.0%
2:rustc    Array             :      1  0.1%,  0.0%   0.0%  0.0%  0.0%
2:rustc    Slice             :      1  0.1%,  0.0%   0.0%  0.0%  0.0%
2:rustc    RawPtr            :      2  0.2%,  0.0%   0.0%  0.0%  0.0%
2:rustc    Ref               :      4  0.3%,  0.1%   0.1%  0.0%  0.0%
2:rustc    FnDef             :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
2:rustc    FnPtr             :     76  5.7%,  0.0%   0.0%  0.0%  0.0%
2:rustc    Placeholder       :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
2:rustc    Generator         :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
2:rustc    GeneratorWitness  :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
2:rustc    Dynamic           :      3  0.2%,  0.0%   0.0%  0.0%  0.0%
2:rustc    Closure           :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
2:rustc    Tuple             :     13  1.0%,  0.0%   0.0%  0.0%  0.0%
2:rustc    Bound             :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
2:rustc    Param             :    146 11.0%,  0.0%   0.0%  0.0%  0.0%
2:rustc    Infer             :      2  0.2%,  0.1%   0.0%  0.0%  0.0%
2:rustc    Projection        :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
2:rustc    Opaque            :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
2:rustc    Foreign           :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
2:rustc                  total   1326         0.2%   0.1%  0.0%  0.0%
2:rustcInternalSubsts interner: #437
2:rustcRegion interner: #355
2:rustcStability interner: #1
2:rustcConst Stability interner: #0
2:rustcAllocation interner: #0
2:rustcLayout interner: #0
```

After:

```
 INFO rustc_interface::passes Post-codegen
Ty interner             total           ty lt ct all
    Adt               :   1078 81.3%,  0.0%   0.0%  0.0%  0.0%
    Array             :      1  0.1%,  0.0%   0.0%  0.0%  0.0%
    Slice             :      1  0.1%,  0.0%   0.0%  0.0%  0.0%
    RawPtr            :      2  0.2%,  0.0%   0.0%  0.0%  0.0%
    Ref               :      4  0.3%,  0.1%   0.1%  0.0%  0.0%
    FnDef             :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
    FnPtr             :     76  5.7%,  0.0%   0.0%  0.0%  0.0%
    Placeholder       :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
    Generator         :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
    GeneratorWitness  :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
    Dynamic           :      3  0.2%,  0.0%   0.0%  0.0%  0.0%
    Closure           :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
    Tuple             :     13  1.0%,  0.0%   0.0%  0.0%  0.0%
    Bound             :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
    Param             :    146 11.0%,  0.0%   0.0%  0.0%  0.0%
    Infer             :      2  0.2%,  0.1%   0.0%  0.0%  0.0%
    Projection        :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
    Opaque            :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
    Foreign           :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
                  total   1326         0.2%   0.1%  0.0%  0.0%
InternalSubsts interner: #437
Region interner: #355
Stability interner: #1
Const Stability interner: #0
Allocation interner: #0
Layout interner: #0
```

Closes https://github.com/rust-lang/rust/issues/78931
r? ``@oli-obk``
2020-11-12 11:31:49 +01:00
Rich Kadel eb9f2bb3b0 Overcome Sync issues with non-parallel compiler
Per Mark's recommendation at:
https://github.com/rust-lang/rust/pull/78963#issuecomment-725790071
2020-11-11 20:36:41 -08:00
Rune Tynan 1e9d5c70c1
Minor stylistic / review changes 2020-11-11 20:16:31 -05:00
Rich Kadel bd0eb07af2 Added some unit tests as requested
As discussed in PR #78267, for example:

* https://github.com/rust-lang/rust/pull/78267#discussion_r515404722
* https://github.com/rust-lang/rust/pull/78267#discussion_r515405958
2020-11-11 16:40:17 -08:00
bors 5a6a41e784 Auto merge of #78782 - petrochenkov:nodoctok, r=Aaron1011
Do not collect tokens for doc comments

Doc comment is a single token and AST has all the information to re-create it precisely.
Doc comments are also responsible for majority of calls to `collect_tokens` (with `num_calls == 1` and `num_calls == 0`, cc https://github.com/rust-lang/rust/pull/78736).

(I also moved token collection into `fn parse_attribute` to deduplicate code a bit.)

r? `@Aaron1011`
2020-11-12 00:33:55 +00:00
Rune Tynan 91eabf59d5
Add a sane error for rust-call functions not taking tuples during type checking, and associated UI tests 2020-11-11 18:15:39 -05:00
Jonas Schievink 904b658303
Rollup merge of #78930 - petrochenkov:notlikeandroid, r=Mark-Simulacrum
rustc_taret: Remove `TargetOptions::is_like_android`

This option was replaced by more specific options and is no longer used by the compiler.
2020-11-11 20:59:10 +01:00
Jonas Schievink 5ac0ae4ae4
Rollup merge of #78929 - petrochenkov:linuxbase, r=joshtriplett
rustc_target: Move target env "gnu" from `linux_base` to `linux_gnu_base`

Follow up to https://github.com/rust-lang/rust/pull/77729.

Changes the target spec hierarchy for Linux from
```
linux_base
├── linux_musl_base
└── linux_uclibc_base
```
where `linux_base` is really `linux_gnu_base` and the inheriting targets replace target env "gnu" with "musl"/"uclibc" to
```
linux_base
├── linux_gnu_base
├── linux_musl_base
└── linux_uclibc_base
```
which is slightly less confusing (I think).
2020-11-11 20:59:09 +01:00
Jonas Schievink 0b521e5c47
Rollup merge of #78899 - tmiasko:inline-diverging, r=oli-obk
Support inlining diverging function calls

The existing heuristic does penalize diverging calls to some degree, but since
it never inlined them previously it might need some further modifications.

Additionally introduce storage markers for all temporaries created by
the inliner. The temporary introduced for destination rebrorrow, didn't
use them previously.
2020-11-11 20:59:05 +01:00
Jonas Schievink 919177f7e4
Rollup merge of #78873 - tmiasko:inline-opts, r=oli-obk
Add flags customizing behaviour of MIR inlining

* `-Zinline-mir-threshold` to change the default threshold.
* `-Zinline-mir-hint-threshold` to change the threshold used by
  functions with inline hint.

Having those as configurable flags makes it possible to experiment with with
different inlining thresholds and substantially increase test coverage of MIR
inlining when used with increased thresholds (for example, necessary to test
#78844).
2020-11-11 20:59:03 +01:00
Jonas Schievink 2e0a0b42ad
Rollup merge of #78832 - lcnr:const-evaluatable-unevaluated, r=oli-obk
look at assoc ct, check the type of nodes

an example where types matter are function objects, see the added test which previously passed.

Now does a shallow comparison of unevaluated constants.

r? ```@oli-obk```
2020-11-11 20:59:02 +01:00
Joshua Nelson 6e9ed8b486 Enable thread names in debug logging only for parallel_compiler 2020-11-11 13:28:30 -05:00
khyperia 0e34b73996 Change capitalization of Spirv to SpirV
This matches the capitalization of RiscV
2020-11-11 19:18:06 +01:00
Vadim Petrochenkov e0a8f22053 rustc_target: Make sure that in-tree targets follow conventions for os and vendor values 2020-11-11 20:59:37 +03:00
Vadim Petrochenkov 1def24c5f4 rustc_target: Normalize vendor from "" to "unknown" for all targets
Majority of targets use "unknown" vendor and changing it from "unknown" to omitted doesn't make sense.
From the LLVM docs (https://clang.llvm.org/docs/CrossCompilation.html#target-triple):

>Most of the time it can be omitted (and Unknown) will be assumed, which sets the defaults for the specified architecture.
>When a parameter is not important, it can be omitted, or you can choose unknown and the defaults will be used. If you choose a parameter that Clang doesn’t know, like blerg, it’ll ignore and assume unknown
2020-11-11 20:40:51 +03:00
Vadim Petrochenkov 443b45fa9f rustc_target: Change os from "unknown" to "none" for bare metal targets
x86_64-fortanix-unknown-sgx and wasm32-unknown-unknown still have os == "unknown" because both have libstd
2020-11-11 20:24:14 +03:00
khyperia f3441348e0 Add asm register information for SPIR-V 2020-11-11 17:38:02 +01:00
Fabian Zaiser de84ad95b4 Implement destructuring assignment for structs and slices
Co-authored-by: varkor <github@varkor.com>
2020-11-11 12:10:52 +00:00
Vadim Petrochenkov ca17a91fb7 rustc_target: Move target env "gnu" from linux_base to linux_gnu_base 2020-11-11 11:38:40 +03:00
Nicholas-Baron 261ca04c92 Changed unwrap_or to unwrap_or_else in some places.
The discussion seems to have resolved that this lint is a bit "noisy" in
that applying it in all places would result in a reduction in
readability.

A few of the trivial functions (like `Path::new`) are fine to leave
outside of closures.

The general rule seems to be that anything that is obviously an
allocation (`Box`, `Vec`, `vec![]`) should be in a closure, even if it
is a 0-sized allocation.
2020-11-10 20:07:47 -08:00
Aman Arora deeb025f39 Address review comments 2 2020-11-10 20:58:58 -05:00
Aman Arora 43423f67a0 Address review comments 2020-11-10 20:58:57 -05:00
Aman Arora abc40040be Remove local testing env var 2020-11-10 20:58:57 -05:00
Aman Arora fa381600dc Handle let _ = x patterns in closure liveness analysis 2020-11-10 20:58:56 -05:00
Roxane Fruytier 825e9e45d1 Reduce verbosity of capture analysis logs
Co-authored-by: Jenny Wills <wills.jenniferg@gmail.com>
Co-authored-by: Aman Arora <me@aman-arora.com>
2020-11-10 20:58:55 -05:00
Aman Arora 8f0c0d656d Initial work for doing minimum capture analysis for RFC-2229
Co-authored-by: Chris Pardy <chrispardy36@gmail.com>
Co-authored-by: Logan Mosier <logmosier@gmail.com>
2020-11-10 20:58:54 -05:00
Aman Arora 145312075f Add helper function for Capture Esclations and expressions
Co-authored-by: Dhruv Jauhar <dhruvjhr@gmail.com>
2020-11-10 20:58:53 -05:00
Aman Arora 58e8f8fd2c Add initial set of testcases for RFC 2229
Co-authored-by: Dhruv Jauhar <dhruvjhr@gmail.com>
2020-11-10 20:58:52 -05:00
Aman Arora 88310cc0eb Indroduce feature flag for RFC-2229
Signed-off-by: Aman Arora <me@aman-arora.com>
2020-11-10 20:58:28 -05:00
Aman Arora 127a6ede1d Use Places to express closure/generator Captures
Co-authored-by: Archer Zhang <archer.xn@gmail.com>
2020-11-10 20:44:47 -05:00
Joshua Nelson 9cf8a49f5d Don't print thread ids and names in tracing logs
Before:

```
2:rustc INFO rustc_interface::passes Pre-codegen
2:rustcTy interner             total           ty lt ct all
2:rustc    Adt               :   1078 81.3%,  0.0%   0.0%  0.0%  0.0%
2:rustc    Array             :      1  0.1%,  0.0%   0.0%  0.0%  0.0%
2:rustc    Slice             :      1  0.1%,  0.0%   0.0%  0.0%  0.0%
2:rustc    RawPtr            :      2  0.2%,  0.0%   0.0%  0.0%  0.0%
2:rustc    Ref               :      4  0.3%,  0.1%   0.1%  0.0%  0.0%
2:rustc    FnDef             :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
2:rustc    FnPtr             :     76  5.7%,  0.0%   0.0%  0.0%  0.0%
2:rustc    Placeholder       :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
2:rustc    Generator         :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
2:rustc    GeneratorWitness  :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
2:rustc    Dynamic           :      3  0.2%,  0.0%   0.0%  0.0%  0.0%
2:rustc    Closure           :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
2:rustc    Tuple             :     13  1.0%,  0.0%   0.0%  0.0%  0.0%
2:rustc    Bound             :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
2:rustc    Param             :    146 11.0%,  0.0%   0.0%  0.0%  0.0%
2:rustc    Infer             :      2  0.2%,  0.1%   0.0%  0.0%  0.0%
2:rustc    Projection        :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
2:rustc    Opaque            :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
2:rustc    Foreign           :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
2:rustc                  total   1326         0.2%   0.1%  0.0%  0.0%
2:rustcInternalSubsts interner: #437
2:rustcRegion interner: #355
2:rustcStability interner: #1
2:rustcConst Stability interner: #0
2:rustcAllocation interner: #0
2:rustcLayout interner: #0
```

After:

```
 INFO rustc_interface::passes Post-codegen
Ty interner             total           ty lt ct all
    Adt               :   1078 81.3%,  0.0%   0.0%  0.0%  0.0%
    Array             :      1  0.1%,  0.0%   0.0%  0.0%  0.0%
    Slice             :      1  0.1%,  0.0%   0.0%  0.0%  0.0%
    RawPtr            :      2  0.2%,  0.0%   0.0%  0.0%  0.0%
    Ref               :      4  0.3%,  0.1%   0.1%  0.0%  0.0%
    FnDef             :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
    FnPtr             :     76  5.7%,  0.0%   0.0%  0.0%  0.0%
    Placeholder       :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
    Generator         :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
    GeneratorWitness  :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
    Dynamic           :      3  0.2%,  0.0%   0.0%  0.0%  0.0%
    Closure           :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
    Tuple             :     13  1.0%,  0.0%   0.0%  0.0%  0.0%
    Bound             :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
    Param             :    146 11.0%,  0.0%   0.0%  0.0%  0.0%
    Infer             :      2  0.2%,  0.1%   0.0%  0.0%  0.0%
    Projection        :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
    Opaque            :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
    Foreign           :      0  0.0%,  0.0%   0.0%  0.0%  0.0%
                  total   1326         0.2%   0.1%  0.0%  0.0%
InternalSubsts interner: #437
Region interner: #355
Stability interner: #1
Const Stability interner: #0
Allocation interner: #0
Layout interner: #0
```
2020-11-10 17:32:29 -05:00
Mara Bos aff7bd66e8 Merge set_panic and set_print into set_output_capture.
There were no use cases for setting them separately.
Merging them simplifies some things.
2020-11-10 21:58:13 +01:00
Mara Bos f534b75f05 Use Vec<u8> for LOCAL_STD{OUT,ERR} instead of dyn Write.
It was only ever used with Vec<u8> anyway. This simplifies some things.

- It no longer needs to be flushed, because that's a no-op anyway for
  a Vec<u8>.

- Writing to a Vec<u8> never fails.

- No #[cfg(test)] code is needed anymore to use `realstd` instead of
  `std`, because Vec comes from alloc, not std (like Write).
2020-11-10 21:58:09 +01:00
Mara Bos 72e96604c0 Remove io::LocalOutput and use Arc<Mutex<dyn>> for local streams. 2020-11-10 21:57:05 +01:00
Vadim Petrochenkov ce91c68943 rustc_taret: Remove TargetOptions::is_like_android 2020-11-10 23:51:34 +03:00
Jonas Schievink 1952f04a61
Rollup merge of #78890 - o752d:patch-2, r=jyn514
comment attribution fix

comment means to refer to the macro in its direct scope
2020-11-10 14:45:25 +01:00
Jonas Schievink a08e7afefd
Rollup merge of #78887 - camelid:dataflow-state-decl, r=jonas-schievink
Add comments to explain memory usage optimization

Add explanatory comments so that people understand that it's just an optimization and doesn't affect behavior.
2020-11-10 14:45:23 +01:00
Jonas Schievink 105f4b8792
Rollup merge of #78875 - petrochenkov:cleantarg, r=Mark-Simulacrum
rustc_target: Further cleanup use of target options

Follow up to https://github.com/rust-lang/rust/pull/77729.

Implements items 2 and 4 from the list in https://github.com/rust-lang/rust/pull/77729#issue-500228243.

The first commit collapses uses of `target.options.foo` into `target.foo`.

The second commit renames some target options to avoid tautology:
`target.target_endian` -> `target.endian`
`target.target_c_int_width` -> `target.c_int_width`
`target.target_os` -> `target.os`
`target.target_env` -> `target.env`
`target.target_vendor` -> `target.vendor`
`target.target_family` -> `target.os_family`
`target.target_mcount` -> `target.mcount`

r? `@Mark-Simulacrum`
2020-11-10 14:45:21 +01:00
Jonas Schievink 9c486882e5
Rollup merge of #78847 - tmiasko:inline-return-place, r=matthewjasper
Assert that a return place is not used for indexing during integration

The inliner integrates call destination place with callee return place
by remapping the local and adding extra projections as necessary.

If a call destination place contains any projections (which is already
possible) and a return place is used in an indexing projection (most
likely doesn't happen yet) the end result would be incorrect.

Add an assertion to ensure that potential issue won't go unnoticed in
the presence of more sophisticated copy propagation scheme.
2020-11-10 14:45:17 +01:00
Jonas Schievink 9596e34ad4
Rollup merge of #76765 - guswynn:async_return, r=tmandry
Make it more clear what an about async fn's returns when referring to what it returns

see #76547

This is *likely* not the ONLY place that this happens to be unclear, but we can move this fn to rustc_middle or something like that and reuse it if need be, to apply it to more diagnostics

One outstanding question I have is, if the fn returns (), should I make the message more clear (what about `fn f()` vs `fn f() -> ()`, can you tell those apart in the hir?)

R? `@tmandry`

`@rustbot` modify labels +A-diagnostics +T-compiler
2020-11-10 14:45:09 +01:00
Tomasz Miąsko c8943c62f7 Add flags customizing behaviour of MIR inlining
* `-Zinline-mir-threshold` to change the default threshold.
* `-Zinline-mir-hint-threshold` to change the threshold used by
  functions with inline hint.
2020-11-10 00:00:00 +00:00
Camelid 0242f963c6 Add comments to explain memory usage optimization 2020-11-09 13:34:16 -08:00
mark 43e4783ce3 address reviewer comments 2020-11-09 12:19:34 -06:00
Dylan DPC c150b933ac
Rollup merge of #78844 - tmiasko:monomorphize-sizeof, r=oli-obk
Monomorphize a type argument of size-of operation during codegen

This wasn't necessary until MIR inliner started to consider drop glue as
a candidate for inlining; introducing for the first time a generic use
of size-of operation.

No test at this point since this only happens with a custom inlining
threshold.
2020-11-09 19:07:02 +01:00
Dylan DPC 7924ecc341
Rollup merge of #78830 - lcnr:mir-folder, r=oli-obk
fix `super_visit_with` for `Terminator`

fixes https://github.com/rust-lang/rust/pull/78182#discussion_r509265149

r? `@oli-obk`

cc `@LeSeulArtichaut`
2020-11-09 19:06:59 +01:00
Dylan DPC 8ebca242bc
Rollup merge of #78710 - petrochenkov:macvisit, r=davidtwco
rustc_ast: Do not panic by default when visiting macro calls

Panicking by default made sense when we didn't have HIR or MIR and everything worked on AST, but now all AST visitors run early and majority of them have to deal with macro calls, often by ignoring them.

The second commit renames `visit_mac` to `visit_mac_call`, the corresponding structures were renamed earlier in https://github.com/rust-lang/rust/pull/69589.
2020-11-09 19:06:55 +01:00
Dylan DPC ee1fedf392
Rollup merge of #78580 - tmiasko:inline-loop, r=oli-obk
inliner: Break inlining cycles

Keep track of all instances inlined so far. When examining a new call
sites from an inlined body, skip those where callee had been inlined
already to avoid potential inlining cycles.

Fixes #78573.
2020-11-09 19:06:53 +01:00
Dylan DPC 0aed74aa43
Rollup merge of #78502 - matthewjasper:chalkup, r=nikomatsakis
Update Chalk to 0.36.0

This PR updates Chalk and fixes a number of bugs in the chalk integration code.

cc `@rust-lang/wg-traits`
r? `@nikomatsakis`
2020-11-09 19:06:46 +01:00
Dylan DPC 99f16e637b
Rollup merge of #76468 - SNCPlay42:lifetime-names, r=Mark-Simulacrum
Improve lifetime name annotations for closures & async functions

* Don't refer to async functions as "generators" in error output
* Where possible, emit annotations pointing exactly at the `&` in the return type of closures (when they have explicit return types) and async functions, like we do for arguments.
Addresses #74072, but I wouldn't call that *closed* until annotations are identical for async and non-async functions.
* Emit a better annotation when the lifetime doesn't appear in the full name type, which currently happens for opaque types like `impl Future`. Addresses #74497, but further improves could probably be made (why *doesn't* it appear in the type as `impl Future + '1`?)
This is included in the same PR because the changes to `give_name_if_anonymous_region_appears_in_output` would introduce ICE otherwise (it would return `None` in cases where it didn't previously, which then gets `unwrap`ped)
2020-11-09 19:06:39 +01:00
SNCPlay42 61b52a33b3 use RegionNameHighlight for async fn and closure returns 2020-11-09 16:14:40 +00:00
David Hewitt 8d43b3cbb9 Add #[cfg(panic = "...")] 2020-11-09 15:30:49 +00:00
o752d 21f44fb88f
comment attribution fix
comment means to refer to the macro in its direct scope
2020-11-09 03:42:10 +00:00
Dylan DPC abaa78baeb
Rollup merge of #78748 - fanzier:tuple-assignment, r=petrochenkov
Implement destructuring assignment for tuples

This is the first step towards implementing destructuring assignment (RFC: https://github.com/rust-lang/rfcs/pull/2909, tracking issue: #71126). This PR is the first part of #71156, which was split up to allow for easier review.

Quick summary: This change allows destructuring the LHS of an assignment if it's a (possibly nested) tuple.
It is implemented via a desugaring (AST -> HIR lowering) as follows:
```rust
(a,b) = (1,2)
```
... becomes ...
```rust
{
  let (lhs0,lhs1) = (1,2);
  a = lhs0;
  b = lhs1;
}
```

Thanks to `@varkor` who helped with the implementation, particularly around default binding modes.

r? `@petrochenkov`
2020-11-09 01:13:44 +01:00
Dylan DPC b4589a86cc
Rollup merge of #78674 - tmiasko:inline-substs-for-mir-body, r=oli-obk
inliner: Use substs_for_mir_body

Changes from 68965 extended the kind of instances that are being
inlined. For some of those, the `instance_mir` returns a MIR body that
is already expressed in terms of the types found in substitution array,
and doesn't need further substitution.

Use `substs_for_mir_body` to take that into account.

Resolves #78529.
Resolves #78560.
2020-11-09 01:13:42 +01:00
Dylan DPC 12c5f786ea
Rollup merge of #78345 - jyn514:proper-names, r=varkor
Fix handling of item names for HIR

- Handle variants, fields, macros in `Node::ident()`
- Handle the crate root in `opt_item_name`
- Rewrite `item_name` in terms of `opt_item_name`

I need this for both https://github.com/rust-lang/rust/pull/77820 and https://github.com/rust-lang/rust/pull/78082, so splitting it out into a separate PR so it can land early.
2020-11-09 01:13:35 +01:00
Dylan DPC b9671ae5f8
Rollup merge of #78114 - jyn514:private, r=oli-obk
Recognize `private_intra_doc_links` as a lint

Previously, trying to allow this would give another error!

```
warning: unknown lint: `private_intra_doc_links`
 --> private.rs:1:10
  |
1 | #![allow(private_intra_doc_links)]
  |          ^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean: `broken_intra_doc_links`
  |
  = note: `#[warn(unknown_lints)]` on by default

warning: public documentation for `DocMe` links to private item `DontDocMe`
 --> private.rs:2:11
  |
2 | /// docs [DontDocMe]
  |           ^^^^^^^^^ this item is private
  |
  = note: `#[warn(private_intra_doc_links)]` on by default
  = note: this link will resolve properly if you pass `--document-private-items`
```

Fixes the issue found in https://github.com/rust-lang/rust/pull/77249#issuecomment-712339227.

r? ````````@Manishearth````````

Does anyone know why this additional step is necessary? It seems weird this has to be declared in 3 different places.
2020-11-09 01:13:31 +01:00
Dylan DPC d69ee57f97
Rollup merge of #77640 - ethanboxx:int_error_matching_attempt_2, r=KodrAus
Refactor IntErrorKind to avoid "underflow" terminology

This PR is a continuation of #76455

# Changes

- `Overflow` renamed to `PosOverflow` and `Underflow` renamed to `NegOverflow` after discussion in #76455
- Changed some of the parsing code to return `InvalidDigit` rather than `Empty` for strings "+" and "-". https://users.rust-lang.org/t/misleading-error-in-str-parse-for-int-types/49178
- Carry the problem `char` with the `InvalidDigit` variant.
- Necessary changes were made to the compiler as it depends on `int_error_matching`.
- Redid tests to match on specific errors.

r? ```@KodrAus```
2020-11-09 01:13:25 +01:00
Tomasz Miąsko ffa70d75c8 Support inlining diverging function calls
Additionally introduce storage markers for all temporaries created by
the inliner. The temporary introduced for destination rebrorrow, didn't
use them previously.
2020-11-09 00:00:00 +00:00
Tomasz Miąsko dc4d74d149 inliner: Break inlining cycles
When examining candidates for inlining, reject those that are determined
to be recursive either because of self-recursive calls or calls to any
instances already inlined.
2020-11-09 00:00:00 +00:00
Tomasz Miąsko b7f16c56d1 inliner: Make inline_call infallible
The inliner does not support inlining of divering calls. Reject them
early on and turn `inline_call` into an infallible operation.
2020-11-09 11:41:10 +01:00
Vadim Petrochenkov 12de1e8985 Do not collect tokens for doc comments 2020-11-09 01:47:11 +03:00
bors 1773f60ea5 Auto merge of #78712 - petrochenkov:visitok, r=Aaron1011
rustc_ast: Visit tokens stored in AST nodes in mutable visitor

After #77271 token visiting is enabled only for one visitor in `rustc_expand\src\mbe\transcribe.rs` which applies hygiene marks to tokens produced by declarative macros (`macro_rules` or `macro`), so this change doesn't affect anything else.

When a macro has some interpolated token from an outer macro in its output
```rust
macro inner() {
    $interpolated
}
```
we can use the usual interpretation of interpolated tokens in token-based model - a None-delimited group - to write this macro in an equivalent form
```rust
macro inner() {
    ⟪ a b c d ⟫
}
```

When we are expanding the macro `inner` we need to apply hygiene marks to all tokens produced by it, including the tokens inside the group.

Before this PR we did this by visiting the AST piece inside the interpolated token and applying marks to all spans in it.
I'm not sure this is 100% correct (ideally we should apply the marks to tokens and then re-parse the AST from tokens), but it's a very good approximation at least.
We didn't however apply the marks to actual tokens stored in the nonterminal, so if we used the nonterminal as a token rather than as an AST piece (e.g. passed it to a proc macro), then we got hygiene bugs.
This PR applies the marks to tokens in addition to the AST pieces thus fixing the issue.

r? `@Aaron1011`
2020-11-08 20:00:51 +00:00
Andreas Molzer eb597f5c4e Remove recursion from sccc walking
This allows constructing the sccc for large that visit many nodes before
finding a single cycle of sccc, for example lists. When used to find
dependencies in borrow checking the list case is what occurs in very
long functions.
2020-11-08 18:07:45 +01:00
Vadim Petrochenkov 7f9117540f Address review comments 2020-11-08 17:31:47 +03:00
Vadim Petrochenkov dc004d4809 rustc_target: Rename some target options to avoid tautology
`target.target_endian` -> `target.endian`
`target.target_c_int_width` -> `target.c_int_width`
`target.target_os` -> `target.os`
`target.target_env` -> `target.env`
`target.target_vendor` -> `target.vendor`
`target.target_family` -> `target.os_family`
`target.target_mcount` -> `target.mcount`
2020-11-08 17:29:13 +03:00
Vadim Petrochenkov bf66988aa1 Collapse all uses of target.options.foo into target.foo
with an eye on merging `TargetOptions` into `Target`.

`TargetOptions` as a separate structure is mostly an implementation detail of `Target` construction, all its fields logically belong to `Target` and available from `Target` through `Deref` impls.
2020-11-08 17:29:13 +03:00
bors b1277d04db Auto merge of #78874 - m-ou-se:rollup-3jp1ijj, r=m-ou-se
Rollup of 19 pull requests

Successful merges:

 - #76097 (Stabilize hint::spin_loop)
 - #76227 (Stabilize `Poll::is_ready` and `is_pending` as const)
 - #78065 (make concurrency helper more pleasant to read)
 - #78570 (Remove FIXME comment in print_type_sizes ui test suite)
 - #78572 (Use SOCK_CLOEXEC and accept4() on more platforms.)
 - #78658 (Add a tool to run `x.py` from any subdirectory)
 - #78706 (Fix run-make tests running when LLVM is disabled)
 - #78728 (Constantify `UnsafeCell::into_inner` and related)
 - #78775 (Bump Rustfmt and RLS)
 - #78788 (Correct unsigned equivalent of isize to be usize)
 - #78811 (Make some std::io functions `const`)
 - #78828 (use single char patterns for split() (clippy::single_char_pattern))
 - #78841 (Small cleanup in `TypeFoldable` derive macro)
 - #78842 (Honor the rustfmt setting in config.toml)
 - #78843 (Less verbose debug logging from inlining integrator)
 - #78852 (Convert a bunch of intra-doc links)
 - #78860 (rustc_resolve: Use `#![feature(format_args_capture)]`)
 - #78861 (typo and formatting)
 - #78865 (Don't fire `CONST_ITEM_MUTATION` lint when borrowing a deref)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2020-11-08 13:49:17 +00:00
Mara Bos 91759b2de5
Rollup merge of #78865 - Aaron1011:fix/const-item-mut-reborrow, r=varkor
Don't fire `CONST_ITEM_MUTATION` lint when borrowing a deref

Fixes #78819

This extends the check for dereferences added in PR #77324
to cover mutable borrows, as well as direct writes. If we're operating
on a dereference of a `const` item, we shouldn't be firing the lint.
2020-11-08 13:36:33 +01:00
Mara Bos c4e262ee6f
Rollup merge of #78861 - o752d:patch-1, r=jonas-schievink
typo and formatting

fixed a typo and modified some line formatting justification while I'm here :)
2020-11-08 13:36:32 +01:00
Mara Bos 829e88032a
Rollup merge of #78860 - petrochenkov:resolvefmt, r=Mark-Simulacrum
rustc_resolve: Use `#![feature(format_args_capture)]`

This is the best new sugar for quite some time.

(I only changed places that already used named arguments.)
2020-11-08 13:36:30 +01:00
Mara Bos e5230fdf96
Rollup merge of #78843 - tmiasko:inline-trace, r=wesleywiser
Less verbose debug logging from inlining integrator

The inlining integrator produces relatively verbose and uninteresting
logs.  Move them from a debug log level to a trace level, so that they
can be easily isolated from others.
2020-11-08 13:36:26 +01:00
Mara Bos 2489ff7123
Rollup merge of #78841 - LeSeulArtichaut:foldable-derive, r=lcnr
Small cleanup in `TypeFoldable` derive macro

r? ```@lcnr```
2020-11-08 13:36:23 +01:00
Mara Bos 5cffa8f531
Rollup merge of #78828 - matthiaskrgr:sing_chr, r=lcnr
use single char patterns for split() (clippy::single_char_pattern)
2020-11-08 13:36:21 +01:00
bors 87a0997ef9 Auto merge of #78410 - lcnr:revert75443, r=nikomatsakis
revert #75443, update mir validator

This PR reverts rust-lang#75443 to fix rust-lang#75992 and instead uses rust-lang#75419 to fix rust-lang#75313.

Adapts rust-lang#75419 to correctly deal with unevaluated constants as otherwise some `feature(const_evaluatable_checked)` tests would ICE.

Note that rust-lang#72793 was also fixed by rust-lang#75443, but as that issue only concerns `feature(type_alias_impl_trait)` I deleted that test case for now and would reopen that issue.

rust-lang#75443 may have also allowed some other code to now successfully compile which would make this revert a breaking change after 2 stable versions, but I hope that this is a purely theoretical concern.

See https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/generator.20upvars/near/214617274 for more reasoning about this.

r? `@nikomatsakis` `@eddyb` `@RalfJung`
2020-11-08 11:27:06 +00:00
mark 459dae94a1 fix #72680 by explicitly checking for or-pattern before test 2020-11-07 23:22:47 -06:00
bors f2ea2f648e Auto merge of #77729 - petrochenkov:mergetarg, r=Mark-Simulacrum
rustc_target: Move some target options from `Target` to `TargetOptions`

The only reason for `Target` to `TargetOptions` to be separate structures is that options in `TargetOptions` have reasonable defaults and options in `Target` don't.
(Otherwise all the options logically belong to a single `Target` struct.)

This PR moves a number of options with reasonable defaults from `Target` to `TargetOptions`, so they no longer needs to be specified explicitly for majority of the targets.
The move also allows to inherit the options from `rustc_target/src/spec/*_base.rs` files in a nicer way.
I didn't change any specific option values here.

The moved options are `target_c_int_width` (defaults to `"32"`), `target_endian` (defaults to `"little"`), `target_os` (defaults to `"none"`), `target_env` (defaults to `""`), `target_vendor` (defaults to `"unknown"`) and `linker_flavor` (defaults to `LinkerFlavor::Gcc`).

Next steps (in later PRs):
- Find a way to merge `TargetOptions` into `Target`
- If not, always access `TargetOptions` fields through `Deref` making it a part of `Target` at least logically (`session.target.target.options.foo` -> `session.target.target.foo`)
- ~Eliminate `session::config::Config` and use `Target` instead (`session.target.target.foo` -> `session.target.foo`)~ Done in https://github.com/rust-lang/rust/pull/77943.
- Avoid tautologies in option names (`target.target_os` -> `target.os`)
- Resolve _ https://github.com/rust-lang/rust/issues/77730 (rustc_target: The differences between `target_os = "none"` and `target_os = "unknown"`, and `target_vendor = "unknown"` and `target_vendor = ""` are unclear) noticed during implementation of this PR.
2020-11-08 02:21:55 +00:00
Aaron Hill bd3f3fa32a
Use a semicolon instead of a dash in lint note 2020-11-07 20:39:35 -05:00
Aaron Hill e4e9bb4a24
Don't fire CONST_ITEM_MUTATION lint when borrowing a deref
Fixes #78819

This extends the check for dereferences added in PR #77324
to cover mutable borrows, as well as direct writes. If we're operating
on a dereference of a `const` item, we shouldn't be firing the lint.
2020-11-07 20:11:53 -05:00
o752d 2550e887b3
typo and formatting
fixed a typo and modified some line formatting justification while I'm here :)
2020-11-07 23:25:10 +00:00
Vadim Petrochenkov 907b87fafa rustc_resolve: Use #![feature(format_args_capture)] 2020-11-08 01:38:11 +03:00
bors 771cc7ffc3 Auto merge of #78784 - Mark-Simulacrum:revert-77421, r=petrochenkov
Revert "Revert "resolve: Avoid "self-confirming" import resolutions in one more case""

Specifically, this reverts commit b20bce8ce5 from #77421 to fix #77586.

The lang team has decided that for the time being we want to avoid the breakage here (perhaps for a future edition; though almost certainly not the upcoming one), though a future PR may want to add a lint around this case (and perhaps others) which are unlikely to be readable code.

r? `@petrochenkov` to confirm this is the right way to fix #77586.
2020-11-07 21:57:02 +00:00
Tomasz Miąsko 425675da42 Less verbose debug logging from inlining integrator
The inlining integrator produces relatively verbose and uninteresting
logs.  Move them from a debug log level to a trace level, so that they
can be easily isolated from others.
2020-11-07 19:56:08 +01:00
Joshua Nelson 622c48e4f1 Allow making RUSTC_BOOTSTRAP conditional on the crate name
The main change is that `UnstableOptions::from_environment` now requires
an (optional) crate name. If the crate name is unknown (`None`), then the new feature is not available and you still have to use `RUSTC_BOOTSTRAP=1`. In practice this means the feature is only available for `--crate-name`, not for `#![crate_name]`; I'm interested in supporting the second but I'm not sure how.

Other major changes:

- Added `Session::is_nightly_build()`, which uses the `crate_name` of
the session
- Added `nightly_options::match_is_nightly_build`, a convenience method
for looking up `--crate-name` from CLI arguments.
`Session::is_nightly_build()`should be preferred where possible, since
it will take into account `#![crate_name]` (I think).
- Added `unstable_features` to `rustdoc::RenderOptions`

  There is a user-facing change here: things like `RUSTC_BOOTSTRAP=0` no
  longer active nightly features. In practice this shouldn't be a big
  deal, since `RUSTC_BOOTSTRAP` is the opposite of stable and everyone
  uses `RUSTC_BOOTSTRAP=1` anyway.

- Add tests

  Check against `Cheat`, not whether nightly features are allowed.
  Nightly features are always allowed on the nightly channel.

- Only call `is_nightly_build()` once within a function

- Use booleans consistently for rustc_incremental

  Sessions can't be passed through threads, so `read_file` couldn't take a
  session. To be consistent, also take a boolean in `write_file_header`.
2020-11-07 13:45:11 -05:00
LeSeulArtichaut 087a9340d5 Small cleanup in TypeFoldable derive macro 2020-11-07 18:20:42 +01:00
Joshua Nelson f60fd49632 Remove unused from_hir call 2020-11-07 10:37:18 -05:00
Joshua Nelson 67d0db6b00 Fix handling of item names for HIR
- Handle variants, fields, macros in `Node::ident()`
- Handle the crate root in `opt_item_name`
- Factor out `item_name_from_def_id` to reduce duplication
- Look at HIR before the DefId for `opt_item_name`

  This gives accurate spans, which are not available from serialized
  metadata.

- Don't panic on the crate root in `opt_item_name`
- Add comments
2020-11-07 10:37:12 -05:00
Fabian Zaiser 3a7a997323 Implement destructuring assignment for tuples
Co-authored-by: varkor <github@varkor.com>
2020-11-07 13:17:19 +00:00
Bastian Kauschke 439171e094 look at assoc ct, check the type of nodes 2020-11-07 12:39:52 +01:00
Vadim Petrochenkov c0c0597e09 Update recently added targets 2020-11-07 14:34:44 +03:00
Vadim Petrochenkov d41fe05d1a rustc_target: Move linker_flavor from Target to TargetOptions 2020-11-07 14:27:48 +03:00
Vadim Petrochenkov b294cc71a2 rustc_target: Move target_vendor from Target to TargetOptions 2020-11-07 14:27:47 +03:00
Vadim Petrochenkov d5fd31197f rustc_target: Move target_env from Target to TargetOptions 2020-11-07 14:27:47 +03:00
Vadim Petrochenkov 74ffb9b4a2 rustc_target: Move target_os from Target to TargetOptions 2020-11-07 14:27:47 +03:00
Vadim Petrochenkov 91533cf10e rustc_target: Move target_endian from Target to TargetOptions 2020-11-07 14:27:46 +03:00
Vadim Petrochenkov ffe65f825b rustc_target: Move target_c_int_width from Target to TargetOptions 2020-11-07 14:27:46 +03:00
Bastian Kauschke 103f7a499b fix super_visit_with for Terminator 2020-11-07 11:56:31 +01:00
Matthias Krüger 020ed653a3 use single char patterns for split() (clippy::single_char_pattern) 2020-11-07 07:27:44 +01:00
Tomasz Miąsko 89c3582d59 Assert that a return place is not used for indexing during integration
The inliner integrates call destination place with callee return place
by remapping the local and adding extra projections as necessary.

If a call destination place contains any projections (which is already
possible) and a return place is used in an indexing projection (most
likely doesn't happen yet) the end result would be incorrect.

Add an assertion to ensure that potential issue won't go unnoticed in
the presence of more sophisticated copy propagation scheme.
2020-11-07 00:00:00 +00:00
Tomasz Miąsko f78f36cdb7 Monomorphize a type argument of size-of operation during codegen
This wasn't necessary until MIR inliner started to consider drop glue as
a candidate for inlining; introducing for the first time a generic use
of size-of operation.

No test at this point since this only happens with a custom inlining
threshold.
2020-11-07 00:00:00 +00:00
Vadim Petrochenkov 922107919d resolve: Collapse macro_rules scope chains on the fly 2020-11-07 02:18:29 +03:00
Bastian Kauschke e06785b676 improve fixme 2020-11-06 22:37:16 +01:00
Mark Rousskov ae4f80b4be Revert "Revert "resolve: Avoid "self-confirming" import resolutions in one more case""
This reverts commit b20bce8ce5.

It retains the test added in that commit as a check-pass test, intended to
prevent future (unintentional) regressions.
2020-11-06 11:22:13 -05:00
Yuki Okushi af50c796fa
Rollup merge of #78798 - ankushduacodes:fixing-typo, r=jonas-schievink
Fixing Spelling Typos

Fixing #78787
2020-11-07 01:02:30 +09:00
Yuki Okushi 5b16a66faf
Rollup merge of #78795 - est31:node_id_assignment_doc_fix, r=oli-obk
The renumber pass is long gone

Originally, there has been a dedicated pass for renumbering
AST NodeIds to have actual values. This pass had been added by
commit a5ad4c3794.

Then, later, this step was moved to where it resides now,
macro expansion. See commit c86c8d41a2
or PR #36438.

The comment snippet, added by the original commit, has
survived the times without any change, becoming outdated
at removal of the dedicated pass.

Nowadays, grepping for the next_node_id function will show up
multiple places in the compiler that call it, but the main
rewriting that the comment talks about is still done in the
expansion step, inside an innocious looking visit_id function
that's called during macro invocation collection.
2020-11-07 01:02:28 +09:00
Yuki Okushi 09a40af85e
Rollup merge of #78794 - est31:collect_bang, r=oli-obk
rustc_expand: use collect_bang helper instead of manual reimplementation
2020-11-07 01:02:26 +09:00
Yuki Okushi 0a89d7bd7e
Rollup merge of #78771 - tmiasko:inline-consts, r=oli-obk
inliner: Copy unevaluated constants only after successful inlining

Inliner copies the unevaluated constants from the callee body to the
caller at the point where decision to inline is yet to be made. The
constants will be unnecessary if inlining were to fail.

Organize the code moving items from callee to the caller together in one
place to avoid the issue.
2020-11-07 01:02:24 +09:00
Yuki Okushi 55bf7911c3
Rollup merge of #78760 - jyn514:deny-invalid-codeblocks, r=GuillaumeGomez
`deny(invalid_codeblock_attributes)` for rustc_error_codes

Closes https://github.com/rust-lang/rust/issues/71478.

r? ``@GuillaumeGomez``
2020-11-07 01:02:22 +09:00
Yuki Okushi 7931b2454d
Rollup merge of #78666 - sasurau4:fix/shellcheck-error, r=jyn514
Fix shellcheck error

## Overview

Helps with #77290

This pr fix only errors of shellcheck, the result of `git ls-files '*.sh' | xargs shellcheck --severity=error`.

Fixing error are following.

- https://github.com/koalaman/shellcheck/wiki/SC2148
- https://github.com/koalaman/shellcheck/wiki/SC1008

Disable error following.
- https://github.com/koalaman/shellcheck/wiki/SC2068
2020-11-07 01:02:14 +09:00
Yuki Okushi 91153d5009
Rollup merge of #78167 - Nadrieril:fix-76836_, r=varkor
Fix unreachable sub-branch detection in or-patterns

The previous implementation was too eager to avoid unnecessary "unreachable pattern" warnings. I feel more confident about this implementation than I felt about the previous one.
Fixes https://github.com/rust-lang/rust/issues/76836.

``@rustbot`` modify labels: +A-exhaustiveness-checking
2020-11-07 01:02:05 +09:00
Daiki Ihara a1af001a55 fix shellcheck error of SC2068 2020-11-06 20:33:12 +09:00
Daiki Ihara f197da655f fix shellcheck error of SC2148 2020-11-06 20:33:12 +09:00
bors 8532e742fc Auto merge of #78267 - richkadel:llvm-coverage-counters-2.0.3r1, r=tmandry
Working expression optimization, and some improvements to branch-level source coverage

This replaces PR #78040 after reorganizing the original commits (by request) into a more logical sequence of major changes.

Most of the work is in the MIR `transform/coverage/` directory (originally, `transform/instrument_coverage.rs`).

Note this PR includes some significant additional debugging capabilities, to help myself and any future developer working on coverage improvements or issues.

In particular, there's a new Graphviz (.dot file) output for the coverage graph (the `BasicCoverageBlock` control flow graph) that provides ways to get some very good insight into the relationships between the MIR, the coverage graph BCBs, coverage spans, and counters. (There are also some cool debugging options, available via environment variable, to alter how some data in the graph appears.)

And the code for this Graphviz view is actually generic... it can be used by any implementation of the Rust `Graph` traits.

Finally (for now), I also now output information from `llvm-cov` that shows the actual counters and spans it found in the coverage map, and their counts (from the `--debug` flag). I found this to be enormously helpful in debugging some coverage issues, so I kept it in the test results as well for additional context.

`@tmandry` `@wesleywiser`

r? `@tmandry`

Here's an example of the new coverage graph:

* Within each `BasicCoverageBlock` (BCB), you can see each `CoverageSpan` and its contributing statements (MIR `Statement`s and/or `Terminator`s)
* Each `CoverageSpan` has a `Counter` or and `Expression`, and `Expression`s show their Add/Subtract operation with nested operations. (This can be changed to show the Counter and Expression IDs instead, or in addition to, the BCB.)
* The terminators of all MIR `BasicBlock`s in the BCB, including one final `Terminator`
* If an "edge counter" is required (because we need to count an edge between blocks, in some cases) the edge's Counter or Expression is shown next to its label. (Not shown in the example below.) (FYI, Edge Counters are converted into a new MIR `BasicBlock` with `Goto`)

<img width="1116" alt="Screen Shot 2020-10-17 at 12 23 29 AM" src="https://user-images.githubusercontent.com/3827298/96331095-616cb480-100f-11eb-8212-60f2d433e2d8.png">

r? `@tmandry`
FYI: `@wesleywiser`
2020-11-06 06:59:44 +00:00
bors f92b931045 Auto merge of #77856 - GuillaumeGomez:automatic-links-lint, r=jyn514,ollie27
Add non_autolinks lint

Part of #77501.

r? `@jyn514`
2020-11-06 04:17:41 +00:00
ankushduacodes 0af959d3a2 Fixing Spelling Typos 2020-11-06 09:25:58 +05:30
Rich Kadel a7d956583c Responded to all feedback as of 2020-10-30 2020-11-05 18:24:18 -08:00
Rich Kadel 1973f84ebb Addressed all feedback to date 2020-11-05 18:24:17 -08:00
Rich Kadel 5545c56e9d Added comments on remapping expression IDs, and URL to spanviews 2020-11-05 18:24:16 -08:00
Rich Kadel 198ba3bd1c Injecting expressions in place of counters where helpful
Implementing the Graph traits for the BasicCoverageBlock
graph.

optimized replacement of counters with expressions plus new BCB graphviz

* Avoid adding coverage to unreachable blocks.
* Special case for Goto at the end of the body. Make it non-reportable.

Improved debugging and formatting options (from env)

Don't automatically add counters to BCBs without CoverageSpans. They may
still get counters but only if there are dependencies from
other BCBs that have spans, I think.

Make CodeRegions optional for Counters too. It is
possible to inject counters (`llvm.instrprof.increment` intrinsic calls
without corresponding code regions in the coverage map. An expression
can still uses these counter values.

Refactored instrument_coverage.rs -> instrument_coverage/mod.rs, and
then broke up the mod into multiple files.

Compiling with coverage, with the expression optimization, works on
the json5format crate and its dependencies.

Refactored debug features from mod.rs to debug.rs
2020-11-05 18:24:15 -08:00
Rich Kadel 3291d28e9a Adds coverage graphviz 2020-11-05 18:24:14 -08:00
Rich Kadel b5020648fe Implemented CoverageGraph of BasicCoverageBlocks 2020-11-05 18:24:13 -08:00
Rich Kadel c7ae4c2cb6 Splitting transform/instrument_coverage.rs into transform/coverage/... 2020-11-05 18:24:12 -08:00
Rich Kadel c7747cc772 Rust coverage before splitting instrument_coverage.rs 2020-11-05 18:24:12 -08:00
est31 dfa5e46fd5 The renumber pass is long gone
Originally, there has been a dedicated pass for renumbering
AST NodeIds to have actual values. This pass had been added by
commit a5ad4c3794.

Then, later, this step was moved to where it resides now,
macro expansion. See commit c86c8d41a2
or PR #36438.

The comment snippet, added by the original commit, has
survived the times without any change, becoming outdated
at removal of the dedicated pass.

Nowadays, grepping for the next_node_id function will show up
multiple places in the compiler that call it, but the main
rewriting that the comment talks about is still done in the
expansion step, inside an innocious looking visit_id function
that's called during macro invocation collection.
2020-11-06 03:18:01 +01:00
est31 de2940ff63 rustc_expand: use collect_bang helper instead of manual reimplementation 2020-11-06 03:16:56 +01:00
Tomasz Miąsko 8a8ee1a3ed inliner: Use substs_for_mir_body
Changes from 68965 extended the kind of instances that are being
inlined. For some of those, the `instance_mir` returns a MIR body that
is already expressed in terms of the types found in substitution array,
and doesn't need further substitution.

Use `substs_for_mir_body` to take that into account.
2020-11-06 00:00:00 +00:00
Nadrieril 107a29a901 Emit lints in the order in which they occur in the file. 2020-11-05 22:17:26 +00:00
Nadrieril 25e272e388 Fix unreachable sub-branch detection
This fixes https://github.com/rust-lang/rust/issues/76836
2020-11-05 22:02:35 +00:00
Vadim Petrochenkov 8def2fc122 rustc_ast: Never clone empty token streams in mutable visitor 2020-11-06 00:59:08 +03:00
Vadim Petrochenkov 1e15606547 rustc_ast: Visit tokens stored in AST nodes in mutable visitor 2020-11-06 00:30:52 +03:00
Guillaume Gomez 99200f760b Fix even more URLs 2020-11-05 20:11:29 +01:00
Andreas Molzer 355904dca0 Add test for sccc of a long list 2020-11-05 19:24:49 +01:00
Andreas Molzer a41e2fd963 Convert the recursive find_state to a loop
The basic conversion is a straightforward conversion of the linear
recursion to a loop forwards and backwards propagation of the result.
But this uses an optimization to avoid the need for extra space that
would otherwise be necessary to store the stack of unfinished states as
the function is not tail recursive.

Observe that only non-root-nodes in cycles have a recursive call and
that every such call overwrites their own node state. Thus we reuse the
node state itself as temporary storage for the stack of unfinished
states by inverting the links to a chain back to the previous state
update. When we hit the root or end of the full explored chain we
propagate the node state update backwards by following the chain until
a node with a link to itself.
2020-11-05 19:24:49 +01:00
Joshua Nelson eed0cebea3 Recognize private_intra_doc_links as a lint
Previously, trying to allow this would give another error!

```
warning: unknown lint: `private_intra_doc_links`
 --> private.rs:1:10
  |
1 | #![allow(private_intra_doc_links)]
  |          ^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean: `broken_intra_doc_links`
  |
  = note: `#[warn(unknown_lints)]` on by default

warning: public documentation for `DocMe` links to private item `DontDocMe`
 --> private.rs:2:11
  |
2 | /// docs [DontDocMe]
  |           ^^^^^^^^^ this item is private
  |
  = note: `#[warn(private_intra_doc_links)]` on by default
  = note: this link will resolve properly if you pass `--document-private-items`
```
2020-11-05 12:55:10 -05:00
Joshua Nelson 9d9292cfda deny(invalid_codeblock_attributes) 2020-11-05 12:13:28 -05:00
bors b1d9f31e04 Auto merge of #78638 - vn-ki:bindigs-after-at-issue-69971, r=oli-obk
reverse binding order in matches to allow the subbinding of copyable fields in bindings after @

Fixes #69971

### TODO

- [x] Regression tests

r? `@oli-obk`
2020-11-05 13:26:08 +00:00
Mara Bos 8416e13d88
Rollup merge of #78758 - eltociear:patch-1, r=jyn514
Fixed typo in comment

paramter -> parameter
2020-11-05 10:30:04 +01:00
Mara Bos 5ffccc4dfa
Rollup merge of #78742 - vn-ki:fix-issue-78655, r=oli-obk
make intern_const_alloc_recursive return error

fix #78655

r? ``@oli-obk``
2020-11-05 10:29:59 +01:00
Mara Bos 171d29c9c5
Rollup merge of #78739 - hameerabbasi:issue-78654, r=nikomatsakis
Fix ICE on type error in async function

Fixes #78654
2020-11-05 10:29:57 +01:00
Mara Bos 8640360870
Rollup merge of #78733 - matthiaskrgr:cl11ppy, r=jyn514
fix a couple of clippy warnings:

filter_next
manual_strip
redundant_static_lifetimes
single_char_pattern
unnecessary_cast
unused_unit
op_ref
redundant_closure
useless_conversion
2020-11-05 10:29:53 +01:00
Guillaume Gomez 16ed8501ef Fix more URLs 2020-11-05 10:23:39 +01:00
Guillaume Gomez 9d114506c6 Rename lint to non_autolinks 2020-11-05 10:22:08 +01:00
Guillaume Gomez 60caf51b0d Rename automatic_links to url_improvements 2020-11-05 10:22:08 +01:00
Guillaume Gomez 55b4d21e25 Fix automatic_links warnings 2020-11-05 10:22:08 +01:00
Guillaume Gomez 7f839b2ece Improve automatic_links globally 2020-11-05 10:22:08 +01:00