Commit Graph

21431 Commits

Author SHA1 Message Date
bors
2a4b00beaa Auto merge of #106908 - cjgillot:copyprop-ssa, r=oli-obk
Implement simple CopyPropagation based on SSA analysis

This PR extracts the "copy propagation" logic from https://github.com/rust-lang/rust/pull/106285.

MIR may produce chains of assignment between locals, like `_x = move? _y`.
This PR attempts to remove such chains by unifying locals.

The current implementation is a bit overzealous in turning moves into copies, and in removing storage statements.
2023-01-29 13:01:06 +00:00
bors
d117135f5a Auto merge of #106253 - nbdd0121:upcast, r=compiler-errors
Skip possible where_clause_object_safety lints when checking `multiple_supertrait_upcastable`

Fix #106247

To achieve this, I lifted the `WhereClauseReferencesSelf` out from `object_safety_violations` and move it into `is_object_safe` (which is changed to a new query).

cc `@dtolnay`
r? `@compiler-errors`
2023-01-29 10:20:25 +00:00
bors
a29efccb1e Auto merge of #107435 - matthiaskrgr:rollup-if5h6yu, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #106618 (Disable `linux_ext` in wasm32 and fortanix rustdoc builds.)
 - #107097 (Fix def-use dominance check)
 - #107154 (library/std/sys_common: Define MIN_ALIGN for m68k-unknown-linux-gnu)
 - #107397 (Gracefully exit if --keep-stage flag is used on a clean source tree)
 - #107401 (remove the usize field from CandidateSource::AliasBound)
 - #107413 (make more pleasant to read)
 - #107422 (Also erase substs for new infcx in pin move error)
 - #107425 (Check for missing space between fat arrow and range pattern)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-01-29 07:01:58 +00:00
Matthias Krüger
4e8f7e4fc9
Rollup merge of #107425 - clubby789:match-range-missing-space, r=compiler-errors
Check for missing space between fat arrow and range pattern

Fixes #107420

Ideally we wouldn't emit an error about expecting `=>` etc., but I'm not sure how to recover from this.

`@rustbot` label +A-diagnostics
2023-01-29 06:14:20 +01:00
Matthias Krüger
5ff6cdca7e
Rollup merge of #107422 - Nilstrieb:erase-the-ice, r=compiler-errors
Also erase substs for new infcx in pin move error

The code originally correctly erased the regions of the type it passed to the newly created infcx. But after the `fn_sig` query was made to return an `EarlyBinder<T>`, some substs that were around were substituted there without erasing their regions. They were then passed into the newly cerated infcx, which caused the ICE.

Fixes #107419

r? compiler-errors who reviewed the original PR adding this diagnostic
2023-01-29 06:14:20 +01:00
Matthias Krüger
74655dc507
Rollup merge of #107413 - tshepang:pleasant-readin, r=Nilstrieb
make more pleasant to read
2023-01-29 06:14:19 +01:00
Matthias Krüger
70fc114ccc
Rollup merge of #107401 - lenko-d:remove_the_usize_field_from_CandidateSource_AliasBound, r=compiler-errors
remove the usize field from CandidateSource::AliasBound

Fixes [#107380](https://github.com/rust-lang/rust/issues/107380)
2023-01-29 06:14:18 +01:00
Matthias Krüger
4caa9dfa71
Rollup merge of #107097 - tmiasko:ssa, r=cjgillot
Fix def-use dominance check

A definition does not dominate a use in the same statement. For example
in MIR generated for compound assignment x += a (when overflow checks
are disabled).
2023-01-29 06:14:17 +01:00
bors
3cdd0197e7 Auto merge of #106227 - bryangarza:ctfe-limit, r=oli-obk
Use stable metric for const eval limit instead of current terminator-based logic

This patch adds a `MirPass` that inserts a new MIR instruction `ConstEvalCounter` to any loops and function calls in the CFG. This instruction is used during Const Eval to count against the `const_eval_limit`, and emit the `StepLimitReached` error, replacing the current logic which uses Terminators only.

The new method of counting loops and function calls should be more stable across compiler versions (i.e., not cause crates that compiled successfully before, to no longer compile when changes to the MIR generation/optimization are made).

Also see: #103877
2023-01-29 04:11:27 +00:00
bors
bcb064a7f4 Auto merge of #107406 - cjgillot:eliminate-witnesses, r=compiler-errors
Only compute mir_generator_witnesses query in drop_tracking_mir mode.

Attempt to fix the perf regression in https://github.com/rust-lang/rust/pull/101692

r? `@ghost`
2023-01-29 01:27:11 +00:00
bors
9f82651a5f Auto merge of #103659 - clubby789:improve-partialord-derive, r=nagisa
Special-case deriving `PartialOrd` for enums with dataless variants

I was able to get slightly better codegen by flipping the derived `PartialOrd` logic for two-variant enums.  I also tried to document the implementation of the derive macro to make the special-case logic a little clearer.
```rs
#[derive(PartialEq, PartialOrd)]
pub enum A<T> {
    A,
    B(T)
}
```
```diff
impl<T: ::core::cmp::PartialOrd> ::core::cmp::PartialOrd for A<T> {
   #[inline]
   fn partial_cmp(
       &self,
       other: &A<T>,
   ) -> ::core::option::Option<::core::cmp::Ordering> {
       let __self_tag = ::core::intrinsics::discriminant_value(self);
       let __arg1_tag = ::core::intrinsics::discriminant_value(other);
-      match ::core::cmp::PartialOrd::partial_cmp(&__self_tag, &__arg1_tag) {
-          ::core::option::Option::Some(::core::cmp::Ordering::Equal) => {
-              match (self, other) {
-                  (A::B(__self_0), A::B(__arg1_0)) => {
-                      ::core::cmp::PartialOrd::partial_cmp(__self_0, __arg1_0)
-                  }
-                  _ => ::core::option::Option::Some(::core::cmp::Ordering::Equal),
-              }
+      match (self, other) {
+          (A::B(__self_0), A::B(__arg1_0)) => {
+              ::core::cmp::PartialOrd::partial_cmp(__self_0, __arg1_0)
           }
-          cmp => cmp,
+          _ => ::core::cmp::PartialOrd::partial_cmp(&__self_tag, &__arg1_tag),
       }
   }
}
```
Godbolt: [Current](https://godbolt.org/z/GYjEzG1T8), [New](https://godbolt.org/z/GoK78qx15)
I'm not sure how common a case comparing two enums like this (such as `Option`) is, and if it's worth the slowdown of adding a special case to the derive. If it causes overall regressions it might be worth just manually implementing this for `Option`.
2023-01-28 22:11:11 +00:00
clubby789
c5688794e2 Migrate some range parsing diagnostics 2023-01-28 21:57:35 +00:00
clubby789
4bfab39f9b Check for missing space between fat arrow and range pattern 2023-01-28 20:52:01 +00:00
Nilstrieb
832751fe1d Also erase substs for new infcx in pin move error
The code originally correctly erased the regions of the type it passed
to the newly created infcx. But after the `fn_sig` query was made to
return an `EarlyBinder<T>`, some substs that were around were
substituted there without erasing their regions. They were then passed
into the newly cerated infcx, which caused the ICE.
2023-01-28 20:43:16 +01:00
bors
1e225413a2 Auto merge of #107303 - compiler-errors:intern-canonical-var-values, r=lcnr
Intern `CanonicalVarValues`

So that they are copy 
2023-01-28 19:41:21 +00:00
bors
d6f0642827 Auto merge of #107206 - cjgillot:no-h2l-map, r=WaffleLapkin
Remove HirId -> LocalDefId map from HIR.

Having this map in HIR prevents the creating of new definitions after HIR has been built.
Thankfully, we do not need it.

Based on https://github.com/rust-lang/rust/pull/103902
2023-01-28 16:11:33 +00:00
Gary Guo
66f3ab90a1 Reintroduce multiple_supertrait_upcastable lint 2023-01-28 15:08:07 +00:00
Gary Guo
94e59cb6e2 Rename is_object_safe to check_is_object_safe to hint side effects 2023-01-28 15:07:57 +00:00
Gary Guo
d6de40b536 Make is_object_safe a query and move lint_object_unsafe_trait call there 2023-01-28 14:49:22 +00:00
Gary Guo
e144a13254 Replace object_safety_violations().is_empty() calls with is_object_safe 2023-01-28 14:49:22 +00:00
Tshepang Mbambo
5251769c9e make more pleasant to read 2023-01-28 16:35:07 +02:00
bors
bca8b4dc32 Auto merge of #107408 - matthiaskrgr:rollup-b5vz2ow, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #104012 (Improve unexpected close and mismatch delimiter hint in TokenTreesReader)
 - #104252 (Stabilize the const_socketaddr feature)
 - #105524 (Replace libc::{type} with crate::ffi::{type})
 - #107096 (Detect references to non-existant messages in Fluent resources)
 - #107355 (Add regression test for #60755)
 - #107384 (Remove `BOOL_TY_FOR_UNIT_TESTING`)
 - #107385 (Use `FallibleTypeFolder` for `ConstInferUnifier` not `TypeRelation`)
 - #107391 (rustdoc: remove inline javascript from copy-path button)
 - #107398 (Remove `ControlFlow::{BREAK, CONTINUE}`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-01-28 13:12:59 +00:00
Lenko Donchev
d3cf813b8d Use field-less variant for AliasBound. 2023-01-28 06:00:27 -06:00
Matthias Krüger
c95707a29b
Rollup merge of #107398 - scottmcm:its-their-funeral, r=dtolnay
Remove `ControlFlow::{BREAK, CONTINUE}`

Libs-API decided to remove these in #102697.

Follow-up to #107023, which removed them from `compiler/`, but a couple new ones showed up since that was merged.

r? libs
2023-01-28 11:11:09 +01:00
Matthias Krüger
18c9c643c1
Rollup merge of #107385 - BoxyUwU:ConstInferUnifier_is_folder, r=compiler-errors
Use `FallibleTypeFolder` for `ConstInferUnifier` not `TypeRelation`

I am not sure why this was using a `TypeRelation`, maybe it predates the ability to have fallible type folders
2023-01-28 11:11:08 +01:00
Matthias Krüger
e0c8359ccf
Rollup merge of #107384 - Nilstrieb:bool-for-deletion, r=oli-obk
Remove `BOOL_TY_FOR_UNIT_TESTING`

It is not used anymore for unit testing.
2023-01-28 11:11:08 +01:00
Matthias Krüger
53ccee0d38
Rollup merge of #107096 - clubby789:fluent-bad-messageref, r=compiler-errors
Detect references to non-existant messages in Fluent resources

Should help with cases like #107091, where `{variable}` (a message reference) is accidentally typed, rather than `{$variable}` (a variable reference)

Fixes #107370

```@rustbot``` label +A-translation
2023-01-28 11:11:07 +01:00
Matthias Krüger
e3048c7838
Rollup merge of #104012 - chenyukang:yukang/fix-103882-deli-indentation, r=petrochenkov
Improve unexpected close and mismatch delimiter hint in TokenTreesReader

Fixes #103882
Fixes #68987
Fixes #69259

The inner indentation mismatching will be covered by outer block, the new added function `report_error_prone_delim_block` will find out the error prone candidates for reporting.
2023-01-28 11:11:05 +01:00
bors
d8da513668 Auto merge of #106916 - lukas-code:overlapping-substs, r=estebank
Remove overlapping parts of multipart suggestions

This PR adds a debug assertion that the parts of a single substitution cannot overlap, fixes a overlapping substitution from the testsuite, and fixes https://github.com/rust-lang/rust/issues/106870.

Note that a single suggestion can still have multiple overlapping substitutions / possible edits, we just don't suggest overlapping replacements in a single edit anymore.

I've also included a fix for an unrelated bug where rustfix for `explicit_outlives_requirements` would produce multiple trailing commas for a where clause.
2023-01-28 10:00:56 +00:00
Camille GILLOT
15d6325747 Remove HirId -> LocalDefId map from HIR. 2023-01-28 09:55:26 +00:00
Camille GILLOT
3175d03d3b Take a LocalDefId in hir::Visitor::visit_fn. 2023-01-28 09:51:50 +00:00
Camille GILLOT
4db4860503 Only compute mir_generator_witnesses query in drop_tracking_mir mode. 2023-01-28 08:41:22 +00:00
bors
226b2496fc Auto merge of #107400 - matthiaskrgr:rollup-l6bycds, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #107022 (Implement `SpecOptionPartialEq` for `cmp::Ordering`)
 - #107100 (Use proper `InferCtxt` when probing for associated types in astconv)
 - #107103 (Use new solver in `evaluate_obligation` query (when new solver is enabled))
 - #107190 (Recover from more const arguments that are not wrapped in curly braces)
 - #107306 (Correct suggestions for closure arguments that need a borrow)
 - #107339 (internally change regions to be covariant)
 - #107344 (Minor tweaks in the new solver)
 - #107373 (Don't merge vtables when full debuginfo is enabled.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-01-28 06:46:42 +00:00
Lenko Donchev
d4a816c813 remove the usize field from CandidateSource::AliasBound 2023-01-27 22:50:24 -06:00
Matthias Krüger
c89bb159f6
Rollup merge of #107373 - michaelwoerister:dont-merge-vtables-when-debuginfo, r=WaffleLapkin
Don't merge vtables when full debuginfo is enabled.

This PR makes the compiler not emit the `unnamed_addr` attribute for vtables when full debuginfo is enabled, so that they don't get merged even if they have the same contents. This allows debuggers to more reliably map from a dyn pointer to the self-type of a trait object by looking at the vtable's debuginfo.

The PR only changes the behavior of the LLVM backend as other backends don't emit vtable debuginfo (as far as I can tell).

The performance impact of this change should be small as [measured](https://github.com/rust-lang/rust/pull/103514#issuecomment-1290833854) in a previous PR.
2023-01-28 05:20:19 +01:00
Matthias Krüger
ab769a0bac
Rollup merge of #107344 - compiler-errors:new-solver-tweaks, r=lcnr
Minor tweaks in the new solver

1. `InferCtxt::probe` is not needed in `compute_subtype_goal` and `compute_well_formed_goal`.
2. Add a handful of comments.
3. Add a micro-optimization in `consider_assumption` where we check the def-ids of the assumption and goal match before instantiating any binders.

r? ``@lcnr``
2023-01-28 05:20:19 +01:00
Matthias Krüger
a5caa989c9
Rollup merge of #107339 - aliemjay:covariant, r=lcnr
internally change regions to be covariant

Surprisingly, we consider the reference type `&'a T` to be contravaraint in its lifetime parameter. This is confusing and conflicts with the documentation we have in the reference, rustnomicon, and rustc-dev-guide. This also arguably not the correct use of terminology since we can use `&'static u8` in a place where `&' a u8` is expected, this implies that `&'static u8 <: &' a u8` and consequently `'static <: ' a`, hence covariance.

Because of this, when relating two types, we used to switch the argument positions in a confusing way:
`Subtype(&'a u8 <: &'b u8) => Subtype('b <: 'a) => Outlives('a: 'b) => RegionSubRegion('b <= 'a)`

The reason for the current behavior is probably that we wanted `Subtype('b <: 'a)` and `RegionSubRegion('b <= 'a)` to be equivalent, but I don' t think this is a good reason since these relations are sufficiently different in that the first is a relation in the subtyping lattice and is intrinsic to the type-systems, while the the second relation is an implementation detail of regionck.

This PR changes this behavior to use covariance, so..
`Subtype(&'a u8 <: &'b u8) => Subtype('a <: 'b) => Outlives('a: 'b) => RegionSubRegion('b <= 'a) `

Resolves #103676

r? `@lcnr`
2023-01-28 05:20:18 +01:00
Matthias Krüger
fa2cd945af
Rollup merge of #107306 - compiler-errors:correct-sugg-for-closure-arg-needs-borrow, r=oli-obk
Correct suggestions for closure arguments that need a borrow

Fixes #107301 by dealing with binders correctly
Fixes another issue where we were suggesting adding just `&` when we expected `&mut _` in a closure arg
2023-01-28 05:20:18 +01:00
Matthias Krüger
260e04879e
Rollup merge of #107190 - fmease:fix-81698, r=compiler-errors
Recover from more const arguments that are not wrapped in curly braces

Recover from some array, borrow, tuple & arithmetic expressions in const argument positions that lack curly braces and provide a suggestion to fix the issue continuing where #92884 left off. Examples of such expressions: `[]`, `[0]`, `[1, 2]`, `[0; 0xff]`, `&9`, `("", 0)` and `(1 + 2) * 3` (we previously did not recover from them).

I am not entirely happy with my current solution because the code that recovers from `[0]` (coinciding with a malformed slice type) and `[0; 0]` (coinciding with a malformed array type) is quite fragile as the aforementioned snippets are actually successfully parsed as types by `parse_ty` since it itself already recovers from them (returning `[⟨error⟩]` and `[⟨error⟩; 0]` respectively) meaning I have to manually look for `TyKind::Err`s and construct a separate diagnostic for the suggestion to attach to (thereby emitting two diagnostics in total).

Fixes #81698.
`@rustbot` label A-diagnostics
r? diagnostics
2023-01-28 05:20:17 +01:00
Matthias Krüger
3b6593a0b4
Rollup merge of #107103 - compiler-errors:new-solver-evaluate_obligation, r=lcnr
Use new solver in `evaluate_obligation` query (when new solver is enabled)

(only when `-Ztrait-solver=next`, of course)

... Does this make sense? It seems to me like it should be reasonable, but maybe there's some reason why this is a bad idea.

r? ``@lcnr``

Needs a perf run because I guess this `solver == TraitSolver::Next` check is on a hot path.
2023-01-28 05:20:16 +01:00
Matthias Krüger
28188d17ba
Rollup merge of #107100 - compiler-errors:issue-107087, r=lcnr
Use proper `InferCtxt` when probing for associated types in astconv

Fixes #107087
2023-01-28 05:20:16 +01:00
bors
252741673b Auto merge of #107360 - bjorn3:fix_thin_archive_reading, r=wesleywiser
Fix thin archive reading

This includes a revert of https://github.com/rust-lang/rust/pull/105221 to restore fat archive reading with LlvmArchiveBuilder.

Should fix #107162, #107334 and https://github.com/google/shaderc-rs/issues/133
2023-01-28 04:02:25 +00:00
Scott McMurray
868d099a72 Remove ControlFlow::{BREAK, CONTINUE}
Libs-API decided to remove these in #102697.

Follow-up to #107023, which removed them from `compiler/`, but a couple new ones showed up since that was merged.
2023-01-27 19:46:42 -08:00
bors
6cd6bad51f Auto merge of #101692 - cjgillot:generator-lazy-witness, r=oli-obk
Compute generator saved locals on MIR

Generators are currently type-checked by introducing a `witness` type variable, which is unified with a `GeneratorWitness(captured types)` whose purpose is to ensure that the auto traits correctly migrate from the captured types to the `witness` type.  This requires computing the captured types on HIR during type-checking, only to re-do it on MIR later.

This PR proposes to drop the HIR-based computation, and only keep the MIR one.  This is done in 3 steps.
1. During type-checking, the `witness` type variable is never unified.  This allows to stall all the obligations that depend on it until the end of type-checking.  Then, the stalled obligations are marked as successful, and saved into the typeck results for later verification.
2. At type-checking writeback, `witness` is replaced by `GeneratorWitnessMIR(def_id, substs)`.  From this point on, all trait selection involving `GeneratorWitnessMIR` will fetch the MIR-computed locals, similar to what opaque types do.  There is no lifetime to be preserved here: we consider all the lifetimes appearing in this witness type to be higher-ranked.
3. After borrowck, the stashed obligations are verified against the actually computed types, in the `check_generator_obligations` query.  If any obligation was wrongly marked as fulfilled in step 1, it should be reported here.

There are still many issues:
- ~I am not too happy having to filter out some locals from the checked bounds, I think this is MIR building that introduces raw pointers polluting the analysis;~ solved by a check specific to static variables.
- the diagnostics for captured types don't show where they are used/dropped;
- I do not attempt to support chalk.

cc `@eholk` `@jyn514` for the drop-tracking work
r? `@oli-obk` as you warned me of potential unsoundness
2023-01-28 01:05:29 +00:00
Camille GILLOT
de110f9208 Pacify tidy. 2023-01-27 22:01:25 +00:00
Camille GILLOT
65c3c90f3e Restrict amount of ignored locals. 2023-01-27 22:01:12 +00:00
Camille GILLOT
60e04d1e8c Compute generator saved locals on MIR. 2023-01-27 20:10:06 +00:00
Michael Goulet
8a0b2156d5 Micro-optimization in consider_assumption 2023-01-27 20:06:12 +00:00
Michael Goulet
0654374750 Add some comments 2023-01-27 20:06:12 +00:00
Michael Goulet
ff2413db1b No need to probe when computing goals 2023-01-27 20:04:59 +00:00