about summary refs log tree commit diff
path: root/compiler/stable_mir/src
AgeCommit message (Collapse)AuthorLines
2023-11-20Add place.ty() and Ty build from a kind to smirCelina G. Val-22/+174
2023-11-17use new apis and add new functionouz-a-15/+14
2023-11-17move pretty into stable_mirOğuz Ağcayazı-3/+295
2023-11-17better formatting for statementsOğuz Ağcayazı-1/+1
2023-11-17emit basic smirOğuz Ağcayazı-0/+2
2023-11-16Fix has_body() and change resolve_drop_in_place() sigCelina G. Val-3/+2
Fixed the `has_body()` function operator. Before that, this function was returning false for all shims. Change resolve_drop_in_place() to also return an instance for empty shims, since they may still be required for vtable construction.
2023-11-16Address PR commentsCelina G. Val-2/+2
2023-11-16Add more APIs and fix `Instance::body`Celina G. Val-15/+243
Add more APIs to retrieve information about types, and add more instance resolution options. Make `Instance::body()` return an Option<Body>, since not every instance might have an available body. For example, foreign instances, virtual instances, dependencies.
2023-11-16Fix bug on MIRVisitorCelina G. Val-2/+2
We were not iterating over all local variables due to a typo.
2023-11-16Add more SMIR internal impl and callback return valueCelina G. Val-8/+12
In cases like Kani, we will invoke the rustc_internal run command directly for now. It would be handly to be able to have a callback that can return a value. We also need extra methods to convert stable constructs into internal ones, so we can break down the transition into finer grain commits.
2023-11-15Auto merge of #117908 - lcnr:region-kind-rename, r=BoxyUwUbors-2/+2
finish `RegionKind` renaming second step of https://github.com/rust-lang/types-team/issues/95 continues the work from #117876. While working on this and I encountered a bunch of further cleanup which I'll either open a tracking issue for or will do in a separate PR: - rewrite the `RegionKind` docs, they still talk about `ReEmpty` and are generally out of date - rename `DescriptionCtx` to `DescriptionCtxt` - what is `CheckRegions::Bound`? - `collect_late_bound_regions` et al - `erase_late_bound_regions` -> `instantiate_bound_regions_with_erased`? - `EraseEarlyRegions` visitor should be removed, feels duplicate r? `@BoxyUwU`
2023-11-15Auto merge of #117517 - klinvill:smir-projections, r=ouz-abors-3/+144
Add richer structure for Stable MIR Projections Resolves https://github.com/rust-lang/project-stable-mir/issues/49. Projections in Stable MIR are currently just strings. This PR replaces that representation with a richer structure, namely projections become vectors of `ProjectionElem`s, just as in MIR. The `ProjectionElem` enum is heavily based off of the MIR `ProjectionElem`. This PR is a draft since there are several outstanding issues to resolve, including: - How should `UserTypeProjection`s be represented in Stable MIR? In MIR, the projections are just a vector of `ProjectionElem<(),()>`, meaning `ProjectionElem`s that don't have Local or Type arguments (for `Index`, `Field`, etc. objects). Should `UserTypeProjection`s be represented this way in Stable MIR as well? Or is there a more user-friendly representation that wouldn't drag along all the `ProjectionElem` variants that presumably can't appear? - What is the expected behavior of a `Place`'s `ty` function? Should it resolve down the chain of projections so that something like `*_1.f` would return the type referenced by field `f`? - Tests should be added for `UserTypeProjection`
2023-11-14Make UserTypeProjection projections OpaqueKirby Linvill-5/+1
Also shifts comments explaining why Stable MIR drops an optional variant name field, for `Downcast` projection elements, to the `Place::stable` function.
2023-11-14finish `RegionKind` renamelcnr-2/+2
- `ReFree` -> `ReLateParam` - `ReEarlyBound` -> `ReEarlyParam`
2023-11-14Auto merge of #117787 - ouz-a:smir_coroutinewitness, r=celinvalbors-0/+5
Add CoroutineWitness to covered types in smir Previously we accepted `CouroutineWitness` as `unreachable!` but https://github.com/rust-lang/project-stable-mir/issues/50 shows it is indeed reachable, this pr fixes that and covers `CouroutineWitness`
2023-11-13rename `ReLateBound` to `ReBound`lcnr-1/+1
other changes: - `Region::new_late_bound` -> `Region::new_bound` - `Region::is_late_bound` -> `Region::is_bound`
2023-11-10Ignore FieldIdx and VariantIdx examples in docsKirby Linvill-2/+2
2023-11-10Add SMIR visitor for Places and projectionsKirby Linvill-2/+33
2023-11-10add CoroutineWitness to covered typesOğuz Ağcayazı-0/+5
2023-11-09Defer Place ty implementation in Stable Mir to later PRKirby Linvill-2/+4
2023-11-09Remove rich UserTypeProjection projections in SMIRKirby Linvill-13/+12
It's not clear to me (klinvill) that UserTypeProjections are produced anymore with the removal of type ascriptions as per https://github.com/rust-lang/rfcs/pull/3307. Furthermore, it's not clear to me which variants of ProjectionElem could appear in such projections. For these reasons, I'm reverting projections in UserTypeProjections to simple strings until I can get more clarity on UserTypeProjections.
2023-11-09Add stable MIR Projections support based on MIR structureKirby Linvill-2/+115
This commit includes richer projections for both Places and UserTypeProjections. However, the tests only touch on Places. There are also outstanding TODOs regarding how projections should be resolved to produce Place types, and regarding if UserTypeProjections should just contain ProjectionElem<(),()> objects as in MIR.
2023-11-08rename `BorrowKind::Shallow` to `Fake`lcnr-2/+3
also adds some comments
2023-11-01Auto merge of #114208 - GKFX:offset_of_enum, r=wesleywiserbors-1/+1
Support enum variants in offset_of! This MR implements support for navigating through enum variants in `offset_of!`, placing the enum variant name in the second argument to `offset_of!`. The RFC placed it in the first argument, but I think it interacts better with nested field access in the second, as you can then write things like ```rust offset_of!(Type, field.Variant.field) ``` Alternatively, a syntactic distinction could be made between variants and fields (e.g. `field::Variant.field`) but I'm not convinced this would be helpful. [RFC 3308 # Enum Support](https://rust-lang.github.io/rfcs/3308-offset_of.html#enum-support-offset_ofsomeenumstructvariant-field_on_variant) Tracking Issue #106655.
2023-10-31Enums in offset_of: update based on est31, scottmcm & llogiq reviewGeorge Bateman-1/+1
2023-10-30Add a stable MIR visitorCelina G. Val-85/+508
Add a few utility functions as well and extend most `mir` and `ty` ADTs to implement `PartialEq` and `Eq`.
2023-10-29Auto merge of #116447 - oli-obk:gen_fn, r=compiler-errorsbors-0/+1
Implement `gen` blocks in the 2024 edition Coroutines tracking issue https://github.com/rust-lang/rust/issues/43122 `gen` block tracking issue https://github.com/rust-lang/rust/issues/117078 This PR implements `gen` blocks that implement `Iterator`. Most of the logic with `async` blocks is shared, and thus I renamed various types that were referring to `async` specifically. An example usage of `gen` blocks is ```rust fn foo() -> impl Iterator<Item = i32> { gen { yield 42; for i in 5..18 { if i.is_even() { continue } yield i * 2; } } } ``` The limitations (to be resolved) of the implementation are listed in the tracking issue
2023-10-27Rollup merge of #117262 - celinval:issue-38-norm, r=oli-obkMatthias Krüger-1/+4
Create a new ConstantKind variant (ZeroSized) for StableMIR ZeroSized constants can be represented as `mir::Const::Val` even if their layout is not yet known. In those cases, CrateItem::body() was crashing when trying to convert a `ConstValue::ZeroSized` into its stable counterpart `ConstantKind::Allocated`. Instead, we now map `ConstValue::ZeroSized` into a new variant: `ConstantKind::ZeroSized`. **Note:** I didn't add any new test here since we already have covering tests in our project repository which I manually confirmed that will fix the issue.
2023-10-26Specialize ZeroSized constantsCelina G. Val-1/+4
ZeroSized constants can be represented as `mir::Const::Val` even if their layout is not yet known. In those cases, CrateItem::body() was crashing when trying to convert a `ConstValue::ZeroSized` into its stable counterpart `ConstantKind::Allocated`. Instead, we now map `ConstValue::ZeroSized` into a new variant: `ConstantKind::ZeroSized`.
2023-10-26Rollup merge of #117095 - klinvill:smir-fn-arg-count, r=oli-obkMatthias Krüger-3/+53
Add way to differentiate argument locals from other locals in Stable MIR This PR resolves rust-lang/project-stable-mir#47 which request a way to differentiate argument locals in a SMIR `Body` from other locals. Specifically, this PR exposes the `arg_count` field from the MIR `Body`. However, I'm opening this as a draft PR because I think there are a few outstanding questions on how this information should be exposed and described. Namely: - Is exposing `arg_count` the best way to surface this information to SMIR users? Would it be better to leave `arg_count` as a private field and add public methods (e.g. `fn arguments(&self) -> Iter<'_, LocalDecls>`) that may use the underlying `arg_count` info from the MIR body, but expose this information to users in a more convenient form? Or is it best to stick close to the current MIR convention? - If the answer to the above point is to stick with the current MIR convention (`arg_count`), is it reasonable to also commit to sticking to the current MIR convention that the first local is always the return local, while the next `arg_count` locals are always the (in-order) argument locals? - Should `Body` in SMIR only represent function bodies (as implied by the comment I added)? That seems to be the current case in MIR, but should this restriction always be the case for SMIR? r? `@celinval` r? `@oli-obk`
2023-10-26Use two slice expressions to save on an offset repetitionOli Scherer-1/+1
2023-10-26Add hir::GeneratorKind::GenOli Scherer-0/+1
2023-10-26Update Place and Operand to take slicesKirby Linvill-2/+2
The latest locals() method in stable MIR returns slices instead of vecs. This commit also includes fixes to the existing tests that previously referenced the private locals field.
2023-10-26Rename internal_locals to inner_localsKirby Linvill-4/+4
The word internal has connotations about information that's not exposed. It's more accurate to say that the remaining locals apply only to the inner part of the function, so I'm renaming them to inner locals.
2023-10-25Rollup merge of #117175 - oli-obk:gen_fn_split, r=compiler-errorsMatthias Krüger-2/+2
Rename AsyncCoroutineKind to CoroutineSource pulled out of https://github.com/rust-lang/rust/pull/116447 Also refactors the printing infra of `CoroutineSource` to be ready for easily extending it with a `Gen` variant for `gen` blocks
2023-10-25Add a public API to get all body localsKirby Linvill-0/+8
This is particularly helpful for the ui tests, but also could be helpful for Stable MIR users who just want all the locals without needing to concatenate responses
2023-10-25Make locals field privateKirby Linvill-5/+5
2023-10-25Add public API to retrieve internal localsKirby Linvill-2/+8
2023-10-25Replace arg_count in public API with return/arg gettersKirby Linvill-6/+32
This commit hides the arg_count field in Body and instead exposes more stable and user-friendly methods to get the return and argument locals. As a result, Body instances must now be constructed using the `new` function.
2023-10-25Add arg_count field to Body in Stable MIRKirby Linvill-0/+10
This field allows SMIR consumers to identify which locals correspond to argument locals. It simply exposes the arg_count field from the MIR representation.
2023-10-25Rename `AsyncCoroutineKind` to `CoroutineSource`Oli Scherer-2/+2
similar to how we have `MatchSource`, it explains where the desugaring came from.
2023-10-24Use IndexMap for handling stable TyCelina G. Val-19/+18
2023-10-24Remove fold code and add Const::internal()Celina G. Val-259/+38
We are not planning to support user generated constant in the foreseeable future, so we are removing the Fold logic for now in favor of the Instance::resolve logic. The Instance::resolve was however incomplete, since we weren't handling internalizing constants yet. Thus, I added that. I decided to keep the Const fields private in case we decide to translate them lazily.
2023-10-23Remove unsafe and `Rc`Celina G. Val-8/+5
2023-10-23Add method to convert internal to stable constructsCelina G. Val-26/+26
2023-10-21Rollup merge of #116964 - celinval:smir-mono-body, r=oli-obkMatthias Krüger-2/+48
Add stable Instance::body() and RustcInternal trait The `Instance::body()` returns a monomorphized body. For that, we had to implement visitor that monomorphize types and constants. We are also introducing the RustcInternal trait that will allow us to convert back from Stable to Internal. Note that this trait is not yet visible for our users as it depends on Tables. We should probably add a new trait that can be exposed. The tests here are very simple, and I'm planning on creating more exhaustive tests in the project-mir repo. But I was hoping to get some feedback here first. r? ```@oli-obk```
2023-10-20Rename `CoroutineKind::Gen` to `::Coroutine`Oli Scherer-1/+1
2023-10-20s/generator/coroutine/Oli Scherer-1/+1
2023-10-20s/Generator/Coroutine/Oli Scherer-14/+14
2023-10-20Remove obsolete commentCelina G. Val-1/+0