summary refs log tree commit diff
path: root/compiler/stable_mir/src
AgeCommit message (Collapse)AuthorLines
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
2023-10-19Add stable Instance::body() and RustcInternal traitCelina G. Val-2/+49
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.
2023-10-16Add MonoItems and Instance to stable_mirCelina G. Val-15/+187
Also add a few methods to instantiate instances and get an instance definition. We're still missing support to actually monomorphize the instance body.
2023-10-13change fn name, return loc info, local nameOğuz Ağcayazı-5/+6
2023-10-11implement get_filename/lines for spanOğuz Ağcayazı-6/+34
2023-10-10Rollup merge of #116560 - ouz-a:efficient_ids, r=oli-obkGuillaume Gomez-4/+39
In smir use `FxIndexMap` to store indexed ids Previously we used `vec` for storing indexed types, which is fine for small cases but will lead to huge performance issues when we use `smir` for real world cases. Addresses https://github.com/rust-lang/project-stable-mir/issues/35 r? ``@oli-obk``
2023-10-10add new wrapper for FxIndexMapOğuz Ağcayazı-4/+39
2023-10-09return crates instead of a crateOğuz Ağcayazı-4/+4
2023-10-05add span to statementsouz-a-1/+7
2023-09-30add span to terminatorouz-a-1/+7
2023-09-30create localdecl and add span to itouz-a-1/+7
2023-09-29Rollup merge of #116024 - ouz-a:smir_region, r=oli-obkMatthias Krüger-9/+82
Implement Region for smir Adds Region and it's relevant types to smir and covers them with stable implementation r? `@oli-obk`
2023-09-28simplify visitouz-a-28/+2
2023-09-28visit and fold ty::refouz-a-2/+8
2023-09-28simplify foldouz-a-34/+3
2023-09-28change visit to fold for ty and regouz-a-5/+5
2023-09-28add visitor for Regionouz-a-2/+35
2023-09-28add real folder to Regionouz-a-2/+39
2023-09-28remove un-needed variantsouz-a-13/+0
2023-09-28fix importsouz-a-1/+1
2023-09-28make reg public and add visit, foldouz-a-3/+22
2023-09-28add stable for RegionKindouz-a-1/+1
2023-09-28add RegionDefouz-a-3/+6