Commit Graph

2323 Commits

Author SHA1 Message Date
bors
bcae781754 Auto merge of #119146 - nnethercote:rm-DiagCtxt-api-duplication, r=compiler-errors
Remove `DiagCtxt` API duplication

`DiagCtxt` defines the internal API for creating and emitting diagnostics: methods like `struct_err`, `struct_span_warn`, `note`, `create_fatal`, `emit_bug`. There are over 50 methods.

Some of these methods are then duplicated across several other types: `Session`, `ParseSess`, `Parser`, `ExtCtxt`, and `MirBorrowckCtxt`. `Session` duplicates the most, though half the ones it does are unused. Each duplicated method just calls forward to the corresponding method in `DiagCtxt`. So this duplication exists to (in the best case) shorten chains like `ecx.tcx.sess.parse_sess.dcx.emit_err()` to `ecx.emit_err()`.

This API duplication is ugly and has been bugging me for a while. And it's inconsistent: there's no real logic about which methods are duplicated, and the use of `#[rustc_lint_diagnostic]` and `#[track_caller]` attributes vary across the duplicates.

This PR removes the duplicated API methods and makes all diagnostic creation and emission go through `DiagCtxt`. It also adds `dcx` getter methods to several types to shorten chains. This approach scales *much* better than API duplication; indeed, the PR adds `dcx()` to numerous types that didn't have API duplication: `TyCtxt`, `LoweringCtxt`, `ConstCx`, `FnCtxt`, `TypeErrCtxt`, `InferCtxt`, `CrateLoader`, `CheckAttrVisitor`, and `Resolver`. These result in a lot of changes from `foo.tcx.sess.emit_err()` to `foo.dcx().emit_err()`. (You could do this with more types, but it gets into diminishing returns territory for types that don't emit many diagnostics.)

After all these changes, some call sites are more verbose, some are less verbose, and many are the same. The total number of lines is reduced, mostly because of the removed API duplication. And consistency is increased, because calls to `emit_err` and friends are always preceded with `.dcx()` or `.dcx`.

r? `@compiler-errors`
2023-12-26 02:24:39 +00:00
bjorn3
653121cd38 Fix borked subtree syncs 2023-12-24 14:38:37 +00:00
bjorn3
7325d0de63 Merge commit '26c02eb2904da9a53d2220d4f3069b19a3c81d3d' into sync_cg_clif-2023-12-24 2023-12-24 14:35:19 +00:00
Nicholas Nethercote
93c86f78b2 Remove more Session methods that duplicate DiagCtxt methods. 2023-12-24 08:17:47 +11:00
Nicholas Nethercote
7e213fe428 Remove Session methods that duplicate DiagCtxt methods.
Also add some `dcx` methods to types that wrap `TyCtxt`, for easier
access.
2023-12-24 08:05:28 +11:00
Michael Goulet
bfda19d5bd Rollup merge of #119171 - nnethercote:cleanup-errors-4, r=compiler-errors
Cleanup error handlers: round 4

More `rustc_errors` cleanups. A sequel to #118933.

r? `@compiler-errors`
2023-12-22 21:41:03 -05:00
Nicholas Nethercote
b94a2a1991 Rename EarlyDiagCtxt methods to match DiagCtxt.
- `early_error_no_abort` -> `early_err`
- `early_error` -> `early_fatal`
- `early_struct_error` -> `early_struct_fatal`
2023-12-23 13:23:28 +11:00
Pietro Albini
71899c3e23 update cfg(bootstrap)s 2023-12-22 11:14:11 +01:00
bjorn3
a4be90ed16 Merge commit '3a9bf729322fb5035518f99b9d76a742bf7c124e' into sync_cg_clif-2023-12-19 2023-12-19 12:46:39 +00:00
Nicholas Nethercote
eeb3db1130 Rename many DiagCtxt and EarlyDiagCtxt locals. 2023-12-18 16:06:22 +11:00
Nicholas Nethercote
8b5a5daad4 Rename many DiagCtxt arguments. 2023-12-18 16:06:22 +11:00
Nicholas Nethercote
b60e208549 Rename Session::span_diagnostic as Session::dcx. 2023-12-18 16:06:21 +11:00
Nicholas Nethercote
b44315c34c Rename EarlyErrorHandler as EarlyDiagCtxt. 2023-12-18 16:06:21 +11:00
Nicholas Nethercote
576b9213b3 Rename Handler as DiagCtxt. 2023-12-18 16:06:19 +11:00
lcnr
89ab75e856 update use of feature flags 2023-12-14 15:22:37 +01:00
bors
e3d2831ff4 Auto merge of #118534 - RalfJung:extern-type-size-of-val, r=WaffleLapkin
codegen: panic when trying to compute size/align of extern type

The alignment is also computed when accessing a field of extern type at non-zero offset, so we also panic in that case.

Previously `size_of_val` worked because the code path there assumed that "thin pointer" means "sized". But that's not true any more with extern types. The returned size and align are just blatantly wrong, so it seems better to panic than returning wrong results. We use a non-unwinding panic since code probably does not expect size_of_val to panic.
2023-12-13 08:33:05 +00:00
Ralf Jung
aa3dc4c225 remove a cranelift test that doesn't make sense any more 2023-12-12 08:15:17 +01:00
bors
b5c0dd6da2 Auto merge of #117758 - Urgau:lint_pointer_trait_comparisons, r=davidtwco
Add lint against ambiguous wide pointer comparisons

This PR is the resolution of https://github.com/rust-lang/rust/issues/106447 decided in https://github.com/rust-lang/rust/issues/117717 by T-lang.

## `ambiguous_wide_pointer_comparisons`

*warn-by-default*

The `ambiguous_wide_pointer_comparisons` lint checks comparison of `*const/*mut ?Sized` as the operands.

### Example

```rust
let ab = (A, B);
let a = &ab.0 as *const dyn T;
let b = &ab.1 as *const dyn T;

let _ = a == b;
```

### Explanation

The comparison includes metadata which may not be expected.

-------

This PR also drops `clippy::vtable_address_comparisons` which is superseded by this one.

~~One thing: is the current naming right? `invalid` seems a bit too much.~~

Fixes https://github.com/rust-lang/rust/issues/117717
2023-12-11 14:33:16 +00:00
surechen
e6376631cc remove redundant imports
detects redundant imports that can be eliminated.

for #117772 :

In order to facilitate review and modification, split the checking code and
removing redundant imports code into two PR.
2023-12-10 10:56:22 +08:00
Jakub Okoński
8ab225df8b Add simd_masked_{load,store} platform-intrinsics
This maps to the LLVM intrinsics: llvm.masked.load and llvm.masked.store
2023-12-09 12:36:08 +01:00
bors
63535997b9 Auto merge of #118324 - RalfJung:ctfe-read-only-pointers, r=saethlin
compile-time evaluation: detect writes through immutable pointers

This has two motivations:
- it unblocks https://github.com/rust-lang/rust/pull/116745 (and therefore takes a big step towards `const_mut_refs` stabilization), because we can now detect if the memory that we find in `const` can be interned as "immutable"
- it would detect the UB that was uncovered in https://github.com/rust-lang/rust/pull/117905, which was caused by accidental stabilization of `copy` functions in `const` that can only be called with UB

When UB is detected, we emit a future-compat warn-by-default lint. This is not a breaking change, so completely in line with [the const-UB RFC](https://rust-lang.github.io/rfcs/3016-const-ub.html), meaning we don't need t-lang FCP here. I made the lint immediately show up for dependencies since it is nearly impossible to even trigger this lint without `const_mut_refs` -- the accidentally stabilized `copy` functions are the only way this can happen, so the crates that popped up in #117905 are the only causes of such UB (in the code that crater covers), and the three cases of UB that we know about have all been fixed in their respective crates already.

The way this is implemented is by making use of the fact that our interpreter is already generic over the notion of provenance. For CTFE we now use the new `CtfeProvenance` type which is conceptually an `AllocId` plus a boolean `immutable` flag (but packed for a more efficient representation). This means we can mark a pointer as immutable when it is created as a shared reference. The flag will be propagated to all pointers derived from this one. We can then check the immutable flag on each write to reject writes through immutable pointers.

I just hope perf works out.
2023-12-07 18:11:01 +00:00
Ralf Jung
994d36bac0 ctfe interpreter: extend provenance so that it can track whether a pointer is immutable 2023-12-07 17:46:36 +01:00
Urgau
9d9459a6f9 Adjust tests for newly added ambiguous_wide_pointer_comparisons lint 2023-12-06 09:03:48 +01:00
Nicholas Nethercote
0657c1b932 Give Handler::fatal and Session::fatal the same return type.
Currently, `Handler::fatal` returns `FatalError`. But `Session::fatal`
returns `!`, because it calls `Handler::fatal` and then calls `raise` on
the result. This inconsistency is unfortunate.

This commit changes `Handler::fatal` to do the `raise` itself, changing
its return type to `!`. This is safe because there are only two calls to
`Handler::fatal`, one in `rustc_session` and one in
`rustc_codegen_cranelift`, and they both call `raise` on the result.

`HandlerInner::fatal` still returns `FatalError`, so I renamed it
`fatal_no_raise` to emphasise the return type difference.
2023-12-04 15:42:06 +11:00
bors
400cd47c28 Auto merge of #118279 - bjorn3:sync_cg_clif-2023-11-25, r=bjorn3
Subtree sync for rustc_codegen_cranelift

The main highlights this time are implementing a bunch of new vendor intrinsics and fixing some existing ones. And fixing polymorphization for coroutines.

r? `@ghost`

`@rustbot` label +A-codegen +A-cranelift +T-compiler
2023-11-25 13:08:29 +00:00
bjorn3
1988cf4a18 Merge commit '710c67909d034e1c663174a016ca82b95c2d6c12' into sync_cg_clif-2023-11-25 2023-11-25 10:05:52 +00:00
David Tolnay
abf08329bb Replace option.map(cond) == Some(true) with option.is_some_and(cond) 2023-11-24 09:14:09 -08:00
bjorn3
4ae658683f Fix fn_sig_for_fn_abi and the coroutine transform for generators
There were three issues previously:
* The self argument was pinned, despite Iterator::next taking an
  unpinned mutable reference.
* A resume argument was passed, despite Iterator::next not having one.
* The return value was CoroutineState<Item, ()> rather than Option<Item>

While these things just so happened to work with the LLVM backend,
cg_clif does much stricter checks when trying to assign a value to a
place. In addition it can't handle the mismatch between the amount of
arguments specified by the FnAbi and the FnSig.
2023-11-23 20:17:19 +00:00
bjorn3
dfc669b74c Merge commit 'def04540a4e2541b995195c752c751295606a388' into sync_cg_clif-2023-11-16 2023-11-16 21:15:07 +00:00
Mark Rousskov
497c17a390 Add check-cfg to cranelift 2023-11-15 21:45:48 -05:00
bjorn3
d49fd9f877 Merge commit 'c84d1871dc4456539b7b578830268ab3539915d0' into sync_cg_clif-2023-11-10 2023-11-10 11:30:51 +00:00
Nicholas Nethercote
8eca01f4b6 Remove support for compiler plugins.
They've been deprecated for four years.

This commit includes the following changes.
- It eliminates the `rustc_plugin_impl` crate.
- It changes the language used for lints in
  `compiler/rustc_driver_impl/src/lib.rs` and
  `compiler/rustc_lint/src/context.rs`. External lints are now called
  "loaded" lints, rather than "plugins" to avoid confusion with the old
  plugins. This only has a tiny effect on the output of `-W help`.
- E0457 and E0498 are no longer used.
- E0463 is narrowed, now only relating to unfound crates, not plugins.
- The `plugin` feature was moved from "active" to "removed".
- It removes the entire plugins chapter from the unstable book.
- It removes quite a few tests, mostly all of those in
  `tests/ui-fulldeps/plugin/`.

Closes #29597.
2023-11-04 08:50:46 +11:00
George Bateman
03c9acdd8f Support enum variants in offset_of! 2023-10-31 23:25:54 +00:00
Guillaume Gomez
aed0ed2875 Rollup merge of #117317 - RalfJung:track-caller, r=oli-obk
share some track_caller logic between interpret and codegen

Also move the code that implements the track_caller intrinsics out of the core interpreter engine -- it's just a helper creating a const-allocation, doesn't need to be part of the interpreter core.
2023-10-30 17:33:16 +01:00
bjorn3
41dcb52153 Merge commit 'dde58803fd6cbb270c7a437f36a8a3a29fbef679' into sync_cg_clif-2023-10-29 2023-10-29 20:30:50 +00:00
bors
da1ed4dc4a Auto merge of #81746 - bjorn3:cg_clif_rustup_component, r=Mark-Simulacrum
Distribute cg_clif as rustup component on the nightly channel

This makes it possible to use cg_clif using:

```bash
$ rustup component add rustc-codegen-cranelift-preview --toolchain nightly
$ RUSTFLAGS="-Zcodegen-backend=cranelift" cargo +nightly build
```

cc https://github.com/rust-lang/compiler-team/issues/405.
r? `@Mark-Simulacrum`
2023-10-28 15:16:27 +00:00
Ralf Jung
c6f5090294 share the track_caller handling within a mir::Body 2023-10-28 16:16:15 +02:00
Ralf Jung
bad4be6e29 interpret: call caller_location logic the same way codegen does, and share some code 2023-10-28 15:40:03 +02:00
bors
9e20870c2e Auto merge of #116609 - eduardosm:bump-stdarch, r=workingjubilee
Bump stdarch submodule and remove special handling for LLVM intrinsics that are no longer needed

Bumps stdarch to pull https://github.com/rust-lang/stdarch/pull/1477, which reimplemented some functions with portable SIMD intrinsics instead of arch specific LLVM intrinsics.

Handling of those LLVM intrinsics is removed from cranelift codegen and miri.

cc `@RalfJung` `@bjorn3`
2023-10-28 11:26:34 +00:00
bjorn3
1cb7bdb757 Update target-lexicon to 0.12.12
This adds support for loongarch and a bunch of other targets
2023-10-27 11:56:39 +00:00
bjorn3
1e39bbf74c Update Cranelift to 0.101.2 and disable host-arch feature of cranelift-codegen
This ensures that cg_clif can be built for targets that aren't natively
supported by Cranelift. It will not be possible to compile for the host
in this case, but cross-compilation will still be possible.

We won't distribute cg_clif as rustup component for any targets that
aren't natively supported by Cranelift, but will still build it if
codegen-backends lists "cranelift".
2023-10-27 11:56:39 +00:00
bjorn3
a302610016 Merge commit '93a5433f17ab5ed48cc88f1e69b0713b16183373' into sync_cg_clif-2023-10-24 2023-10-24 12:22:23 +00:00
bjorn3
e472b5573a Merge commit 'c07d1e2f88cb3b1a0604ae8f18b478c1aeb7a7fa' into sync_cg_clif-2023-10-21 2023-10-21 19:54:51 +00:00
Oli Scherer
4519e68957 s/generator/coroutine/ 2023-10-20 21:14:01 +00:00
Oli Scherer
8e264ab07a s/Generator/Coroutine/ 2023-10-20 21:10:38 +00:00
Urgau
2f461b74ff [RFC 3127 - Trim Paths]: Condition remapped filepath on remap scopes 2023-10-17 10:11:30 +02:00
Michael Howell
8c3eda36df docs: add Rust logo to more compiler crates
c6e6ecb1af added it to some of the
compiler's crates, but avoided adding it to all of them to reduce
bit-rot. This commit adds to more.
2023-10-16 15:38:08 -07:00
Eduardo Sánchez Muñoz
40cc89137b Remove from cranelift codegen LLVM intrinsics that are no longer needed 2023-10-12 11:20:00 +02:00
bjorn3
3c0d3f2bf1 Fix review comments 2023-10-09 18:39:43 +00:00
bjorn3
e006e2c9c6 Remove cgu_reuse_tracker from Session
This removes a bit of global mutable state
2023-10-09 18:39:41 +00:00