Commit Graph

455 Commits

Author SHA1 Message Date
Ding Xiang Fei
297b618944
reduce false positives of tail-expr-drop-order from consumed values
take 2

open up coroutines

tweak the wordings

the lint works up until 2021

We were missing one case, for ADTs, which was
causing `Result` to yield incorrect results.

only include field spans with significant types

deduplicate and eliminate field spans

switch to emit spans to impl Drops

Co-authored-by: Niko Matsakis <nikomat@amazon.com>

collect drops instead of taking liveness diff

apply some suggestions and add explantory notes

small fix on the cache

let the query recurse through coroutine

new suggestion format with extracted variable name

fine-tune the drop span and messages

bugfix on runtime borrows

tweak message wording

filter out ecosystem types earlier

apply suggestions

clippy

check lint level at session level

further restrict applicability of the lint

translate bid into nop for stable mir

detect cycle in type structure
2024-11-20 20:53:11 +08:00
lcnr
7a90e84f4d InterpCx store TypingEnv instead of a ParamEnv 2024-11-19 21:36:23 +01:00
lcnr
9cba14b95b use TypingEnv when no infcx is available
the behavior of the type system not only depends on the current
assumptions, but also the currentnphase of the compiler. This is
mostly necessary as we need to decide whether and how to reveal
opaque types. We track this via the `TypingMode`.
2024-11-18 10:38:56 +01:00
Jubilee
4036472749
Rollup merge of #132131 - celinval:smir-crate-defs, r=compiler-errors
[StableMIR] API to retrieve definitions from crates

Add functions to retrieve function definitions and static items from all crates (local and external).

For external crates, we're still missing items from trait implementation and primitives.

r? ````@compiler-errors:```` Do you know what is the best way to retrieve the associated items for primitives and trait implementations for external crates? Thanks!
2024-11-07 18:48:22 -08:00
Celina G. Val
0ce579f6f3 [StableMIR] API to retrieve definitions from crates
Add functions to retrieve function definitions and static items from
all crates (local and external).

For external crates, add a query to retrieve the number of defs in a
foreign crate.
2024-11-07 13:11:46 -08:00
Michael Goulet
d458f850aa ty::BrK -> ty::BoundRegionKind::K 2024-11-04 04:45:52 +00:00
Michael Goulet
8e6af16192 Remove the trivial constkind imports 2024-11-04 04:45:51 +00:00
Jubilee Young
6c16a3123b compiler: Directly use rustc_abi in smir again 2024-11-03 13:38:47 -08:00
Jubilee Young
7086dd83cc compiler: rustc_abi::Abi => BackendRepr
The initial naming of "Abi" was an awful mistake, conveying wrong ideas
about how psABIs worked and even more about what the enum meant.
It was only meant to represent the way the value would be described to
a codegen backend as it was lowered to that intermediate representation.
It was never meant to mean anything about the actual psABI handling!
The conflation is because LLVM typically will associate a certain form
with a certain ABI, but even that does not hold when the special cases
that actually exist arise, plus the IR annotations that modify the ABI.

Reframe `rustc_abi::Abi` as the `BackendRepr` of the type, and rename
`BackendRepr::Aggregate` as `BackendRepr::Memory`. Unfortunately, due to
the persistent misunderstandings, this too is now incorrect:
- Scattered ABI-relevant code is entangled with BackendRepr
- We do not always pre-compute a correct BackendRepr that reflects how
  we "actually" want this value to be handled, so we leave the backend
  interface to also inject various special-cases here
- In some cases `BackendRepr::Memory` is a "real" aggregate, but in
  others it is in fact using memory, and in some cases it is a scalar!

Our rustc-to-backend lowering code handles this sort of thing right now.
That will eventually be addressed by lifting duplicated lowering code
to either rustc_codegen_ssa or rustc_target as appropriate.
2024-10-29 14:56:00 -07:00
Jubilee Young
5f91811c77 stable_mir: Directly use types from rustc_abi 2024-10-28 10:13:19 -07:00
Jubilee Young
e1781297f3 compiler: Rename LayoutS to LayoutData
The last {UninternedType}S is in captivity. The galaxy is at peace.
2024-10-27 22:31:14 -07:00
Deadbeef
f6fea83342 Effects cleanup
- removed extra bits from predicates queries that are no longer needed in the new system
- removed the need for `non_erasable_generics` to take in tcx and DefId, removed unused arguments in callers
2024-10-26 10:19:07 +08:00
Michael Goulet
cde29b9ec9 Implement const effect predicate in new solver 2024-10-24 09:46:36 +00:00
Michael Goulet
a16d491054 Remove associated type based effects logic 2024-10-24 09:46:36 +00:00
Matthias Krüger
3f15d296f4
Rollup merge of #131049 - compiler-errors:more-validation, r=spastorino
Validate args are correct for `UnevaluatedConst`, `ExistentialTraitRef`/`ExistentialProjection`

For the `Existential*` ones, we have to do some adjustment to the args list to deal with the missing `Self` type, so we introduce a `debug_assert_existential_args_compatible` function to the interner as well.
2024-10-22 15:28:38 +02:00
Michael Goulet
e83e4e8112 Get rid of const eval_* and try_eval_* helpers 2024-10-19 18:07:35 +00:00
Folkert de Vries
5fc60d1e52 various fixes for naked_asm! implementation
- fix for divergence
- fix error message
- fix another cranelift test
- fix some cranelift things
- don't set the NORETURN option for naked asm
- fix use of naked_asm! in doc comment
- fix use of naked_asm! in run-make test
- use `span_bug` in unreachable branch
2024-10-06 19:00:09 +02:00
Michael Goulet
2239f1c5cd Validate ExistentialPredicate args 2024-09-30 01:14:03 -04:00
Matthias Krüger
a935064fae
Rollup merge of #130826 - fmease:compiler-mv-obj-safe-dyn-compat, r=compiler-errors
Compiler: Rename "object safe" to "dyn compatible"

Completed T-lang FCP: https://github.com/rust-lang/lang-team/issues/286#issuecomment-2338905118.
Tracking issue: https://github.com/rust-lang/rust/issues/130852

Excludes `compiler/rustc_codegen_cranelift` (to be filed separately).
Includes Stable MIR.

Regarding https://github.com/rust-lang/rust/labels/relnotes, I guess I will manually open a https://github.com/rust-lang/rust/labels/relnotes-tracking-issue since this change affects everything (compiler, library, tools, docs, books, everyday language).

r? ghost
2024-09-27 21:35:08 +02:00
León Orell Valerian Liehr
01a063f9df
Compiler: Rename "object safe" to "dyn compatible" 2024-09-25 13:26:48 +02:00
Lukas Markeffsky
bd31e3ed70 be even more precise about "cast" vs "coercion" 2024-09-24 23:12:02 +02:00
Lukas Markeffsky
46ecb23198 unify dyn* coercions with other pointer coercions 2024-09-24 22:17:55 +02:00
Michael Goulet
702a644b74 Check vtable projections for validity in miri 2024-09-23 19:38:26 -04:00
Michael Goulet
c682aa162b Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
Folkert de Vries
1ddd67a79a add C-cmse-nonsecure-entry ABI 2024-09-21 13:04:14 +02:00
bors
6199b69c53 Auto merge of #129777 - nnethercote:unreachable_pub-4, r=Urgau
Add `unreachable_pub`, round 4

A follow-up to #129732.

r? `@Urgau`
2024-09-03 01:27:20 +00:00
Nicholas Nethercote
b457ab3186 Add warn(unreachable_pub) to rustc_smir. 2024-09-03 08:49:54 +10:00
Alexander Cyon
00de006f22
chore: Fix typos in 'compiler' (batch 2) 2024-09-02 07:50:22 +02:00
Michael Goulet
4609841c07 Stop using a special inner body for the coroutine by-move body for async closures 2024-08-26 18:44:19 -04:00
Michael Goulet
0b2525c787 Simplify some redundant field names 2024-08-21 01:31:42 -04:00
Ralf Jung
35709be02d rename AddressOf -> RawBorrow inside the compiler 2024-08-18 19:46:53 +02:00
Nicholas Nethercote
c4717cc9d1 Shrink TyKind::FnPtr.
By splitting the `FnSig` within `TyKind::FnPtr` into `FnSigTys` and
`FnHeader`, which can be packed more efficiently. This reduces the size
of the hot `TyKind` type from 32 bytes to 24 bytes on 64-bit platforms.
This reduces peak memory usage by a few percent on some benchmarks. It
also reduces cache misses and page faults similarly, though this doesn't
translate to clear cycles or wall-time improvements on CI.
2024-08-09 14:33:25 +10:00
Nicholas Nethercote
84ac80f192 Reformat use declarations.
The previous commit updated `rustfmt.toml` appropriately. This commit is
the outcome of running `x fmt --all` with the new formatting options.
2024-07-29 08:26:52 +10:00
Nicholas Nethercote
75b6ec9800 Avoid comments that describe multiple use items.
There are some comments describing multiple subsequent `use` items. When
the big `use` reformatting happens some of these `use` items will be
reordered, possibly moving them away from the comment. With this
additional level of formatting it's not really feasible to have comments
of this type. This commit removes them in various ways:

- merging separate `use` items when appropriate;

- inserting blank lines between the comment and the first `use` item;

- outright deletion (for comments that are relatively low-value);

- adding a separate "top-level" comment.

We also entirely skip formatting for four library files that contain
nothing but `pub use` re-exports, where reordering would be painful.
2024-07-17 08:02:46 +10:00
Nikita Popov
8a50bcbdce Remove extern "wasm" ABI
Remove the unstable `extern "wasm"` ABI (`wasm_abi` feature tracked
in #83788).

As discussed in https://github.com/rust-lang/rust/pull/127513#issuecomment-2220410679
and following, this ABI is a failed experiment that did not end
up being used for anything. Keeping support for this ABI in LLVM 19
would require us to switch wasm targets to the `experimental-mv`
ABI, which we do not want to do.

It should be noted that `Abi::Wasm` was internally used for two
things: The `-Z wasm-c-abi=legacy` ABI that is still used by
default on some wasm targets, and the `extern "wasm"` ABI. Despite
both being `Abi::Wasm` internally, they were not the same. An
explicit `extern "wasm"` additionally enabled the `+multivalue`
feature.

I've opted to remove `Abi::Wasm` in this patch entirely, instead
of keeping it as an ABI with only internal usage. Both
`-Z wasm-c-abi` variants are now treated as part of the normal
C ABI, just with different different treatment in
adjust_for_foreign_abi.
2024-07-11 12:20:26 +02:00
bors
9af6fee87d Auto merge of #113128 - WaffleLapkin:become_trully_unuwuable, r=oli-obk,RalfJung
Support tail calls in mir via `TerminatorKind::TailCall`

This is one of the interesting bits in tail call implementation — MIR support.

This adds a new `TerminatorKind` which represents a tail call:
```rust
    TailCall {
        func: Operand<'tcx>,
        args: Vec<Operand<'tcx>>,
        fn_span: Span,
    },
```

*Structurally* this is very similar to a normal `Call` but is missing a few fields:
- `destination` — tail calls don't write to destination, instead they pass caller's destination to the callee (such that eventual `return` will write to the caller of the function that used tail call)
- `target` — similarly to `destination` tail calls pass the caller's return address to the callee, so there is nothing to do
- `unwind` — I _think_ this is applicable too, although it's a bit confusing
- `call_source` — `become` forbids operators and is not created as a lowering of something else; tail calls always come from HIR (at least for now)

It might be helpful to read the interpreter implementation to understand what `TailCall` means exactly, although I've tried documenting it too.

-----

There are a few `FIXME`-questions still left, ideally we'd be able to answer them during review ':)

-----

r? `@oli-obk`
cc `@scottmcm` `@DrMeepster` `@JakobDegen`
2024-07-08 04:35:04 +00:00
Maybe Waffle
484152d562 Support tail calls in mir via TerminatorKind::TailCall 2024-07-07 17:11:04 +02:00
bors
489233170a Auto merge of #123781 - RalfJung:miri-fn-identity, r=oli-obk
Miri function identity hack: account for possible inlining

Having a non-lifetime generic is not the only reason a function can be duplicated. Another possibility is that the function may be eligible for cross-crate inlining. So also take into account the inlining attribute in this Miri hack for function pointer identity.

That said, `cross_crate_inlinable` will still sometimes return true even for `inline(never)` functions:
- when they are `DefKind::Ctor(..) | DefKind::Closure` -- I assume those cannot be `InlineAttr::Never` anyway?
- when `cross_crate_inline_threshold == InliningThreshold::Always`

so maybe this is still not quite the right criterion to use for function pointer identity.
2024-07-04 23:45:56 +00:00
Michael Goulet
b1059ccda2 Instance::resolve -> Instance::try_resolve, and other nits 2024-07-02 17:28:03 -04:00
Ralf Jung
41b98da42d Miri function identity hack: account for possible inlining 2024-07-02 21:05:30 +02:00
Deadbeef
72e8244e64 implement new effects desugaring 2024-06-28 10:57:35 +00:00
Adwin White
9387b0bad9 Add method to get all attributes on a definition 2024-06-28 13:24:41 +08:00
Adwin White
84071e2662 Support fetching Attribute of items. 2024-06-28 13:24:41 +08:00
Trevor Gross
518b74ec5d Remove f16 and f128 ICE paths from smir 2024-06-26 02:56:48 -04:00
Michael Goulet
f26cc349d9 Split out IntoIterator and non-Iterator constructors for AliasTy/AliasTerm/TraitRef/projection 2024-06-24 11:28:21 -04:00
Adwin White
225796a2df Add method to get FnAbi of function pointer 2024-06-21 14:50:56 +08:00
Nicholas Nethercote
665821cb60 Add blank lines after module-level //! comments.
Most modules have such a blank line, but some don't. Inserting the blank
line makes it clearer that the `//!` comments are describing the entire
module, rather than the `use` declaration(s) that immediately follows.
2024-06-20 09:23:20 +10:00
Michael Goulet
342c1b03d6 Rename InstanceDef -> InstanceKind 2024-06-16 21:35:21 -04:00
Guillaume Gomez
be1d42776d
Rollup merge of #126410 - RalfJung:smir-const-operand, r=oli-obk
smir: merge identical Constant and ConstOperand types

The first commit renames the const operand visitor functions on regular MIR to match the type name, that was forgotten in the original rename.

The second commit changes stable MIR, fixing https://github.com/rust-lang/project-stable-mir/issues/71. Previously there were two different smir types for the MIR type `ConstOperand`, one used in `Operand` and one in `VarDebugInfoContents`.

Maybe we should have done this with https://github.com/rust-lang/rust/pull/125967, so there's only a single breaking change... but I saw that PR too late.

Fixes https://github.com/rust-lang/project-stable-mir/issues/71
2024-06-15 19:51:35 +02:00
bors
92af831290 Auto merge of #126518 - matthiaskrgr:rollup-wb70rzq, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #125829 (rustc_span: Add conveniences for working with span formats)
 - #126361 (Unify intrinsics body handling in StableMIR)
 - #126417 (Add `f16` and `f128` inline ASM support for `x86` and `x86-64`)
 - #126424 ( Also sort `crt-static` in `--print target-features` output)
 - #126428 (Polish `std::path::absolute` documentation.)
 - #126429 (Add `f16` and `f128` const eval for binary and unary operationations)
 - #126448 (End support for Python 3.8 in tidy)
 - #126488 (Use `std::path::absolute` in bootstrap)
 - #126511 (.mailmap: Associate both my work and my private email with me)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-06-15 14:51:12 +00:00