about summary refs log tree commit diff
path: root/compiler/rustc_smir
AgeCommit message (Collapse)AuthorLines
2023-12-20Rollup merge of #119141 - celinval:smir-instance-args, r=compiler-errorsMatthias Krüger-0/+6
Add method to get instance instantiation arguments Add a method to get the instance instantiation arguments, and include that information in the instance debug.
2023-12-20Add method to get instance instantiation argumentsCelina G. Val-0/+6
2023-12-20Add `ItemKind::Ctor` to stable mirCelina G. Val-9/+7
2023-12-20Fix crash for `CrateItem::kind()` with constructorsCelina G. Val-5/+8
Change how we classify item kind for DefKind::Ctor
2023-12-20Rollup merge of #119094 - celinval:smir-layout, r=compiler-errorsMatthias Krüger-21/+344
Add function ABI and type layout to StableMIR This change introduces a new module to StableMIR named `abi` with information from `rustc_target::abi` and `rustc_abi`, that allow users to retrieve more low level information required to perform bit-precise analysis. The layout of a type can be retrieved via `Ty::layout`, and the instance ABI can be retrieved via `Instance::fn_abi()`. To properly handle errors while retrieve layout information, we had to implement a few layout related traits. r? ```@compiler-errors```
2023-12-19Fix c_variadic flag and add opaque info to PassModeCelina G. Val-4/+17
We should expand the information in PassMode later.
2023-12-18Add the function body span to StableMIRCelina G. Val-0/+1
2023-12-18Add function ABI and type layout to StableMIRCelina G. Val-21/+331
This change introduces a new module to StableMIR named `abi` with information from `rustc_target::abi` and `rustc_abi`, that allow users to retrieve more low level information required to perform bit-precise analysis. The layout of a type can be retrieved via `Ty::layout`, and the instance ABI can be retrieved via `Instance::fn_abi()`. To properly handle errors while retrieve layout information, we had to implement a few layout related traits.
2023-12-17Auto merge of #119000 - celinval:smir-cstr, r=ouz-abors-0/+6
Add a method to StableMIR to check if a type is a CStr Also add a check that StableMIR works properly with C string literal.
2023-12-15NFC don't convert types to identical typesMatthias Krüger-1/+0
2023-12-15Add a method to check if type is a CStrCelina G. Val-0/+6
2023-12-14Address PR commentsCelina G. Val-12/+6
- Remove `fn_sig()` from Instance. - Change return value of `AssertMessage::description` to `Cow<>`. - Add assert to instance `ty()`. - Generalize uint / int type creation.
2023-12-13Add spread arg and missing CoroutineKindCelina G. Val-1/+4
2023-12-13Erase late bound regions from instance `fn_sig()`Celina G. Val-3/+12
Late bound regions were still part of the signature.
2023-12-12Rollup merge of #118889 - matthiaskrgr:compl_2023_2, r=WaffleLapkinJubilee-1/+1
more clippy::complexity fixes redundant_guards redundant_slicing filter_next needless_borrowed_reference useless_format
2023-12-12more clippy::complexity fixesMatthias Krüger-1/+1
redundant_guards redundant_slicing filter_next needless_borrowed_reference useless_format
2023-12-12clippy::complexity fixesMatthias Krüger-1/+1
filter_map_identity needless_bool search_is_some unit_arg map_identity needless_question_mark derivable_impls
2023-12-12Rollup merge of #118846 - celinval:smir-ty-methods, r=compiler-errorsMatthias Krüger-0/+12
Fix BinOp `ty()` assertion and `fn_sig()` for closures `BinOp::ty()` was asserting that the argument types were primitives. However, the primitive check doesn't include pointers, which can be used in a `BinaryOperation`. Thus extend the arguments to include them. Since I had to add methods to check for pointers in TyKind, I just went ahead and added a bunch more utility checks that can be handy for our users and fixed the `fn_sig()` method to also include closures. `@compiler-errors` just wanted to confirm that today no `BinaryOperation` accept SIMD types. Is that correct? r? `@compiler-errors`
2023-12-11Fix BinOp ty assertion and `fn_sig` for closuresCelina G. Val-0/+12
Also added a few more util methods to TyKind to check for specific types.
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/+89
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/+89
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.