about summary refs log tree commit diff
path: root/compiler/stable_mir/src
AgeCommit message (Collapse)AuthorLines
2023-12-20Rollup merge of #119141 - celinval:smir-instance-args, r=compiler-errorsMatthias Krüger-0/+9
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/+9
2023-12-20Add `ItemKind::Ctor` to stable mirCelina G. Val-0/+7
2023-12-20Rollup merge of #119094 - celinval:smir-layout, r=compiler-errorsMatthias Krüger-0/+306
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-9/+6
We should expand the information in PassMode later.
2023-12-18Add the function body span to StableMIRCelina G. Val-2/+8
2023-12-18Add function ABI and type layout to StableMIRCelina G. Val-0/+309
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-15Add a method to check if type is a CStrCelina G. Val-0/+9
2023-12-15Rollup merge of #118927 - celinval:smir-missing-info, r=compiler-errorsAli MJ Al-Nasrawy-16/+85
Erase late bound regions from `Instance::fn_sig()` and add a few more details to StableMIR APIs The Instance `fn_sig()` still included a late bound regions which needed a new compiler function in order to be erased. I've also bundled the following small fixes in this PR, let me know if you want me to isolate any of them. - Add missing `CoroutineKind::AsyncGen`. - Add optional spread argument to function body which is needed to properly analyze compiler shims. - Add a utility method to iterate over all locals together with their declaration. - Add a method to get the description of `AssertMessage`*. * For the last one, we could consider eventually calling the internal `AssertKind::description()` to avoid code duplication. However, we still don't have ways to convert `AssertMessage`, `Operand`, `Place` and others, in order to use that. The other downside of using the internal method is that it will panic for some of the variants. r ? `@ouz-a`
2023-12-14Revert signature change for AssertMessage descriptionCelina G. Val-34/+21
2023-12-14Address PR commentsCelina G. Val-37/+46
- 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-14add stable_mir output testouz-a-13/+30
2023-12-13Add spread arg and missing CoroutineKindCelina G. Val-10/+80
2023-12-13Erase late bound regions from instance `fn_sig()`Celina G. Val-4/+7
Late bound regions were still part of the signature.
2023-12-12Rollup merge of #118846 - celinval:smir-ty-methods, r=compiler-errorsMatthias Krüger-13/+144
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-11Remove scalar fn and tighten the BiOp Ty assertionsCelina G. Val-24/+12
2023-12-11Fix doc commentCelina G. Val-1/+1
2023-12-11Fix BinOp ty assertion and `fn_sig` for closuresCelina G. Val-12/+155
Also added a few more util methods to TyKind to check for specific types.
2023-12-11remove some redundant clonesMatthias Krüger-1/+1
2023-12-10remove redundant importssurechen-1/+0
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-07Add tests to allocation methods and fix is_null()Celina G. Val-2/+24
2023-12-07Fix conversion to StaticDef and add testCelina G. Val-2/+2
2023-12-07Add instance evaluation and methods to read allocCelina G. Val-9/+205
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-3/+186
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-06Add sanity check to `BinOp::ty()`Celina G. Val-8/+27
2023-12-06Update compiler/stable_mir/src/mir/body.rsCelina G. Val-1/+1
Co-authored-by: Michael Goulet <michael@errs.io>
2023-12-06Simplify StaticDef to Instance conversionCelina G. Val-4/+5
2023-12-06Add method to get type of an Rvalue in StableMIRCelina G. Val-0/+163
2023-12-06Rollup merge of #118681 - celinval:fix-foreign-item, r=ouz-aMatthias Krüger-4/+11
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-06Also add an API to check if an instance has bodyCelina G. Val-0/+8
This is much cheaper than building a body just for the purpose of checking if the body exists.
2023-12-06Fix `is_foreign_item` for StableMIR instanceCelina G. Val-4/+3
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-5/+10
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-3/+47
2023-12-04Finish implementing `RustcInternal` for `TyKind`Celina G. Val-1/+1
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-23/+111
2023-12-01Add more information to stable InstanceCelina G. Val-16/+82
- Retrieve `FnSig`. - Implement CrateDef for InstanceDef. - Add VTable index for Virtual instances.
2023-11-30Fix SwitchTarget pretty printCelina G. Val-4/+1
We currently rely on the order of successors to be conditional branches first, followed by the otherwise target.
2023-11-30Change SwitchTarget representationCelina G. Val-38/+67
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-11/+279
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-2/+2
2023-11-26add successors and their formatterouz-a-24/+160
2023-11-25add pretty_terminatorouz-a-2/+134
2023-11-25is_{some,ok}_andMichael Goulet-1/+1
2023-11-25Rollup merge of #118274 - celinval:smir-fix-pretty, r=ouz-aLeón Orell Valerian Liehr-2/+4
Fix smir's `Ty::Ref` pretty printing Add `&` or `&mut` to reference when generating a string for `TyKind::Ref`. r? `@ouz-a`
2023-11-24Fix smir's `Ty::Ref` pretty printingCelina G. Val-2/+4
2023-11-24Reorder imports and remove re-exportCelina G. Val-10/+12
2023-11-24Move the compiler interface defs to its own moduleCelina G. Val-160/+172
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-24Rollup merge of #118215 - celinval:smir-def-paths, r=ouz-aMichael Goulet-46/+156
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-8/+17
2023-11-22Auto merge of #118120 - compiler-errors:closure-kind, r=lcnrbors-1/+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.