Commit Graph

139726 Commits

Author SHA1 Message Date
Santiago Pastorino fde8d6ee81
For better consistency change mir_opt_level <= 1 to < 2 2021-03-05 17:13:56 -03:00
Santiago Pastorino 8152da22a1
Extract mir_opt_level to a method and use Option to be able to know if the value is provided or not 2021-03-05 17:13:56 -03:00
bors caca2121ff Auto merge of #74024 - Folyd:master, r=m-ou-se
Improve slice.binary_search_by()'s best-case performance to O(1)

This PR aimed to improve the [slice.binary_search_by()](https://doc.rust-lang.org/std/primitive.slice.html#method.binary_search_by)'s best-case performance to O(1).

# Noticed

I don't know why the docs of `binary_search_by` said `"If there are multiple matches, then any one of the matches could be returned."`, but the implementation isn't the same thing. Actually, it returns the **last one** if multiple matches found.

Then we got two options:

## If returns the last one is the correct or desired result

Then I can rectify the docs and revert my changes.

## If the docs are correct or desired result

Then my changes can be merged after fully reviewed.

However, if my PR gets merged, another issue raised: this could be a **breaking change** since if multiple matches found, the returning order no longer the last one instead of it could be any one.

For example:
```rust
let mut s = vec![0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55];
let num = 1;
let idx = s.binary_search(&num);
s.insert(idx, 2);

// Old implementations
assert_eq!(s, [0, 1, 1, 1, 1, 2, 2, 3, 5, 8, 13, 21, 34, 42, 55]);

// New implementations
assert_eq!(s, [0, 1, 1, 1, 2, 1, 2, 3, 5, 8, 13, 21, 34, 42, 55]);
```

# Benchmarking

**Old implementations**
```sh
$ ./x.py bench --stage 1 library/libcore
test slice::binary_search_l1           ... bench:          59 ns/iter (+/- 4)
test slice::binary_search_l1_with_dups ... bench:          59 ns/iter (+/- 3)
test slice::binary_search_l2           ... bench:          76 ns/iter (+/- 5)
test slice::binary_search_l2_with_dups ... bench:          77 ns/iter (+/- 17)
test slice::binary_search_l3           ... bench:         183 ns/iter (+/- 23)
test slice::binary_search_l3_with_dups ... bench:         185 ns/iter (+/- 19)
```

**New implementations (1)**

Implemented by this PR.
```rust
if cmp == Equal {
    return Ok(mid);
} else if cmp == Less {
    base = mid
}
```
```sh
$ ./x.py bench --stage 1 library/libcore
test slice::binary_search_l1           ... bench:          58 ns/iter (+/- 2)
test slice::binary_search_l1_with_dups ... bench:          37 ns/iter (+/- 4)
test slice::binary_search_l2           ... bench:          76 ns/iter (+/- 3)
test slice::binary_search_l2_with_dups ... bench:          57 ns/iter (+/- 6)
test slice::binary_search_l3           ... bench:         200 ns/iter (+/- 30)
test slice::binary_search_l3_with_dups ... bench:         157 ns/iter (+/- 6)

$ ./x.py bench --stage 1 library/libcore
test slice::binary_search_l1           ... bench:          59 ns/iter (+/- 8)
test slice::binary_search_l1_with_dups ... bench:          37 ns/iter (+/- 2)
test slice::binary_search_l2           ... bench:          77 ns/iter (+/- 2)
test slice::binary_search_l2_with_dups ... bench:          57 ns/iter (+/- 2)
test slice::binary_search_l3           ... bench:         198 ns/iter (+/- 21)
test slice::binary_search_l3_with_dups ... bench:         158 ns/iter (+/- 11)

```

**New implementations (2)**

Suggested by `@nbdd0121` in [comment](https://github.com/rust-lang/rust/pull/74024#issuecomment-665430239).
```rust
base = if cmp == Greater { base } else { mid };
if cmp == Equal { break }
```

```sh
$ ./x.py bench --stage 1 library/libcore
test slice::binary_search_l1           ... bench:          59 ns/iter (+/- 7)
test slice::binary_search_l1_with_dups ... bench:          37 ns/iter (+/- 5)
test slice::binary_search_l2           ... bench:          75 ns/iter (+/- 3)
test slice::binary_search_l2_with_dups ... bench:          56 ns/iter (+/- 3)
test slice::binary_search_l3           ... bench:         195 ns/iter (+/- 15)
test slice::binary_search_l3_with_dups ... bench:         151 ns/iter (+/- 7)

$ ./x.py bench --stage 1 library/libcore
test slice::binary_search_l1           ... bench:          57 ns/iter (+/- 2)
test slice::binary_search_l1_with_dups ... bench:          38 ns/iter (+/- 2)
test slice::binary_search_l2           ... bench:          77 ns/iter (+/- 11)
test slice::binary_search_l2_with_dups ... bench:          57 ns/iter (+/- 4)
test slice::binary_search_l3           ... bench:         194 ns/iter (+/- 15)
test slice::binary_search_l3_with_dups ... bench:         151 ns/iter (+/- 18)

```

I run some benchmarking testings against on two implementations. The new implementation has a lot of improvement in duplicates cases, while in `binary_search_l3` case, it's a little bit slower than the old one.
2021-03-05 20:12:13 +00:00
Maarten de Vries c946d1d620 Bump libc dependency of std to 0.2.88. 2021-03-05 20:54:14 +01:00
Marianna Rapoport 2a57a5dcc4 Typo fix: cargo cov -> cargo profdata 2021-03-05 20:08:58 +01:00
Michael Howell 0571bc4263 Use substrings instead of split to grab enum variant paths
Both versions are about equally readable, but this version avoids scanning
the entire path and building an intermediate array (`split()` in Rust is
a lazy iterator, but not in JavaScript).
2021-03-05 11:20:31 -07:00
bjorn3 7a6ea77473 Merge commit '9a0c32934ebe376128230aa8da3275697b2053e7' into sync_cg_clif-2021-03-05 2021-03-05 19:12:59 +01:00
Giacomo Stevanato c1bfb9a78d Add relevant test 2021-03-05 19:09:23 +01:00
Giacomo Stevanato 2371914a05 Prevent Zip specialization from calling __iterator_get_unchecked twice with the same index after calling next_back 2021-03-05 19:03:32 +01:00
Nikita Popov c484bfe8fc Backport some LLVM compile-time improvements
This backports two compile-time improvements from the LLVM 13
branch, which reduce the number of alias analysis queries.
2021-03-05 17:59:28 +01:00
Felix S. Klock II 444a756769 Revise prefix a bit, adding both `--test` (conditionally) and `[RUSTC-SHIM]` unconditionally.
1. I added `--test` based on review feedback from simulacrum: I decided I would
rather include such extra context than get confused later on by its absence.
(However, I chose to encode it differently than how `[RUSTC-TIMING]` does... I
don't have much basis for doing so, other than `--test` to me more directly
reflects what it came from.)

2. I also decided to include `[RUSTC-SHIM]` at start of all of these lines
driven by the verbosity level, to make to clear where these lines of text
originate from. (Basically, I skimmed over the output and realized that a casual
observer might not be able to tell where this huge set of new lines were coming
from.)
2021-03-05 11:46:04 -05:00
mark e64138c534 use pat<no_top_alt> for patterns in let bindings 2021-03-05 10:10:04 -06:00
bjorn3 9a0c32934e Disable value debuginfo
This prevents an expensive Cranelift pass from running to reconstruct the debuginfo
2021-03-05 16:59:35 +01:00
Joshua Nelson 69a879f3d1 Store `UNVERSIONED_FILES` in a data structure
This allows querying it programatically.
2021-03-05 10:55:15 -05:00
Joshua Nelson a05a890c35 Build rustdoc for run-make tests, not just run-make-fulldeps
Rustdoc almost never needs a full stage 2 compiler, and requiring
rustdoc tests to be in run-make-fulldeps adds a lot of compile time for
no reason.
2021-03-05 10:48:21 -05:00
Guillaume Gomez 286a357045 Refactor from_clean_item_kind to improve ExternCrateItem handling 2021-03-05 16:05:07 +01:00
Guillaume Gomez f879ecc4ef Make ItemKind::ExternCrate looks like hir::ItemKind::ExternCrate to make transition over hir::ItemKind simpler 2021-03-05 16:04:24 +01:00
Dániel Buga 10a4c67a61 Add regression test for #75525 2021-03-05 16:01:46 +01:00
Guillaume Gomez a11e87e74d Make invalid_doc_attribute lint plural 2021-03-05 14:44:31 +01:00
bors 8fd946c63a Auto merge of #82795 - m-ou-se:rollup-uzx0b92, r=m-ou-se
Rollup of 10 pull requests

Successful merges:

 - #80723 (Implement NOOP_METHOD_CALL lint)
 - #80763 (resolve: Reduce scope of `pub_use_of_private_extern_crate` deprecation lint)
 - #81136 (Improved IO Bytes Size Hint)
 - #81939 (Add suggestion `.collect()` for iterators in iterators)
 - #82289 (Fix underflow in specialized ZipImpl::size_hint)
 - #82728 (Avoid unnecessary Vec construction in BufReader)
 - #82764 (Add {BTreeMap,HashMap}::try_insert)
 - #82770 (Add assert_matches macro.)
 - #82773 (Add diagnostic item to `Default` trait)
 - #82787 (Remove unused code from main.js)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-03-05 13:34:33 +00:00
Steven Fackler 1b4860ab2a
Update compiler/rustc/src/main.rs 2021-03-05 07:12:02 -05:00
Henry Boisdequin cb9b10cbd2 Update tests names to start with `issue-`
See @JohnTitor's [comment](https://github.com/rust-lang/rust/pull/82720#discussion_r586488083)

@rustbot label +C-cleanup
2021-03-05 17:04:58 +05:30
bjorn3 5e736293b3 Rustfmt 2021-03-05 11:21:44 +01:00
bjorn3 b5f67dc703 Rustup to rustc 1.52.0-nightly (45b3c2851 2021-03-04) 2021-03-05 10:58:30 +01:00
Mara 16518e70fb
Rollup merge of #82787 - notriddle:main-js-cleanup, r=GuillaumeGomez
Remove unused code from main.js

It looks like `lev_distance` was used in a very old version of the function, since it was written but never read, and Blame reports that it was added before the `checkGenerics` function header itself.

`convertHTMLToPlaintext` is was removed by 768d5e9509
2021-03-05 10:57:25 +01:00
Mara 2cd1f79aa1
Rollup merge of #82773 - mgacek8:feature/add_diagnostic_item_to_Default_trait, r=oli-obk
Add diagnostic item to `Default` trait

This PR adds diagnostic item to `Default` trait to be used by rust-lang/rust-clippy#6562 issue.
Also fixes the obsolete path to the `symbols.rs` file in the comment.
2021-03-05 10:57:24 +01:00
Mara 04045cc83f
Rollup merge of #82770 - m-ou-se:assert-match, r=joshtriplett
Add assert_matches macro.

This adds `assert_matches!(expression, pattern)`.

Unlike the other asserts, this one ~~consumes the expression~~ may consume the expression, to be able to match the pattern. (It could add a `&` implicitly, but that's noticable in the pattern, and will make a consuming guard impossible.)

See https://github.com/rust-lang/rust/issues/62633#issuecomment-790737853

This re-uses the same `left: .. right: ..` output as the `assert_eq` and `assert_ne` macros, but with the pattern as the right part:

assert_eq:
```
assertion failed: `(left == right)`
  left: `Some("asdf")`,
 right: `None`
```
assert_matches:
```
assertion failed: `(left matches right)`
  left: `Ok("asdf")`,
 right: `Err(_)`
```

cc ```@cuviper```
2021-03-05 10:57:23 +01:00
Mara 232caad395
Rollup merge of #82764 - m-ou-se:map-try-insert, r=Amanieu
Add {BTreeMap,HashMap}::try_insert

`{BTreeMap,HashMap}::insert(key, new_val)` returns `Some(old_val)` if the key was already in the map. It's often useful to assert no duplicate values are inserted.

We experimented with `map.insert(key, val).unwrap_none()` (https://github.com/rust-lang/rust/issues/62633), but decided that that's not the kind of method we'd like to have on `Option`s.

`insert` always succeeds because it replaces the old value if it exists. One could argue that `insert()` is never the right method for panicking on duplicates, since already handles that case by replacing the value, only allowing you to panic after that already happened.

This PR adds a `try_insert` method that instead returns a `Result::Err` when the key already exists. This error contains both the `OccupiedEntry` and the value that was supposed to be inserted. This means that unwrapping that result gives more context:
```rust
    map.insert(10, "world").unwrap_none();
    // thread 'main' panicked at 'called `Option::unwrap_none()` on a `Some` value: "hello"', src/main.rs:8:29
```

```rust
    map.try_insert(10, "world").unwrap();
    // thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value:
    // OccupiedError { key: 10, old_value: "hello", new_value: "world" }', src/main.rs:6:33
```

It also allows handling the failure in any other way, as you have full access to the `OccupiedEntry` and the value.

`try_insert` returns a reference to the value in case of success, making it an alternative to `.entry(key).or_insert(value)`.

r? ```@Amanieu```

Fixes https://github.com/rust-lang/rfcs/issues/3092
2021-03-05 10:57:22 +01:00
Mara 68f2934a15
Rollup merge of #82728 - calebsander:refactor/bufreader-buf, r=m-ou-se
Avoid unnecessary Vec construction in BufReader

As mentioned in #80460, creating a `Vec` and calling `Vec::into_boxed_slice()` emits unnecessary calls to `realloc()` and `free()`. Updated the code to use `Box::new_uninit_slice()` to create a boxed slice directly. I think this also makes it more explicit that the initial contents of the buffer are uninitialized.

r? ``@m-ou-se``
2021-03-05 10:57:20 +01:00
Mara ee796c6523
Rollup merge of #82289 - SkiFire13:fix-issue-82282, r=m-ou-se
Fix underflow in specialized ZipImpl::size_hint

Fixes #82282
2021-03-05 10:57:19 +01:00
Mara 20887b7ebf
Rollup merge of #81939 - kper:fixing-81584-allocate-in-iter, r=davidtwco
Add suggestion `.collect()` for iterators in iterators

Closes #81584

```
error[E0515]: cannot return value referencing function parameter `y`
 --> main3.rs:4:38
  |
4 | ...                   .map(|y| y.iter().map(|x| x + 1))
  |                                -^^^^^^^^^^^^^^^^^^^^^^
  |                                |
  |                                returns a value referencing data owned by the current function
  |                                `y` is borrowed here
  |                                help: Maybe use `.collect()` to allocate the iterator
```

Added the suggestion: `help: Maybe use `.collect()` to allocate the iterator`
2021-03-05 10:57:18 +01:00
Mara 60138110d7
Rollup merge of #81136 - Xavientois:io_reader_size_hint, r=cramertj
Improved IO Bytes Size Hint

After trying to implement better `size_hint()` return values for `File` in [this PR](https://github.com/rust-lang/rust/pull/81044) and changing to implementing it for `BufReader` in [this PR](https://github.com/rust-lang/rust/pull/81052), I have arrived at this implementation that provides tighter bounds for the `Bytes` iterator of various readers including `BufReader`, `Empty`, and `Chain`.

Unfortunately, for `BufReader`, the size_hint only improves after calling `fill_buffer` due to it using the contents of the buffer for the hint. Nevertheless, the the tighter bounds  should result in better pre-allocation of space to handle the contents of the `Bytes` iterator.

Closes #81052
2021-03-05 10:57:17 +01:00
Mara ec2619ca62
Rollup merge of #80763 - petrochenkov:pubusecrate, r=estebank
resolve: Reduce scope of `pub_use_of_private_extern_crate` deprecation lint

This lint was deny-by-default since July 2017, crater showed 7 uses on crates.io back then (https://github.com/rust-lang/rust/pull/42894#issuecomment-311921147).

Unfortunately, the construction `pub use foo as bar` where `foo` is `extern crate foo;` was used by an older version `bitflags`, so turning it into an error causes too many regressions.
So, this PR reduces the scope of the lint instead of turning it into a hard error, and only turns some more rarely used components of it into errors.
2021-03-05 10:57:15 +01:00
Mara e6a6df5daa
Rollup merge of #80723 - rylev:noop-lint-pass, r=estebank
Implement NOOP_METHOD_CALL lint

Implements the beginnings of https://github.com/rust-lang/lang-team/issues/67 - a lint for detecting noop method calls (e.g, calling `<&T as Clone>::clone()` when `T: !Clone`).

This PR does not fully realize the vision and has a few limitations that need to be addressed either before merging or in subsequent PRs:
* [ ] No UFCS support
* [ ] The warning message is pretty plain
* [ ] Doesn't work for `ToOwned`

The implementation uses [`Instance::resolve`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/instance/struct.Instance.html#method.resolve) which is normally later in the compiler. It seems that there are some invariants that this function relies on that we try our best to respect. For instance, it expects substitutions to have happened, which haven't yet performed, but we check first for `needs_subst` to ensure we're dealing with a monomorphic type.

Thank you to ```@davidtwco,``` ```@Aaron1011,``` and ```@wesleywiser``` for helping me at various points through out this PR ❤️.
2021-03-05 10:57:14 +01:00
bjorn3 9406510cee Sync from rust a0d66b54fb 2021-03-05 10:46:59 +01:00
Oli Scherer 9a2362e5a9 Shrink the size of Rvalue by 16 bytes 2021-03-05 09:33:01 +00:00
bors 8ccc89bc31 Auto merge of #82777 - GuillaumeGomez:rollup-etcsupl, r=GuillaumeGomez
Rollup of 5 pull requests

Successful merges:

 - #76716 (Don't warn for `missing_doc_examples` when item is #[doc(hidden)])
 - #82088 (Shorten html::render)
 - #82690 (Update rustdoc documentation)
 - #82752 (Add a regression test for issue-81712)
 - #82765 (Fix polymorphization ICE on associated types in trait decls using const generics in bounds)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-03-05 09:28:07 +00:00
bors a0d66b54fb Auto merge of #71481 - estebank:inherit-stability, r=nikomatsakis
Inherit `#[stable(..)]` annotations in enum variants and fields from its item

Lint changes for #65515. The stdlib will have to be updated once this lands in beta and that version is promoted in master.
2021-03-05 05:28:07 +00:00
Michael Howell ad91915455 Remove unused code from main.js
It looks like `lev_distance` was used in a very old version of the function,
since it was written but never read, and Blame reports that it was added
before the `checkGenerics` function header itself.

`convertHTMLToPlaintext` is was removed by 768d5e9509
2021-03-04 19:41:20 -07:00
Vadim Petrochenkov 1fe2eb83ec expand: Introduce enum for module loading errors and make module loading speculative 2021-03-05 01:33:43 +03:00
Vadim Petrochenkov 1e1d574aea expand: Share some code between inline and out-of-line module treatment 2021-03-05 01:33:43 +03:00
Vadim Petrochenkov 29a9ef2818 expand: Align some code with the PR fixing inner attributes on out-of-line modules 2021-03-05 01:33:43 +03:00
Vadim Petrochenkov da3419e18c rustc_interface: Hide some hacky details of early linting from expand 2021-03-05 01:33:43 +03:00
Vadim Petrochenkov 46b67aa74d expand: Some more consistent naming in module loading 2021-03-05 01:33:43 +03:00
Vadim Petrochenkov 3d0b622ab7 expand: Less path cloning during module loading 2021-03-05 01:33:43 +03:00
Vadim Petrochenkov 5bdf81d5fa expand: Determine module directory path directly instead of relying on span 2021-03-05 01:33:43 +03:00
Vadim Petrochenkov 39052c55bb expand: Move module file path stack from global session to expansion data
Also don't push the paths on the stack directly in `fn parse_external_mod`, return them instead.
2021-03-05 01:33:43 +03:00
Vadim Petrochenkov bc18eb4717 expand: Remove obsolete `DirectoryOwnership::UnownedViaMod`
This ownership kind is only constructed in the case of path attributes like `#[path = ".."]` without a file name segment, which always represent some kind of directories and will produce and error on attempt to parse them as a module file.
2021-03-05 01:33:43 +03:00
Felix S. Klock II f5eb5c884f Make rustc shim's verbose output include crate_name being compiled.
This change is mainly motivated by an issue with the environment
printing I added in PR 82403: multiple rustc invocations progress
in parallel, and the environment output, spanning multiple lines,
gets interleaved in ways make it difficult to extra the enviroment settings.

(This aforementioned difficulty is more of a hiccup than an outright
show-stopper, because the environment variables tend to be the same for all of
the rustc invocations, so it doesn't matter too much if one mixes up which lines
one is looking at. But still: Better to fix it.)
2021-03-04 17:19:41 -05:00
yn0ga ccca767834 Add powerpc-unknown-openbsd target
Add powerpc-unknown-openbsd target

* Fix missing abi::endian crate
* Missing platform-support.md
2021-03-04 22:43:34 +01:00