Commit graph

280 commits

Author SHA1 Message Date
Makai
707d356d00 let rustc_smir host stable_mir for refactoring 2025-04-05 18:23:07 +08:00
Stuart Cook
93f7583491
Rollup merge of #138826 - makai410:assoc-items, r=celinval
StableMIR: Add `associated_items`.

Resolves: https://github.com/rust-lang/project-stable-mir/issues/87
2025-04-05 13:18:15 +11:00
makai410
f9ef4563c2 Implement associated_items api. 2025-04-01 17:11:53 +08:00
Yotam Ofek
827cb1b2a7 use try_fold instead of fold 2025-03-28 12:14:09 +00:00
Matthias Krüger
1cb17dd6f2
Rollup merge of #138536 - makai410:mut-mir-visitor, r=celinval
stable_mir: Add `MutMirVisitor`

Resolves: [rust-lang/project-stable-mir#81](https://github.com/rust-lang/project-stable-mir/issues/81).

I am unsure if we should add a `MutableBody` like Kani did.
Currently, I use `&mut Body` in `MutMirVisitor::visit_body()`.

r? ``````@celinval``````
2025-03-22 11:59:17 +01:00
makai410
69a3ad0d0a Add MutMirVisitor
Implement `make_mir_visitor` macro to generate `MirVisitor` and `MutMirVisitor`.

Add `ret_local_mut()`, `arg_locals_mut()` and `inner_locals_mut()` to `Body`, specifically for `MutMirVisitor`.
2025-03-18 09:48:30 +08:00
许杰友 Jieyou Xu (Joe)
063ef18fdc Revert "Use workspace lints for crates in compiler/ #138084"
Revert <https://github.com/rust-lang/rust/pull/138084> to buy time to
consider options that avoids breaking downstream usages of cargo on
distributed `rustc-src` artifacts, where such cargo invocations fail due
to inability to inherit `lints` from workspace root manifest's
`workspace.lints` (this is only valid for the source rust-lang/rust
workspace, but not really the distributed `rustc-src` artifacts).

This breakage was reported in
<https://github.com/rust-lang/rust/issues/138304>.

This reverts commit 48caf81484, reversing
changes made to c6662879b2.
2025-03-10 18:12:47 +08:00
Matthias Krüger
48caf81484
Rollup merge of #138084 - nnethercote:workspace-lints, r=jieyouxu
Use workspace lints for crates in `compiler/`

This is nicer and hopefully less error prone than specifying lints via bootstrap.

r? ``@jieyouxu``
2025-03-09 10:34:50 +01:00
Matthias Krüger
c6662879b2
Rollup merge of #138040 - thaliaarchi:use-prelude-size-of.compiler, r=compiler-errors
compiler: Use `size_of` from the prelude instead of imported

Use `std::mem::{size_of, size_of_val, align_of, align_of_val}` from the prelude instead of importing or qualifying them. Apply this change across the compiler.

These functions were added to all preludes in Rust 1.80.

r? ``@compiler-errors``
2025-03-09 10:34:49 +01:00
Nicholas Nethercote
beba32cebb Specify rust lints for compiler/ crates via Cargo.
By naming them in `[workspace.lints.rust]` in the top-level
`Cargo.toml`, and then making all `compiler/` crates inherit them with
`[lints] workspace = true`. (I omitted `rustc_codegen_{cranelift,gcc}`,
because they're a bit different.)

The advantages of this over the current approach:
- It uses a standard Cargo feature, rather than special handling in
  bootstrap. So, easier to understand, and less likely to get
  accidentally broken in the future.
- It works for proc macro crates.

It's a shame it doesn't work for rustc-specific lints, as the comments
explain.
2025-03-08 08:41:09 +11:00
Thalia Archibald
38fad984c6 compiler: Use size_of from the prelude instead of imported
Use `std::mem::{size_of, size_of_val, align_of, align_of_val}` from the
prelude instead of importing or qualifying them.

These functions were added to all preludes in Rust 1.80.
2025-03-07 13:37:04 -08:00
Celina G. Val
4d75c4f8f3 Make CrateItem::body() function return an option
When we initially created `CrateItem`, it would only represent items
that contain a body.

That is no longer the case, for now, make this explicit by expanding
the APIs to retrieve the item body.

This is related to https://github.com/rust-lang/project-stable-mir/issues/34
2025-03-04 17:46:40 -08:00
NotLebedev
a3378f5938
Remove duplication in name/trimmed_anem docs
Reference `DefId` in `CrateDef` docs to avoid duplicating long
description of `trimmed_name`
2025-03-02 13:02:20 +03:00
NotLebedev
141d2f3f02
Replace usages of Context.def_name
Use `DefId.name` and `DefId.trimmed_name` instead
2025-03-02 12:11:18 +03:00
NotLebedev
298fb8af65
Add name and trimmed_name methods to DefId 2025-03-02 12:11:14 +03:00
Jana Dönszelmann
d8ea2a230f
change smir attributes getters to only support tool attributes 2025-02-24 14:31:19 +01:00
Jacob Pratt
f5c6287d76
Rollup merge of #137448 - compiler-errors:control-flow-oops, r=scottmcm
Fix bugs due to unhandled `ControlFlow` in compiler

Well, one bug and one nit.
2025-02-23 02:44:20 -05:00
Michael Goulet
04c453c4bc Fix bugs due to unhandled ControlFlow 2025-02-22 23:56:14 +00:00
Michael Goulet
12e3911d81 Greatly simplify lifetime captures in edition 2024 2025-02-22 22:24:52 +00:00
Michael Goulet
76d341fa09 Upgrade the compiler to edition 2024 2025-02-22 00:01:48 +00:00
Zachary S
7ba3d7b54e Remove BackendRepr::Uninhabited, replaced with an uninhabited: bool field in LayoutData.
Also update comments that refered to BackendRepr::Uninhabited.
2025-02-20 13:27:32 -06:00
Bastian Kersting
432ff5e559 Extend the renaming to coerce_unsafe_ptr 2025-02-10 13:01:55 +00:00
Michael Goulet
a61537f6c0 occured -> occurred 2025-02-08 22:28:21 +00:00
Felix S. Klock II
bcb8565f30 Contracts core intrinsics.
These are hooks to:

  1. control whether contract checks are run
  2. allow 3rd party tools to intercept and reintepret the results of running contracts.
2025-02-03 12:53:57 -08:00
Bastian Kersting
b151b513ba Insert null checks for pointer dereferences when debug assertions are enabled
Similar to how the alignment is already checked, this adds a check
for null pointer dereferences in debug mode. It is implemented similarly
to the alignment check as a MirPass.

This is related to a 2025H1 project goal for better UB checks in debug
mode: https://github.com/rust-lang/rust-project-goals/pull/177.
2025-01-31 11:13:34 +00:00
Michael Goulet
eeecb56b73 Represent the raw pointer for a array length check as a new kind of fake borrow 2025-01-28 00:00:33 +00:00
Flakebi
e7e5202978
Add gpu-kernel calling convention
The amdgpu-kernel calling convention was reverted in commit
f6b21e90d1 due to inactivity in the amdgpu
target.

Introduce a `gpu-kernel` calling convention that translates to
`ptx_kernel` or `amdgpu_kernel`, depending on the target that rust
compiles for.
2025-01-16 00:26:55 +01:00
Ralf Jung
e023590de4 make no-variant types a dedicated Variants variant 2024-12-18 11:01:54 +01:00
Ralf Jung
21de42bf8d Variants::Single: do not use invalid VariantIdx for uninhabited enums 2024-12-18 11:00:21 +01:00
Michael Goulet
91e74edca0 Encode coroutine-closures in SMIR 2024-12-14 03:45:35 +00:00
Stuart Cook
5043c574ac
Rollup merge of #132161 - celinval:smir-fix-indent, r=compiler-errors
[StableMIR] A few fixes to pretty printing

Improve identation, and a few other rvalue printing

try-job: x86_64-msvc
try-job: test-various
2024-11-08 18:51:28 +11: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
dd6ddcb18e [StableMIR] A few fixes to pretty printing
Improve identation, and a few other rvalue printing
2024-11-07 16:16:38 -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
Jubilee
7782b0dd56
Rollup merge of #132085 - celinval:update-smir-doc, r=compiler-errors
Update StableMIR doc to reflect current status

Update stable-mir documentation, since we no longer use git subtree, and we have 2 different crates.
2024-10-24 23:23:55 -07:00
Celina G. Val
aa2f9681db
Update README.md
Clarify that the translation between unstable and stable items is currently done in the `rustc_smir` crate.
2024-10-24 16:19:55 -07:00
Celina G. Val
f1114babeb
Apply suggestions from code review
Co-authored-by: Michael Goulet <michael@errs.io>
2024-10-24 16:12:31 -07:00
Michael Goulet
a16d491054 Remove associated type based effects logic 2024-10-24 09:46:36 +00:00
Matthias Krüger
50e93bc080
Rollup merge of #131778 - practicalrs:fix_needless_lifetimes, r=jieyouxu
Fix needless_lifetimes in stable_mir

Hi,

This PR fixes the following clippy warning

```
warning: the following explicit lifetimes could be elided: 'a
   --> compiler/stable_mir/src/mir/visit.rs:490:6
    |
490 | impl<'a> PlaceRef<'a> {
    |      ^^           ^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
    = note: `#[warn(clippy::needless_lifetimes)]` on by default
help: elide the lifetimes
    |
490 - impl<'a> PlaceRef<'a> {
490 + impl PlaceRef<'_> {
    |
```

Best regards,
Michal
2024-10-16 20:15:56 +02:00
Matthias Krüger
ac6353ed43
Rollup merge of #131777 - practicalrs:fix_trivially_copy_pass_by_ref, r=jieyouxu
Fix trivially_copy_pass_by_ref in stable_mir

Hi,

This PR fixes the following clippy warnings

```
warning: this argument (8 byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte)
    --> compiler/stable_mir/src/mir/body.rs:1042:34
     |
1042 |     fn subslice_ty(ty: Ty, from: &u64, to: &u64, from_end: &bool) -> Result<Ty, Error> {
     |                                  ^^^^ help: consider passing by value instead: `u64`
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref
     = note: requested on the command line with `-W clippy::trivially-copy-pass-by-ref`

warning: this argument (8 byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte)
    --> compiler/stable_mir/src/mir/body.rs:1042:44
     |
1042 |     fn subslice_ty(ty: Ty, from: &u64, to: &u64, from_end: &bool) -> Result<Ty, Error> {
     |                                            ^^^^ help: consider passing by value instead: `u64`
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref

warning: this argument (1 byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte)
    --> compiler/stable_mir/src/mir/body.rs:1042:60
     |
1042 |     fn subslice_ty(ty: Ty, from: &u64, to: &u64, from_end: &bool) -> Result<Ty, Error> {
     |                                                            ^^^^^ help: consider passing by value instead: `bool`
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref

```

Best regards,
Michal
2024-10-16 20:15:56 +02:00
Michal Piotrowski
a10a44956e
Fix needless_lifetimes in stable_mir 2024-10-16 13:31:23 +02:00
Michal Piotrowski
89ea9e44f0
Fix trivially_copy_pass_by_ref in stable_mir 2024-10-16 12:36:44 +02:00
Urgau
9c7d57954c
Rollup merge of #131700 - practicalrs:fix_match_same_arms, r=celinval
Fix match_same_arms in stable_mir

Hi,

This PR fixes some clippy warnings

(Reopened https://github.com/rust-lang/rust/pull/131688)

```
warning: this match arm has an identical body to another arm
   --> compiler/stable_mir/src/mir/visit.rs:197:13
    |
197 | /             StatementKind::FakeRead(_, place) => {
198 | |                 self.visit_place(place, PlaceContext::NON_MUTATING, location);
199 | |             }
    | |_____________^
    |
    = help: try changing either arm body
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
help: or try merging the arm patterns
    |
197 |             StatementKind::FakeRead(_, place) | StatementKind::PlaceMention(place) => {
    |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
help: and remove this obsolete arm
    |
209 -             StatementKind::PlaceMention(place) => {
210 -                 self.visit_place(place, PlaceContext::NON_MUTATING, location);
211 -             }
    |

```

Best regards,
Michal
2024-10-16 12:03:41 +02:00
Michal Piotrowski
d3d59055a9
Fix uninlined_format_args in stable_mir 2024-10-15 13:49:07 +02:00
Michal Piotrowski
f708d6de79
Fix match_same_arms in stable_mir 2024-10-14 19:48:41 +02:00
Ralf Jung
f0ddc7b472 clarify semantics of ConstantIndex MIR projection 2024-10-05 12:19:14 +02:00
Jubilee
bc2f732870
Rollup merge of #131194 - practicalrs:fix_needless_lifetimes, r=celinval
Fix needless_lifetimes in stable_mir

Hi,

This PR fixes the following clippy warning in stable_mir

```
warning: the following explicit lifetimes could be elided: 'a
  --> compiler/stable_mir/src/mir/visit.rs:79:30
   |
79 |     fn visit_projection_elem<'a>(
   |                              ^^
80 |         &mut self,
81 |         place_ref: PlaceRef<'a>,
   |                             ^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
   = note: `#[warn(clippy::needless_lifetimes)]` on by default
help: elide the lifetimes
   |
79 ~     fn visit_projection_elem(
80 |         &mut self,
81 ~         place_ref: PlaceRef<'_>,
   |
```

Best regards,
Michal
2024-10-04 19:19:25 -07:00
Urgau
018ba0528f Use wide pointers consistenly across the compiler 2024-10-04 14:06:48 +02:00
Michal Piotrowski
8918a9d265
Fix needless_lifetimes in stable_mir 2024-10-03 13:15:48 +02:00
bors
83e4e18896 Auto merge of #130946 - matthiaskrgr:rollup-ia4mf0y, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #130718 (Cleanup some known-bug issues)
 - #130730 (Reorganize Test Headers)
 - #130826 (Compiler: Rename "object safe" to "dyn compatible")
 - #130915 (fix typo in triagebot.toml)
 - #130926 (Update cc to 1.1.22 in library/)
 - #130932 (etc: Add sample rust-analyzer configs for eglot & helix)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-09-27 21:23:29 +00:00