Commit Graph

234 Commits

Author SHA1 Message Date
Matthias Krüger
8b3914ce48
Rollup merge of #119094 - celinval:smir-layout, r=compiler-errors
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-20 09:46:12 +01:00
Celina G. Val
76b3e6de55 Fix c_variadic flag and add opaque info to PassMode
We should expand the information in PassMode later.
2023-12-19 11:04:34 -08:00
Celina G. Val
36bb79fc5e Add the function body span to StableMIR 2023-12-18 17:13:49 -08:00
Celina G. Val
1a83c5b55b 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.
2023-12-18 19:58:48 +00:00
Celina G. Val
86451badf1 Add a method to check if type is a CStr 2023-12-15 13:18:41 -08:00
Ali MJ Al-Nasrawy
578758ae04
Rollup merge of #118927 - celinval:smir-missing-info, r=compiler-errors
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-15 10:58:23 +03:00
Celina G. Val
600438679d Revert signature change for AssertMessage description 2023-12-14 22:04:14 -08:00
Celina G. Val
c0f1207a12 Address PR comments
- 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-14 17:56:33 -08:00
ouz-a
82ee18c4ea add stable_mir output test 2023-12-14 18:10:38 +03:00
Celina G. Val
a66cac92cc Add spread arg and missing CoroutineKind 2023-12-13 16:36:15 -08:00
Celina G. Val
c3a2302fb0 Erase late bound regions from instance fn_sig()
Late bound regions were still part of the signature.
2023-12-13 16:36:14 -08:00
Matthias Krüger
d67e80f12d
Rollup merge of #118846 - celinval:smir-ty-methods, r=compiler-errors
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-12 06:52:51 +01:00
Celina G. Val
638b08ebdf Remove scalar fn and tighten the BiOp Ty assertions 2023-12-11 19:02:54 -08:00
Celina G. Val
3b97b5130a Fix doc comment 2023-12-11 16:37:33 -08:00
Celina G. Val
2f790af726 Fix BinOp ty assertion and fn_sig for closures
Also added a few more util methods to TyKind to check for specific types.
2023-12-11 16:06:48 -08:00
Matthias Krüger
0564de10b1 remove some redundant clones 2023-12-11 21:54:36 +01:00
surechen
40ae34194c remove redundant imports
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-10 10:56:22 +08:00
Celina G. Val
0a0e7e6c0d Add tests to allocation methods and fix is_null() 2023-12-07 17:01:29 -08:00
Celina G. Val
9cb6463af7 Fix conversion to StaticDef and add test 2023-12-07 17:01:29 -08:00
Celina G. Val
4c9e842a09 Add instance evaluation and methods to read alloc
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-07 17:01:29 -08:00
Matthias Krüger
20ed80523a
Rollup merge of #118688 - celinval:smir-rvalue-ty, r=compiler-errors
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-07 21:38:08 +01:00
Celina G. Val
4616b9fd1d Add sanity check to BinOp::ty() 2023-12-06 22:15:36 -08:00
Celina G. Val
77d7e44573
Update compiler/stable_mir/src/mir/body.rs
Co-authored-by: Michael Goulet <michael@errs.io>
2023-12-06 17:48:38 -08:00
Celina G. Val
e16ebdbb06 Simplify StaticDef to Instance conversion 2023-12-06 15:08:08 -08:00
Celina G. Val
281b65aad9 Add method to get type of an Rvalue in StableMIR 2023-12-06 14:26:52 -08:00
Matthias Krüger
3c1357ca6b
Rollup merge of #118681 - celinval:fix-foreign-item, r=ouz-a
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-06 21:52:33 +01:00
Celina G. Val
4a75d1893e Also add an API to check if an instance has body
This is much cheaper than building a body just for the purpose of
checking if the body exists.
2023-12-06 11:02:13 -08:00
Celina G. Val
1bcd162465 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`.

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-06 10:48:18 -08:00
Celina G. Val
326fea0fb8 Change ty_with_args to return Ty instead of Result
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-05 12:03:44 -08:00
Celina G. Val
1720b108f7 Add FieldDef to StableMIR and methods to get type 2023-12-04 20:08:25 -08:00
Celina G. Val
e19c7cd159 Finish implementing RustcInternal for TyKind
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-04 11:05:29 -08:00
Celina G. Val
efaf4258ba Add Variant and a few more APIs to stable_mir 2023-12-04 11:03:52 -08:00
Celina G. Val
c997c6d822 Add more information to stable Instance
- Retrieve `FnSig`.
  - Implement CrateDef for InstanceDef.
  - Add VTable index for Virtual instances.
2023-12-01 16:22:06 -08:00
Celina G. Val
9d2c92377d Fix SwitchTarget pretty print
We currently rely on the order of successors to be conditional branches
first, followed by the otherwise target.
2023-11-30 11:45:34 -08:00
Celina G. Val
3e0b2fac5d Change SwitchTarget representation
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-30 11:45:34 -08:00
Michael Goulet
7aa513b861
Rollup merge of #118172 - ouz-a:improve_emit_stable1, r=celinval
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-27 19:06:47 -05:00
ouz-a
15f9bab7ba add otherwise into targets 2023-11-27 21:26:11 +03:00
ouz-a
de2779077a add successors and their formatter 2023-11-26 11:23:28 +03:00
ouz-a
879c7f91ab add pretty_terminator 2023-11-25 22:28:41 +03:00
Michael Goulet
079a2e865f is_{some,ok}_and 2023-11-25 18:47:16 +00:00
León Orell Valerian Liehr
20d243e854
Rollup merge of #118274 - celinval:smir-fix-pretty, r=ouz-a
Fix smir's `Ty::Ref` pretty printing

Add `&` or `&mut` to reference when generating a string for `TyKind::Ref`.

r? `@ouz-a`
2023-11-25 10:21:09 +01:00
Celina G. Val
60817e6863 Fix smir's Ty::Ref pretty printing 2023-11-24 18:43:35 -08:00
Celina G. Val
f8c2478b6b Reorder imports and remove re-export 2023-11-24 15:09:26 -08:00
Celina G. Val
d7c7236845 Move the compiler interface defs to its own module
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-24 13:49:31 -08:00
Michael Goulet
8294352b2d
Rollup merge of #118215 - celinval:smir-def-paths, r=ouz-a
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-24 07:29:12 -08:00
Celina G. Val
b6e977243f Improve documentation and fix the fixme comment 2023-11-23 12:29:20 -08:00
bors
1e9dda77b5 Auto merge of #118120 - compiler-errors:closure-kind, r=lcnr
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-22 21:09:01 +00:00
Celina G. Val
d5afea51dc Add CrateDef trait and methods to get def names 2023-11-22 07:32:37 -08:00
Celina G. Val
c07a6d5c9a Add allocation test and a bit more documentation 2023-11-21 19:16:58 -08:00
Celina G. Val
5b3cf6610b Add support to get virtual table allocation 2023-11-21 19:16:58 -08:00
Celina G. Val
fa5ff859e6 Add support to global allocation to stable-mir 2023-11-21 19:16:53 -08:00
bors
ed10a53025 Auto merge of #118152 - matthiaskrgr:rollup-bqcck4w, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #117972 (Add VarDebugInfo to Stable MIR)
 - #118109 (rustdoc-search: simplify `checkPath` and `sortResults`)
 - #118110 (Document `DefiningAnchor` a bit more)
 - #118112 (Don't ICE when ambiguity is found when selecting `Index` implementation in typeck)
 - #118135 (Remove quotation from filename in stable_mir)

Failed merges:

 - #118012 (Add support for global allocation in smir)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-11-22 00:30:56 +00:00
Matthias Krüger
914891fc58
Rollup merge of #118135 - ouz-a:fix_stable_span, r=celinval
Remove quotation from filename in stable_mir

Previously we had quotation marks in filenames which is obviously wrong this fixes that.

r? ```@celinval```
2023-11-21 23:46:20 +01:00
Nilstrieb
21a870515b Fix clippy::needless_borrow in the compiler
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`.

Then I had to remove a few unnecessary parens and muts that were exposed
now.
2023-11-21 20:13:40 +01:00
Michael Goulet
93298ee0dd Remove ClosureKind predicate kind 2023-11-21 18:35:45 +00:00
ouz-a
0b25415559 remove quotation from filename 2023-11-21 16:56:19 +03:00
ouz-a
d0dd19a6c9 de-structure variable and add stables 2023-11-21 15:38:45 +03:00
ouz-a
018b85986d Add VarDebugInfo to Stable MIR 2023-11-21 15:38:45 +03:00
Celina G. Val
d94df62398 Improve code per PR comments
- Simplified DefTy::internal
 - Break down place::ty() method
2023-11-20 12:46:14 -08:00
Celina G. Val
d3fa6a0e35 Add place.ty() and Ty build from a kind to smir 2023-11-20 12:43:39 -08:00
ouz-a
92657f163a use new apis and add new function 2023-11-17 23:28:17 +03:00
Oğuz Ağcayazı
71c990470a move pretty into stable_mir 2023-11-17 13:28:43 +03:00
Oğuz Ağcayazı
ebd9c145f6 better formatting for statements 2023-11-17 13:28:07 +03:00
Oğuz Ağcayazı
ae179a04b6 emit basic smir 2023-11-17 13:28:07 +03:00
Celina G. Val
8e81fc0087 Fix has_body() and change resolve_drop_in_place() sig
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-16 12:04:25 -08:00
Celina G. Val
08036a8005 Address PR comments 2023-11-16 12:01:18 -08:00
Celina G. Val
6515ac9d3f Add more APIs and fix Instance::body
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-16 12:01:10 -08:00
Celina G. Val
3f87dac9a2 Fix bug on MIRVisitor
We were not iterating over all local variables due to a typo.
2023-11-16 11:05:36 -08:00
Celina G. Val
e70839ac84 Add more SMIR internal impl and callback return value
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-16 11:05:36 -08:00
bors
1500db7314 Auto merge of #117908 - lcnr:region-kind-rename, r=BoxyUwU
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-15 12:55:42 +00:00
bors
698fcc8219 Auto merge of #117517 - klinvill:smir-projections, r=ouz-a
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-15 06:05:54 +00:00
Kirby Linvill
c036a10ed5
Make UserTypeProjection projections Opaque
Also shifts comments explaining why Stable MIR drops an optional variant
name field, for `Downcast` projection elements, to the `Place::stable`
function.
2023-11-14 19:19:35 -07:00
lcnr
15f21562e6 finish RegionKind rename
- `ReFree` -> `ReLateParam`
- `ReEarlyBound` -> `ReEarlyParam`
2023-11-14 13:13:27 +00:00
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