Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a conversion method for going from smir::Ty to rustc::Ty #46

Closed
1 task
oli-obk opened this issue Oct 11, 2023 · 2 comments · Fixed by rust-lang/rust#118516
Closed
1 task

Add a conversion method for going from smir::Ty to rustc::Ty #46

oli-obk opened this issue Oct 11, 2023 · 2 comments · Fixed by rust-lang/rust#118516

Comments

@oli-obk
Copy link
Contributor

oli-obk commented Oct 11, 2023

In order to be able to invoke some rustc operations (like Instance::resolve), we need the rustc version of GenericArgs, which contains Ty, Lifetime and Const. We should add functionality in the rustc_smir crate for converting back to these three rustc types when starting out with a smir type. This will mostly involve writing the inverse of their Stable::stable method.

Tasks

@celinval
Copy link
Contributor

@celinval
Copy link
Contributor

BTW, for Lifetime, we currently return re_erased which was added here: rust-lang/rust#117688. However, we should implement a better mechanism without any loss of information.

rust-timer added a commit to rust-lang-ci/rust that referenced this issue Dec 6, 2023
Rollup merge of rust-lang#118516 - celinval:smir-variants, r=ouz-a

Add ADT variant infomation to StableMIR and finish implementing TyKind::internal()

Introduce a `VariantDef` type and a mechanism to retrieve the definition from an `AdtDef`.

The `VariantDef` representation itself is just a combination of `AdtDef` and `VariantIdx`, which allow us to retrieve further information of a variant. I don't think we need to cache extra information for now, and we can translate on an on demand manner. I am  leaving the fields public today due to rust-lang/project-stable-mir#56, but they shouldn't. For this PR, I've only added a method to retrieve the variant name, and its fields. I also added an implementation of `RustcInternal` that allow users to retrieve more information using Rust internal APIs.

I have also finished the implementation of `RustcInternal` for `TyKind` which fixes rust-lang/project-stable-mir#46.

## Motivation

Both of these changes are needed in order to properly interpret things like projections. For example,
- The variant definition is used to find out which variant we are downcasting to.
- Being able to create `Ty` from `TyKind` helps for example processing each stage of a projection, like the code in `place.ty()`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants