about summary refs log tree commit diff
path: root/compiler/rustc_smir/src
AgeCommit message (Collapse)AuthorLines
2023-12-11Monomorphize args while building Instance bodyCelina G. Val-1/+5
2023-12-10remove redundant importssurechen-2/+2
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-08Rollup merge of #118694 - celinval:smir-alloc-methods, r=ouz-aMatthias Krüger-13/+88
Add instance evaluation and methods to read an allocation in StableMIR The instance evaluation is needed to handle intrinsics such as `type_id` and `type_name`. Since we now use Allocation to represent all evaluated constants, provide a few methods to help process the data inside an allocation. I've also started to add a structured way to get information about the compilation target machine. For now, I've only added information needed to process an allocation. r? ``````@ouz-a``````
2023-12-08Implement `async gen` blocksMichael Goulet-0/+1
2023-12-08Auto merge of #118725 - lcnr:normalizes-to-projection-split-3, r=BoxyUwUbors-0/+1
split `NormalizesTo` out of `Projection` 3 third attempt at #112658. Rebasing #116262 is very annoying, so I am doing it again from scratch. We should now be able to merge it without regressing anything as we handle occurs check failures involving aliases correctly since #117088. see https://hackmd.io/ktEL8knTSYmtdfrMMnA-Hg fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/1 r? `@compiler-errors`
2023-12-07Add instance evaluation and methods to read allocCelina G. Val-13/+88
The instance evaluation is needed to handle intrinsics such as `type_id` and `type_name`. Since we now use Allocation to represent all evaluated constants, provide a few methods to help process the data inside an allocation.
2023-12-07Rollup merge of #118688 - celinval:smir-rvalue-ty, r=compiler-errorsMatthias Krüger-2/+16
Add method to get type of an Rvalue in StableMIR Provide a method to StableMIR users to retrieve the type of an Rvalue operation. There were two possible implementation: 1. Create the logic inside stable_mir to process the type according to the Rvalue semantics, which duplicates the logic of `rustc_middle::mir::Rvalue::ty()`. 2. Implement the Rvalue translation from StableMIR back to internal representation, invoke the `rustc_middle::mir::Rvalue::ty()`, and translate the return value to StableMIR. I chose the first one for now since the duplication was fairly small, and the option 2 would require way more work to translate everything back to rustc internal representation. If we eventually add those translations, we could easily swap to the option 2. ```@compiler-errors``` / ```@ouz-a``` Please let me know if you have any strong opinion here. r? ```@compiler-errors```
2023-12-07Auto merge of #118324 - RalfJung:ctfe-read-only-pointers, r=saethlinbors-2/+5
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-07add unused `NormalizesTo` predicatelcnr-0/+1
2023-12-07ctfe interpreter: extend provenance so that it can track whether a pointer ↵Ralf Jung-2/+5
is immutable
2023-12-06Simplify StaticDef to Instance conversionCelina G. Val-2/+2
2023-12-06Add method to get type of an Rvalue in StableMIRCelina G. Val-0/+14
2023-12-06Rollup merge of #118681 - celinval:fix-foreign-item, r=ouz-aMatthias Krüger-2/+2
Fix is_foreign_item for StableMIR instance Change the implementation of `Instance::is_foreign_item` to directly query the compiler for the instance `def_id` instead of incorrectly relying on the conversion to `CrateItem`. I also added a method to check if the instance has body, since the function already existed and it just wasn't exposed via public APIs. This makes it much cheaper for the user to check if the instance has body. ## Background: - In pull https://github.com/rust-lang/rust/pull/118524, I fixed the conversion from Instance to CrateItem to avoid the conversion if the instance didn't have a body available. This broke the `is_foreign_item`. r? `@ouz-a`
2023-12-06Fix `is_foreign_item` for StableMIR instanceCelina G. Val-2/+2
Change the implementation of `Instance::is_foreign_item` to directly query the compiler for the instance `def_id` instead of incorrectly relying on the conversion to `CrateItem`. Background: - In pull https://github.com/rust-lang/rust/pull/118524, I fixed the conversion from Instance to CrateItem to avoid the conversion if the instance didn't have a body available. This broke the `is_foreign_item`.
2023-12-05Change ty_with_args to return Ty instead of ResultCelina G. Val-28/+23
Although, we would like to avoid crashes whenever possible, and that's why I wanted to make this API fallible. It's looking pretty hard to do proper validation. I think many of our APIs will unfortunately depend on the user doing the correct thing since at the MIR level we are working on, we expect types to have been checked already.
2023-12-04Add FieldDef to StableMIR and methods to get typeCelina G. Val-2/+48
2023-12-04Finish implementing `RustcInternal` for `TyKind`Celina G. Val-12/+185
This will allow us to provide methods to create `Ty` inside the stable MIR, which can be helpful while handling pointers and other stuff.
2023-12-04Add Variant and a few more APIs to stable_mirCelina G. Val-16/+42
2023-12-01Add more information to stable InstanceCelina G. Val-3/+25
- Retrieve `FnSig`. - Implement CrateDef for InstanceDef. - Add VTable index for Virtual instances.
2023-11-30Change SwitchTarget representationCelina G. Val-6/+5
The new structure encodes its invariant, which reduces the likelihood of having an inconsistent representation. It is also more intuitive and user friendly. I encapsulated the structure for now in case we decide to change it back.
2023-11-27Rollup merge of #118172 - ouz-a:improve_emit_stable1, r=celinvalMichael Goulet-7/+7
Add `pretty_terminator` to pretty stable-mir ~Because we don't have successors in `stable_mir` this is somewhat lacking but it's better than nothing~, also fixed bug(?) with `Opaque` which printed extra `"` when we try to print opaqued `String`. **Edit**: Added successors so this covers Terminators as a whole. r? `@celinval`
2023-11-27add otherwise into targetsouz-a-1/+3
2023-11-26merge `DefKind::Coroutine` into `DefKind::Closure`bohan-1/+1
2023-11-26add successors and their formatterouz-a-7/+5
2023-11-24Reorder imports and remove re-exportCelina G. Val-3/+8
2023-11-24Move the compiler interface defs to its own moduleCelina G. Val-3/+4
Separate items that are exposed in the `stable_mir` crate to be used by the compiler from items that we expect to be used by tool developers.
2023-11-24Break down `rustc_smir/mod.rs` fileCelina G. Val-1986/+2021
This file was getting too big and causing a lot of merge conflicts. All these changes shouldn't be visible to users since this module is private.
2023-11-24Rollup merge of #118215 - celinval:smir-def-paths, r=ouz-aMichael Goulet-7/+42
Add common trait for crate definitions In stable mir, we specialize DefId, however some functionality is the same for every definition, such as def paths, and getting their crate. Use a trait to implement those.
2023-11-23Improve documentation and fix the fixme commentCelina G. Val-0/+3
2023-11-22Auto merge of #118120 - compiler-errors:closure-kind, r=lcnrbors-7/+0
Remove `PredicateKind::ClosureKind` We don't need the `ClosureKind` predicate kind -- instead, `Fn`-family trait goals are left as ambiguous, and we only need to make progress on `FnOnce` projection goals for inference purposes. This is similar to how we do confirmation of `Fn`-family trait and projection goals in the new trait solver, which also doesn't use the `ClosureKind` predicate. Some hacky logic is added in the second commit so that we can keep the error messages the same.
2023-11-22Provide conversion of stable span to internal spanCelina G. Val-2/+10
This will allow users to use rustc span messages to display user friendly messages.
2023-11-22Add CrateDef trait and methods to get def namesCelina G. Val-5/+29
2023-11-21Add support to get virtual table allocationCelina G. Val-3/+44
2023-11-21Add support to global allocation to stable-mirCelina G. Val-7/+71
2023-11-22Auto merge of #118152 - matthiaskrgr:rollup-bqcck4w, r=matthiaskrgrbors-10/+61
Rollup of 5 pull requests Successful merges: - #117972 (Add VarDebugInfo to Stable MIR) - #118109 (rustdoc-search: simplify `checkPath` and `sortResults`) - #118110 (Document `DefiningAnchor` a bit more) - #118112 (Don't ICE when ambiguity is found when selecting `Index` implementation in typeck) - #118135 (Remove quotation from filename in stable_mir) Failed merges: - #118012 (Add support for global allocation in smir) r? `@ghost` `@rustbot` modify labels: rollup
2023-11-21Rollup merge of #118135 - ouz-a:fix_stable_span, r=celinvalMatthias Krüger-9/+7
Remove quotation from filename in stable_mir Previously we had quotation marks in filenames which is obviously wrong this fixes that. r? ```@celinval```
2023-11-21Fix `clippy::needless_borrow` in the compilerNilstrieb-2/+2
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`. Then I had to remove a few unnecessary parens and muts that were exposed now.
2023-11-21Remove ClosureKind predicate kindMichael Goulet-7/+0
2023-11-21remove quotation from filenameouz-a-9/+7
2023-11-21de-structure variable and add stablesouz-a-29/+39
2023-11-21Add VarDebugInfo to Stable MIRouz-a-1/+44
2023-11-20Improve code per PR commentsCelina G. Val-6/+2
- Simplified DefTy::internal - Break down place::ty() method
2023-11-20Add place.ty() and Ty build from a kind to smirCelina G. Val-9/+128
2023-11-17use new apis and add new functionouz-a-2/+6
2023-11-17move pretty into stable_mirOğuz Ağcayazı-302/+13
2023-11-17change smir to StableMirOğuz Ağcayazı-15/+27
2023-11-17remove unwrapOğuz Ağcayazı-10/+15
2023-11-17better formatting for statementsOğuz Ağcayazı-23/+46
2023-11-17cover statementsOğuz Ağcayazı-26/+155
2023-11-17emit basic smirOğuz Ağcayazı-2/+144