Commit Graph

539 Commits

Author SHA1 Message Date
Jonas Schievink
c7a67209c8
Rollup merge of #79287 - jonas-schievink:const-trait-impl, r=oli-obk
Allow using generic trait methods in `const fn`

Next step for https://github.com/rust-lang/rust/issues/67792, this now also allows code like the following:

```rust
struct S;

impl const PartialEq for S {
    fn eq(&self, _: &S) -> bool {
        true
    }
}

const fn equals_self<T: PartialEq>(t: &T) -> bool {
    *t == *t
}

pub const EQ: bool = equals_self(&S);
```

This works by threading const-ness of trait predicates through trait selection, in particular through `ParamCandidate`, and exposing it in the resulting `ImplSource`.

Since this change makes two bounds `T: Trait` and `T: ?const Trait` that only differ in their const-ness be treated like different bounds, candidate winnowing has been changed to drop the `?const` candidate in favor of the const candidate, to avoid ambiguities when both a const and a non-const bound is present.
2020-11-23 15:25:44 +01:00
Jonas Schievink
d4a05696d9
Rollup merge of #79080 - camelid:mir-visit-debuginfo-project, r=jonas-schievink
MIR visitor: Don't treat debuginfo field access as a use of the struct

Fixes #77454.

r? `@jonas-schievink`
2020-11-23 15:25:40 +01:00
Camelid
b196bec236 Add comment and remove obsolete special case 2020-11-22 17:39:15 -08:00
Jonas Schievink
e69fcea609 const fn: allow use of trait impls from bounds 2020-11-22 04:19:46 +01:00
Dylan DPC
68c9caa6f6
Rollup merge of #79272 - tmiasko:array-clone, r=jonas-schievink
Support building clone shims for arrays with generic size

Fixes #79269.
2020-11-21 19:44:20 +01:00
Ngo Iok Ui
ef34e06781
List all variants of TyKind 2020-11-21 13:45:59 +08:00
Tomasz Miąsko
fac8b4e21a Support building clone shims for arrays with generic size 2020-11-21 00:00:00 +00:00
Ngo Iok Ui
459c83f980
Exhaustively match in variant count instrinsic 2020-11-20 21:49:49 +08:00
bors
5c45969502 Auto merge of #79192 - tmiasko:naked-noinline, r=oli-obk
Never inline naked functions

The `#[naked]` attribute disabled prologue / epilogue emission for the
function and it is responsibility of a developer to provide them. The
compiler is no position to inline such functions correctly.

Disable inlining of naked functions at LLVM and MIR level.

Closes #60919.
2020-11-20 06:01:49 +00:00
Tomasz Miąsko
c2fb99984c Never inline naked functions
The `#[naked]` attribute disabled prologue / epilogue emission for the
function and it is responsibility of a developer to provide them. The
compiler is no position to inline such functions correctly.

Disable inlining of naked functions at LLVM and MIR level.
2020-11-20 00:00:00 +00:00
Dylan DPC
084fc293eb
Rollup merge of #79193 - tmiasko:revert-78969-normalize, r=davidtwco
Revert #78969 "Normalize function type during validation"

Closes #79066.
Reopens #78442.
2020-11-19 23:58:43 +01:00
Dylan DPC
2fdcd245df
Rollup merge of #79117 - cjkenn:mir-fuel, r=oli-obk
add optimization fuel checks to some mir passes

Fixes #77402

Inserts a bunch of calls to `consider_optimizing`. Note that `consider_optimizing` is the method that actually decrements the fuel count, so the point at which it's called is when the optimization takes place, from a fuel perspective. This means that where we call it has some thought behind it:

1. We probably don't want to decrement the fuel count before other simple checks, otherwise we count an optimization as being performed even if nothing was mutated (ie. it returned early).
2. In cases like `InstCombine`, where we gather optimizations in a pass and then mutate values, we probably would rather skip the gathering pass for performance reasons rather than skip the mutations afterwards.
2020-11-19 16:26:35 +01:00
Dylan DPC
05ff58e645
Rollup merge of #79101 - tmiasko:lower-func-type, r=jonas-schievink
Don't special case constant operands when lowering intrinsics
2020-11-19 16:26:27 +01:00
cjkenn
1d3305aa66 remove check from const promotion 2020-11-19 08:21:20 -05:00
Tomasz Miąsko
0ab44584aa Revert "Normalize function type during validation"
This reverts commit d486bfcbff.
2020-11-19 05:36:55 +01:00
Tomasz Miąsko
8247223f74 Revert "Always use param_env_reveal_all_normalized in validator"
This reverts commit 99be78d135.
2020-11-19 05:36:51 +01:00
cjkenn
b556690c53 move checks later into optimization passes 2020-11-18 19:16:23 -05:00
cjkenn
51c2218d1f move fuel checks to later points in instcombine and const_prop, add opt level flag to test 2020-11-18 08:49:46 -05:00
bors
e0ef0fc392 Auto merge of #78779 - LeSeulArtichaut:ty-visitor-return, r=oli-obk
Introduce `TypeVisitor::BreakTy`

Implements MCP rust-lang/compiler-team#383.
r? `@ghost`
cc `@lcnr` `@oli-obk`

~~Blocked on FCP in rust-lang/compiler-team#383.~~
2020-11-17 12:24:34 +00:00
Mara Bos
336dc18aa3
Rollup merge of #79027 - tmiasko:inline-always-live-locals, r=oli-obk
Limit storage duration of inlined always live locals

Closes #76375.
2020-11-17 10:06:21 +01:00
bors
b5c37e86ff Auto merge of #78801 - sexxi-goose:min_capture, r=nikomatsakis
RFC-2229: Implement Precise Capture Analysis

### This PR introduces
- Feature gate for RFC-2229 (incomplete) `capture_disjoint_field`
- Rustc Attribute to print out the capture analysis `rustc_capture_analysis`
- Precise capture analysis

### Description of the analysis
1. If the feature gate is not set then all variables that are not local to the closure will be added to the list of captures. (This is for backcompat)
2. The rest of the analysis is based entirely on how the captured `Place`s are used within the closure. Precise information (i.e. projections) about the `Place` is maintained throughout.
3. To reduce the amount of information we need to keep track of, we do a minimization step. In this step, we determine a list such that no Place within this list represents an ancestor path to another entry in the list.  Check rust-lang/project-rfc-2229#9 for more detailed examples.
4. To keep the compiler functional as before we implement a Bridge between the results of this new analysis to existing data structures used for closure captures. Note the new capture analysis results are only part of MaybeTypeckTables that is the information is only available during typeck-ing.

### Known issues
- Statements like `let _ = x` will make the compiler ICE when used within a closure with the feature enabled. More generally speaking the issue is caused by `let` statements that create no bindings and are init'ed using a Place expression.

### Testing
We removed the code that would handle the case where the feature gate is not set, to enable the feature as default and did a bors try and perf run. More information here: #78762

### Thanks
This has been slowly in the works for a while now.
I want to call out `@Azhng` `@ChrisPardy` `@null-sleep` `@jenniferwills` `@logmosier` `@roxelo` for working on this and the previous PRs that led up to this, `@nikomatsakis` for guiding us.

Closes rust-lang/project-rfc-2229#7
Closes rust-lang/project-rfc-2229#9
Closes rust-lang/project-rfc-2229#6
Closes rust-lang/project-rfc-2229#19

r? `@nikomatsakis`
2020-11-17 03:56:03 +00:00
cjkenn
78a37f888a add optimization fuel checks to some mir passes 2020-11-16 18:09:10 -05:00
Bastian Kauschke
2bf93bd852 compiler: fold by value 2020-11-16 22:34:57 +01:00
Tomasz Miąsko
2b7ffecee0 Don't special case constant operands when lowering intrinsics 2020-11-16 00:00:00 +00:00
Jonas Schievink
ce775bc4f6
Rollup merge of #79036 - cjgillot:steal, r=oli-obk
Move Steal to rustc_data_structures.
2020-11-15 13:39:59 +01:00
Jonas Schievink
9c6d3c0940
Rollup merge of #79031 - camelid:mir-validate-local-decl, r=jonas-schievink
Validate that locals have a corresponding `LocalDecl`

Fixes #73356.
2020-11-15 13:39:56 +01:00
Jonas Schievink
8825942e86
Rollup merge of #77802 - jyn514:bootstrap-specific, r=nikomatsakis
Allow making `RUSTC_BOOTSTRAP` conditional on the crate name

Motivation: This came up in the [Zulip stream](https://rust-lang.zulipchat.com/#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/Require.20users.20to.20confirm.20they.20know.20RUSTC_.E2.80.A6.20compiler-team.23350/near/208403962) for https://github.com/rust-lang/compiler-team/issues/350.
See also https://github.com/rust-lang/cargo/pull/6608#issuecomment-458546258; this implements https://github.com/rust-lang/cargo/issues/6627.
The goal is for this to eventually allow prohibiting setting `RUSTC_BOOTSTRAP` in build.rs (https://github.com/rust-lang/cargo/issues/7088).

## User-facing changes

- `RUSTC_BOOTSTRAP=1` still works; there is no current plan to remove this.
- Things like `RUSTC_BOOTSTRAP=0` no longer activate 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.
- `RUSTC_BOOTSTRAP=x` will enable nightly features only for crate `x`.
- `RUSTC_BOOTSTRAP=x,y` will enable nightly features only for crates `x` and `y`.

## Implementation changes

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`

I'm not sure whether this counts as T-compiler or T-lang; _technically_ RUSTC_BOOTSTRAP is an implementation detail, but it's been used so much it seems like this counts as a language change too.

r? `@joshtriplett`
cc `@Mark-Simulacrum` `@hsivonen`
2020-11-15 13:39:43 +01:00
Dylan DPC
7e0441dc36
Rollup merge of #78969 - tmiasko:normalize, r=davidtwco
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.

Closes #78442.
2020-11-15 03:02:51 +01:00
Dylan DPC
6be44ed3b5
Rollup merge of #78966 - tmiasko:inline-never, r=oli-obk
Never inline C variadics, cold functions, functions with incompatible attributes ...

... and fix generator inlining.

Closes #67863.
Closes #78859.
2020-11-15 03:02:48 +01:00
Dylan DPC
335a2554f9
Rollup merge of #78963 - richkadel:llvm-coverage-counters-2.0.4, r=tmandry
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

r? ```````@tmandry```````
FYI: ```````@wesleywiser```````

This is pretty much self contained, but depending on feedback and timing, I may have a chance to add a few more unit tests requested against `counters.rs`. I'm looking at those now.
2020-11-15 03:02:46 +01:00
Tomasz Miąsko
f27d56d1ff Limit storage duration of inlined always live locals 2020-11-15 00:00:00 +00:00
bors
361c4ea224 Auto merge of #79049 - tmiasko:lower-intrinsics, r=jonas-schievink
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.

Currently enabled by default to determine the performance impact (no
significant impact expected). In practice only useful when combined with
inlining since intrinsics are rarely used directly (with exception of
`unreachable` and `discriminant_value` used by built-in derive macros).

Closes #32716.
2020-11-14 22:05:54 +00:00
LeSeulArtichaut
65cdc21f06 Set the default BreakTy to ! 2020-11-14 21:46:39 +01:00
LeSeulArtichaut
e0f3119103 Introduce TypeVisitor::BreakTy 2020-11-14 20:25:27 +01: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
Camelid
7eb1a1afcf Validate that locals have a corresponding LocalDecl 2020-11-13 12:54:42 -08:00
Rich Kadel
b4b0ef3e4b Addressed feedback 2020-11-13 09:07:39 -08: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
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
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
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
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