Commit Graph

1283 Commits

Author SHA1 Message Date
varkor 5a440f1bc2 Fix control flow check for breaking with diverging values 2020-10-21 21:46:03 +01:00
bors 1d2726726f Auto merge of #78195 - tmiasko:instcombine, r=jonas-schievink
Disable "optimization to avoid load of address" in InstCombine

The transformation is incorrect #78192. Disable it.
2020-10-21 17:44:48 +00:00
bors 22e6b9c689 Auto merge of #77250 - Aaron1011:feature/flat-token-collection, r=petrochenkov
Rewrite `collect_tokens` implementations to use a flattened buffer

Instead of trying to collect tokens at each depth, we 'flatten' the
stream as we go allong, pushing open/close delimiters to our buffer
just like regular tokens. One capturing is complete, we reconstruct a
nested `TokenTree::Delimited` structure, producing a normal
`TokenStream`.

The reconstructed `TokenStream` is not created immediately - instead, it is
produced on-demand by a closure (wrapped in a new `LazyTokenStream` type). This
closure stores a clone of the original `TokenCursor`, plus a record of the
number of calls to `next()/next_desugared()`. This is sufficient to reconstruct
the tokenstream seen by the callback without storing any additional state. If
the tokenstream is never used (e.g. when a captured `macro_rules!` argument is
never passed to a proc macro), we never actually create a `TokenStream`.

This implementation has a number of advantages over the previous one:

* It is significantly simpler, with no edge cases around capturing the
  start/end of a delimited group.

* It can be easily extended to allow replacing tokens an an arbitrary
  'depth' by just using `Vec::splice` at the proper position. This is
  important for PR #76130, which requires us to track information about
  attributes along with tokens.

* The lazy approach to `TokenStream` construction allows us to easily
  parse an AST struct, and then decide after the fact whether we need a
  `TokenStream`. This will be useful when we start collecting tokens for
  `Attribute` - we can discard the `LazyTokenStream` if the parsed
  attribute doesn't need tokens (e.g. is a builtin attribute).

The performance impact seems to be neglibile (see
https://github.com/rust-lang/rust/pull/77250#issuecomment-703960604). There is a
small slowdown on a few benchmarks, but it only rises above 1% for incremental
builds, where it represents a larger fraction of the much smaller instruction
count. There a ~1% speedup on a few other incremental benchmarks - my guess is
that the speedups and slowdowns will usually cancel out in practice.
2020-10-21 15:03:14 +00:00
Yuki Okushi de24210ebf
Rollup merge of #78118 - spastorino:inline-const-followups, r=petrochenkov
Inline const followups

r? @petrochenkov

Follow ups of #77124
2020-10-21 13:59:44 +09:00
Yuki Okushi 83f126bedf
Rollup merge of #78101 - RalfJung:foreign-static, r=oli-obk
fix static_ptr_ty for foreign statics

Cc https://github.com/rust-lang/rust/issues/74840

This does not fix that issue but fixes a problem in `static_ptr_ty` that we noticed while discussing that issue. I also added and updated a few comments. The one about `internal` locals being ignored does not seem to have been true [even in the commit that introduced it](https://github.com/rust-lang/rust/pull/44700/files#diff-ae2f3c7e2f9744f7ef43e96072b10e98d4e3fe74a3a399a3ad8a810fbe56c520R139).

r? @oli-obk
2020-10-21 13:59:43 +09:00
Yuki Okushi 89c98cd6b4
Rollup merge of #78063 - camelid:improve-cannot-multiply-error, r=estebank
Improve wording of "cannot multiply" type error

For example, if you had this code:

    fn foo(x: i32, y: f32) -> f32 {
        x * y
    }

You would get this error:

    error[E0277]: cannot multiply `f32` to `i32`
     --> src/lib.rs:2:7
      |
    2 |     x * y
      |       ^ no implementation for `i32 * f32`
      |
      = help: the trait `Mul<f32>` is not implemented for `i32`

However, that's not usually how people describe multiplication. People
usually describe multiplication like how the division error words it:

    error[E0277]: cannot divide `i32` by `f32`
     --> src/lib.rs:2:7
      |
    2 |     x / y
      |       ^ no implementation for `i32 / f32`
      |
      = help: the trait `Div<f32>` is not implemented for `i32`

So that's what this change does. It changes this:

    error[E0277]: cannot multiply `f32` to `i32`
     --> src/lib.rs:2:7
      |
    2 |     x * y
      |       ^ no implementation for `i32 * f32`
      |
      = help: the trait `Mul<f32>` is not implemented for `i32`

To this:

    error[E0277]: cannot multiply `i32` by `f32`
     --> src/lib.rs:2:7
      |
    2 |     x * y
      |       ^ no implementation for `i32 * f32`
      |
      = help: the trait `Mul<f32>` is not implemented for `i32`
2020-10-21 13:59:39 +09:00
Yuki Okushi 9583029a2d
Rollup merge of #78002 - estebank:issue-77598, r=oli-obk
Tweak "object unsafe" errors

CC #77598.
2020-10-21 13:59:35 +09:00
Tomasz Miąsko e200a4a0d2 Disable "optimization to avoid load of address" in InstCombine 2020-10-21 00:00:00 +00:00
Guillaume Gomez 0c2dbb2a18
Rollup merge of #78145 - LingMan:ast_pretty_mut, r=jonas-schievink
Drop unneeded `mut`

These parameters don't get modified.

Note that `trailing_comment` is pub and gets exported from `rustc_ast_pretty`. Is that considered to be a stable API? If yes, and you want to reserve the right to modify `self` in `trailing_comment` in the future, that hunk would need to be dropped.
2020-10-20 21:46:42 +02:00
Guillaume Gomez ad218f9bb9
Rollup merge of #78144 - bugadani:elements-nodrop, r=oli-obk
Don't update `entries` in `TypedArena` if T does not need drop

As far as I can tell, `entries` is only used when dropping `TypedArenaChunk`s and their contents. It is already ignored there, if T is not `mem::needs_drop`, this PR just skips updating it's value.

You can see `TypedArenaChunk` ignoring the entry count in L71. The reasoning is similar to what you can find in `DroplessArena`.

r? @oli-obk
2020-10-20 21:46:40 +02:00
Guillaume Gomez 01e6019448
Rollup merge of #78076 - est31:orphan_mod, r=Mark-Simulacrum
Move orphan module-name/mod.rs files into module-name.rs files
2020-10-20 21:46:35 +02:00
Guillaume Gomez 3fea201b11
Rollup merge of #78061 - wesleywiser:opt_zst_const_interning, r=oli-obk
Optimize const value interning for ZST types

Interning can skip any inhabited ZST type in general.

Fixes #68010

r? @oli-obk
2020-10-20 21:46:32 +02:00
Esteban Küber 88f5e110db review comments 2020-10-20 09:26:15 -07:00
Esteban Küber ae0e3d0511 Tweak "object unsafe" errors
Fix #77598.
2020-10-20 09:26:14 -07:00
Dániel Buga 2705caed8a Track element count only for types that need drop 2020-10-20 17:01:51 +02:00
LingMan 13f0f49a4e Drop unneeded `mut`
These parameters don't get modified.
2020-10-20 16:42:51 +02:00
bors 9832374f6e Auto merge of #76893 - lcnr:existential-proj, r=estebank
Improve `skip_binder` usage during FlagComputation

It looks like there was previously a bug around `ExistentialPredicate::Projection` here, don't know how to best trigger that one to add a regression test though.
2020-10-20 08:59:12 +00:00
bors 554633534c Auto merge of #76696 - Aaron1011:tokenstream-avoid-clone, r=petrochenkov
Avoid cloning the contents of a `TokenStream` in a few places
2020-10-20 05:45:08 +00:00
Yuki Okushi 21df410a62
Rollup merge of #78121 - LeSeulArtichaut:issue-78115, r=tmandry
Do not ICE on pattern that uses a binding multiple times in generator

Fixes #78115.
r? @tmandry
2020-10-20 12:11:13 +09:00
Yuki Okushi 3f1c637db4
Rollup merge of #78111 - SNCPlay42:not-always-self, r=lcnr
Trait predicate ambiguities are not always in `Self`

When reporting ambiguities in trait predicates, the compiler incorrectly assumed the ambiguity was always in the type the trait should be implemented on, and never the generic parameters of the trait. This caused silly suggestions for predicates like `<KnownType as Trait<_>>`, such as giving explicit types to completely unrelated variables that happened to be of type `KnownType`.

This also reverts #73027, which worked around this issue in some cases and does not appear to be necessary any more.

fixes #77982
fixes #78055
2020-10-20 12:11:11 +09:00
Yuki Okushi 378ca5e640
Rollup merge of #77931 - aticu:fix_60336, r=petrochenkov
Fix false positive for `unused_parens` lint

Fixes #60336
2020-10-20 12:11:06 +09:00
Tomasz Miąsko c2af254e3b Disable MatchBranchSimplification
This optimization can result in unsoundness, because it introduces
additional uses of a place holding the discriminant value without
ensuring that it is valid to do so.
2020-10-20 00:00:00 +00:00
Santiago Pastorino d641cb82c1
Allow NtBlock to parse on check inline const next token 2020-10-19 18:50:58 -03:00
LeSeulArtichaut 66ac5a2d63 Do not ICE on pattern that uses a binding multiple times in generator 2020-10-19 23:34:47 +02:00
SNCPlay42 c146e8c54f revert workaround #73027 2020-10-19 21:11:40 +01:00
SNCPlay42 71ca239f80 don't assume trait ambiguity happens in `Self` 2020-10-19 21:11:40 +01:00
Santiago Pastorino 9dd0bb6fbc
Do not print braces again print_anon_const already does it 2020-10-19 16:26:13 -03:00
Aaron Hill 593fdd3d45
Rewrite `collect_tokens` implementations to use a flattened buffer
Instead of trying to collect tokens at each depth, we 'flatten' the
stream as we go allong, pushing open/close delimiters to our buffer
just like regular tokens. One capturing is complete, we reconstruct a
nested `TokenTree::Delimited` structure, producing a normal
`TokenStream`.

The reconstructed `TokenStream` is not created immediately - instead, it is
produced on-demand by a closure (wrapped in a new `LazyTokenStream` type). This
closure stores a clone of the original `TokenCursor`, plus a record of the
number of calls to `next()/next_desugared()`. This is sufficient to reconstruct
the tokenstream seen by the callback without storing any additional state. If
the tokenstream is never used (e.g. when a captured `macro_rules!` argument is
never passed to a proc macro), we never actually create a `TokenStream`.

This implementation has a number of advantages over the previous one:

* It is significantly simpler, with no edge cases around capturing the
  start/end of a delimited group.

* It can be easily extended to allow replacing tokens an an arbitrary
  'depth' by just using `Vec::splice` at the proper position. This is
  important for PR #76130, which requires us to track information about
  attributes along with tokens.

* The lazy approach to `TokenStream` construction allows us to easily
  parse an AST struct, and then decide after the fact whether we need a
  `TokenStream`. This will be useful when we start collecting tokens for
  `Attribute` - we can discard the `LazyTokenStream` if the parsed
  attribute doesn't need tokens (e.g. is a builtin attribute).

The performance impact seems to be neglibile (see
https://github.com/rust-lang/rust/pull/77250#issuecomment-703960604). There is a
small slowdown on a few benchmarks, but it only rises above 1% for incremental
builds, where it represents a larger fraction of the much smaller instruction
count. There a ~1% speedup on a few other incremental benchmarks - my guess is
that the speedups and slowdowns will usually cancel out in practice.
2020-10-19 13:59:18 -04:00
bors a85e949276 Auto merge of #78106 - GuillaumeGomez:rollup-06vwk7p, r=GuillaumeGomez
Rollup of 4 pull requests

Successful merges:

 - #77877 (Use `try{}` in `try_fold` to decouple iterators in the library from `Try` details)
 - #78089 (Fix issue with specifying generic arguments for primitive types)
 - #78099 (Add missing punctuation)
 - #78103 (Add link to rustdoc book in rustdoc help popup)

Failed merges:

r? `@ghost`
2020-10-19 17:53:17 +00:00
Aaron Hill f6aec82d4d
Avoid cloning the contents of a `TokenStream` in a few places 2020-10-19 12:30:41 -04:00
Guillaume Gomez 684fbd50ab
Rollup merge of #78089 - varkor:opt_const_param_of-error, r=lcnr
Fix issue with specifying generic arguments for primitive types

Fixes https://github.com/rust-lang/rust/issues/78005.

r? @lcnr
2020-10-19 18:20:23 +02:00
bors f90e617305 Auto merge of #77908 - bugadani:obl-forest, r=nnethercote
Try to make ObligationForest more efficient

This PR tries to decrease the number of allocations in ObligationForest, as well as moves some cold path code to an uninlined function.
2020-10-19 15:14:15 +00:00
Ralf Jung 153e843c49 fix Rvalue::ty for ThreadLocalRef 2020-10-19 11:44:28 +02:00
Ralf Jung c1766c6372 fix static_ptr_ty for foreign statics, and more comments in check_unsafety 2020-10-19 09:47:18 +02:00
Ralf Jung cb33f956c3 remove what seems to be an outdated comment
Even in the PR that introduced this comment, it does not seem like these locals are actually ignored -- just their `source_info` is adjusted:
https://github.com/rust-lang/rust/pull/44700/files#diff-ae2f3c7e2f9744f7ef43e96072b10e98d4e3fe74a3a399a3ad8a810fbe56c520R139
2020-10-19 09:46:18 +02:00
bors 78307d8700 Auto merge of #77278 - camelid:use-correct-article, r=estebank
Use correct article in help message for conversion or cast

Before it always used `an`; now it uses the correct article for the type.
2020-10-19 02:19:21 +00:00
Camelid 3eab21e22d Don't ICE if called with a `TyKind::Error`
It felt too harsh to estebank and others to ICE even though it's
technically a mistake to show a `TyKind::Error`.
2020-10-18 17:38:47 -07:00
varkor c0d29fe7d7 Fix issue with specifying generic arguments for primitive types 2020-10-18 22:40:50 +01:00
bors b1496c6e60 Auto merge of #78075 - est31:remove_redundant_static, r=jonas-schievink
Remove redundant 'static
2020-10-18 21:02:05 +00:00
est31 66c1fc4c87 Move orphan module-name/mod.rs files into module-name.rs files 2020-10-18 20:56:15 +02:00
bors 4d247ad7d3 Auto merge of #77306 - lcnr:inline-ok, r=eddyb
normalize substs while inlining

fixes #68347 or more precisely, this fixes the same ICE in rust analyser as veloren is pinned to a specific nightly
and had an error with the current one.

I didn't look into creating an MVCE here as that seems fairly annoying, will spend a few minutes doing so rn. (failed)

r? `@eddyb` cc `@bjorn3`
2020-10-18 16:10:00 +00:00
est31 b87e4f36e7 Remove redundant 'static in the compiler 2020-10-18 17:30:15 +02:00
bors 834821e3b6 Auto merge of #78066 - bugadani:wat, r=jonas-schievink
Clean up small, surprising bits of code

This PR clean up a small number of unrelated, small things I found while browsing the code base.
2020-10-18 13:50:31 +00:00
bors 98e16884b1 Auto merge of #78058 - bugadani:arena2, r=lcnr
Make sure arenas don't allocate bigger than HUGE_PAGE

Right now, arenas allocate based on the size of the last chunk. It is possible for a `grow` call to allocate a chunk that is not a multiple of `PAGE`, and this size is doubled for each subsequent allocation. This means, instead of `HUGE_PAGE`, the biggest page possible is actually unknown.

This change fixes this, and also removes an unnecessary checked multiplication. It is still possible to allocate bigger than `HUGE_PAGE` pages, but this will only happen as many times as absolutely necessary.
2020-10-18 11:19:14 +00:00
bors ad268bd638 Auto merge of #78035 - camelid:basic-block-pointer-note, r=RalfJung
Note that `BasicBlock` is just an index

r? `@RalfJung`
2020-10-18 09:08:00 +00:00
Dániel Buga 2e99439900 Replace unnecessary map_or_else with map_or 2020-10-18 11:01:09 +02:00
Dániel Buga f3a0f68453 Zip -> Enumerate 2020-10-18 11:01:08 +02:00
Dániel Buga d708d7fb79 No need to map the max_distance 2020-10-18 11:01:08 +02:00
Dániel Buga ed7c6819e4 Early return to decrease indentation 2020-10-18 11:01:08 +02:00
Dániel Buga 8e548bf8d6 Remove weird slice conversion 2020-10-18 10:31:58 +02:00