Commit graph

211 commits

Author SHA1 Message Date
bors d97bb195bf Auto merge of #117787 - ouz-a:smir_coroutinewitness, r=celinval
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-14 13:10:25 +00:00
lcnr 86fa1317a3 rename ReLateBound to ReBound
other changes:
- `Region::new_late_bound` -> `Region::new_bound`
- `Region::is_late_bound` -> `Region::is_bound`
2023-11-13 14:13:54 +00:00
Kirby Linvill ae1726bfce
Ignore FieldIdx and VariantIdx examples in docs 2023-11-10 17:18:59 -07:00
Kirby Linvill d517a1cbda
Add SMIR visitor for Places and projections 2023-11-10 11:25:58 -07:00
Oğuz Ağcayazı 6812f64c35 add CoroutineWitness to covered types 2023-11-10 17:02:08 +03:00
Kirby Linvill 998aa383ba
Defer Place ty implementation in Stable Mir to later PR 2023-11-09 20:56:40 -07:00
Kirby Linvill 2e70d95cdb
Remove rich UserTypeProjection projections in SMIR
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-09 20:56:40 -07:00
Kirby Linvill b1585983cc
Add stable MIR Projections support based on MIR structure
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-09 20:56:35 -07:00
lcnr 992d93f687 rename BorrowKind::Shallow to Fake
also adds some comments
2023-11-08 22:55:28 +01:00
bors 146dafa262 Auto merge of #114208 - GKFX:offset_of_enum, r=wesleywiser
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-11-01 14:17:56 +00:00
George Bateman d995bd61e7
Enums in offset_of: update based on est31, scottmcm & llogiq review 2023-10-31 23:26:02 +00:00
Celina G. Val af7472ecbc Add a stable MIR visitor
Add a few utility functions as well and extend most `mir` and `ty`
ADTs to implement `PartialEq` and `Eq`.
2023-10-30 13:11:14 -07:00
bors 2cad938a81 Auto merge of #116447 - oli-obk:gen_fn, r=compiler-errors
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-29 00:03:52 +00:00
Matthias Krüger 33744804fe
Rollup merge of #117262 - celinval:issue-38-norm, r=oli-obk
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-27 11:48:07 +02:00
Celina G. Val 613e6181a6 Specialize ZeroSized constants
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-26 20:17:44 -07:00
Matthias Krüger b66c6e719f
Rollup merge of #117095 - klinvill:smir-fn-arg-count, r=oli-obk
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-26 17:45:43 +02:00
Oli Scherer d55487d7e9
Use two slice expressions to save on an offset repetition 2023-10-26 12:32:47 +02:00
Oli Scherer 14423080f1 Add hir::GeneratorKind::Gen 2023-10-26 07:10:25 +00:00
Kirby Linvill 4b23bd4734
Update Place and Operand to take slices
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-26 00:21:28 +01:00
Kirby Linvill fe4dfb814b
Rename internal_locals to inner_locals
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-26 00:18:42 +01:00
Matthias Krüger 4e4e5619af
Rollup merge of #117175 - oli-obk:gen_fn_split, r=compiler-errors
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-25 23:37:11 +02:00
Kirby Linvill 39b293fb5a
Add a public API to get all body locals
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-25 22:18:58 +01:00
Kirby Linvill 372c533532
Make locals field private 2023-10-25 22:15:47 +01:00
Kirby Linvill f4d80a5f09
Add public API to retrieve internal locals 2023-10-25 22:15:47 +01:00
Kirby Linvill 93d1b3e92a
Replace arg_count in public API with return/arg getters
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-25 22:15:47 +01:00
Kirby Linvill e4c41b07f0
Add arg_count field to Body in Stable MIR
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-25 22:15:47 +01:00
Oli Scherer af8a998b1e Rename AsyncCoroutineKind to CoroutineSource
similar to how we have `MatchSource`, it explains where the desugaring came from.
2023-10-25 16:14:05 +00:00
Celina G. Val 17f6df9c63 Use IndexMap for handling stable Ty 2023-10-24 15:37:43 -07:00
Celina G. Val 3f60165d27 Remove fold code and add Const::internal()
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-24 14:50:58 -07:00
Celina G. Val 421631a3a1 Remove unsafe and Rc 2023-10-23 14:22:04 -07:00
Celina G. Val 66a554b045 Add method to convert internal to stable constructs 2023-10-23 12:01:39 -07:00
Matthias Krüger b7035198e6
Rollup merge of #116964 - celinval:smir-mono-body, r=oli-obk
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-21 10:08:17 +02:00
Oli Scherer 2d91c76d5d Rename CoroutineKind::Gen to ::Coroutine 2023-10-20 21:14:01 +00:00
Oli Scherer e96ce20b34 s/generator/coroutine/ 2023-10-20 21:14:01 +00:00
Oli Scherer 60956837cf s/Generator/Coroutine/ 2023-10-20 21:10:38 +00:00
Celina G. Val 6e643e12bb
Remove obsolete comment 2023-10-20 08:23:16 -07:00
Celina G. Val 6ed2a76bcc 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.
2023-10-19 17:12:26 -07:00
Celina G. Val 364f1a3f16 Add MonoItems and Instance to stable_mir
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-16 12:01:24 -07:00
Oğuz Ağcayazı d6a55d3409 change fn name, return loc info, local name 2023-10-13 11:44:38 +03:00
Oğuz Ağcayazı 1d9481fdc8 implement get_filename/lines for span 2023-10-11 17:55:57 +03:00
Guillaume Gomez 100713ef08
Rollup merge of #116560 - ouz-a:efficient_ids, r=oli-obk
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-10 18:44:46 +02:00
Oğuz Ağcayazı 0bcb058fb1 add new wrapper for FxIndexMap 2023-10-10 13:18:31 +03:00
Oğuz Ağcayazı 4ff6e87a8c return crates instead of a crate 2023-10-09 10:33:23 +03:00
ouz-a a79567b01c add span to statements 2023-10-05 11:15:34 +03:00
ouz-a 999a354a81 add span to terminator 2023-09-30 16:52:10 +03:00
ouz-a 9130484db9 create localdecl and add span to it 2023-09-30 16:40:15 +03:00
Matthias Krüger 26be5754c6
Rollup merge of #116024 - ouz-a:smir_region, r=oli-obk
Implement Region for smir

Adds Region and it's relevant types to smir and covers them with stable implementation

r? `@oli-obk`
2023-09-29 22:27:50 +02:00
ouz-a eb779038de simplify visit 2023-09-28 19:51:49 +03:00
ouz-a 0cca109473 visit and fold ty::ref 2023-09-28 19:46:39 +03:00
ouz-a 8c41cd0d78 simplify fold 2023-09-28 19:43:28 +03:00
ouz-a 9f2e15d232 change visit to fold for ty and reg 2023-09-28 19:21:12 +03:00
ouz-a fed72e0664 add visitor for Region 2023-09-28 12:47:21 +03:00
ouz-a bb17fe8bf5 add real folder to Region 2023-09-28 12:32:15 +03:00
ouz-a da2f897e59 remove un-needed variants 2023-09-28 11:43:21 +03:00
ouz-a 2069e8c218 fix imports 2023-09-28 11:36:53 +03:00
ouz-a d83559939c make reg public and add visit, fold 2023-09-28 11:19:51 +03:00
ouz-a 5dc2214884 add stable for RegionKind 2023-09-28 11:19:51 +03:00
ouz-a e49aa04000 add RegionDef 2023-09-28 11:19:51 +03:00
ouz-a 02b01a46de make region struct and add neccesasry types 2023-09-28 11:16:32 +03:00
Matthias Krüger e8a33847fd don't clone copy types 2023-09-28 00:20:32 +02:00
Oli Scherer a38e98371b Split out the stable part of smir into its own crate to prevent accidental usage of forever unstable things 2023-09-25 14:38:27 +00:00