Commit graph

156502 commits

Author SHA1 Message Date
Yuki Okushi
371fd4f1c0
Rollup merge of #90074 - klensy:upvar-all, r=wesleywiser
2229 migrations small cleanup

This removes needless `format!`'ing of empty string and replaces `vec!` with const strings with const array.
2021-10-21 14:11:09 +09:00
Yuki Okushi
afdd0c3ade
Rollup merge of #90071 - cjgillot:no-blocks, r=oli-obk
Remove hir::map::blocks and use FnKind instead

The principal tool is `FnLikeNode`, which is not often used and can be easily implemented using `rustc_hir::intravisit::FnKind`.
2021-10-21 14:11:08 +09:00
Yuki Okushi
47a1f67a8d
Rollup merge of #90048 - GuillaumeGomez:line-number-setting, r=jsha
Add test for line-number setting

The first commit updates the version of the package to be able to have multi-line commands (which looks much nicer for this test).

r? ````@jsha````
2021-10-21 14:11:08 +09:00
Yuki Okushi
632f06d8eb
Rollup merge of #90031 - durin42:allow-llvm-tests, r=Mark-Simulacrum
config: add the option to enable LLVM tests

I'm working on some LLVM patches in concert with a Rust patch, and it's
helping me quite a bit to have this as an option. It doesn't seem that
hard, so I figured I'd formalize it in x.py and send it upstream.
2021-10-21 14:11:07 +09:00
Yuki Okushi
a980587421
Rollup merge of #90029 - tgnottingham:incr-debug-logging-test, r=Mark-Simulacrum
Add test for debug logging during incremental compilation

Debug logging during incremental compilation had been broken for some
time, until #89343 fixed it (among other things). Add a test so this is
less likely to break without being noticed. This test is nearly a copy
of the `src/test/ui/rustc-rust-log.rs` test, but tests debug logging in
the incremental compliation code paths.
2021-10-21 14:11:06 +09:00
Yuki Okushi
d29e98fe93
Rollup merge of #90010 - rusticstuff:vecdeque_with_capacity_in_overflow, r=m-ou-se
Avoid overflow in `VecDeque::with_capacity_in()`.

The overflow only happens if alloc is compiled with overflow checks enabled and the passed capacity is greater or equal 2^(usize::BITS-1). The overflow shadows the expected "capacity overflow" panic leading to a test failure if overflow checks are enabled for std in the CI.

Unblocks [CI: Enable overflow checks for test (non-dist) builds #89776](https://github.com/rust-lang/rust/pull/89776).

For some reason the overflow is only observable with optimization turned off, but that is a separate issue.
2021-10-21 14:11:05 +09:00
Yuki Okushi
20687bb4f1
Rollup merge of #89292 - CleanCut:stabilize-cstring_from_vec_with_nul, r=JohnTitor
Stabilize CString::from_vec_with_nul[_unchecked]

Closes the tracking issue #73179. I am keeping this in _draft_ mode until the FCP has ended.

This is my first time stabilizing a feature, so I would appreciate any guidance on things I should do differently.

Closes #73179
2021-10-21 14:11:04 +09:00
Yuki Okushi
6f0acbcbd0
Rollup merge of #88644 - eopb:abstractconst_leaf_subst, r=lcnr
`AbstractConst` private fields

Calls `subst` in `AbstractConst::root` when `Node` is `Leaf`.

r? ``@lcnr``
2021-10-21 14:11:03 +09:00
Yuki Okushi
fb9232b453
Rollup merge of #87440 - twetzel59:fix-barrier-no-op, r=yaahc
Remove unnecessary condition in Barrier::wait()

This is my first pull request for Rust, so feel free to call me out if anything is amiss.

After some examination, I realized that the second condition of the "spurious-wakeup-handler" loop in ``std::sync::Barrier::wait()`` should always evaluate to ``true``, making it redundant in the ``&&`` expression.

Here is the affected function before the fix:
```rust
#[stable(feature = "rust1", since = "1.0.0")]
pub fn wait(&self) -> BarrierWaitResult {
    let mut lock = self.lock.lock().unwrap();
    let local_gen = lock.generation_id;
    lock.count += 1;
    if lock.count < self.num_threads {
        // We need a while loop to guard against spurious wakeups.
        // https://en.wikipedia.org/wiki/Spurious_wakeup
        while local_gen == lock.generation_id && lock.count < self.num_threads { // fixme
            lock = self.cvar.wait(lock).unwrap();
        }
        BarrierWaitResult(false)
    } else {
        lock.count = 0;
        lock.generation_id = lock.generation_id.wrapping_add(1);
        self.cvar.notify_all();
        BarrierWaitResult(true)
    }
}
```

At first glance, it seems that the check that ``lock.count < self.num_threads`` would be necessary in order for a thread A to detect when another thread B has caused the barrier to reach its thread count, making thread B the "leader".

However, the control flow implicitly results in an invariant that makes observing ``!(lock.count < self.num_threads)``, i.e. ``lock.count >= self.num_threads`` impossible from thread A.

When thread B, which will be the leader, calls ``.wait()`` on this shared instance of the ``Barrier``, it locks the mutex in the first line and saves the ``MutexGuard`` in the ``lock`` variable. It then increments the value of ``lock.count``. However, it then proceeds to check if ``lock.count < self.num_threads``. Since it is the leader, it is the case that (after the increment of ``lock.count``), the lock count is *equal* to the number of threads. Thus, the second branch is immediately taken and ``lock.count`` is zeroed. Additionally, the generation ID is incremented (with wrap). Then, the condition variable is signalled. But, the other threads are waiting at the line ``lock = self.cvar.wait(lock).unwrap();``, so they cannot resume until thread B's call to ``Barrier::wait()`` returns, which drops the ``MutexGuard`` acquired in the first ``let`` statement and unlocks the mutex.

The order of events is thus:
1. A thread A calls `.wait()`
2. `.wait()` acquires the mutex, increments `lock.count`, and takes the first branch
3. Thread A enters the ``while`` loop since the generation ID has not changed and the count is less than the number of threads for the ``Barrier``
3. Spurious wakeups occur, but both conditions hold, so the thread A waits on the condition variable
4. This process repeats for N - 2 additional times for non-leader threads A'
5. *Meanwhile*, Thread B calls ``Barrier::wait()`` on the same barrier that threads A, A', A'', etc. are waiting on. The thread count reaches the number of threads for the ``Barrier``, so all threads should now proceed, with B being the leader. B acquires the mutex and increments the value ``lock.count`` only to find that it is not less than ``self.num_threads``. Thus, it immediately clamps ``self.num_threads`` back down to 0 and increments the generation. Then, it signals the condvar to tell the A (prime) threads that they may continue.
6. The A, A', A''... threads wake up and attempt to re-acquire the ``lock`` as per the internal operation of a condition variable. When each A has exclusive access to the mutex, it finds that ``lock.generation_id`` no longer matches ``local_generation`` **and the ``&&`` expression short-circuits -- and even if it were to evaluate it, ``self.count`` is definitely less than ``self.num_threads`` because it has been reset to ``0`` by thread B *before* B dropped its ``MutexGuard``**.

Therefore, it my understanding that it would be impossible for the non-leader threads to ever see the second boolean expression evaluate to anything other than ``true``. This PR simply removes that condition.

Any input would be appreciated. Sorry if this is terribly verbose. I'm new to the Rust community and concurrency can be hard to explain in words. Thanks!
2021-10-21 14:11:02 +09:00
Yuki Okushi
09de34c107
Rollup merge of #86984 - Smittyvb:ipv4-octal-zero, r=m-ou-se
Reject octal zeros in IPv4 addresses

This fixes #86964 by rejecting octal zeros in IP addresses, such that `192.168.00.00000000` is rejected with a parse error, since having leading zeros in front of another zero indicates it is a zero written in octal notation, which is not allowed in the strict mode specified by RFC 6943 3.1.1. Octal rejection was implemented in #83652, but due to the way it was implemented octal zeros were still allowed.
2021-10-21 14:11:01 +09:00
bors
4626184caf Auto merge of #89998 - camelid:box-default, r=jyn514
rustdoc: Box some fields of `GenericParamDefKind` to reduce size

This change shrinks `GenericParamDef` from 120 to 56 bytes. `GenericParamDef` is
used a lot, so the extra indirection should hopefully be worth the size savings.

r? `@ghost`
2021-10-21 01:38:55 +00:00
Nathan Stocks
39af41ed65
fix 'since' version number
Co-authored-by: Yuki Okushi <jtitor@2k36.org>
2021-10-20 15:36:55 -06:00
Nathan Stocks
86b3dd9e0a stabilize CString::from_vec_with_nul[_unchecked] 2021-10-20 14:19:13 -06:00
bors
efd0483949 Auto merge of #89978 - cjgillot:qarray, r=Mark-Simulacrum
Merge the two depkind vtables

Knowledge of `DepKind`s is managed using two arrays containing flags (is_anon, eval_always, fingerprint_style), and function pointers (forcing and loading code).

This PR aims at merging the two arrays so as to reduce unneeded indirect calls and (hopefully) increase code locality.
r? `@ghost`
2021-10-20 17:57:35 +00:00
Camille GILLOT
b11ec29e28 Address review. 2021-10-20 18:51:15 +02:00
Camille GILLOT
8785b70774 Inline DepNodeParams methods. 2021-10-20 18:46:25 +02:00
Camille GILLOT
df71d0874a Compute query vtable manually. 2021-10-20 18:41:28 +02:00
Camille GILLOT
69a3594635 Store node_intern_event_id in CurrentDepGraph. 2021-10-20 18:37:11 +02:00
Camille GILLOT
bd5c107672 Build jump table at runtime. 2021-10-20 18:32:29 +02:00
Camille GILLOT
602d3cbce3 Invoke callbacks from rustc_middle. 2021-10-20 18:29:33 +02:00
Camille GILLOT
b09de95fab Merge two query callbacks arrays. 2021-10-20 18:29:27 +02:00
Camille GILLOT
dc7143367c Drop has_params. 2021-10-20 18:29:22 +02:00
Camille GILLOT
aa404c24dd Make hash_result an Option. 2021-10-20 18:29:18 +02:00
Camille GILLOT
e53404cca6 Move def_path_hash_to_def_id to rustc_middle. 2021-10-20 18:28:54 +02:00
Camille GILLOT
88c6d3de95 Avoid trivial lambdas. 2021-10-20 18:24:16 +02:00
bors
3d71e749a2 Auto merge of #90050 - michaelwoerister:fix-vtable-debug-name-crash-90019, r=wesleywiser
Erase late-bound regions before computing vtable debuginfo name.

Fixes #90019.

The `msvc_enum_fallback()` for computing enum type names needs to access the memory layout of niche enums in order to determine the type name. `compute_debuginfo_vtable_name()` did not properly erase regions before computing type names which made memory layout computation ICE when encountering un-erased regions.

r? `@wesleywiser`
2021-10-20 14:37:48 +00:00
Guillaume Gomez
457f5782f3 Add test for line-number setting 2021-10-20 13:36:08 +02:00
Ethan Brierley
be30e60296 remove duplicate subst 2021-10-20 10:21:06 +01:00
bors
6162529a01 Auto merge of #89100 - petrochenkov:localbind, r=cjgillot
resolve: Use `NameBinding` for local variables and generic parameters

`NameBinding` is a structure used for representing any name introduction (an item, or import, or even a built-in).
Except that local variables and generic parameters weren't represented as `NameBinding`s, for this reason they requires separate paths in name resolution code in several places.

This PR introduces `NameBinding`s for local variables as well and simplifies all the code working with them leaving only the `NameBinding` paths.
2021-10-20 07:21:01 +00:00
klensy
f3fb821f3b use array explicitly instead of vec for const content (even if optimizer smart enought to remove allocation) 2021-10-20 03:24:07 +03:00
klensy
aad48f71b3 replace format!("") with String::new()
use array explicitly instead of vec for const content (even if optimizer smart enought to remove allocation)
2021-10-20 03:23:24 +03:00
bors
42983a28ab Auto merge of #90067 - JohnTitor:rollup-afrjulz, r=JohnTitor
Rollup of 10 pull requests

Successful merges:

 - #86479 (Automatic exponential formatting in Debug)
 - #87404 (Add support for artifact size profiling)
 - #87769 (Alloc features cleanup)
 - #88789 (remove unnecessary bound on Zip specialization impl)
 - #88860 (Deduplicate panic_fmt)
 - #90009 (Make more `From` impls `const` (libcore))
 - #90018 (Fix rustdoc UI for very long type names)
 - #90025 (Revert #86011 to fix an incorrect bound check)
 - #90036 (Remove border-bottom from most docblocks.)
 - #90060 (Update RELEASES.md)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-10-19 22:14:21 +00:00
Camille GILLOT
6e98688e68 Replace FnLikeNode by FnKind. 2021-10-19 23:31:51 +02:00
Ethan Brierley
99b8c016ce Address lcnr review 2021-10-19 22:18:13 +01:00
Camille GILLOT
05eb6f36f1 Cleanup dead code in hir::map::blocks. 2021-10-19 23:10:09 +02:00
Yuki Okushi
e54ebe91dd
Rollup merge of #90060 - vincentdephily:patch-1, r=Mark-Simulacrum
Update RELEASES.md

Fix typo.
2021-10-20 04:35:18 +09:00
Yuki Okushi
570b999c96
Rollup merge of #90036 - jsha:less-rule, r=GuillaumeGomez
Remove border-bottom from most docblocks.

Headings in the top-doc docblock still get a border-bottom due to a rule
that covers all h2, h3, and h4. Method docblocks are generally h5, and
so don't get a border-bottom anymore.

This fixes a problem where a sub-sub-heading within a method would have
a line that went all the way across the page, creating a division that
made that sub-sub-heading look much more important than it really is.

Fixes #90033

Demo at https://jacob.hoffman-andrews.com/rust/less-rule/std/string/struct.String.html

r? ``@GuillaumeGomez``
2021-10-20 04:35:17 +09:00
Yuki Okushi
d8b3764bd2
Rollup merge of #90025 - JohnTitor:revert-86011, r=estebank
Revert #86011 to fix an incorrect bound check

This reverts commit 36a1076d24, reversing
changes made to e1e9319d93.

Fixes #89935
r? ``@estebank``
2021-10-20 04:35:17 +09:00
Yuki Okushi
7ceab9ef14
Rollup merge of #90018 - GuillaumeGomez:too-long-item-names, r=jsha
Fix rustdoc UI for very long type names

Fixes #89972.

While working on it, I also discovered that when the item name is too long, it also breaks the flow of the page.

To make things right, I also renamed the `type-decl` CSS class into `item-decl` (because this PR also generates it for more than type declarations).

So here are the before/after screenshots:

![Screenshot from 2021-10-18 16-58-03](https://user-images.githubusercontent.com/3050060/137757247-637fcf04-4406-49c6-8a8a-18c2074aacd9.png)
![Screenshot from 2021-10-18 16-58-26](https://user-images.githubusercontent.com/3050060/137757252-17935e63-53b3-449f-a535-7be91ff0e257.png)

![Screenshot from 2021-10-18 16-58-07](https://user-images.githubusercontent.com/3050060/137757278-8b12e348-2980-4fc4-8853-bef99d58981f.png)
![Screenshot from 2021-10-18 16-58-28](https://user-images.githubusercontent.com/3050060/137757282-534a0e1b-3016-49ba-b3ac-e45bdb9035cb.png)

r? ``@jsha``
2021-10-20 04:35:15 +09:00
Yuki Okushi
9f2ad0a061
Rollup merge of #90009 - woppopo:const_from_more, r=dtolnay
Make more `From` impls `const` (libcore)

Adding `const` to `From` implementations in the core. `rustc_const_unstable` attribute is not added to unstable implementations.

Tracking issue: #88674

<details>
<summary>Done</summary><div>

- `T` from `T`
- `T` from `!`
- `Option<T>` from `T`
- `Option<&T>` from `&Option<T>`
- `Option<&mut T>` from `&mut Option<T>`
- `Cell<T>` from `T`
- `RefCell<T>` from `T`
- `UnsafeCell<T>` from `T`
- `OnceCell<T>` from `T`
- `Poll<T>` from `T`
- `u32` from `char`
- `u64` from `char`
- `u128` from `char`
- `char` from `u8`
- `AtomicBool` from `bool`
- `AtomicPtr<T>` from `*mut T`
- `AtomicI(bits)` from `i(bits)`
- `AtomicU(bits)` from `u(bits)`
- `i(bits)` from `NonZeroI(bits)`
- `u(bits)` from `NonZeroU(bits)`
- `NonNull<T>` from `Unique<T>`
- `NonNull<T>` from `&T`
- `NonNull<T>` from `&mut T`
- `Unique<T>` from `&mut T`
- `Infallible` from `!`
- `TryIntError` from `!`
- `TryIntError` from `Infallible`
- `TryFromSliceError` from `Infallible`
- `FromResidual for Option<T>`
</div></details>

<details>
<summary>Remaining</summary><dev>

- `NonZero` from `NonZero`
These can't be made const at this time because these use Into::into.
https://github.com/rust-lang/rust/blob/master/library/core/src/convert/num.rs#L393

- `std`, `alloc`
There may still be many implementations that can be made `const`.
</div></details>
2021-10-20 04:35:15 +09:00
Yuki Okushi
f7024998c7
Rollup merge of #88860 - nbdd0121:panic, r=m-ou-se
Deduplicate panic_fmt

std's begin_panic_fmt and core's panic_fmt are duplicates. Merge them to declutter code and remove a lang item.
2021-10-20 04:35:14 +09:00
Yuki Okushi
84fe598f00
Rollup merge of #88789 - the8472:rm-zip-bound, r=JohnTitor
remove unnecessary bound on Zip specialization impl

I originally added this bound in an attempt to make the specialization
sound for owning iterators but it was never correct here and the correct
and [already implemented](497ee321af/library/alloc/src/vec/into_iter.rs (L220-L232)) solution is is to place it on the IntoIter
implementation.
2021-10-20 04:35:13 +09:00
Yuki Okushi
71fcb72307
Rollup merge of #87769 - m-ou-se:alloc-features-cleanup, r=yaahc,dtolnay
Alloc features cleanup

This sorts and categorizes the `#![features]` in `alloc` and removes unused ones.

This is part of #87766

The following feature attributes were unnecessary and are removed:

```diff
// Library features:
-#![feature(cow_is_borrowed)]
-#![feature(maybe_uninit_uninit_array)]
-#![feature(slice_partition_dedup)]

// Language features:
-#![feature(arbitrary_self_types)]
-#![feature(auto_traits)]
-#![feature(box_patterns)]
-#![feature(decl_macro)]
-#![feature(nll)]
```
2021-10-20 04:35:12 +09:00
Yuki Okushi
3d95330230
Rollup merge of #87404 - rylev:artifact-size-profiling, r=wesleywiser
Add support for artifact size profiling

This adds support for profiling artifact file sizes (incremental compilation artifacts and query cache to begin with).

Eventually we want to track this in perf.rlo so we can ensure that file sizes do not change dramatically on each pull request.

This relies on support in measureme: https://github.com/rust-lang/measureme/pull/169. Once that lands we can update this PR to not point to a git dependency.

This was worked on together with `@michaelwoerister.`

r? `@wesleywiser`
2021-10-20 04:35:11 +09:00
Yuki Okushi
ca6798ab07
Rollup merge of #86479 - exphp-forks:float-debug-exponential, r=yaahc
Automatic exponential formatting in Debug

Context: See [this comment from the libs team](https://github.com/rust-lang/rfcs/pull/2729#issuecomment-853454204)

---

Makes `"{:?}"` switch to exponential for floats based on magnitude. The libs team suggested exploring this idea in the discussion thread for RFC rust-lang/rfcs#2729. (**note:** this is **not** an implementation of the RFC; it is an implementation of one of the alternatives)

Thresholds chosen were 1e-4 and 1e16.  Justification described [here](https://github.com/rust-lang/rfcs/pull/2729#issuecomment-864482954).

**This will require a crater run.**

---

As mentioned in the commit message of 8731d4dfb4, this behavior will not apply when a precision is supplied, because I wanted to preserve the following existing and useful behavior of `{:.PREC?}` (which recursively applies `{:.PREC}` to floats in a struct):

```rust
assert_eq!(
    format!("{:.2?}", [100.0, 0.000004]),
    "[100.00, 0.00]",
)
```

I looked around and am not sure where there are any tests that actually use this in the test suite, though?

All things considered, I'm surprised that this change did not seem to break even a single existing test in `x.py test --stage 2`.  (even when I tried a smaller threshold of 1e6)
2021-10-20 04:35:10 +09:00
Wesley Wiser
5929cf0d67
Update src/test/codegen/debug-vtable.rs
Co-authored-by: r00ster <r00ster91@protonmail.com>
2021-10-19 11:36:21 -04:00
Vincent de Phily
3b53c8ef3d
Update RELEASES.md
Fix typo.
2021-10-19 15:50:27 +01:00
bors
1af55d19c7 Auto merge of #89933 - est31:let_else, r=michaelwoerister
Adopt let_else across the compiler

This performs a substitution of code following the pattern:

```
let <id> = if let <pat> = ... { identity } else { ... : ! };
```

To simplify it to:

```
let <pat> = ... { identity } else { ... : ! };
```

By adopting the `let_else` feature (cc #87335).

The PR also updates the syn crate because the currently used version of the crate doesn't support `let_else` syntax yet.

Note: Generally I'm the person who *removes* usages of unstable features from the compiler, not adds more usages of them, but in this instance I think it hopefully helps the feature get stabilized sooner and in a better state. I have written a [comment](https://github.com/rust-lang/rust/issues/87335#issuecomment-944846205) on the tracking issue about my experience and what I feel could be improved before stabilization of `let_else`.
2021-10-19 14:41:39 +00:00
Gary Guo
7bd93dfeef Remove begin_panic_fmt from clippy 2021-10-19 15:15:59 +01:00
Gary Guo
9370156957 Deduplicate panic_fmt
std's begin_panic_fmt and core's panic_fmt are duplicates.
Merge them to declutter code and remove a lang item.
2021-10-19 15:02:21 +01:00