Commit Graph

252457 Commits

Author SHA1 Message Date
Michael Goulet 05bb3d2683 Just use type_dependent_def_id to figure out what the method is for an expr 2024-04-15 17:14:59 -04:00
bors 99d0186b1d Auto merge of #123968 - jieyouxu:rollup-1pnkxor, r=jieyouxu
Rollup of 12 pull requests

Successful merges:

 - #123423 (Distribute LLVM bitcode linker as a preview component)
 - #123548 (libtest: also measure time in Miri)
 - #123666 (Fix some typos in doc)
 - #123864 (Remove a HACK by instead inferring opaque types during expected/formal type checking)
 - #123896 (Migrate some diagnostics in `rustc_resolve` to session diagnostic)
 - #123919 (builtin-derive: tag → discriminant)
 - #123922 (Remove magic constants when using `base_n`.)
 - #123931 (Don't leak unnameable types in `-> _` recover)
 - #123933 (move the LargeAssignments lint logic into its own file)
 - #123934 (`rustc_data_structures::graph` mini refactor)
 - #123941 (Fix UB in LLVM FFI when passing zero or >1 bundle)
 - #123957 (disable create_dir_all_bare test on all(miri, windows))

r? `@ghost`
`@rustbot` modify labels: rollup
2024-04-15 16:46:59 +00:00
许杰友 Jieyou Xu (Joe) 723c0e23bc
Rollup merge of #123957 - RalfJung:create_dir_all_bare, r=joboet
disable create_dir_all_bare test on all(miri, windows)
2024-04-15 16:56:19 +01:00
许杰友 Jieyou Xu (Joe) 4f3a39ba79
Rollup merge of #123941 - Mark-Simulacrum:fix-llvm-ub, r=nikic
Fix UB in LLVM FFI when passing zero or >1 bundle

Rust passes a `*const &OperandBundleDef` to these APIs, usually from a `Vec<&OperandBundleDef>` or so. Previously we were dereferencing that pointer and passing it to the ArrayRef constructor with some length (N).

This meant that if the length was 0, we were dereferencing a pointer to nowhere (if the vector on the Rust side didn't actually get allocated or so), and if the length was >1 then loading the *second* element somewhere in LLVM would've been reading past the end.

Since Rust can't hold OperandBundleDef by-value we're forced to indirect through a vector that copies out the OperandBundleDefs from the by-reference list on the Rust side in order to match the LLVM expected API.
2024-04-15 16:56:19 +01:00
许杰友 Jieyou Xu (Joe) 5580ae9795
Rollup merge of #123934 - WaffleLapkin:graph-mini-refactor, r=fmease
`rustc_data_structures::graph` mini refactor

Who doesn't love to breathe dust from the ancient times?
2024-04-15 16:56:18 +01:00
许杰友 Jieyou Xu (Joe) b79d0b0849
Rollup merge of #123933 - RalfJung:large-assignments, r=michaelwoerister
move the LargeAssignments lint logic into its own file

The collector is a file full of very subtle logic, so let's try to keep that separate from the logic that only serves to implement this lint.
2024-04-15 16:56:18 +01:00
许杰友 Jieyou Xu (Joe) 313b02a86b
Rollup merge of #123931 - compiler-errors:variance-unnameables, r=fmease
Don't leak unnameable types in `-> _` recover

Fixes #123899
2024-04-15 16:56:17 +01:00
许杰友 Jieyou Xu (Joe) 1870e2d09f
Rollup merge of #123922 - TDecking:base_n_magic_removal, r=jieyouxu
Remove magic constants when using `base_n`.

Some use cases of `base_n` use number literals instead of the predefined constants. The latter are more descriptive so it might be better to use those instead.
2024-04-15 16:56:17 +01:00
许杰友 Jieyou Xu (Joe) b1d1e081be
Rollup merge of #123919 - RalfJung:discriminant, r=compiler-errors
builtin-derive: tag → discriminant

As far as I can tell, all of this operates on the discriminant, not the tag. After all, with something like `Option<&T>`, the "tag" of the `Some` variant is basically just the reference value, which is never what you want to compare when figuring out which variant the enum is in.

See [here](https://rustc-dev-guide.rust-lang.org/appendix/glossary.html) for an explanation of the difference between tag and discriminant.
2024-04-15 16:56:16 +01:00
许杰友 Jieyou Xu (Joe) 18e6bb2851
Rollup merge of #123896 - JeanCASPAR:rustc_resolve-to-session-diagnostic, r=jieyouxu
Migrate some diagnostics in `rustc_resolve` to session diagnostic

Hello, I migrated some diagnostics in `rustc_resolve` to session diagnostic.

r? ``@davidtwco``
2024-04-15 16:56:15 +01:00
许杰友 Jieyou Xu (Joe) 699612fb8a
Rollup merge of #123864 - oli-obk:define_opaque_types3, r=compiler-errors
Remove a HACK by instead inferring opaque types during expected/formal type checking

I was wondering why I couldn't come up with a test that hits the code path of the argument check checking the types we inferred from the return type... Turns out we reject those attempts early during fudging.

I have absolutely no information for you as to what kind of type inference changes this may incur, but I think we should just land this out of two reasons:

* had I found the other place to use opaque type inference on before I added the hack, we'd be using that today and this PR would never have happened
* if it is possible to hit this path, it requires some god awful recursive RPIT logic that I doubt anyone would have written without actively trying to write obscure code

r? ``@ghost``
2024-04-15 16:56:15 +01:00
许杰友 Jieyou Xu (Joe) 4d2a8e3692
Rollup merge of #123666 - mountcount:master, r=lqd
Fix some typos in doc
2024-04-15 16:56:14 +01:00
许杰友 Jieyou Xu (Joe) 2074631732
Rollup merge of #123548 - RalfJung:what-is-time, r=joboet
libtest: also measure time in Miri

A long time ago we disabled timekeeping of the default test harness in Miri, as otherwise it would fail to run without `-Zmiri-disable-isolation`. However, since then Miri gained a "fake clock" that lets it present some deterministic notion of time when isolation is enabled.

So we could now let libtest do timekeeping again when running in Miri. That's nice as it can help detect tests that run too long. However it can also be confusing as the results with isolation can be quite different than the real time.

``@rust-lang/miri`` what do you think?
2024-04-15 16:56:14 +01:00
许杰友 Jieyou Xu (Joe) e07d18fb2f
Rollup merge of #123423 - kjetilkjeka:llvm_bitcode_linker_component, r=Mark-Simulacrum
Distribute LLVM bitcode linker as a preview component

The self-contained LLVM bitcode linker was recently added in #117458. It is currently only in use to link the Nvidia ptx assembly tests when running rustc tests (local or CI). In fact, the linker itself is currently only usable for the `nvptx64-nvidia-cuda` target, but more targets will be supported in the future.

The reason a new linker was needed for the ptx format is that the [old one](https://github.com/denzp/rust-ptx-linker) has not been updated the last few years. It worked fine for a while, but as LLVM changed it broke and the nvptx tests was [disabled in rustc back in 2019](f8f9a2869c). It was ad-hoc patched and have been used in a sub-optimal state by the community until now.

If this PR is merged, the LLVM bitcode linker will be distributed as a preview component that can be used as a replacement for the old ptx-linker for development in addition to rustc tests. In addition to installing the `llvm-bitcode-linker` component, also the `llvm-tools` component must be installed as the `llvm-bitcode-linker` works by calling llvm tools.

Even though the LLVM bitcode linker is in its early stages it already now provides a lot of value over the old ptx-linker just by working and using up-to-date llvm tooling. By shipping it as a component it will be easier to gather user experience and improving it.

``@petrochenkov`` when installing as a component it will be installed in the self-contained folder and will not work with `-Clink-self-contained=no` (although for some reason I expect to be a bug `-Clink-self-contained=-linker` doesn't properly disable it). However, when building using `x.py build` it will be placed in the `lib/rustlib/<target>/bin` directory and will be available for internal tests even if `-Clink-self-contained=no` is passed.

CC: ``@Mark-Simulacrum`` as I very briefly discussed it with you some months ago https://rust-lang.zulipchat.com/#narrow/stream/242791-t-infra/topic/.E2.9C.94.20How.20to.20ship.20a.20new.20tool.20.28embedded.20linker.29.20to.20users.3F
2024-04-15 16:56:13 +01:00
bors 023084804e Auto merge of #123937 - RalfJung:miri-link-section, r=oli-obk
Miri on Windows: run .CRT$XLB linker section on thread-end

Hopefully fixes https://github.com/rust-lang/rust/issues/123583

First commit is originally by `@bjorn3`

r? `@oli-obk`
Cc `@ChrisDenton`
2024-04-15 14:36:12 +00:00
Maybe Waffle 435db9b9bd Use RPITIT for `Successors` and `Predecessors` traits
Now with RPITIT instead of GAT!
2024-04-15 13:34:08 +00:00
Kjetil Kjeka 235d45e9c9 Distribute LLVM bitcode linker as a preview component 2024-04-15 15:11:28 +02:00
bors 84e729a59f Auto merge of #123851 - NobodyXu:patch-1, r=BurntSushi
Update document for std::io::Error::downcast

Resolve concern raised by `@BurntSushi` https://github.com/rust-lang/rust/issues/99262#issuecomment-2042641813
2024-04-15 12:32:57 +00:00
Jiahao XU 05366ee270
Update doc for std::io::Error::downcast 2024-04-15 21:58:36 +10:00
bors d493fd148d Auto merge of #115717 - jsgf:stablize-json-unused-externs, r=oli-obk
Stabilize --json unused-externs(-silent)

Implement https://github.com/rust-lang/compiler-team/issues/674 ~~(pending its approval)~~
2024-04-15 10:11:46 +00:00
mountcount 7d1ee8c0fb Fix some typos in doc
Signed-off-by: mountcount <cuimoman@outlook.com>
2024-04-15 16:39:37 +08:00
Ralf Jung 24dac6cd45 disable create_dir_all_bare on all(miri, windows) 2024-04-15 10:15:14 +02:00
bors 5dcb678ad8 Auto merge of #122917 - saethlin:atomicptr-to-int, r=nikic
Add the missing inttoptr when we ptrtoint in ptr atomics

Ralf noticed this here: https://github.com/rust-lang/rust/pull/122220#discussion_r1535172094

Our previous codegen forgot to add the cast back to integer type. The code compiles anyway, because of course all locals are in-memory to start with, so previous codegen would do the integer atomic, store the integer to a local, then load a pointer from that local. Which is definitely _not_ what we wanted: That's an integer-to-pointer transmute, so all pointers returned by these `AtomicPtr` methods didn't have provenance. Yikes.

Here's the IR for `AtomicPtr::fetch_byte_add` on 1.76: https://godbolt.org/z/8qTEjeraY
```llvm
define noundef ptr `@atomicptr_fetch_byte_add(ptr` noundef nonnull align 8 %a, i64 noundef %v) unnamed_addr #0 !dbg !7 {
start:
  %0 = alloca ptr, align 8, !dbg !12
  %val = inttoptr i64 %v to ptr, !dbg !12
  call void `@llvm.lifetime.start.p0(i64` 8, ptr %0), !dbg !28
  %1 = ptrtoint ptr %val to i64, !dbg !28
  %2 = atomicrmw add ptr %a, i64 %1 monotonic, align 8, !dbg !28
  store i64 %2, ptr %0, align 8, !dbg !28
  %self = load ptr, ptr %0, align 8, !dbg !28
  call void `@llvm.lifetime.end.p0(i64` 8, ptr %0), !dbg !28
  ret ptr %self, !dbg !33
}
```

r? `@RalfJung`
cc `@nikic`
2024-04-15 08:07:47 +00:00
Ralf Jung 510720e9fc libtest: also measure time in Miri 2024-04-15 09:50:42 +02:00
bors 85b884b058 Auto merge of #122997 - matthiaskrgr:compiletest_ices, r=oli-obk
compiletest ice tracking

see https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/where.20to.20mass-add.20known.20ices.20.2F.20merging.20glacier.20into.20rust/near/429082963

This will allow us to sunset most of https://github.com/rust-lang/glacier
The rustc ices will be tracked directly inside the rust testsuite
There are a couple of .sh tests remaining that I have not ported over yet.

This adds `tests/crashes`, a file inside this directory MUST ice, otherwise it is considered test-fail.
This will be used to track ICEs from glacier and the bugtracker.
When someones pr accidentally fixes one of these ICEs, they can move the test from `crashes` into `ui` for example.

I also added a new tidy lint that warns when a test inside `tests/crashes` does not have a `//@ known-bug: ` line

the env var `COMPILETEST_VERBOSE_CRASHES` can be set to get exit code, stderr and stdout of a crash-test to aid debugging/adding tests.
2024-04-15 06:04:50 +00:00
Mark Rousskov bf3deccdad Fix UB in LLVM FFI when passing zero or >1 bundle
Rust passes a *const &OperandBundleDef to these APIs, usually from a
Vec<&OperandBundleDef> or so. Previously we were dereferencing that
pointer and passing it to the ArrayRef constructor with some length (N).

This meant that if the length was 0, we were dereferencing a pointer to
nowhere, and if the length was >1 then loading the *second* element
somewhere in LLVM would've been reading past the end.

Since Rust can't hold OperandBundleDef by-value we're forced to indirect
through a vector that copies out the OperandBundleDefs from the
by-reference list on the Rust side in order to match the LLVM expected
API.
2024-04-14 22:18:33 -04:00
bors 9db7a74525 Auto merge of #123928 - tbu-:pr_statx_enosys, r=workingjubilee
`statx` probe: `ENOSYS` might come from a faulty FUSE driver

Do the availability check regardless of the error returned from `statx`.

CC https://github.com/rust-lang/rust/pull/122079#discussion_r1564761281
2024-04-15 02:07:35 +00:00
bors 1d8f4a6d9c Auto merge of #123828 - cuviper:cargo-aarch64-gnu, r=Mark-Simulacrum
ci: test cargo on `aarch64-gnu`

Since `aarch64-unknown-linux-gnu` is a tier-1 target, we should also test cargo on it, especially since cargo's own CI doesn't cover this yet. This might have helped us discover #123733 sooner, which is not a cargo problem but was uncovered by a new cargo test (which we'll have to skip for now). Everything else passes in my local run, so at least we'll have a guard against future regressions.
2024-04-15 00:04:04 +00:00
Matthias Krüger 2ce487c45c crashes: limit a couple tests to only run on x86_64 and/or not on windows 2024-04-14 23:53:39 +02:00
bors 0d8b3346a3 Auto merge of #123945 - GuillaumeGomez:rollup-14x3enh, r=GuillaumeGomez
Rollup of 5 pull requests

Successful merges:

 - #120900 (std: use `stream_position` where applicable)
 - #123373 (skip Codegen{GCC,Cranelift} when using CI rustc)
 - #123618 (Discard overflow obligations in `impl_may_apply`)
 - #123905 (rustdoc: check redundant explicit links with correct itemid)
 - #123915 (improve documentation slightly regarding some pointer methods)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-04-14 21:47:39 +00:00
Guillaume Gomez 32be7b7129
Rollup merge of #123915 - shenawy29:patch-1, r=Nilstrieb
improve documentation slightly regarding some pointer methods
2024-04-14 23:24:34 +02:00
Guillaume Gomez 4d32bc3801
Rollup merge of #123905 - notriddle:notriddle/redundant-explicit-link-hunks, r=GuillaumeGomez
rustdoc: check redundant explicit links with correct itemid

Fixes #123677 (a regression caused by #120702)
2024-04-14 23:24:34 +02:00
Guillaume Gomez 86b791a272
Rollup merge of #123618 - compiler-errors:overflow-ambig, r=spastorino
Discard overflow obligations in `impl_may_apply`

Hacky fix for #123493. Throws away obligations that are overflowing in `impl_may_apply` when we recompute if an impl applies, since those will lead to fatal overflow if processed during fulfillment.

Something about #114811 (I think it's the predicate reordering) caused us to evaluate predicates differently in error reporting leading to fatal overflow, though I believe the underlying overflow is possible to hit since this code was rewritten to use fulfillment.

Fixes #123493
2024-04-14 23:24:33 +02:00
Guillaume Gomez f3a68fb718
Rollup merge of #123373 - onur-ozkan:skip-codegen, r=Mark-Simulacrum
skip Codegen{GCC,Cranelift} when using CI rustc

CI rustc uses the default codegen backend, therefore we can't run `CodegenGCC` and `CodegenCranelift` tests when using it.

cc `@bjorn3` (to make sure I am not doing anything wrong)

Fixes #123331
2024-04-14 23:24:33 +02:00
Guillaume Gomez fa483a4829
Rollup merge of #120900 - marcospb19:std-use-seek-stream-position, r=joshtriplett
std: use `stream_position` where applicable

by replacing `seek(SeekFrom::Current(0))` calls
2024-04-14 23:24:32 +02:00
Jeremy Fitzhardinge 8880b702fe Add documentation for unused-externs(-silent) 2024-04-14 14:20:58 -07:00
Jeremy Fitzhardinge fdcb8a9fea Stabilize --json unused-externs(-silent)
Implement https://github.com/rust-lang/compiler-team/issues/674
2024-04-14 14:20:55 -07:00
bors 29b120740b Auto merge of #123719 - RalfJung:compiler_builtins, r=Mark-Simulacrum
update compiler_builtins to 0.1.109

This pulls in https://github.com/rust-lang/compiler-builtins/pull/583 so we should make sure that does not come with any perf surprises.

Cc `@Amanieu`
2024-04-14 18:42:50 +00:00
Ralf Jung 5934aaaa97 Miri: run .CRT$XLB linker section on thread-end 2024-04-14 20:09:05 +02:00
Josh Stone 2970ae5a6b
Fix ENV quotes in aarch64-gnu/Dockerfile
Co-authored-by: Eric Huss <eric@huss.org>
2024-04-14 10:42:59 -07:00
bjorn3 3305e71095 Run static initializers 2024-04-14 18:19:52 +02:00
Ralf Jung 80dc3d14c9 move the LargeAssignments lint logic into its own file 2024-04-14 18:09:44 +02:00
Maybe Waffle e8d2221e3b Make `depth_first_search` into a standalone function
Does not necessarily change much, but we never overwrite it, so I see no reason
for it to be in the `Successors` trait. (+we already have a similar `is_cyclic`)
2024-04-14 16:03:08 +00:00
Maybe Waffle 3124fa9310 Document `ControlFlowGraph` 2024-04-14 15:53:38 +00:00
Maybe Waffle f5144938bd Rename `WithNumEdges` => `NumEdges` and `WithStartNode` => `StartNode` 2024-04-14 15:51:29 +00:00
Maybe Waffle 0d5fc9bf58 Merge `{With,Graph}{Successors,Predecessors}` into `{Successors,Predecessors}`
Now with GAT!
2024-04-14 15:48:53 +00:00
Maybe Waffle 398da593a5 Merge `WithNumNodes` into DirectedGraph 2024-04-14 15:46:40 +00:00
Michael Goulet b09c177743 Don't leak unnameable types in -> _ recover 2024-04-14 11:43:05 -04:00
Tobias Bucher 2325b81d04 `statx` probe: `ENOSYS` might come from a faulty FUSE driver
Do the availability check regardless of the error returned from `statx`.

CC https://github.com/rust-lang/rust/pull/122079#discussion_r1564761281
2024-04-14 17:04:41 +02:00
bors a8a88fe524 Auto merge of #122268 - ChrisDenton:no-libc, r=Mark-Simulacrum
Link MSVC default lib in core

## The Problem

On Windows MSVC, Rust invokes the linker directly. This means only the objects and libraries Rust explicitly passes to the linker are used. In short, this is equivalent to passing `-nodefaultlibs`, `-nostartfiles`, etc for gnu compilers.

To compensate for this [the libc crate links to the necessary libraries](a0f5b4b213/src/windows/mod.rs (L258-L261)). The libc crate is then linked from std, thus when you use std you get the defaults back.or integrate with C/C++.

However, this has a few problems:

- For `no_std`, users are left to manually pass the default lib to the linker
- Whereas `std` has the opposite problem, using [`/nodefaultlib`](https://learn.microsoft.com/en-us/cpp/build/reference/nodefaultlib-ignore-libraries?view=msvc-170) doesn't work as expected because Rust treats them as normal libs. This is a particular problem when you want to use e.g. the debug CRT libraries in their place or integrate with C/C++..

## The solution

This PR fixes this in two ways:

- moves linking the default lib into `core`
- passes the lib to the linker using [`/defaultlib`](https://learn.microsoft.com/en-us/cpp/build/reference/defaultlib-specify-default-library?view=msvc-170). This allows users to override it in the normal way (i.e. with [`/nodefaultlib`](https://learn.microsoft.com/en-us/cpp/build/reference/nodefaultlib-ignore-libraries?view=msvc-170)).

This is more or less equivalent to what the MSVC C compiler does. You can see what this looks like in my second commit, which I'll reproduce here for convenience:

```rust
// In library/core
#[cfg(all(windows, target_env = "msvc"))]
#[link(
    name = "/defaultlib:msvcrt",
    modifiers = "+verbatim",
    cfg(not(target_feature = "crt-static"))
)]
#[link(name = "/defaultlib:libcmt", modifiers = "+verbatim", cfg(target_feature = "crt-static"))]
extern "C" {}
```

## Alternatives

- Add the above to `unwind` and `std` but not `core`
- The status quo
- Some other kind of compiler magic maybe

This bares some discussion so I've t-libs nominated it.
2024-04-14 13:28:21 +00:00